svn merge ^/trunk/blender -r46612:46629
[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 #include "ED_mask.h"
66
67 /* only call once on startup, storage is global in BKE kernel listbase */
68 void ED_spacetypes_init(void)
69 {
70         const ListBase *spacetypes;
71         SpaceType *type;
72
73         /* UI_UNIT_X is now a variable, is used in some spacetype inits? */
74         U.widget_unit = 20;
75         
76         /* create space types */
77         ED_spacetype_outliner();
78         ED_spacetype_time();
79         ED_spacetype_view3d();
80         ED_spacetype_ipo();
81         ED_spacetype_image();
82         ED_spacetype_node();
83         ED_spacetype_buttons();
84         ED_spacetype_info();
85         ED_spacetype_file();
86         ED_spacetype_action();
87         ED_spacetype_nla();
88         ED_spacetype_script();
89         ED_spacetype_text();
90         ED_spacetype_sequencer();
91         ED_spacetype_logic();
92         ED_spacetype_console();
93         ED_spacetype_userpref();
94         ED_spacetype_clip();
95 //      ...
96         
97         /* register operator types for screen and all spaces */
98         ED_operatortypes_screen();
99         ED_operatortypes_anim();
100         ED_operatortypes_animchannels();
101         ED_operatortypes_gpencil();
102         ED_operatortypes_object();
103         ED_operatortypes_mesh();
104         ED_operatortypes_sculpt();
105         ED_operatortypes_uvedit();
106         ED_operatortypes_paint();
107         ED_operatortypes_physics();
108         ED_operatortypes_curve();
109         ED_operatortypes_armature();
110         ED_operatortypes_marker();
111         ED_operatortypes_metaball();
112         ED_operatortypes_sound();
113         ED_operatortypes_render();
114         ED_operatortypes_logic();
115         ED_operatortypes_mask();
116         
117         UI_view2d_operatortypes();
118         UI_buttons_operatortypes();
119         
120         /* register operators */
121         spacetypes = BKE_spacetypes_list();
122         for (type = spacetypes->first; type; type = type->next) {
123                 if (type->operatortypes)
124                         type->operatortypes();
125         }
126
127         /* Macros's must go last since they reference other operators
128          * maybe we'll need to have them go after python operators too? */
129         ED_operatormacros_armature();
130         ED_operatormacros_mesh();
131         ED_operatormacros_node();
132         ED_operatormacros_object();
133         ED_operatormacros_file();
134         ED_operatormacros_graph();
135         ED_operatormacros_action();
136         ED_operatormacros_clip();
137         ED_operatormacros_curve();
138         ED_operatormacros_mask();
139         
140         /* register dropboxes (can use macros) */
141         spacetypes = BKE_spacetypes_list();
142         for (type = spacetypes->first; type; type = type->next) {
143                 if (type->dropboxes)
144                         type->dropboxes();
145         }
146         
147 }
148
149 /* called in wm.c */
150 /* keymap definitions are registered only once per WM initialize, usually on file read,
151  * using the keymap the actual areas/regions add the handlers */
152 void ED_spacetypes_keymap(wmKeyConfig *keyconf)
153 {
154         const ListBase *spacetypes;
155         SpaceType *stype;
156         ARegionType *atype;
157
158         ED_keymap_screen(keyconf);
159         ED_keymap_anim(keyconf);
160         ED_keymap_animchannels(keyconf);
161         ED_keymap_gpencil(keyconf);
162         ED_keymap_object(keyconf); /* defines lattice also */
163         ED_keymap_mesh(keyconf);
164         ED_keymap_uvedit(keyconf);
165         ED_keymap_curve(keyconf);
166         ED_keymap_armature(keyconf);
167         ED_keymap_physics(keyconf);
168         ED_keymap_metaball(keyconf);
169         ED_keymap_paint(keyconf);
170         ED_keymap_mask(keyconf);
171         ED_marker_keymap(keyconf);
172
173         UI_view2d_keymap(keyconf);
174
175         spacetypes = BKE_spacetypes_list();
176         for (stype = spacetypes->first; stype; stype = stype->next) {
177                 if (stype->keymap)
178                         stype->keymap(keyconf);
179                 for (atype = stype->regiontypes.first; atype; atype = atype->next) {
180                         if (atype->keymap)
181                                 atype->keymap(keyconf);
182                 }
183         }
184 }
185
186 /* ********************** custom drawcall api ***************** */
187
188 typedef struct RegionDrawCB {
189         struct RegionDrawCB *next, *prev;
190         
191         void (*draw)(const struct bContext *, struct ARegion *, void *);        
192         void *customdata;
193         
194         int type;
195         
196 } RegionDrawCB;
197
198 void *ED_region_draw_cb_activate(ARegionType *art, 
199                                  void (*draw)(const struct bContext *, struct ARegion *, void *),
200                                  void *customdata, int type)
201 {
202         RegionDrawCB *rdc = MEM_callocN(sizeof(RegionDrawCB), "RegionDrawCB");
203         
204         BLI_addtail(&art->drawcalls, rdc);
205         rdc->draw = draw;
206         rdc->customdata = customdata;
207         rdc->type = type;
208         
209         return rdc;
210 }
211
212 void ED_region_draw_cb_exit(ARegionType *art, void *handle)
213 {
214         RegionDrawCB *rdc;
215         
216         for (rdc = art->drawcalls.first; rdc; rdc = rdc->next) {
217                 if (rdc == (RegionDrawCB *)handle) {
218                         BLI_remlink(&art->drawcalls, rdc);
219                         MEM_freeN(rdc);
220                         return;
221                 }
222         }
223 }
224
225 void *ED_region_draw_cb_customdata(void *handle)
226 {
227         return ((RegionDrawCB *)handle)->customdata;
228 }
229
230 void ED_region_draw_cb_draw(const bContext *C, ARegion *ar, int type)
231 {
232         RegionDrawCB *rdc;
233         
234         for (rdc = ar->type->drawcalls.first; rdc; rdc = rdc->next) {
235                 if (rdc->type == type)
236                         rdc->draw(C, ar, rdc->customdata);
237         }               
238 }
239
240
241
242 /* ********************* space template *********************** */
243 /* forward declare */
244 void ED_spacetype_xxx(void);
245
246 /* allocate and init some vars */
247 static SpaceLink *xxx_new(const bContext *UNUSED(C))
248 {
249         return NULL;
250 }
251
252 /* not spacelink itself */
253 static void xxx_free(SpaceLink *UNUSED(sl))
254 {
255
256 }
257
258 /* spacetype; init callback for usage, should be redoable */
259 static void xxx_init(wmWindowManager *UNUSED(wm), ScrArea *UNUSED(sa))
260 {
261         
262         /* link area to SpaceXXX struct */
263         
264         /* define how many regions, the order and types */
265         
266         /* add types to regions */
267 }
268
269 static SpaceLink *xxx_duplicate(SpaceLink *UNUSED(sl))
270 {
271         
272         return NULL;
273 }
274
275 static void xxx_operatortypes(void)
276 {
277         /* register operator types for this space */
278 }
279
280 static void xxx_keymap(wmKeyConfig *UNUSED(keyconf))
281 {
282         /* add default items to keymap */
283 }
284
285 /* only called once, from screen/spacetypes.c */
286 void ED_spacetype_xxx(void)
287 {
288         static SpaceType st;
289         
290         st.spaceid = SPACE_VIEW3D;
291         
292         st.new = xxx_new;
293         st.free = xxx_free;
294         st.init = xxx_init;
295         st.duplicate = xxx_duplicate;
296         st.operatortypes = xxx_operatortypes;
297         st.keymap = xxx_keymap;
298         
299         BKE_spacetype_register(&st);
300 }
301
302 /* ****************************** end template *********************** */
303
304
305
306