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) Blender Foundation, 2008
17 */
18
19 /** \file
20 * \ingroup spapi
21 */
22
23 #include <stdlib.h>
24
25 #include "MEM_guardedalloc.h"
26
27 #include "BLI_blenlib.h"
28 #include "BLI_utildefines.h"
29
30 #include "DNA_scene_types.h"
31 #include "DNA_windowmanager_types.h"
32
33 #include "BKE_context.h"
34 #include "BKE_screen.h"
35
36 #include "GPU_state.h"
37
38 #include "UI_interface.h"
39 #include "UI_view2d.h"
40
41 #include "ED_anim_api.h"
42 #include "ED_armature.h"
43 #include "ED_clip.h"
44 #include "ED_curve.h"
45 #include "ED_fileselect.h"
46 #include "ED_geometry.h"
47 #include "ED_gizmo_library.h"
48 #include "ED_gpencil.h"
49 #include "ED_lattice.h"
50 #include "ED_markers.h"
51 #include "ED_mask.h"
52 #include "ED_mball.h"
53 #include "ED_mesh.h"
54 #include "ED_node.h"
55 #include "ED_object.h"
56 #include "ED_paint.h"
57 #include "ED_physics.h"
58 #include "ED_render.h"
59 #include "ED_scene.h"
60 #include "ED_screen.h"
61 #include "ED_sculpt.h"
62 #include "ED_sequencer.h"
63 #include "ED_sound.h"
64 #include "ED_space_api.h"
65 #include "ED_transform.h"
66 #include "ED_userpref.h"
67 #include "ED_uvedit.h"
68
69 #include "io_ops.h"
70
71 /* only call once on startup, storage is global in BKE kernel listbase */
ED_spacetypes_init(void)72 void ED_spacetypes_init(void)
73 {
74 const ListBase *spacetypes;
75 SpaceType *type;
76
77 /* UI_UNIT_X is now a variable, is used in some spacetype inits? */
78 U.widget_unit = 20;
79
80 /* create space types */
81 ED_spacetype_outliner();
82 ED_spacetype_view3d();
83 ED_spacetype_ipo();
84 ED_spacetype_image();
85 ED_spacetype_node();
86 ED_spacetype_buttons();
87 ED_spacetype_info();
88 ED_spacetype_file();
89 ED_spacetype_action();
90 ED_spacetype_nla();
91 ED_spacetype_script();
92 ED_spacetype_text();
93 ED_spacetype_sequencer();
94 ED_spacetype_console();
95 ED_spacetype_userpref();
96 ED_spacetype_clip();
97 ED_spacetype_statusbar();
98 ED_spacetype_topbar();
99 // ...
100
101 /* register operator types for screen and all spaces */
102 ED_operatortypes_userpref();
103 ED_operatortypes_workspace();
104 ED_operatortypes_scene();
105 ED_operatortypes_screen();
106 ED_operatortypes_anim();
107 ED_operatortypes_animchannels();
108 ED_operatortypes_gpencil();
109 ED_operatortypes_object();
110 ED_operatortypes_lattice();
111 ED_operatortypes_mesh();
112 ED_operatortypes_geometry();
113 ED_operatortypes_sculpt();
114 ED_operatortypes_uvedit();
115 ED_operatortypes_paint();
116 ED_operatortypes_physics();
117 ED_operatortypes_curve();
118 ED_operatortypes_armature();
119 ED_operatortypes_marker();
120 ED_operatortypes_metaball();
121 ED_operatortypes_sound();
122 ED_operatortypes_render();
123 ED_operatortypes_mask();
124 ED_operatortypes_io();
125
126 ED_operatortypes_view2d();
127 ED_operatortypes_ui();
128
129 ED_screen_user_menu_register();
130
131 /* gizmo types */
132 ED_gizmotypes_button_2d();
133 ED_gizmotypes_dial_3d();
134 ED_gizmotypes_move_3d();
135 ED_gizmotypes_arrow_3d();
136 ED_gizmotypes_preselect_3d();
137 ED_gizmotypes_primitive_3d();
138 ED_gizmotypes_blank_3d();
139 ED_gizmotypes_cage_2d();
140 ED_gizmotypes_cage_3d();
141 ED_gizmotypes_snap_3d();
142
143 /* register types for operators and gizmos */
144 spacetypes = BKE_spacetypes_list();
145 for (type = spacetypes->first; type; type = type->next) {
146 /* init gizmo types first, operator-types need them */
147 if (type->gizmos) {
148 type->gizmos();
149 }
150 if (type->operatortypes) {
151 type->operatortypes();
152 }
153 }
154 }
155
ED_spacemacros_init(void)156 void ED_spacemacros_init(void)
157 {
158 const ListBase *spacetypes;
159 SpaceType *type;
160
161 /* Macros's must go last since they reference other operators.
162 * We need to have them go after python operators too */
163 ED_operatormacros_armature();
164 ED_operatormacros_mesh();
165 ED_operatormacros_uvedit();
166 ED_operatormacros_metaball();
167 ED_operatormacros_node();
168 ED_operatormacros_object();
169 ED_operatormacros_file();
170 ED_operatormacros_graph();
171 ED_operatormacros_action();
172 ED_operatormacros_clip();
173 ED_operatormacros_curve();
174 ED_operatormacros_mask();
175 ED_operatormacros_sequencer();
176 ED_operatormacros_paint();
177 ED_operatormacros_gpencil();
178
179 /* register dropboxes (can use macros) */
180 spacetypes = BKE_spacetypes_list();
181 for (type = spacetypes->first; type; type = type->next) {
182 if (type->dropboxes) {
183 type->dropboxes();
184 }
185 }
186 }
187
188 /* called in wm.c */
189 /* keymap definitions are registered only once per WM initialize, usually on file read,
190 * using the keymap the actual areas/regions add the handlers */
ED_spacetypes_keymap(wmKeyConfig * keyconf)191 void ED_spacetypes_keymap(wmKeyConfig *keyconf)
192 {
193 const ListBase *spacetypes;
194 SpaceType *stype;
195 ARegionType *atype;
196
197 ED_keymap_screen(keyconf);
198 ED_keymap_anim(keyconf);
199 ED_keymap_animchannels(keyconf);
200 ED_keymap_gpencil(keyconf);
201 ED_keymap_object(keyconf);
202 ED_keymap_lattice(keyconf);
203 ED_keymap_mesh(keyconf);
204 ED_keymap_uvedit(keyconf);
205 ED_keymap_curve(keyconf);
206 ED_keymap_armature(keyconf);
207 ED_keymap_physics(keyconf);
208 ED_keymap_metaball(keyconf);
209 ED_keymap_paint(keyconf);
210 ED_keymap_mask(keyconf);
211 ED_keymap_marker(keyconf);
212
213 ED_keymap_view2d(keyconf);
214 ED_keymap_ui(keyconf);
215
216 ED_keymap_transform(keyconf);
217
218 spacetypes = BKE_spacetypes_list();
219 for (stype = spacetypes->first; stype; stype = stype->next) {
220 if (stype->keymap) {
221 stype->keymap(keyconf);
222 }
223 for (atype = stype->regiontypes.first; atype; atype = atype->next) {
224 if (atype->keymap) {
225 atype->keymap(keyconf);
226 }
227 }
228 }
229 }
230
231 /* ********************** custom drawcall api ***************** */
232
233 typedef struct RegionDrawCB {
234 struct RegionDrawCB *next, *prev;
235
236 void (*draw)(const struct bContext *, struct ARegion *, void *);
237 void *customdata;
238
239 int type;
240
241 } RegionDrawCB;
242
ED_region_draw_cb_activate(ARegionType * art,void (* draw)(const struct bContext *,struct ARegion *,void *),void * customdata,int type)243 void *ED_region_draw_cb_activate(ARegionType *art,
244 void (*draw)(const struct bContext *, struct ARegion *, void *),
245 void *customdata,
246 int type)
247 {
248 RegionDrawCB *rdc = MEM_callocN(sizeof(RegionDrawCB), "RegionDrawCB");
249
250 BLI_addtail(&art->drawcalls, rdc);
251 rdc->draw = draw;
252 rdc->customdata = customdata;
253 rdc->type = type;
254
255 return rdc;
256 }
257
ED_region_draw_cb_exit(ARegionType * art,void * handle)258 void ED_region_draw_cb_exit(ARegionType *art, void *handle)
259 {
260 RegionDrawCB *rdc;
261
262 for (rdc = art->drawcalls.first; rdc; rdc = rdc->next) {
263 if (rdc == (RegionDrawCB *)handle) {
264 BLI_remlink(&art->drawcalls, rdc);
265 MEM_freeN(rdc);
266 return;
267 }
268 }
269 }
270
ED_region_draw_cb_draw(const bContext * C,ARegion * region,int type)271 void ED_region_draw_cb_draw(const bContext *C, ARegion *region, int type)
272 {
273 RegionDrawCB *rdc;
274 bool has_drawn_something = false;
275
276 for (rdc = region->type->drawcalls.first; rdc; rdc = rdc->next) {
277 if (rdc->type == type) {
278 rdc->draw(C, region, rdc->customdata);
279 has_drawn_something = true;
280 }
281 }
282 if (has_drawn_something) {
283 /* This is needed until we get rid of BGL which can change the states we are tracking. */
284 GPU_bgl_end();
285 }
286 }
287
288 /* ********************* space template *********************** */
289 /* forward declare */
290 void ED_spacetype_xxx(void);
291
292 /* allocate and init some vars */
xxx_create(const ScrArea * UNUSED (area),const Scene * UNUSED (scene))293 static SpaceLink *xxx_create(const ScrArea *UNUSED(area), const Scene *UNUSED(scene))
294 {
295 return NULL;
296 }
297
298 /* not spacelink itself */
xxx_free(SpaceLink * UNUSED (sl))299 static void xxx_free(SpaceLink *UNUSED(sl))
300 {
301 }
302
303 /* spacetype; init callback for usage, should be redoable */
xxx_init(wmWindowManager * UNUSED (wm),ScrArea * UNUSED (area))304 static void xxx_init(wmWindowManager *UNUSED(wm), ScrArea *UNUSED(area))
305 {
306
307 /* link area to SpaceXXX struct */
308
309 /* define how many regions, the order and types */
310
311 /* add types to regions */
312 }
313
xxx_duplicate(SpaceLink * UNUSED (sl))314 static SpaceLink *xxx_duplicate(SpaceLink *UNUSED(sl))
315 {
316
317 return NULL;
318 }
319
xxx_operatortypes(void)320 static void xxx_operatortypes(void)
321 {
322 /* register operator types for this space */
323 }
324
xxx_keymap(wmKeyConfig * UNUSED (keyconf))325 static void xxx_keymap(wmKeyConfig *UNUSED(keyconf))
326 {
327 /* add default items to keymap */
328 }
329
330 /* only called once, from screen/spacetypes.c */
ED_spacetype_xxx(void)331 void ED_spacetype_xxx(void)
332 {
333 static SpaceType st;
334
335 st.spaceid = SPACE_VIEW3D;
336
337 st.create = xxx_create;
338 st.free = xxx_free;
339 st.init = xxx_init;
340 st.duplicate = xxx_duplicate;
341 st.operatortypes = xxx_operatortypes;
342 st.keymap = xxx_keymap;
343
344 BKE_spacetype_register(&st);
345 }
346
347 /* ****************************** end template *********************** */
348