Blender  V2.59
spacetypes.c
Go to the documentation of this file.
00001 /*
00002  * $Id: spacetypes.c 37206 2011-06-05 12:57:09Z ton $
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version. 
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  * The Original Code is Copyright (C) Blender Foundation, 2008
00021  *
00022  * ***** END GPL/BL DUAL LICENSE BLOCK *****
00023  */
00024 
00030 #include <stdlib.h>
00031 
00032 #include "MEM_guardedalloc.h"
00033 
00034 #include "BLI_blenlib.h"
00035 #include "BLI_utildefines.h"
00036 
00037 #include "DNA_object_types.h"
00038 #include "DNA_windowmanager_types.h"
00039 
00040 
00041 #include "BKE_context.h"
00042 #include "BKE_screen.h"
00043 
00044 #include "UI_interface.h"
00045 #include "UI_view2d.h"
00046 
00047 
00048 #include "ED_anim_api.h"
00049 #include "ED_armature.h"
00050 #include "ED_curve.h"
00051 #include "ED_fileselect.h"
00052 #include "ED_gpencil.h"
00053 #include "ED_markers.h"
00054 #include "ED_mesh.h"
00055 #include "ED_node.h"
00056 #include "ED_object.h"
00057 #include "ED_physics.h"
00058 #include "ED_render.h"
00059 #include "ED_screen.h"
00060 #include "ED_sculpt.h"
00061 #include "ED_space_api.h"
00062 #include "ED_sound.h"
00063 #include "ED_uvedit.h"
00064 #include "ED_mball.h"
00065 #include "ED_logic.h"
00066 
00067 /* only call once on startup, storage is global in BKE kernel listbase */
00068 void ED_spacetypes_init(void)
00069 {
00070         const ListBase *spacetypes;
00071         SpaceType *type;
00072 
00073         /* UI_UNIT_X is now a variable, is used in some spacetype inits? */
00074         U.widget_unit= 20;
00075         
00076         /* create space types */
00077         ED_spacetype_outliner();
00078         ED_spacetype_time();
00079         ED_spacetype_view3d();
00080         ED_spacetype_ipo();
00081         ED_spacetype_image();
00082         ED_spacetype_node();
00083         ED_spacetype_buttons();
00084         ED_spacetype_info();
00085         ED_spacetype_file();
00086         ED_spacetype_sound();
00087         ED_spacetype_action();
00088         ED_spacetype_nla();
00089         ED_spacetype_script();
00090         ED_spacetype_text();
00091         ED_spacetype_sequencer();
00092         ED_spacetype_logic();
00093         ED_spacetype_console();
00094         ED_spacetype_userpref();
00095 //      ...
00096         
00097         /* register operator types for screen and all spaces */
00098         ED_operatortypes_screen();
00099         ED_operatortypes_anim();
00100         ED_operatortypes_animchannels();
00101         ED_operatortypes_gpencil();
00102         ED_operatortypes_object();
00103         ED_operatortypes_mesh();
00104         ED_operatortypes_sculpt();
00105         ED_operatortypes_uvedit();
00106         ED_operatortypes_paint();
00107         ED_operatortypes_physics();
00108         ED_operatortypes_curve();
00109         ED_operatortypes_armature();
00110         ED_operatortypes_marker();
00111         ED_operatortypes_metaball();
00112         ED_operatortypes_sound();
00113         ED_operatortypes_render();
00114         ED_operatortypes_logic();
00115         
00116         UI_view2d_operatortypes();
00117         UI_buttons_operatortypes();
00118         
00119         /* register operators */
00120         spacetypes = BKE_spacetypes_list();
00121         for(type=spacetypes->first; type; type=type->next) {
00122                 if(type->operatortypes)
00123                         type->operatortypes();
00124         }
00125 
00126         /* Macros's must go last since they reference other operators
00127          * maybe we'll need to have them go after python operators too? */
00128         ED_operatormacros_armature();
00129         ED_operatormacros_mesh();
00130         ED_operatormacros_node();
00131         ED_operatormacros_object();
00132         ED_operatormacros_file();
00133         ED_operatormacros_graph();
00134         ED_operatormacros_action();
00135         
00136         /* register dropboxes (can use macros) */
00137         spacetypes = BKE_spacetypes_list();
00138         for(type=spacetypes->first; type; type=type->next) {
00139                 if(type->dropboxes)
00140                         type->dropboxes();
00141         }
00142         
00143 }
00144 
00145 /* called in wm.c */
00146 /* keymap definitions are registered only once per WM initialize, usually on file read,
00147    using the keymap the actual areas/regions add the handlers */
00148 void ED_spacetypes_keymap(wmKeyConfig *keyconf)
00149 {
00150         const ListBase *spacetypes;
00151         SpaceType *stype;
00152         ARegionType *atype;
00153 
00154         ED_keymap_screen(keyconf);
00155         ED_keymap_anim(keyconf);
00156         ED_keymap_animchannels(keyconf);
00157         ED_keymap_gpencil(keyconf);
00158         ED_keymap_object(keyconf); /* defines lattice also */
00159         ED_keymap_mesh(keyconf);
00160         ED_keymap_uvedit(keyconf);
00161         ED_keymap_curve(keyconf);
00162         ED_keymap_armature(keyconf);
00163         ED_keymap_physics(keyconf);
00164         ED_keymap_metaball(keyconf);
00165         ED_keymap_paint(keyconf);
00166         ED_marker_keymap(keyconf);
00167 
00168         UI_view2d_keymap(keyconf);
00169 
00170         spacetypes = BKE_spacetypes_list();
00171         for(stype=spacetypes->first; stype; stype=stype->next) {
00172                 if(stype->keymap)
00173                         stype->keymap(keyconf);
00174                 for(atype=stype->regiontypes.first; atype; atype=atype->next) {
00175                         if(atype->keymap)
00176                                 atype->keymap(keyconf);
00177                 }
00178         }
00179 }
00180 
00181 /* ********************** custom drawcall api ***************** */
00182 
00183 typedef struct RegionDrawCB {
00184         struct RegionDrawCB *next, *prev;
00185         
00186         void (*draw)(const struct bContext *, struct ARegion *, void *);        
00187         void *customdata;
00188         
00189         int type;
00190         
00191 } RegionDrawCB;
00192 
00193 void *ED_region_draw_cb_activate(ARegionType *art, 
00194                                                                  void   (*draw)(const struct bContext *, struct ARegion *, void *),
00195                                                                  void *customdata, int type)
00196 {
00197         RegionDrawCB *rdc= MEM_callocN(sizeof(RegionDrawCB), "RegionDrawCB");
00198         
00199         BLI_addtail(&art->drawcalls, rdc);
00200         rdc->draw= draw;
00201         rdc->customdata= customdata;
00202         rdc->type= type;
00203         
00204         return rdc;
00205 }
00206 
00207 void ED_region_draw_cb_exit(ARegionType *art, void *handle)
00208 {
00209         RegionDrawCB *rdc;
00210         
00211         for(rdc= art->drawcalls.first; rdc; rdc= rdc->next) {
00212                 if(rdc==(RegionDrawCB *)handle) {
00213                         BLI_remlink(&art->drawcalls, rdc);
00214                         MEM_freeN(rdc);
00215                         return;
00216                 }
00217         }
00218 }
00219 
00220 void *ED_region_draw_cb_customdata(void *handle)
00221 {
00222         return ((RegionDrawCB *)handle)->customdata;
00223 }
00224 
00225 void ED_region_draw_cb_draw(const bContext *C, ARegion *ar, int type)
00226 {
00227         RegionDrawCB *rdc;
00228         
00229         for(rdc= ar->type->drawcalls.first; rdc; rdc= rdc->next) {
00230                 if(rdc->type==type)
00231                         rdc->draw(C, ar, rdc->customdata);
00232         }               
00233 }
00234 
00235 
00236 
00237 /* ********************* space template *********************** */
00238 /* forward declare */
00239 void ED_spacetype_xxx(void);
00240 
00241 /* allocate and init some vars */
00242 static SpaceLink *xxx_new(const bContext *UNUSED(C))
00243 {
00244         return NULL;
00245 }
00246 
00247 /* not spacelink itself */
00248 static void xxx_free(SpaceLink *UNUSED(sl))
00249 {
00250 
00251 }
00252 
00253 /* spacetype; init callback for usage, should be redoable */
00254 static void xxx_init(wmWindowManager *UNUSED(wm), ScrArea *UNUSED(sa))
00255 {
00256         
00257         /* link area to SpaceXXX struct */
00258         
00259         /* define how many regions, the order and types */
00260         
00261         /* add types to regions */
00262 }
00263 
00264 static SpaceLink *xxx_duplicate(SpaceLink *UNUSED(sl))
00265 {
00266         
00267         return NULL;
00268 }
00269 
00270 static void xxx_operatortypes(void)
00271 {
00272         /* register operator types for this space */
00273 }
00274 
00275 static void xxx_keymap(wmKeyConfig *UNUSED(keyconf))
00276 {
00277         /* add default items to keymap */
00278 }
00279 
00280 /* only called once, from screen/spacetypes.c */
00281 void ED_spacetype_xxx(void)
00282 {
00283         static SpaceType st;
00284         
00285         st.spaceid= SPACE_VIEW3D;
00286         
00287         st.new= xxx_new;
00288         st.free= xxx_free;
00289         st.init= xxx_init;
00290         st.duplicate= xxx_duplicate;
00291         st.operatortypes= xxx_operatortypes;
00292         st.keymap= xxx_keymap;
00293         
00294         BKE_spacetype_register(&st);
00295 }
00296 
00297 /* ****************************** end template *********************** */
00298 
00299 
00300 
00301