Blender V2.61 - r43446

spacetypes.c

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