Blender  V2.93
space_script.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2008 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include <stdio.h>
25 #include <string.h>
26 
27 #include "MEM_guardedalloc.h"
28 
29 #include "BLI_blenlib.h"
30 #include "BLI_utildefines.h"
31 
32 #include "BKE_context.h"
33 #include "BKE_screen.h"
34 
35 #include "ED_screen.h"
36 #include "ED_space_api.h"
37 
38 #include "WM_api.h"
39 
40 #include "UI_resources.h"
41 #include "UI_view2d.h"
42 
43 #ifdef WITH_PYTHON
44 #endif
45 
46 #include "script_intern.h" /* own include */
47 
48 // static script_run_python(char *funcname, )
49 
50 /* ******************** default callbacks for script space ***************** */
51 
53 {
54  ARegion *region;
55  SpaceScript *sscript;
56 
57  sscript = MEM_callocN(sizeof(SpaceScript), "initscript");
58  sscript->spacetype = SPACE_SCRIPT;
59 
60  /* header */
61  region = MEM_callocN(sizeof(ARegion), "header for script");
62 
63  BLI_addtail(&sscript->regionbase, region);
64  region->regiontype = RGN_TYPE_HEADER;
66 
67  /* main region */
68  region = MEM_callocN(sizeof(ARegion), "main region for script");
69 
70  BLI_addtail(&sscript->regionbase, region);
71  region->regiontype = RGN_TYPE_WINDOW;
72 
73  /* channel list region XXX */
74 
75  return (SpaceLink *)sscript;
76 }
77 
78 /* not spacelink itself */
79 static void script_free(SpaceLink *sl)
80 {
81  SpaceScript *sscript = (SpaceScript *)sl;
82 
83 #ifdef WITH_PYTHON
84  /*free buttons references*/
85  if (sscript->but_refs) {
86  sscript->but_refs = NULL;
87  }
88 #endif
89  sscript->script = NULL;
90 }
91 
92 /* spacetype; init callback */
93 static void script_init(struct wmWindowManager *UNUSED(wm), ScrArea *UNUSED(area))
94 {
95 }
96 
98 {
99  SpaceScript *sscriptn = MEM_dupallocN(sl);
100 
101  /* clear or remove stuff from old */
102 
103  return (SpaceLink *)sscriptn;
104 }
105 
106 /* add handlers, stuff you only do once or on area/region changes */
108 {
109  wmKeyMap *keymap;
110 
111  UI_view2d_region_reinit(&region->v2d, V2D_COMMONVIEW_STANDARD, region->winx, region->winy);
112 
113  /* own keymap */
114  keymap = WM_keymap_ensure(wm->defaultconf, "Script", SPACE_SCRIPT, 0);
116 }
117 
118 static void script_main_region_draw(const bContext *C, ARegion *region)
119 {
120  /* draw entirely, view changes should be handled here */
122  View2D *v2d = &region->v2d;
123 
124  /* clear and setup matrix */
126 
128 
129  /* data... */
130  // BPY_script_exec(C, "/root/blender-svn/blender25/test.py", NULL);
131 
132 #ifdef WITH_PYTHON
133  if (sscript->script) {
134  // BPY_run_script_space_draw(C, sscript);
135  }
136 #else
137  (void)sscript;
138 #endif
139 
140  /* reset view matrix */
142 
143  /* scrollers? */
144 }
145 
146 /* add handlers, stuff you only do once or on area/region changes */
148 {
149  ED_region_header_init(region);
150 }
151 
152 static void script_header_region_draw(const bContext *C, ARegion *region)
153 {
154  ED_region_header(C, region);
155 }
156 
158 {
159 /* XXX - Todo, need the ScriptSpace accessible to get the python script to run. */
160 #if 0
161  BPY_run_script_space_listener()
162 #endif
163 }
164 
165 /* only called once, from space/spacetypes.c */
167 {
168  SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype script");
169  ARegionType *art;
170 
171  st->spaceid = SPACE_SCRIPT;
172  strncpy(st->name, "Script", BKE_ST_MAXNAME);
173 
174  st->create = script_create;
175  st->free = script_free;
176  st->init = script_init;
179  st->keymap = script_keymap;
180 
181  /* regions: main window */
182  art = MEM_callocN(sizeof(ARegionType), "spacetype script region");
183  art->regionid = RGN_TYPE_WINDOW;
187  /* XXX: Need to further test this ED_KEYMAP_UI is needed for button interaction. */
189 
190  BLI_addhead(&st->regiontypes, art);
191 
192  /* regions: header */
193  art = MEM_callocN(sizeof(ARegionType), "spacetype script region");
194  art->regionid = RGN_TYPE_HEADER;
195  art->prefsizey = HEADERY;
197 
200 
201  BLI_addhead(&st->regiontypes, art);
202 
204 }
struct SpaceLink * CTX_wm_space_data(const bContext *C)
Definition: context.c:719
#define BKE_ST_MAXNAME
Definition: BKE_screen.h:68
void BKE_spacetype_register(struct SpaceType *st)
Definition: screen.c:420
void BLI_addhead(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:87
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:110
#define UNUSED(x)
#define HEADERY
@ RGN_ALIGN_BOTTOM
@ RGN_ALIGN_TOP
@ RGN_TYPE_WINDOW
@ RGN_TYPE_HEADER
@ SPACE_SCRIPT
@ USER_HEADER_BOTTOM
void ED_region_header(const struct bContext *C, struct ARegion *region)
void ED_region_header_init(struct ARegion *region)
Definition: area.c:3358
@ ED_KEYMAP_UI
Definition: ED_screen.h:440
@ ED_KEYMAP_HEADER
Definition: ED_screen.h:446
@ ED_KEYMAP_VIEW2D
Definition: ED_screen.h:443
@ ED_KEYMAP_FRAMES
Definition: ED_screen.h:445
Read Guarded memory(de)allocation.
#define C
Definition: RandGen.cpp:39
@ TH_BACK
Definition: UI_resources.h:55
void UI_ThemeClearColor(int colorid)
Definition: resources.c:1478
void UI_view2d_region_reinit(struct View2D *v2d, short type, int winx, int winy)
Definition: view2d.c:240
void UI_view2d_view_restore(const struct bContext *C)
void UI_view2d_view_ortho(const struct View2D *v2d)
@ V2D_COMMONVIEW_STANDARD
Definition: UI_view2d.h:51
unsigned int U
Definition: btGjkEpa3.h:78
Scene scene
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void *(* MEM_dupallocN)(const void *vmemh)
Definition: mallocn.c:42
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
static void area(int d1, int d2, int e1, int e2, float weights[2])
void script_operatortypes(void)
Definition: script_ops.c:33
void script_keymap(struct wmKeyConfig *keyconf)
static void script_header_region_init(wmWindowManager *UNUSED(wm), ARegion *region)
Definition: space_script.c:147
static SpaceLink * script_duplicate(SpaceLink *sl)
Definition: space_script.c:97
static void script_free(SpaceLink *sl)
Definition: space_script.c:79
static void script_header_region_draw(const bContext *C, ARegion *region)
Definition: space_script.c:152
static void script_init(struct wmWindowManager *UNUSED(wm), ScrArea *UNUSED(area))
Definition: space_script.c:93
void ED_spacetype_script(void)
Definition: space_script.c:166
static void script_main_region_listener(const wmRegionListenerParams *UNUSED(params))
Definition: space_script.c:157
static SpaceLink * script_create(const ScrArea *UNUSED(area), const Scene *UNUSED(scene))
Definition: space_script.c:52
static void script_main_region_init(wmWindowManager *wm, ARegion *region)
Definition: space_script.c:107
static void script_main_region_draw(const bContext *C, ARegion *region)
Definition: space_script.c:118
void(* draw)(const struct bContext *C, struct ARegion *region)
Definition: BKE_screen.h:169
void(* listener)(const wmRegionListenerParams *params)
Definition: BKE_screen.h:183
int keymapflag
Definition: BKE_screen.h:226
void(* init)(struct wmWindowManager *wm, struct ARegion *region)
Definition: BKE_screen.h:165
ListBase handlers
short alignment
short regiontype
struct Script * script
ListBase regionbase
struct SpaceLink *(* duplicate)(struct SpaceLink *sl)
Definition: BKE_screen.h:104
ListBase regiontypes
Definition: BKE_screen.h:130
void(* keymap)(struct wmKeyConfig *keyconf)
Definition: BKE_screen.h:109
void(* operatortypes)(void)
Definition: BKE_screen.h:107
void(* free)(struct SpaceLink *sl)
Definition: BKE_screen.h:88
struct SpaceLink *(* create)(const struct ScrArea *area, const struct Scene *scene)
Definition: BKE_screen.h:86
void(* init)(struct wmWindowManager *wm, struct ScrArea *area)
Definition: BKE_screen.h:91
int spaceid
Definition: BKE_screen.h:81
char name[BKE_ST_MAXNAME]
Definition: BKE_screen.h:80
struct wmKeyConfig * defaultconf
wmEventHandler_Keymap * WM_event_add_keymap_handler_v2d_mask(ListBase *handlers, wmKeyMap *keymap)
wmKeyMap * WM_keymap_ensure(wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid)
Definition: wm_keymap.c:852