Node Editor - More Cleanups (Reshuffling):
[blender.git] / source / blender / editors / space_api / spacetypes.c
1 /**
2  * $Id: spacetypes.c
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) Blender Foundation, 2008
21  *
22  * ***** END GPL/BL DUAL LICENSE BLOCK *****
23  */
24
25 #include <stdlib.h>
26
27 #include "MEM_guardedalloc.h"
28 #include "BLI_blenlib.h"
29
30 #include "DNA_object_types.h"
31 #include "DNA_scene_types.h"
32 #include "DNA_windowmanager_types.h"
33
34 #include "BKE_context.h"
35 #include "BKE_screen.h"
36
37 #include "UI_interface.h"
38 #include "UI_view2d.h"
39
40 #include "BIF_gl.h"
41
42 #include "ED_anim_api.h"
43 #include "ED_armature.h"
44 #include "ED_curve.h"
45 #include "ED_gpencil.h"
46 #include "ED_markers.h"
47 #include "ED_mesh.h"
48 #include "ED_node.h"
49 #include "ED_object.h"
50 #include "ED_physics.h"
51 #include "ED_render.h"
52 #include "ED_screen.h"
53 #include "ED_sculpt.h"
54 #include "ED_space_api.h"
55 #include "ED_sound.h"
56 #include "ED_uvedit.h"
57 #include "ED_mball.h"
58
59 /* only call once on startup, storage is global in BKE kernel listbase */
60 void ED_spacetypes_init(void)
61 {
62         const ListBase *spacetypes;
63         SpaceType *type;
64
65         /* create space types */
66         ED_spacetype_outliner();
67         ED_spacetype_time();
68         ED_spacetype_view3d();
69         ED_spacetype_ipo();
70         ED_spacetype_image();
71         ED_spacetype_node();
72         ED_spacetype_buttons();
73         ED_spacetype_info();
74         ED_spacetype_file();
75         ED_spacetype_sound();
76         ED_spacetype_action();
77         ED_spacetype_nla();
78         ED_spacetype_script();
79         ED_spacetype_text();
80         ED_spacetype_sequencer();
81         ED_spacetype_logic();
82         ED_spacetype_console();
83         ED_spacetype_userpref();
84 //      ...
85         
86         /* register operator types for screen and all spaces */
87         ED_operatortypes_screen();
88         ED_operatortypes_anim();
89         ED_operatortypes_animchannels();
90         ED_operatortypes_gpencil();
91         ED_operatortypes_object();
92         ED_operatortypes_mesh();
93         ED_operatortypes_sculpt();
94         ED_operatortypes_uvedit();
95         ED_operatortypes_paint();
96         ED_operatortypes_physics();
97         ED_operatortypes_curve();
98         ED_operatortypes_armature();
99         ED_operatortypes_marker();
100         ED_operatortypes_metaball();
101         ED_operatortypes_sound();
102         ED_operatortypes_render();
103         
104         ui_view2d_operatortypes();
105         
106         spacetypes = BKE_spacetypes_list();
107         for(type=spacetypes->first; type; type=type->next)
108                 type->operatortypes();
109
110
111         /* Macros's must go last since they reference other operators
112          * maybe we'll need to have them go after python operators too? */
113         ED_operatormacros_armature();
114         ED_operatormacros_mesh();
115         ED_operatormacros_node();
116         ED_operatormacros_object();
117 }
118
119 /* called in wm.c */
120 /* keymap definitions are registered only once per WM initialize, usually on file read,
121    using the keymap the actual areas/regions add the handlers */
122 void ED_spacetypes_keymap(wmKeyConfig *keyconf)
123 {
124         const ListBase *spacetypes;
125         SpaceType *stype;
126         ARegionType *atype;
127
128         ED_keymap_screen(keyconf);
129         ED_keymap_anim(keyconf);
130         ED_keymap_animchannels(keyconf);
131         ED_keymap_gpencil(keyconf);
132         ED_keymap_object(keyconf); /* defines lattice also */
133         ED_keymap_mesh(keyconf);
134         ED_keymap_uvedit(keyconf);
135         ED_keymap_curve(keyconf);
136         ED_keymap_armature(keyconf);
137         ED_keymap_physics(keyconf);
138         ED_keymap_metaball(keyconf);
139         ED_keymap_paint(keyconf);
140         ED_marker_keymap(keyconf);
141
142         UI_view2d_keymap(keyconf);
143
144         spacetypes = BKE_spacetypes_list();
145         for(stype=spacetypes->first; stype; stype=stype->next) {
146                 if(stype->keymap)
147                         stype->keymap(keyconf);
148                 for(atype=stype->regiontypes.first; atype; atype=atype->next) {
149                         if(atype->keymap)
150                                 atype->keymap(keyconf);
151                 }
152         }
153 }
154
155 /* ********************** custom drawcall api ***************** */
156
157 typedef struct RegionDrawCB {
158         struct RegionDrawCB *next, *prev;
159         
160         void (*draw)(const struct bContext *, struct ARegion *, void *);        
161         void *customdata;
162         
163         int type;
164         
165 } RegionDrawCB;
166
167 void *ED_region_draw_cb_activate(ARegionType *art, 
168                                                                  void   (*draw)(const struct bContext *, struct ARegion *, void *),
169                                                                  void *customdata, int type)
170 {
171         RegionDrawCB *rdc= MEM_callocN(sizeof(RegionDrawCB), "RegionDrawCB");
172         
173         BLI_addtail(&art->drawcalls, rdc);
174         rdc->draw= draw;
175         rdc->customdata= customdata;
176         rdc->type= type;
177         
178         return rdc;
179 }
180
181 void ED_region_draw_cb_exit(ARegionType *art, void *handle)
182 {
183         RegionDrawCB *rdc;
184         
185         for(rdc= art->drawcalls.first; rdc; rdc= rdc->next) {
186                 if(rdc==(RegionDrawCB *)handle) {
187                         BLI_remlink(&art->drawcalls, rdc);
188                         MEM_freeN(rdc);
189                         return;
190                 }
191         }
192 }
193
194 void ED_region_draw_cb_draw(const bContext *C, ARegion *ar, int type)
195 {
196         RegionDrawCB *rdc;
197         
198         for(rdc= ar->type->drawcalls.first; rdc; rdc= rdc->next) {
199                 if(rdc->type==type)
200                         rdc->draw(C, ar, rdc->customdata);
201         }               
202 }
203
204
205
206 /* ********************* space template *********************** */
207
208 /* allocate and init some vars */
209 static SpaceLink *xxx_new(const bContext *C)
210 {
211         return NULL;
212 }
213
214 /* not spacelink itself */
215 static void xxx_free(SpaceLink *sl)
216 {
217
218 }
219
220 /* spacetype; init callback for usage, should be redoable */
221 static void xxx_init(wmWindowManager *wm, ScrArea *sa)
222 {
223         
224         /* link area to SpaceXXX struct */
225         
226         /* define how many regions, the order and types */
227         
228         /* add types to regions */
229 }
230
231 static SpaceLink *xxx_duplicate(SpaceLink *sl)
232 {
233         
234         return NULL;
235 }
236
237 static void xxx_operatortypes(void)
238 {
239         /* register operator types for this space */
240 }
241
242 static void xxx_keymap(wmKeyConfig *keyconf)
243 {
244         /* add default items to keymap */
245 }
246
247 /* only called once, from screen/spacetypes.c */
248 void ED_spacetype_xxx(void)
249 {
250         static SpaceType st;
251         
252         st.spaceid= SPACE_VIEW3D;
253         
254         st.new= xxx_new;
255         st.free= xxx_free;
256         st.init= xxx_init;
257         st.duplicate= xxx_duplicate;
258         st.operatortypes= xxx_operatortypes;
259         st.keymap= xxx_keymap;
260         
261         BKE_spacetype_register(&st);
262 }
263
264 /* ****************************** end template *********************** */
265
266
267
268