style cleanup: follow style guide for formatting of if/for/while loops, and else...
[blender.git] / source / blender / editors / space_api / spacetypes.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version. 
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) Blender Foundation, 2008
19  *
20  * ***** END GPL/BL DUAL LICENSE BLOCK *****
21  */
22
23 /** \file blender/editors/space_api/spacetypes.c
24  *  \ingroup spapi
25  */
26
27
28 #include <stdlib.h>
29
30 #include "MEM_guardedalloc.h"
31
32 #include "BLI_blenlib.h"
33 #include "BLI_utildefines.h"
34
35 #include "DNA_object_types.h"
36 #include "DNA_windowmanager_types.h"
37
38
39 #include "BKE_context.h"
40 #include "BKE_screen.h"
41
42 #include "UI_interface.h"
43 #include "UI_view2d.h"
44
45
46 #include "ED_anim_api.h"
47 #include "ED_armature.h"
48 #include "ED_curve.h"
49 #include "ED_fileselect.h"
50 #include "ED_gpencil.h"
51 #include "ED_markers.h"
52 #include "ED_mesh.h"
53 #include "ED_node.h"
54 #include "ED_object.h"
55 #include "ED_physics.h"
56 #include "ED_render.h"
57 #include "ED_screen.h"
58 #include "ED_sculpt.h"
59 #include "ED_space_api.h"
60 #include "ED_sound.h"
61 #include "ED_uvedit.h"
62 #include "ED_mball.h"
63 #include "ED_logic.h"
64 #include "ED_clip.h"
65
66 /* only call once on startup, storage is global in BKE kernel listbase */
67 void ED_spacetypes_init(void)
68 {
69         const ListBase *spacetypes;
70         SpaceType *type;
71
72         /* UI_UNIT_X is now a variable, is used in some spacetype inits? */
73         U.widget_unit= 20;
74         
75         /* create space types */
76         ED_spacetype_outliner();
77         ED_spacetype_time();
78         ED_spacetype_view3d();
79         ED_spacetype_ipo();
80         ED_spacetype_image();
81         ED_spacetype_node();
82         ED_spacetype_buttons();
83         ED_spacetype_info();
84         ED_spacetype_file();
85         ED_spacetype_action();
86         ED_spacetype_nla();
87         ED_spacetype_script();
88         ED_spacetype_text();
89         ED_spacetype_sequencer();
90         ED_spacetype_logic();
91         ED_spacetype_console();
92         ED_spacetype_userpref();
93         ED_spacetype_clip();
94 //      ...
95         
96         /* register operator types for screen and all spaces */
97         ED_operatortypes_screen();
98         ED_operatortypes_anim();
99         ED_operatortypes_animchannels();
100         ED_operatortypes_gpencil();
101         ED_operatortypes_object();
102         ED_operatortypes_mesh();
103         ED_operatortypes_sculpt();
104         ED_operatortypes_uvedit();
105         ED_operatortypes_paint();
106         ED_operatortypes_physics();
107         ED_operatortypes_curve();
108         ED_operatortypes_armature();
109         ED_operatortypes_marker();
110         ED_operatortypes_metaball();
111         ED_operatortypes_sound();
112         ED_operatortypes_render();
113         ED_operatortypes_logic();
114         
115         UI_view2d_operatortypes();
116         UI_buttons_operatortypes();
117         
118         /* register operators */
119         spacetypes = BKE_spacetypes_list();
120         for (type=spacetypes->first; type; type=type->next) {
121                 if (type->operatortypes)
122                         type->operatortypes();
123         }
124
125         /* Macros's must go last since they reference other operators
126          * maybe we'll need to have them go after python operators too? */
127         ED_operatormacros_armature();
128         ED_operatormacros_mesh();
129         ED_operatormacros_node();
130         ED_operatormacros_object();
131         ED_operatormacros_file();
132         ED_operatormacros_graph();
133         ED_operatormacros_action();
134         ED_operatormacros_clip();
135         ED_operatormacros_curve();
136         
137         /* register dropboxes (can use macros) */
138         spacetypes = BKE_spacetypes_list();
139         for (type=spacetypes->first; type; type=type->next) {
140                 if (type->dropboxes)
141                         type->dropboxes();
142         }
143         
144 }
145
146 /* called in wm.c */
147 /* keymap definitions are registered only once per WM initialize, usually on file read,
148  * using the keymap the actual areas/regions add the handlers */
149 void ED_spacetypes_keymap(wmKeyConfig *keyconf)
150 {
151         const ListBase *spacetypes;
152         SpaceType *stype;
153         ARegionType *atype;
154
155         ED_keymap_screen(keyconf);
156         ED_keymap_anim(keyconf);
157         ED_keymap_animchannels(keyconf);
158         ED_keymap_gpencil(keyconf);
159         ED_keymap_object(keyconf); /* defines lattice also */
160         ED_keymap_mesh(keyconf);
161         ED_keymap_uvedit(keyconf);
162         ED_keymap_curve(keyconf);
163         ED_keymap_armature(keyconf);
164         ED_keymap_physics(keyconf);
165         ED_keymap_metaball(keyconf);
166         ED_keymap_paint(keyconf);
167         ED_marker_keymap(keyconf);
168
169         UI_view2d_keymap(keyconf);
170
171         spacetypes = BKE_spacetypes_list();
172         for (stype=spacetypes->first; stype; stype=stype->next) {
173                 if (stype->keymap)
174                         stype->keymap(keyconf);
175                 for (atype=stype->regiontypes.first; atype; atype=atype->next) {
176                         if (atype->keymap)
177                                 atype->keymap(keyconf);
178                 }
179         }
180 }
181
182 /* ********************** custom drawcall api ***************** */
183
184 typedef struct RegionDrawCB {
185         struct RegionDrawCB *next, *prev;
186         
187         void (*draw)(const struct bContext *, struct ARegion *, void *);        
188         void *customdata;
189         
190         int type;
191         
192 } RegionDrawCB;
193
194 void *ED_region_draw_cb_activate(ARegionType *art, 
195                                                                  void   (*draw)(const struct bContext *, struct ARegion *, void *),
196                                                                  void *customdata, int type)
197 {
198         RegionDrawCB *rdc= MEM_callocN(sizeof(RegionDrawCB), "RegionDrawCB");
199         
200         BLI_addtail(&art->drawcalls, rdc);
201         rdc->draw= draw;
202         rdc->customdata= customdata;
203         rdc->type= type;
204         
205         return rdc;
206 }
207
208 void ED_region_draw_cb_exit(ARegionType *art, void *handle)
209 {
210         RegionDrawCB *rdc;
211         
212         for (rdc= art->drawcalls.first; rdc; rdc= rdc->next) {
213                 if (rdc==(RegionDrawCB *)handle) {
214                         BLI_remlink(&art->drawcalls, rdc);
215                         MEM_freeN(rdc);
216                         return;
217                 }
218         }
219 }
220
221 void *ED_region_draw_cb_customdata(void *handle)
222 {
223         return ((RegionDrawCB *)handle)->customdata;
224 }
225
226 void ED_region_draw_cb_draw(const bContext *C, ARegion *ar, int type)
227 {
228         RegionDrawCB *rdc;
229         
230         for (rdc= ar->type->drawcalls.first; rdc; rdc= rdc->next) {
231                 if (rdc->type==type)
232                         rdc->draw(C, ar, rdc->customdata);
233         }               
234 }
235
236
237
238 /* ********************* space template *********************** */
239 /* forward declare */
240 void ED_spacetype_xxx(void);
241
242 /* allocate and init some vars */
243 static SpaceLink *xxx_new(const bContext *UNUSED(C))
244 {
245         return NULL;
246 }
247
248 /* not spacelink itself */
249 static void xxx_free(SpaceLink *UNUSED(sl))
250 {
251
252 }
253
254 /* spacetype; init callback for usage, should be redoable */
255 static void xxx_init(wmWindowManager *UNUSED(wm), ScrArea *UNUSED(sa))
256 {
257         
258         /* link area to SpaceXXX struct */
259         
260         /* define how many regions, the order and types */
261         
262         /* add types to regions */
263 }
264
265 static SpaceLink *xxx_duplicate(SpaceLink *UNUSED(sl))
266 {
267         
268         return NULL;
269 }
270
271 static void xxx_operatortypes(void)
272 {
273         /* register operator types for this space */
274 }
275
276 static void xxx_keymap(wmKeyConfig *UNUSED(keyconf))
277 {
278         /* add default items to keymap */
279 }
280
281 /* only called once, from screen/spacetypes.c */
282 void ED_spacetype_xxx(void)
283 {
284         static SpaceType st;
285         
286         st.spaceid= SPACE_VIEW3D;
287         
288         st.new= xxx_new;
289         st.free= xxx_free;
290         st.init= xxx_init;
291         st.duplicate= xxx_duplicate;
292         st.operatortypes= xxx_operatortypes;
293         st.keymap= xxx_keymap;
294         
295         BKE_spacetype_register(&st);
296 }
297
298 /* ****************************** end template *********************** */
299
300
301
302