2003-12-14 01:18:09 +00:00
|
|
|
/**
|
|
|
|
|
* $Id$
|
|
|
|
|
*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
2003-12-14 01:18:09 +00:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
2008-04-16 22:40:48 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2003-12-14 01:18:09 +00:00
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* The Original Code is: drawtext.c.
|
|
|
|
|
*
|
|
|
|
|
* Contributor(s): Willian Padovani Germano.
|
|
|
|
|
*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2003-12-14 01:18:09 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#else
|
|
|
|
|
#include <io.h>
|
|
|
|
|
#endif
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
#include "PIL_time.h"
|
|
|
|
|
|
|
|
|
|
#include "BMF_Api.h"
|
|
|
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
|
|
|
|
|
|
#include "DNA_space_types.h"
|
|
|
|
|
#include "DNA_screen_types.h"
|
|
|
|
|
#include "DNA_userdef_types.h"
|
|
|
|
|
|
|
|
|
|
#include "BKE_utildefines.h"
|
|
|
|
|
#include "BKE_text.h"
|
|
|
|
|
#include "BKE_global.h"
|
|
|
|
|
#include "BKE_main.h"
|
|
|
|
|
|
|
|
|
|
#include "BPY_extern.h"
|
|
|
|
|
|
|
|
|
|
#include "BIF_gl.h"
|
|
|
|
|
#include "BIF_keyval.h"
|
|
|
|
|
#include "BIF_interface.h"
|
|
|
|
|
#include "BIF_drawscript.h"
|
|
|
|
|
#include "BIF_editfont.h"
|
|
|
|
|
#include "BIF_spacetypes.h"
|
|
|
|
|
#include "BIF_usiblender.h"
|
|
|
|
|
#include "BIF_screen.h"
|
|
|
|
|
#include "BIF_toolbox.h"
|
|
|
|
|
#include "BIF_space.h"
|
|
|
|
|
#include "BIF_mywindow.h"
|
|
|
|
|
|
|
|
|
|
#include "BSE_filesel.h"
|
|
|
|
|
|
|
|
|
|
#include "mydevice.h"
|
|
|
|
|
#include "blendef.h"
|
|
|
|
|
#include "interface.h"
|
|
|
|
|
|
|
|
|
|
void drawscriptspace(ScrArea *sa, void *spacedata);
|
|
|
|
|
void winqreadscriptspace(struct ScrArea *sa, void *spacedata, struct BWinEvent *evt);
|
|
|
|
|
|
|
|
|
|
void drawscriptspace(ScrArea *sa, void *spacedata)
|
|
|
|
|
{
|
|
|
|
|
SpaceScript *sc = curarea->spacedata.first;
|
BPython bug fixes:
- #2646 reported by Campbell: Python/Fileselector (moving from fileselector called by script to another space caused script to hang around open but not accessible)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2646&group_id=9
- #2676 reported by Wim Van Hoydonck: 2.37 python scripts gui: event 8 ignored (thanks Ton for discussing / pointing what to do, Ken Hughes for also working on a fix)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2676&group_id=9
- gui-less scripts with calls to progress bar inside fileselector callbacks didn't return to the previous space on exit (staying on Scripts win), requiring an event to do so (mouse movement, for example). Quick fix for now, will rework a little after 2.37a for a better alternative, not needing to move to the Scripts win at all.
- added syntax colors access to Window.Theme module.
Scripts:
- updates by Jean-Michel Soler: svg2obj (svg paths import), tex2uvbaker, fixfromarmature;
- updates by Campbell Barton: obj import / export, console;
- tiny: converted vrml97 export to unix line endings;
- updates in ac3d exporter, help browser, save theme.
Thanks all mentioned above.
2005-06-11 05:30:14 +00:00
|
|
|
Script *script = NULL;
|
2003-12-14 01:18:09 +00:00
|
|
|
|
|
|
|
|
glClearColor(0.6, 0.6, 0.6, 1.0);
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
|
myortho2(-0.5, curarea->winrct.xmax-curarea->winrct.xmin-0.5, -0.5, curarea->winrct.ymax-curarea->winrct.ymin-0.5);
|
|
|
|
|
|
2004-08-17 04:26:00 +00:00
|
|
|
if (!sc->script) return;
|
|
|
|
|
|
BPython bug fixes:
- #2646 reported by Campbell: Python/Fileselector (moving from fileselector called by script to another space caused script to hang around open but not accessible)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2646&group_id=9
- #2676 reported by Wim Van Hoydonck: 2.37 python scripts gui: event 8 ignored (thanks Ton for discussing / pointing what to do, Ken Hughes for also working on a fix)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2676&group_id=9
- gui-less scripts with calls to progress bar inside fileselector callbacks didn't return to the previous space on exit (staying on Scripts win), requiring an event to do so (mouse movement, for example). Quick fix for now, will rework a little after 2.37a for a better alternative, not needing to move to the Scripts win at all.
- added syntax colors access to Window.Theme module.
Scripts:
- updates by Jean-Michel Soler: svg2obj (svg paths import), tex2uvbaker, fixfromarmature;
- updates by Campbell Barton: obj import / export, console;
- tiny: converted vrml97 export to unix line endings;
- updates in ac3d exporter, help browser, save theme.
Thanks all mentioned above.
2005-06-11 05:30:14 +00:00
|
|
|
script = sc->script;
|
|
|
|
|
|
2008-03-06 21:25:15 +00:00
|
|
|
/* Is this script loaded from a file and it needs running??? */
|
|
|
|
|
if ( (G.f & G_DOSCRIPTLINKS) &&
|
|
|
|
|
script->scriptname[0] != '\0' &&
|
2008-03-07 03:24:23 +00:00
|
|
|
(script->flags == 0 &&
|
2008-03-06 21:25:15 +00:00
|
|
|
script->py_event == NULL &&
|
|
|
|
|
script->py_button == NULL &&
|
|
|
|
|
script->py_draw == NULL )
|
|
|
|
|
) {
|
|
|
|
|
if (!BPY_run_script(script)) {
|
|
|
|
|
/* if this fails, script will be free'd */
|
|
|
|
|
script = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-04 16:32:13 +00:00
|
|
|
if (script) {
|
|
|
|
|
if (script->py_draw) {
|
|
|
|
|
BPY_spacescript_do_pywin_draw(sc);
|
|
|
|
|
} else if (!script->flags && !script->py_event && !script->py_button) {
|
|
|
|
|
/* quick hack for 2.37a for scripts that call the progress bar inside a
|
|
|
|
|
* file selector callback, to show previous space after finishing, w/o
|
|
|
|
|
* needing an event */
|
|
|
|
|
addqueue(curarea->win, MOUSEX, 0);
|
|
|
|
|
}
|
BPython bug fixes:
- #2646 reported by Campbell: Python/Fileselector (moving from fileselector called by script to another space caused script to hang around open but not accessible)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2646&group_id=9
- #2676 reported by Wim Van Hoydonck: 2.37 python scripts gui: event 8 ignored (thanks Ton for discussing / pointing what to do, Ken Hughes for also working on a fix)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2676&group_id=9
- gui-less scripts with calls to progress bar inside fileselector callbacks didn't return to the previous space on exit (staying on Scripts win), requiring an event to do so (mouse movement, for example). Quick fix for now, will rework a little after 2.37a for a better alternative, not needing to move to the Scripts win at all.
- added syntax colors access to Window.Theme module.
Scripts:
- updates by Jean-Michel Soler: svg2obj (svg paths import), tex2uvbaker, fixfromarmature;
- updates by Campbell Barton: obj import / export, console;
- tiny: converted vrml97 export to unix line endings;
- updates in ac3d exporter, help browser, save theme.
Thanks all mentioned above.
2005-06-11 05:30:14 +00:00
|
|
|
}
|
2003-12-14 01:18:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void winqreadscriptspace(struct ScrArea *sa, void *spacedata, struct BWinEvent *evt)
|
|
|
|
|
{
|
|
|
|
|
unsigned short event = evt->event;
|
|
|
|
|
short val = evt->val;
|
BPython:
- Made Blender.event var (previously only used by script links) hold ascii value -- where it applies -- of current event during events callback registered with Draw.Register(gui, events, button_events). Useful for gui scripts like Campbell's Python console. No problem using this var to hold the value, since in gui scripts it was not used (always None).
- Updated Window and Window.Theme with new theme vars and the Time space.
- Script links:
-- Added "Render" event for script links (runs twice, second time as "PostEvent", for clean-up actions). Now FrameChanged links don't run when a single pic is rendered.
-- Added "Enable Script Links" button in the script buttons tab. Now this bit gets saved in .blends along with the rest of G.f, so users can define per .blend if they are on or off by default. "blender -y" also disables all slinks as happened before with OnLoad ones only.
-- Other small changes in the script buttons tab:
When a link is added (button "new"), it becomes the active one for the window, no need to press a button to reach it.
Also, a pupmenu showing all available texts is shown when "new" is pressed, so users can choose a text w/o having to type. Cancel the popup to leave the string button empty (link exists, but has no script assigned). A pulldown would be better UI-wise, but it's kinda weird to show both scripts and normal texts (Blender doesn't differentiate them) in a script links pulldown. With a popup we can show only texts ending in ".py" (not done in this commit, need opinions) and if the script has no or another extension, case of many in old and current .blend's, there's still the string box for writing its name.
-- Implemented Ton's space handler script links:
Right now only for the 3d View, but it's trivial to add for others. There are two types: EVENT, to receive 3d View events from a chosen window and DRAW, to draw on the window. Ton's idea was to give scripts a controlled way to integrate better within Blender.
Here's how it works:
- scripts must have a proper header, like:
# SPACEHANDLER.VIEW3D.EVENT
and then they are shown in 3d View's View menu, "Space Handler Scripts" submenu. Check (mark, click on it) a script to make it active.
EVENT handlers should consult the Blender.event var to get the current event, which can be compared with values from the Draw module:
import Blender
from Blender import Draw
evt = Blender.event
if evt == Draw.AKEY:
print "a"
elif evt == Draw.LEFTMOUSE:
print "left mouse button"
else:
return # ignore, pass event back to Blender
Blender.event = None # tell Blender not to process itself the event
DRAW handlers are free to draw to their owner 3D View. OpenGL attributes and modelview and projection matrices are pushed before running the handler and poped when it finishes.
To communicate between EVENT and DRAW handler scripts we have the Blender.Registry module, as always.
Still need to code some nice example, which should also serve to test properly space handlers. Simple tests went fine.
- doc updates about the additions.
=======
Note: the UI part of the space handlers and script links is of course open for changes, I just tried to make it understandable. Probably we won't use the scriptlinks icon for "None Available" (check 3d View -> View -> Space Handler Scripts), though it hints at what space handlers are. The tooltips may not be accepted either, since other menus don't use them. Opinions welcomed.
2005-05-08 21:20:34 +00:00
|
|
|
char ascii = evt->ascii;
|
2003-12-14 01:18:09 +00:00
|
|
|
SpaceScript *sc = curarea->spacedata.first;
|
|
|
|
|
Script *script = sc->script;
|
|
|
|
|
|
2008-03-06 21:25:15 +00:00
|
|
|
if (script) {
|
|
|
|
|
/* Is this script loaded from a file and it needs running??? */
|
|
|
|
|
if ( (G.f & G_DOSCRIPTLINKS) &&
|
|
|
|
|
script->scriptname[0] != '\0' &&
|
2008-03-07 03:24:23 +00:00
|
|
|
(script->flags == 0 &&
|
2008-03-06 21:25:15 +00:00
|
|
|
script->py_event == NULL &&
|
|
|
|
|
script->py_button == NULL &&
|
|
|
|
|
script->py_draw == NULL )
|
|
|
|
|
) {
|
|
|
|
|
if (!BPY_run_script(script)) {
|
|
|
|
|
/* if this fails, script will be free'd */
|
|
|
|
|
script = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-12-14 01:18:09 +00:00
|
|
|
if (script) {
|
BPython bug fixes:
- #2646 reported by Campbell: Python/Fileselector (moving from fileselector called by script to another space caused script to hang around open but not accessible)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2646&group_id=9
- #2676 reported by Wim Van Hoydonck: 2.37 python scripts gui: event 8 ignored (thanks Ton for discussing / pointing what to do, Ken Hughes for also working on a fix)
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2676&group_id=9
- gui-less scripts with calls to progress bar inside fileselector callbacks didn't return to the previous space on exit (staying on Scripts win), requiring an event to do so (mouse movement, for example). Quick fix for now, will rework a little after 2.37a for a better alternative, not needing to move to the Scripts win at all.
- added syntax colors access to Window.Theme module.
Scripts:
- updates by Jean-Michel Soler: svg2obj (svg paths import), tex2uvbaker, fixfromarmature;
- updates by Campbell Barton: obj import / export, console;
- tiny: converted vrml97 export to unix line endings;
- updates in ac3d exporter, help browser, save theme.
Thanks all mentioned above.
2005-06-11 05:30:14 +00:00
|
|
|
if (script->py_event || script->py_button)
|
|
|
|
|
BPY_spacescript_do_pywin_event(sc, event, val, ascii);
|
|
|
|
|
|
|
|
|
|
/* for file/image sel scripts: if user leaves file/image selection space,
|
|
|
|
|
* this frees the script (since it can't be accessed anymore): */
|
|
|
|
|
else if (script->flags == SCRIPT_FILESEL) {
|
|
|
|
|
script->flags = 0;
|
|
|
|
|
script->lastspace = SPACE_SCRIPT;
|
|
|
|
|
}
|
2003-12-14 01:18:09 +00:00
|
|
|
|
2004-01-21 04:38:03 +00:00
|
|
|
if (!script->flags) {/* finished with this script, let's free it */
|
|
|
|
|
if (script->lastspace != SPACE_SCRIPT)
|
|
|
|
|
newspace (curarea, script->lastspace);
|
2003-12-14 01:18:09 +00:00
|
|
|
BPY_free_finished_script(script);
|
2004-01-21 04:38:03 +00:00
|
|
|
sc->script = NULL;
|
|
|
|
|
}
|
2003-12-14 01:18:09 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (event == QKEY)
|
2006-12-26 12:51:55 +00:00
|
|
|
if (val && (G.qual & LR_CTRLKEY) && okee("Quit Blender")) exit_usiblender();
|
2003-12-14 01:18:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void free_scriptspace (SpaceScript *sc)
|
|
|
|
|
{
|
|
|
|
|
if (!sc) return;
|
2007-07-27 06:14:25 +00:00
|
|
|
|
|
|
|
|
/*free buttons references*/
|
|
|
|
|
if (sc->but_refs) {
|
|
|
|
|
BPy_Set_DrawButtonsList(sc->but_refs);
|
|
|
|
|
BPy_Free_DrawButtonsList();
|
|
|
|
|
sc->but_refs = NULL;
|
|
|
|
|
}
|
2003-12-14 01:18:09 +00:00
|
|
|
sc->script = NULL;
|
|
|
|
|
}
|