Blender V2.61 - r43446
|
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) 2009 Blender Foundation. 00019 * All rights reserved. 00020 * 00021 * 00022 * Contributor(s): Blender Foundation 00023 * 00024 * ***** END GPL LICENSE BLOCK ***** 00025 */ 00026 00032 #include <string.h> 00033 #include <stdio.h> 00034 00035 00036 #include "MEM_guardedalloc.h" 00037 00038 #include "BLI_blenlib.h" 00039 #include "BLI_math.h" 00040 #include "BLI_utildefines.h" 00041 00042 #include "BKE_context.h" 00043 #include "BKE_screen.h" 00044 00045 #include "ED_space_api.h" 00046 #include "ED_screen.h" 00047 00048 #include "BIF_gl.h" 00049 00050 00051 #include "WM_api.h" 00052 #include "WM_types.h" 00053 00054 #include "UI_resources.h" 00055 #include "UI_view2d.h" 00056 00057 #include "logic_intern.h" 00058 00059 /* ******************** manage regions ********************* */ 00060 00061 ARegion *logic_has_buttons_region(ScrArea *sa) 00062 { 00063 ARegion *ar, *arnew; 00064 00065 ar= BKE_area_find_region_type(sa, RGN_TYPE_UI); 00066 if(ar) return ar; 00067 00068 /* add subdiv level; after header */ 00069 ar= BKE_area_find_region_type(sa, RGN_TYPE_HEADER); 00070 00071 /* is error! */ 00072 if(ar==NULL) return NULL; 00073 00074 arnew= MEM_callocN(sizeof(ARegion), "buttons for image"); 00075 00076 BLI_insertlinkafter(&sa->regionbase, ar, arnew); 00077 arnew->regiontype= RGN_TYPE_UI; 00078 arnew->alignment= RGN_ALIGN_LEFT; 00079 00080 arnew->flag = RGN_FLAG_HIDDEN; 00081 00082 return arnew; 00083 } 00084 00085 /* ******************** default callbacks for image space ***************** */ 00086 00087 static SpaceLink *logic_new(const bContext *UNUSED(C)) 00088 { 00089 ARegion *ar; 00090 SpaceLogic *slogic; 00091 00092 slogic= MEM_callocN(sizeof(SpaceLogic), "initlogic"); 00093 slogic->spacetype= SPACE_LOGIC; 00094 00095 /* default options */ 00096 slogic->scaflag = (BUTS_SENS_SEL|BUTS_SENS_ACT|BUTS_SENS_LINK) | 00097 (BUTS_CONT_SEL|BUTS_CONT_ACT|BUTS_CONT_LINK) | 00098 (BUTS_ACT_SEL|BUTS_ACT_ACT|BUTS_ACT_LINK) | 00099 (BUTS_SENS_STATE|BUTS_ACT_STATE); 00100 00101 00102 /* header */ 00103 ar= MEM_callocN(sizeof(ARegion), "header for logic"); 00104 00105 BLI_addtail(&slogic->regionbase, ar); 00106 ar->regiontype= RGN_TYPE_HEADER; 00107 ar->alignment= RGN_ALIGN_BOTTOM; 00108 00109 /* buttons/list view */ 00110 ar= MEM_callocN(sizeof(ARegion), "buttons for logic"); 00111 00112 BLI_addtail(&slogic->regionbase, ar); 00113 ar->regiontype= RGN_TYPE_UI; 00114 ar->alignment= RGN_ALIGN_LEFT; 00115 00116 /* main area */ 00117 ar= MEM_callocN(sizeof(ARegion), "main area for logic"); 00118 00119 BLI_addtail(&slogic->regionbase, ar); 00120 ar->regiontype= RGN_TYPE_WINDOW; 00121 00122 ar->v2d.tot.xmin= 0.0f; 00123 ar->v2d.tot.ymin= 0.0f; 00124 ar->v2d.tot.xmax= 1280; 00125 ar->v2d.tot.ymax= 240.0f; 00126 00127 ar->v2d.cur.xmin= 0.0f; 00128 ar->v2d.cur.ymin= 0.0f; 00129 ar->v2d.cur.xmax= 1280.0f; 00130 ar->v2d.cur.ymax= 240.0f; 00131 00132 ar->v2d.min[0]= 1.0f; 00133 ar->v2d.min[1]= 1.0f; 00134 00135 ar->v2d.max[0]= 32000.0f; 00136 ar->v2d.max[1]= 32000.0f; 00137 00138 ar->v2d.minzoom= 0.5f; 00139 ar->v2d.maxzoom= 1.21f; 00140 00141 ar->v2d.scroll= (V2D_SCROLL_RIGHT|V2D_SCROLL_BOTTOM); 00142 ar->v2d.keepzoom= V2D_LIMITZOOM|V2D_KEEPASPECT; 00143 ar->v2d.keeptot= 0; 00144 00145 00146 return (SpaceLink *)slogic; 00147 } 00148 00149 /* not spacelink itself */ 00150 static void logic_free(SpaceLink *UNUSED(sl)) 00151 { 00152 // Spacelogic *slogic= (SpaceLogic*) sl; 00153 00154 // if(slogic->gpd) 00155 // XXX free_gpencil_data(slogic->gpd); 00156 00157 } 00158 00159 00160 /* spacetype; init callback */ 00161 static void logic_init(struct wmWindowManager *UNUSED(wm), ScrArea *UNUSED(sa)) 00162 { 00163 00164 } 00165 00166 static SpaceLink *logic_duplicate(SpaceLink *sl) 00167 { 00168 SpaceLogic *slogicn= MEM_dupallocN(sl); 00169 00170 return (SpaceLink *)slogicn; 00171 } 00172 00173 static void logic_operatortypes(void) 00174 { 00175 WM_operatortype_append(LOGIC_OT_properties); 00176 WM_operatortype_append(LOGIC_OT_links_cut); 00177 } 00178 00179 static void logic_keymap(struct wmKeyConfig *keyconf) 00180 { 00181 wmKeyMap *keymap= WM_keymap_find(keyconf, "Logic Editor", SPACE_LOGIC, 0); 00182 00183 WM_keymap_add_item(keymap, "LOGIC_OT_properties", NKEY, KM_PRESS, 0, 0); 00184 WM_keymap_add_item(keymap, "LOGIC_OT_links_cut", LEFTMOUSE, KM_PRESS, KM_CTRL, 0); 00185 WM_keymap_add_menu(keymap, "LOGIC_MT_logicbricks_add", AKEY, KM_PRESS, KM_SHIFT, 0); 00186 } 00187 00188 static void logic_refresh(const bContext *UNUSED(C), ScrArea *UNUSED(sa)) 00189 { 00190 // SpaceLogic *slogic= CTX_wm_space_logic(C); 00191 // Object *obedit= CTX_data_edit_object(C); 00192 00193 } 00194 00195 static void logic_listener(ARegion *ar, wmNotifier *wmn) 00196 { 00197 /* context changes */ 00198 switch(wmn->category) { 00199 case NC_LOGIC: 00200 ED_region_tag_redraw(ar); 00201 break; 00202 case NC_SCENE: 00203 switch(wmn->data) { 00204 case ND_FRAME: 00205 ED_region_tag_redraw(ar); 00206 break; 00207 00208 case ND_OB_ACTIVE: 00209 ED_region_tag_redraw(ar); 00210 break; 00211 } 00212 break; 00213 case NC_OBJECT: 00214 break; 00215 case NC_ID: 00216 if(wmn->action == NA_RENAME) 00217 ED_region_tag_redraw(ar); 00218 break; 00219 } 00220 } 00221 00222 static int logic_context(const bContext *UNUSED(C), const char *UNUSED(member), bContextDataResult *UNUSED(result)) 00223 { 00224 // SpaceLogic *slogic= CTX_wm_space_logic(C); 00225 return 0; 00226 } 00227 00228 /************************** main region ***************************/ 00229 00230 00231 /* add handlers, stuff you only do once or on area/region changes */ 00232 static void logic_main_area_init(wmWindowManager *wm, ARegion *ar) 00233 { 00234 wmKeyMap *keymap; 00235 00236 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy); 00237 00238 /* own keymaps */ 00239 keymap= WM_keymap_find(wm->defaultconf, "Logic Editor", SPACE_LOGIC, 0); 00240 WM_event_add_keymap_handler(&ar->handlers, keymap); 00241 } 00242 00243 static void logic_main_area_draw(const bContext *C, ARegion *ar) 00244 { 00245 /* draw entirely, view changes should be handled here */ 00246 // SpaceLogic *slogic= CTX_wm_space_logic(C); 00247 View2D *v2d= &ar->v2d; 00248 View2DScrollers *scrollers; 00249 00250 /* clear and setup matrix */ 00251 UI_ThemeClearColor(TH_BACK); 00252 glClear(GL_COLOR_BUFFER_BIT); 00253 00254 UI_view2d_view_ortho(v2d); 00255 00256 logic_buttons((bContext *)C, ar); 00257 00258 /* reset view matrix */ 00259 UI_view2d_view_restore(C); 00260 00261 /* scrollers */ 00262 scrollers= UI_view2d_scrollers_calc(C, v2d, 10, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY); 00263 UI_view2d_scrollers_draw(C, v2d, scrollers); 00264 UI_view2d_scrollers_free(scrollers); 00265 00266 } 00267 00268 00269 /* *********************** buttons region ************************ */ 00270 00271 /* add handlers, stuff you only do once or on area/region changes */ 00272 static void logic_buttons_area_init(wmWindowManager *wm, ARegion *ar) 00273 { 00274 wmKeyMap *keymap; 00275 00276 ED_region_panels_init(wm, ar); 00277 00278 keymap= WM_keymap_find(wm->defaultconf, "Logic Editor", SPACE_LOGIC, 0); 00279 WM_event_add_keymap_handler(&ar->handlers, keymap); 00280 } 00281 00282 static void logic_buttons_area_draw(const bContext *C, ARegion *ar) 00283 { 00284 ED_region_panels(C, ar, 1, NULL, -1); 00285 } 00286 00287 /************************* header region **************************/ 00288 00289 /* add handlers, stuff you only do once or on area/region changes */ 00290 static void logic_header_area_init(wmWindowManager *UNUSED(wm), ARegion *ar) 00291 { 00292 ED_region_header_init(ar); 00293 } 00294 00295 static void logic_header_area_draw(const bContext *C, ARegion *ar) 00296 { 00297 ED_region_header(C, ar); 00298 } 00299 00300 /**************************** spacetype *****************************/ 00301 00302 /* only called once, from space/spacetypes.c */ 00303 void ED_spacetype_logic(void) 00304 { 00305 SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype logic"); 00306 ARegionType *art; 00307 00308 st->spaceid= SPACE_LOGIC; 00309 strncpy(st->name, "Logic", BKE_ST_MAXNAME); 00310 00311 st->new= logic_new; 00312 st->free= logic_free; 00313 st->init= logic_init; 00314 st->duplicate= logic_duplicate; 00315 st->operatortypes= logic_operatortypes; 00316 st->keymap= logic_keymap; 00317 st->refresh= logic_refresh; 00318 st->context= logic_context; 00319 00320 /* regions: main window */ 00321 art= MEM_callocN(sizeof(ARegionType), "spacetype logic region"); 00322 art->regionid = RGN_TYPE_WINDOW; 00323 art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_FRAMES|ED_KEYMAP_VIEW2D; 00324 art->init= logic_main_area_init; 00325 art->draw= logic_main_area_draw; 00326 art->listener= logic_listener; 00327 00328 BLI_addhead(&st->regiontypes, art); 00329 00330 /* regions: listview/buttons */ 00331 art= MEM_callocN(sizeof(ARegionType), "spacetype logic region"); 00332 art->regionid = RGN_TYPE_UI; 00333 art->prefsizex= 220; // XXX 00334 art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_FRAMES; 00335 art->listener= logic_listener; 00336 art->init= logic_buttons_area_init; 00337 art->draw= logic_buttons_area_draw; 00338 BLI_addhead(&st->regiontypes, art); 00339 00340 logic_buttons_register(art); 00341 00342 /* regions: header */ 00343 art= MEM_callocN(sizeof(ARegionType), "spacetype logic region"); 00344 art->regionid = RGN_TYPE_HEADER; 00345 art->prefsizey= HEADERY; 00346 art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D|ED_KEYMAP_FRAMES|ED_KEYMAP_HEADER; 00347 art->init= logic_header_area_init; 00348 art->draw= logic_header_area_draw; 00349 00350 BLI_addhead(&st->regiontypes, art); 00351 00352 BKE_spacetype_register(st); 00353 } 00354 00355