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) 2001-2002 by NaN Holding BV.
21 * All rights reserved.
23 * The Original Code is: drawtext.c.
25 * Contributor(s): Willian Padovani Germano.
27 * ***** END GPL LICENSE BLOCK *****
42 #include "MEM_guardedalloc.h"
47 #include "BLI_blenlib.h"
49 #include "DNA_space_types.h"
50 #include "DNA_screen_types.h"
51 #include "DNA_userdef_types.h"
53 #include "BKE_utildefines.h"
55 #include "BKE_global.h"
58 #ifndef DISABLE_PYTHON
59 #include "BPY_extern.h"
63 #include "BIF_keyval.h"
64 #include "BIF_interface.h"
65 #include "BIF_drawscript.h"
66 #include "BIF_editfont.h"
67 #include "BIF_spacetypes.h"
68 #include "BIF_usiblender.h"
69 #include "BIF_screen.h"
70 #include "BIF_toolbox.h"
71 #include "BIF_space.h"
72 #include "BIF_mywindow.h"
74 #include "BSE_filesel.h"
78 #include "interface.h"
80 void drawscriptspace(ScrArea *sa, void *spacedata);
81 void winqreadscriptspace(struct ScrArea *sa, void *spacedata, struct BWinEvent *evt);
83 void drawscriptspace(ScrArea *sa, void *spacedata)
85 SpaceScript *sc = curarea->spacedata.first;
86 Script *script = NULL;
88 glClearColor(0.6, 0.6, 0.6, 1.0);
89 glClear(GL_COLOR_BUFFER_BIT);
90 myortho2(-0.5, curarea->winrct.xmax-curarea->winrct.xmin-0.5, -0.5, curarea->winrct.ymax-curarea->winrct.ymin-0.5);
95 if (!sc->script) return;
99 /* Is this script loaded from a file and it needs running??? */
100 if ( (G.f & G_DOSCRIPTLINKS) &&
101 script->scriptname[0] != '\0' &&
102 (script->flags == 0 &&
103 script->py_event == NULL &&
104 script->py_button == NULL &&
105 script->py_draw == NULL )
107 if (!BPY_run_script(script)) {
108 /* if this fails, script will be free'd */
114 if (script->py_draw) {
115 BPY_spacescript_do_pywin_draw(sc);
116 } else if (!script->flags && !script->py_event && !script->py_button) {
117 /* quick hack for 2.37a for scripts that call the progress bar inside a
118 * file selector callback, to show previous space after finishing, w/o
119 * needing an event */
120 addqueue(curarea->win, MOUSEX, 0);
123 #endif /* DISABLE_PYTHON */
126 void winqreadscriptspace(struct ScrArea *sa, void *spacedata, struct BWinEvent *evt)
128 #ifndef DISABLE_PYTHON
129 unsigned short event = evt->event;
130 short val = evt->val;
131 char ascii = evt->ascii;
132 SpaceScript *sc = curarea->spacedata.first;
133 Script *script = sc->script;
136 /* Is this script loaded from a file and it needs running??? */
137 if ( (G.f & G_DOSCRIPTLINKS) &&
138 script->scriptname[0] != '\0' &&
139 (script->flags == 0 &&
140 script->py_event == NULL &&
141 script->py_button == NULL &&
142 script->py_draw == NULL )
144 if (!BPY_run_script(script)) {
145 /* if this fails, script will be free'd */
152 if (script->py_event || script->py_button)
153 BPY_spacescript_do_pywin_event(sc, event, val, ascii);
155 /* for file/image sel scripts: if user leaves file/image selection space,
156 * this frees the script (since it can't be accessed anymore): */
157 else if (script->flags == SCRIPT_FILESEL) {
159 script->lastspace = SPACE_SCRIPT;
162 if (!script->flags) {/* finished with this script, let's free it */
163 if (script->lastspace != SPACE_SCRIPT)
164 newspace (curarea, script->lastspace);
165 BPY_free_finished_script(script);
171 if (val && (G.qual & LR_CTRLKEY) && okee("Quit Blender")) exit_usiblender();
178 void free_scriptspace (SpaceScript *sc)
181 #ifndef DISABLE_PYTHON
182 /*free buttons references*/
184 BPy_Set_DrawButtonsList(sc->but_refs);
185 BPy_Free_DrawButtonsList();