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