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