* First commit merging 2.4-based sim_physics in to volume25 branch.
[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_markers.h"
46 #include "ED_mesh.h"
47 #include "ED_object.h"
48 #include "ED_particle.h"
49 #include "ED_physics.h"
50 #include "ED_screen.h"
51 #include "ED_sculpt.h"
52 #include "ED_space_api.h"
53 #include "ED_uvedit.h"
54 #include "ED_mball.h"
55
56 /* only call once on startup, storage is global in BKE kernel listbase */
57 void ED_spacetypes_init(void)
58 {
59         const ListBase *spacetypes;
60         SpaceType *type;
61
62         /* create space types */
63         ED_spacetype_outliner();
64         ED_spacetype_time();
65         ED_spacetype_view3d();
66         ED_spacetype_ipo();
67         ED_spacetype_image();
68         ED_spacetype_node();
69         ED_spacetype_buttons();
70         ED_spacetype_info();
71         ED_spacetype_file();
72         ED_spacetype_sound();
73         ED_spacetype_action();
74         ED_spacetype_nla();
75         ED_spacetype_script();
76         ED_spacetype_text();
77         ED_spacetype_sequencer();
78         ED_spacetype_logic();
79         ED_spacetype_console();
80 //      ...
81         
82         /* register operator types for screen and all spaces */
83         ED_operatortypes_screen();
84         ED_operatortypes_anim();
85         ED_operatortypes_animchannels(); // XXX have this as part of anim() ones instead?
86         ED_operatortypes_object();
87         ED_operatortypes_mesh();
88         ED_operatortypes_sculpt();
89         ED_operatortypes_uvedit();
90         ED_operatortypes_paint();
91         ED_operatortypes_particle();
92         ED_operatortypes_curve();
93         ED_operatortypes_armature();
94         ED_operatortypes_marker();
95         ED_operatortypes_pointcache();
96         ED_operatortypes_fluid();
97         ED_operatortypes_metaball();
98         ED_operatortypes_boids();
99         
100         ui_view2d_operatortypes();
101         
102         spacetypes = BKE_spacetypes_list();
103         for(type=spacetypes->first; type; type=type->next)
104                 type->operatortypes();
105 }
106
107 /* called in wm.c */
108 /* keymap definitions are registered only once per WM initialize, usually on file read,
109    using the keymap the actual areas/regions add the handlers */
110 void ED_spacetypes_keymap(wmWindowManager *wm)
111 {
112         const ListBase *spacetypes;
113         SpaceType *stype;
114         ARegionType *atype;
115
116         ED_keymap_screen(wm);
117         ED_keymap_anim(wm);
118         ED_keymap_animchannels(wm);
119         ED_keymap_object(wm);
120         ED_keymap_mesh(wm);
121         ED_keymap_uvedit(wm);
122         ED_keymap_curve(wm);
123         ED_keymap_armature(wm);
124         ED_keymap_particle(wm);
125         ED_keymap_metaball(wm);
126         ED_marker_keymap(wm);
127
128         UI_view2d_keymap(wm);
129
130         spacetypes = BKE_spacetypes_list();
131         for(stype=spacetypes->first; stype; stype=stype->next) {
132                 if(stype->keymap)
133                         stype->keymap(wm);
134                 for(atype=stype->regiontypes.first; atype; atype=atype->next) {
135                         if(atype->keymap)
136                                 atype->keymap(wm);
137                 }
138         }
139 }
140
141 /* ********************** custom drawcall api ***************** */
142
143 /* type */
144 #define REGION_DRAW_PRE         1
145 #define REGION_DRAW_POST        0
146
147 typedef struct RegionDrawCB {
148         struct RegionDrawCB *next, *prev;
149         
150         void (*draw)(const struct bContext *, struct ARegion *, void *);        
151         void *customdata;
152         
153         int type;
154         
155 } RegionDrawCB;
156
157 void *ED_region_draw_cb_activate(ARegionType *art, 
158                                                                  void   (*draw)(const struct bContext *, struct ARegion *, void *),
159                                                                  void *customdata, int type)
160 {
161         RegionDrawCB *rdc= MEM_callocN(sizeof(RegionDrawCB), "RegionDrawCB");
162         
163         BLI_addtail(&art->drawcalls, rdc);
164         rdc->draw= draw;
165         rdc->customdata= customdata;
166         rdc->type= type;
167         
168         return rdc;
169 }
170
171 void ED_region_draw_cb_exit(ARegionType *art, void *handle)
172 {
173         RegionDrawCB *rdc;
174         
175         for(rdc= art->drawcalls.first; rdc; rdc= rdc->next) {
176                 if(rdc==(RegionDrawCB *)handle) {
177                         BLI_remlink(&art->drawcalls, rdc);
178                         MEM_freeN(rdc);
179                         return;
180                 }
181         }
182 }
183
184 void ED_region_draw_cb_draw(const bContext *C, ARegion *ar, int type)
185 {
186         RegionDrawCB *rdc;
187         
188         for(rdc= ar->type->drawcalls.first; rdc; rdc= rdc->next) {
189                 if(rdc->type==type)
190                         rdc->draw(C, ar, rdc->customdata);
191         }               
192 }
193
194
195
196 /* ********************* space template *********************** */
197
198 /* allocate and init some vars */
199 static SpaceLink *xxx_new(const bContext *C)
200 {
201         return NULL;
202 }
203
204 /* not spacelink itself */
205 static void xxx_free(SpaceLink *sl)
206 {
207
208 }
209
210 /* spacetype; init callback for usage, should be redoable */
211 static void xxx_init(wmWindowManager *wm, ScrArea *sa)
212 {
213         
214         /* link area to SpaceXXX struct */
215         
216         /* define how many regions, the order and types */
217         
218         /* add types to regions */
219 }
220
221 static SpaceLink *xxx_duplicate(SpaceLink *sl)
222 {
223         
224         return NULL;
225 }
226
227 static void xxx_operatortypes(void)
228 {
229         /* register operator types for this space */
230 }
231
232 static void xxx_keymap(wmWindowManager *wm)
233 {
234         /* add default items to keymap */
235 }
236
237 /* only called once, from screen/spacetypes.c */
238 void ED_spacetype_xxx(void)
239 {
240         static SpaceType st;
241         
242         st.spaceid= SPACE_VIEW3D;
243         
244         st.new= xxx_new;
245         st.free= xxx_free;
246         st.init= xxx_init;
247         st.duplicate= xxx_duplicate;
248         st.operatortypes= xxx_operatortypes;
249         st.keymap= xxx_keymap;
250         
251         BKE_spacetype_register(&st);
252 }
253
254 /* ****************************** end template *********************** */
255
256
257
258