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