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