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