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