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