4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * The Original Code is Copyright (C) 2008 Blender Foundation.
21 * All rights reserved.
24 * Contributor(s): Blender Foundation
26 * ***** END GPL LICENSE BLOCK *****
32 #include "DNA_object_types.h"
33 #include "DNA_space_types.h"
34 #include "DNA_scene_types.h"
35 #include "DNA_screen_types.h"
37 #include "MEM_guardedalloc.h"
39 #include "BLI_blenlib.h"
40 #include "BLI_arithb.h"
43 #include "BKE_colortools.h"
44 #include "BKE_global.h"
45 #include "BKE_screen.h"
47 #include "ED_space_api.h"
48 #include "ED_screen.h"
55 #include "UI_interface.h"
56 #include "UI_resources.h"
57 #include "UI_view2d.h"
59 #include "ED_markers.h"
61 #include "script_intern.h" // own include
63 /* ******************** default callbacks for script space ***************** */
65 static SpaceLink *script_new(void)
70 sscript= MEM_callocN(sizeof(SpaceScript), "initscript");
71 sscript->spacetype= SPACE_SCRIPT;
75 ar= MEM_callocN(sizeof(ARegion), "header for script");
77 BLI_addtail(&sscript->regionbase, ar);
78 ar->regiontype= RGN_TYPE_HEADER;
79 ar->alignment= RGN_ALIGN_BOTTOM;
82 ar= MEM_callocN(sizeof(ARegion), "main area for script");
84 BLI_addtail(&sscript->regionbase, ar);
85 ar->regiontype= RGN_TYPE_WINDOW;
87 /* channel list region XXX */
90 return (SpaceLink *)sscript;
93 /* not spacelink itself */
94 static void script_free(SpaceLink *sl)
96 SpaceScript *sscript= (SpaceScript*) sl;
98 #ifndef DISABLE_PYTHON
99 /*free buttons references*/
100 if (sscript->but_refs) {
101 // XXX BPy_Set_DrawButtonsList(sscript->but_refs);
102 // BPy_Free_DrawButtonsList();
103 sscript->but_refs = NULL;
106 sscript->script = NULL;
110 /* spacetype; init callback */
111 static void script_init(struct wmWindowManager *wm, ScrArea *sa)
116 static SpaceLink *script_duplicate(SpaceLink *sl)
118 SpaceScript *sscriptn= MEM_dupallocN(sl);
120 /* clear or remove stuff from old */
122 return (SpaceLink *)sscriptn;
127 /* add handlers, stuff you only do once or on area/region changes */
128 static void script_main_area_init(wmWindowManager *wm, ARegion *ar)
132 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_VIEWCANVAS, ar->winx, ar->winy);
135 keymap= WM_keymap_listbase(wm, "Script", SPACE_SCRIPT, 0); /* XXX weak? */
136 WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
139 static void script_main_area_draw(const bContext *C, ARegion *ar)
141 /* draw entirely, view changes should be handled here */
142 // SpaceScript *sscript= C->area->spacedata.first;
143 View2D *v2d= &ar->v2d;
146 /* clear and setup matrix */
147 UI_GetThemeColor3fv(TH_BACK, col);
148 glClearColor(col[0], col[1], col[2], 0.0);
149 glClear(GL_COLOR_BUFFER_BIT);
151 UI_view2d_view_ortho(C, v2d);
156 /* reset view matrix */
157 UI_view2d_view_restore(C);
162 void script_operatortypes(void)
167 void script_keymap(struct wmWindowManager *wm)
172 /* add handlers, stuff you only do once or on area/region changes */
173 static void script_header_area_init(wmWindowManager *wm, ARegion *ar)
175 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy);
178 static void script_header_area_draw(const bContext *C, ARegion *ar)
183 if(ED_screen_area_active(C))
184 UI_GetThemeColor3fv(TH_HEADER, col);
186 UI_GetThemeColor3fv(TH_HEADERDESEL, col);
188 glClearColor(col[0], col[1], col[2], 0.0);
189 glClear(GL_COLOR_BUFFER_BIT);
191 /* set view2d view matrix for scrolling (without scrollers) */
192 UI_view2d_view_ortho(C, &ar->v2d);
194 script_header_buttons(C, ar);
196 /* restore view matrix? */
197 UI_view2d_view_restore(C);
200 static void script_main_area_listener(ARegion *ar, wmNotifier *wmn)
202 /* context changes */
205 /* only called once, from space/spacetypes.c */
206 void ED_spacetype_script(void)
208 SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype script");
211 st->spaceid= SPACE_SCRIPT;
214 st->free= script_free;
215 st->init= script_init;
216 st->duplicate= script_duplicate;
217 st->operatortypes= script_operatortypes;
218 st->keymap= script_keymap;
220 /* regions: main window */
221 art= MEM_callocN(sizeof(ARegionType), "spacetype script region");
222 art->regionid = RGN_TYPE_WINDOW;
223 art->init= script_main_area_init;
224 art->draw= script_main_area_draw;
225 art->listener= script_main_area_listener;
226 art->keymapflag= ED_KEYMAP_VIEW2D;
228 BLI_addhead(&st->regiontypes, art);
230 /* regions: header */
231 art= MEM_callocN(sizeof(ARegionType), "spacetype script region");
232 art->regionid = RGN_TYPE_HEADER;
233 art->minsizey= HEADERY;
234 art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
236 art->init= script_header_area_init;
237 art->draw= script_header_area_draw;
239 BLI_addhead(&st->regiontypes, art);
242 BKE_spacetype_register(st);