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 #include "BPY_extern.h"
61 #include "BIF_keyval.h"
62 #include "BIF_interface.h"
63 #include "BIF_drawscript.h"
64 #include "BIF_editfont.h"
65 #include "BIF_spacetypes.h"
66 #include "BIF_usiblender.h"
67 #include "BIF_screen.h"
68 #include "BIF_toolbox.h"
69 #include "BIF_space.h"
70 #include "BIF_mywindow.h"
72 #include "BSE_filesel.h"
76 #include "interface.h"
78 void drawscriptspace(ScrArea *sa, void *spacedata);
79 void winqreadscriptspace(struct ScrArea *sa, void *spacedata, struct BWinEvent *evt);
81 void drawscriptspace(ScrArea *sa, void *spacedata)
83 SpaceScript *sc = curarea->spacedata.first;
84 Script *script = NULL;
86 glClearColor(0.6, 0.6, 0.6, 1.0);
87 glClear(GL_COLOR_BUFFER_BIT);
88 myortho2(-0.5, curarea->winrct.xmax-curarea->winrct.xmin-0.5, -0.5, curarea->winrct.ymax-curarea->winrct.ymin-0.5);
90 if (!sc->script) return;
94 /* Is this script loaded from a file and it needs running??? */
95 if ( (G.f & G_DOSCRIPTLINKS) &&
96 script->scriptname[0] != '\0' &&
97 (script->flags == 0 &&
98 script->py_event == NULL &&
99 script->py_button == NULL &&
100 script->py_draw == NULL )
102 if (!BPY_run_script(script)) {
103 /* if this fails, script will be free'd */
109 if (script->py_draw) {
110 BPY_spacescript_do_pywin_draw(sc);
111 } else if (!script->flags && !script->py_event && !script->py_button) {
112 /* quick hack for 2.37a for scripts that call the progress bar inside a
113 * file selector callback, to show previous space after finishing, w/o
114 * needing an event */
115 addqueue(curarea->win, MOUSEX, 0);
120 void winqreadscriptspace(struct ScrArea *sa, void *spacedata, struct BWinEvent *evt)
122 unsigned short event = evt->event;
123 short val = evt->val;
124 char ascii = evt->ascii;
125 SpaceScript *sc = curarea->spacedata.first;
126 Script *script = sc->script;
129 /* Is this script loaded from a file and it needs running??? */
130 if ( (G.f & G_DOSCRIPTLINKS) &&
131 script->scriptname[0] != '\0' &&
132 (script->flags == 0 &&
133 script->py_event == NULL &&
134 script->py_button == NULL &&
135 script->py_draw == NULL )
137 if (!BPY_run_script(script)) {
138 /* if this fails, script will be free'd */
145 if (script->py_event || script->py_button)
146 BPY_spacescript_do_pywin_event(sc, event, val, ascii);
148 /* for file/image sel scripts: if user leaves file/image selection space,
149 * this frees the script (since it can't be accessed anymore): */
150 else if (script->flags == SCRIPT_FILESEL) {
152 script->lastspace = SPACE_SCRIPT;
155 if (!script->flags) {/* finished with this script, let's free it */
156 if (script->lastspace != SPACE_SCRIPT)
157 newspace (curarea, script->lastspace);
158 BPY_free_finished_script(script);
164 if (val && (G.qual & LR_CTRLKEY) && okee("Quit Blender")) exit_usiblender();
170 void free_scriptspace (SpaceScript *sc)
174 /*free buttons references*/
176 BPy_Set_DrawButtonsList(sc->but_refs);
177 BPy_Free_DrawButtonsList();