~diresu/blender/blender-command-port

« back to all changes in this revision

Viewing changes to source/blender/src/drawscript.c

  • Committer: theeth
  • Date: 2008-10-14 16:52:04 UTC
  • Revision ID: vcs-imports@canonical.com-20081014165204-r32w2gm6s0osvdhn
copy back trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * $Id: drawscript.c 14444 2008-04-16 22:40:48Z hos $
 
3
 *
 
4
 * ***** BEGIN GPL LICENSE BLOCK *****
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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.
 
19
 *
 
20
 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
 
21
 * All rights reserved.
 
22
 *
 
23
 * The Original Code is: drawtext.c.
 
24
 *
 
25
 * Contributor(s): Willian Padovani Germano.
 
26
 *
 
27
 * ***** END GPL LICENSE BLOCK *****
 
28
 */
 
29
 
 
30
#include <stdlib.h>
 
31
#include <math.h>
 
32
 
 
33
#ifdef HAVE_CONFIG_H
 
34
#include <config.h>
 
35
#endif
 
36
 
 
37
#ifndef _WIN32
 
38
#include <unistd.h>
 
39
#else
 
40
#include <io.h>
 
41
#endif   
 
42
#include "MEM_guardedalloc.h"
 
43
#include "PIL_time.h"
 
44
 
 
45
#include "BMF_Api.h"
 
46
 
 
47
#include "BLI_blenlib.h"
 
48
 
 
49
#include "DNA_space_types.h"
 
50
#include "DNA_screen_types.h"
 
51
#include "DNA_userdef_types.h"
 
52
 
 
53
#include "BKE_utildefines.h"
 
54
#include "BKE_text.h"
 
55
#include "BKE_global.h"
 
56
#include "BKE_main.h"
 
57
 
 
58
#include "BPY_extern.h"
 
59
 
 
60
#include "BIF_gl.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"
 
71
 
 
72
#include "BSE_filesel.h"
 
73
 
 
74
#include "mydevice.h"
 
75
#include "blendef.h" 
 
76
#include "interface.h"
 
77
 
 
78
void drawscriptspace(ScrArea *sa, void *spacedata);
 
79
void winqreadscriptspace(struct ScrArea *sa, void *spacedata, struct BWinEvent *evt);
 
80
 
 
81
void drawscriptspace(ScrArea *sa, void *spacedata)
 
82
{
 
83
        SpaceScript *sc = curarea->spacedata.first;
 
84
        Script *script = NULL;
 
85
 
 
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);
 
89
 
 
90
        if (!sc->script) return;
 
91
 
 
92
        script = sc->script;
 
93
 
 
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 )
 
101
                ) {
 
102
                if (!BPY_run_script(script)) {
 
103
                        /* if this fails, script will be free'd */
 
104
                        script = NULL;
 
105
                }
 
106
        }
 
107
        
 
108
        if (script) {
 
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);
 
116
                }
 
117
        }
 
118
}
 
119
 
 
120
void winqreadscriptspace(struct ScrArea *sa, void *spacedata, struct BWinEvent *evt)
 
121
{
 
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;
 
127
 
 
128
        if (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 )
 
136
                   ) {
 
137
                        if (!BPY_run_script(script)) {
 
138
                                /* if this fails, script will be free'd */
 
139
                                script = NULL;
 
140
                        }
 
141
                }
 
142
        }
 
143
        
 
144
        if (script) {
 
145
                if (script->py_event || script->py_button)
 
146
                        BPY_spacescript_do_pywin_event(sc, event, val, ascii);
 
147
 
 
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) {
 
151
                        script->flags = 0;
 
152
                        script->lastspace = SPACE_SCRIPT;
 
153
                }
 
154
 
 
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);
 
159
                        sc->script = NULL;
 
160
                }
 
161
        }
 
162
        else {
 
163
                if (event == QKEY)
 
164
                        if (val && (G.qual & LR_CTRLKEY) && okee("Quit Blender")) exit_usiblender();
 
165
        }
 
166
 
 
167
        return;
 
168
}
 
169
 
 
170
void free_scriptspace (SpaceScript *sc)
 
171
{
 
172
        if (!sc) return;
 
173
        
 
174
        /*free buttons references*/
 
175
        if (sc->but_refs) {
 
176
                BPy_Set_DrawButtonsList(sc->but_refs);
 
177
                BPy_Free_DrawButtonsList();
 
178
                sc->but_refs = NULL;
 
179
        }
 
180
        sc->script = NULL;
 
181
}