|
Blender
V2.59
|
00001 /* 00002 * $Id: space_script.c 35242 2011-02-27 20:29:51Z jesterking $ 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) 2008 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 #include "MEM_guardedalloc.h" 00038 00039 #include "BLI_blenlib.h" 00040 #include "BLI_math.h" 00041 #include "BLI_rand.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 #include "WM_api.h" 00053 #include "WM_types.h" 00054 00055 #include "UI_resources.h" 00056 #include "UI_view2d.h" 00057 00058 #ifdef WITH_PYTHON 00059 #include "BPY_extern.h" 00060 #endif 00061 00062 #include "script_intern.h" // own include 00063 00064 00065 //static script_run_python(char *funcname, ) 00066 00067 00068 /* ******************** default callbacks for script space ***************** */ 00069 00070 static SpaceLink *script_new(const bContext *UNUSED(C)) 00071 { 00072 ARegion *ar; 00073 SpaceScript *sscript; 00074 00075 sscript= MEM_callocN(sizeof(SpaceScript), "initscript"); 00076 sscript->spacetype= SPACE_SCRIPT; 00077 00078 00079 /* header */ 00080 ar= MEM_callocN(sizeof(ARegion), "header for script"); 00081 00082 BLI_addtail(&sscript->regionbase, ar); 00083 ar->regiontype= RGN_TYPE_HEADER; 00084 ar->alignment= RGN_ALIGN_BOTTOM; 00085 00086 /* main area */ 00087 ar= MEM_callocN(sizeof(ARegion), "main area for script"); 00088 00089 BLI_addtail(&sscript->regionbase, ar); 00090 ar->regiontype= RGN_TYPE_WINDOW; 00091 00092 /* channel list region XXX */ 00093 00094 00095 return (SpaceLink *)sscript; 00096 } 00097 00098 /* not spacelink itself */ 00099 static void script_free(SpaceLink *sl) 00100 { 00101 SpaceScript *sscript= (SpaceScript*) sl; 00102 00103 #ifdef WITH_PYTHON 00104 /*free buttons references*/ 00105 if (sscript->but_refs) { 00106 // XXX BPy_Set_DrawButtonsList(sscript->but_refs); 00107 // BPy_Free_DrawButtonsList(); 00108 sscript->but_refs = NULL; 00109 } 00110 #endif 00111 sscript->script = NULL; 00112 } 00113 00114 00115 /* spacetype; init callback */ 00116 static void script_init(struct wmWindowManager *UNUSED(wm), ScrArea *UNUSED(sa)) 00117 { 00118 00119 } 00120 00121 static SpaceLink *script_duplicate(SpaceLink *sl) 00122 { 00123 SpaceScript *sscriptn= MEM_dupallocN(sl); 00124 00125 /* clear or remove stuff from old */ 00126 00127 return (SpaceLink *)sscriptn; 00128 } 00129 00130 00131 00132 /* add handlers, stuff you only do once or on area/region changes */ 00133 static void script_main_area_init(wmWindowManager *wm, ARegion *ar) 00134 { 00135 wmKeyMap *keymap; 00136 00137 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_STANDARD, ar->winx, ar->winy); 00138 00139 /* own keymap */ 00140 keymap= WM_keymap_find(wm->defaultconf, "Script", SPACE_SCRIPT, 0); 00141 WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); 00142 } 00143 00144 static void script_main_area_draw(const bContext *C, ARegion *ar) 00145 { 00146 /* draw entirely, view changes should be handled here */ 00147 SpaceScript *sscript= (SpaceScript*)CTX_wm_space_data(C); 00148 View2D *v2d= &ar->v2d; 00149 00150 /* clear and setup matrix */ 00151 UI_ThemeClearColor(TH_BACK); 00152 glClear(GL_COLOR_BUFFER_BIT); 00153 00154 UI_view2d_view_ortho(v2d); 00155 00156 /* data... */ 00157 // BPY_script_exec(C, "/root/blender-svn/blender25/test.py", NULL); 00158 00159 #ifdef WITH_PYTHON 00160 if (sscript->script) { 00161 // BPY_run_script_space_draw(C, sscript); 00162 } 00163 #else 00164 (void)sscript; 00165 #endif 00166 00167 /* reset view matrix */ 00168 UI_view2d_view_restore(C); 00169 00170 /* scrollers? */ 00171 } 00172 00173 /* add handlers, stuff you only do once or on area/region changes */ 00174 static void script_header_area_init(wmWindowManager *UNUSED(wm), ARegion *ar) 00175 { 00176 ED_region_header_init(ar); 00177 } 00178 00179 static void script_header_area_draw(const bContext *C, ARegion *ar) 00180 { 00181 ED_region_header(C, ar); 00182 } 00183 00184 static void script_main_area_listener(ARegion *UNUSED(ar), wmNotifier *UNUSED(wmn)) 00185 { 00186 /* context changes */ 00187 // XXX - Todo, need the ScriptSpace accessible to get the python script to run. 00188 // BPY_run_script_space_listener() 00189 } 00190 00191 /* only called once, from space/spacetypes.c */ 00192 void ED_spacetype_script(void) 00193 { 00194 SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype script"); 00195 ARegionType *art; 00196 00197 st->spaceid= SPACE_SCRIPT; 00198 strncpy(st->name, "Script", BKE_ST_MAXNAME); 00199 00200 st->new= script_new; 00201 st->free= script_free; 00202 st->init= script_init; 00203 st->duplicate= script_duplicate; 00204 st->operatortypes= script_operatortypes; 00205 st->keymap= script_keymap; 00206 00207 /* regions: main window */ 00208 art= MEM_callocN(sizeof(ARegionType), "spacetype script region"); 00209 art->regionid = RGN_TYPE_WINDOW; 00210 art->init= script_main_area_init; 00211 art->draw= script_main_area_draw; 00212 art->listener= script_main_area_listener; 00213 art->keymapflag= ED_KEYMAP_VIEW2D| ED_KEYMAP_UI|ED_KEYMAP_FRAMES; // XXX need to further test this ED_KEYMAP_UI is needed for button interaction 00214 00215 BLI_addhead(&st->regiontypes, art); 00216 00217 /* regions: header */ 00218 art= MEM_callocN(sizeof(ARegionType), "spacetype script region"); 00219 art->regionid = RGN_TYPE_HEADER; 00220 art->prefsizey= HEADERY; 00221 art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D|ED_KEYMAP_HEADER; 00222 00223 art->init= script_header_area_init; 00224 art->draw= script_header_area_draw; 00225 00226 BLI_addhead(&st->regiontypes, art); 00227 00228 00229 BKE_spacetype_register(st); 00230 } 00231