2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2008-12-14 14:43:08 +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
|
2018-06-01 18:19:39 +02:00
|
|
|
* of the License, or (at your option) any later version.
|
2008-12-14 14:43:08 +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,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2008-12-14 14:43:08 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2008 Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup spscript
|
2011-02-27 20:29:51 +00:00
|
|
|
*/
|
|
|
|
|
2008-12-14 14:43:08 +00:00
|
|
|
#include <stdio.h>
|
2020-03-19 09:33:03 +01:00
|
|
|
#include <string.h>
|
2008-12-14 14:43:08 +00:00
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2008-12-14 14:43:08 +00:00
|
|
|
|
2008-12-18 02:56:48 +00:00
|
|
|
#include "BKE_context.h"
|
2008-12-14 14:43:08 +00:00
|
|
|
#include "BKE_screen.h"
|
|
|
|
|
|
|
|
#include "ED_screen.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "ED_space_api.h"
|
2008-12-14 14:43:08 +00:00
|
|
|
|
|
|
|
#include "WM_api.h"
|
|
|
|
|
|
|
|
#include "UI_resources.h"
|
|
|
|
#include "UI_view2d.h"
|
|
|
|
|
2010-10-31 04:11:39 +00:00
|
|
|
#ifdef WITH_PYTHON
|
2010-06-06 01:15:44 +00:00
|
|
|
#endif
|
2.5
More cleanup!
- removed old UI font completely, including from uiBeginBlock
- emboss hints for uiBlock only have three types now;
Regular, Pulldown, or "Nothing" (only icon/text)
- removed old font path from Userdef
- removed all old button theme hinting
- removed old "auto block" to merge buttons in groups
(was only in use for radiosity buttons)
And went over all warnings. One hooray for make giving clean output :)
Well, we need uniform definitions for warnings, so people at least fix
them... here's the real bad bugs I found:
- in mesh code, a call to editmesh mixed *em and *me
- in armature, ED_util.h was not included, so no warnings for wrong call
to ED_undo_push()
- The extern Py api .h was not included in the bpy_interface.c, showing
a several calls using different args.
Further just added the missing includes, and removed unused vars.
2009-04-14 15:59:52 +00:00
|
|
|
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "script_intern.h" /* own include */
|
2008-12-14 14:43:08 +00:00
|
|
|
|
2019-05-01 11:09:22 +10:00
|
|
|
// static script_run_python(char *funcname, )
|
2009-02-28 13:27:45 +00:00
|
|
|
|
2008-12-14 14:43:08 +00:00
|
|
|
/* ******************** default callbacks for script space ***************** */
|
|
|
|
|
2020-08-04 14:39:53 +02:00
|
|
|
static SpaceLink *script_create(const ScrArea *UNUSED(area), const Scene *UNUSED(scene))
|
2008-12-14 14:43:08 +00:00
|
|
|
{
|
2020-03-06 16:56:42 +01:00
|
|
|
ARegion *region;
|
2008-12-14 14:43:08 +00:00
|
|
|
SpaceScript *sscript;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-05-08 11:48:19 +00:00
|
|
|
sscript = MEM_callocN(sizeof(SpaceScript), "initscript");
|
|
|
|
sscript->spacetype = SPACE_SCRIPT;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2008-12-14 14:43:08 +00:00
|
|
|
/* header */
|
2020-03-06 16:56:42 +01:00
|
|
|
region = MEM_callocN(sizeof(ARegion), "header for script");
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2020-03-06 16:56:42 +01:00
|
|
|
BLI_addtail(&sscript->regionbase, region);
|
|
|
|
region->regiontype = RGN_TYPE_HEADER;
|
|
|
|
region->alignment = (U.uiflag & USER_HEADER_BOTTOM) ? RGN_ALIGN_BOTTOM : RGN_ALIGN_TOP;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2015-11-28 17:14:45 +01:00
|
|
|
/* main region */
|
2020-03-06 16:56:42 +01:00
|
|
|
region = MEM_callocN(sizeof(ARegion), "main region for script");
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2020-03-06 16:56:42 +01:00
|
|
|
BLI_addtail(&sscript->regionbase, region);
|
|
|
|
region->regiontype = RGN_TYPE_WINDOW;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2008-12-14 14:43:08 +00:00
|
|
|
/* channel list region XXX */
|
|
|
|
|
|
|
|
return (SpaceLink *)sscript;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* not spacelink itself */
|
|
|
|
static void script_free(SpaceLink *sl)
|
2018-06-04 09:31:30 +02:00
|
|
|
{
|
2012-05-08 11:48:19 +00:00
|
|
|
SpaceScript *sscript = (SpaceScript *)sl;
|
2008-12-14 14:43:08 +00:00
|
|
|
|
2010-10-31 04:11:39 +00:00
|
|
|
#ifdef WITH_PYTHON
|
2008-12-14 14:43:08 +00:00
|
|
|
/*free buttons references*/
|
|
|
|
if (sscript->but_refs) {
|
|
|
|
sscript->but_refs = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
sscript->script = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* spacetype; init callback */
|
2020-04-03 13:25:03 +02:00
|
|
|
static void script_init(struct wmWindowManager *UNUSED(wm), ScrArea *UNUSED(area))
|
2008-12-14 14:43:08 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static SpaceLink *script_duplicate(SpaceLink *sl)
|
|
|
|
{
|
2012-05-08 11:48:19 +00:00
|
|
|
SpaceScript *sscriptn = MEM_dupallocN(sl);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2008-12-14 14:43:08 +00:00
|
|
|
/* clear or remove stuff from old */
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2008-12-14 14:43:08 +00:00
|
|
|
return (SpaceLink *)sscriptn;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add handlers, stuff you only do once or on area/region changes */
|
2020-03-06 16:56:42 +01:00
|
|
|
static void script_main_region_init(wmWindowManager *wm, ARegion *region)
|
2008-12-14 14:43:08 +00:00
|
|
|
{
|
2009-09-17 21:36:02 +00:00
|
|
|
wmKeyMap *keymap;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2020-03-06 16:56:42 +01:00
|
|
|
UI_view2d_region_reinit(®ion->v2d, V2D_COMMONVIEW_STANDARD, region->winx, region->winy);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2008-12-14 14:43:08 +00:00
|
|
|
/* own keymap */
|
2018-08-31 13:36:14 +10:00
|
|
|
keymap = WM_keymap_ensure(wm->defaultconf, "Script", SPACE_SCRIPT, 0);
|
2020-03-06 16:56:42 +01:00
|
|
|
WM_event_add_keymap_handler_v2d_mask(®ion->handlers, keymap);
|
2008-12-14 14:43:08 +00:00
|
|
|
}
|
|
|
|
|
2020-03-06 16:56:42 +01:00
|
|
|
static void script_main_region_draw(const bContext *C, ARegion *region)
|
2008-12-14 14:43:08 +00:00
|
|
|
{
|
|
|
|
/* draw entirely, view changes should be handled here */
|
2012-05-08 11:48:19 +00:00
|
|
|
SpaceScript *sscript = (SpaceScript *)CTX_wm_space_data(C);
|
2020-03-06 16:56:42 +01:00
|
|
|
View2D *v2d = ®ion->v2d;
|
2010-04-06 07:02:16 +00:00
|
|
|
|
2008-12-14 14:43:08 +00:00
|
|
|
/* clear and setup matrix */
|
2010-04-06 07:02:16 +00:00
|
|
|
UI_ThemeClearColor(TH_BACK);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2010-10-14 01:22:14 +00:00
|
|
|
UI_view2d_view_ortho(v2d);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2008-12-14 14:43:08 +00:00
|
|
|
/* data... */
|
2011-01-05 02:08:54 +00:00
|
|
|
// BPY_script_exec(C, "/root/blender-svn/blender25/test.py", NULL);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2010-10-31 04:11:39 +00:00
|
|
|
#ifdef WITH_PYTHON
|
2009-02-28 13:27:45 +00:00
|
|
|
if (sscript->script) {
|
2011-01-05 02:08:54 +00:00
|
|
|
// BPY_run_script_space_draw(C, sscript);
|
2009-02-28 13:27:45 +00:00
|
|
|
}
|
2010-10-31 03:20:33 +00:00
|
|
|
#else
|
|
|
|
(void)sscript;
|
2009-03-06 14:58:37 +00:00
|
|
|
#endif
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2008-12-14 14:43:08 +00:00
|
|
|
/* reset view matrix */
|
|
|
|
UI_view2d_view_restore(C);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2008-12-14 14:43:08 +00:00
|
|
|
/* scrollers? */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add handlers, stuff you only do once or on area/region changes */
|
2020-03-06 16:56:42 +01:00
|
|
|
static void script_header_region_init(wmWindowManager *UNUSED(wm), ARegion *region)
|
2008-12-14 14:43:08 +00:00
|
|
|
{
|
2020-03-06 16:56:42 +01:00
|
|
|
ED_region_header_init(region);
|
2008-12-14 14:43:08 +00:00
|
|
|
}
|
|
|
|
|
2020-03-06 16:56:42 +01:00
|
|
|
static void script_header_region_draw(const bContext *C, ARegion *region)
|
2008-12-14 14:43:08 +00:00
|
|
|
{
|
2020-03-06 16:56:42 +01:00
|
|
|
ED_region_header(C, region);
|
2008-12-14 14:43:08 +00:00
|
|
|
}
|
|
|
|
|
2021-01-19 12:59:00 +11:00
|
|
|
static void script_main_region_listener(const wmRegionListenerParams *UNUSED(params))
|
2008-12-14 14:43:08 +00:00
|
|
|
{
|
2009-02-28 13:27:45 +00:00
|
|
|
/* XXX - Todo, need the ScriptSpace accessible to get the python script to run. */
|
2020-10-10 18:19:55 +11:00
|
|
|
#if 0
|
2009-02-28 13:27:45 +00:00
|
|
|
BPY_run_script_space_listener()
|
2020-10-10 18:19:55 +11:00
|
|
|
#endif
|
2008-12-14 14:43:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* only called once, from space/spacetypes.c */
|
|
|
|
void ED_spacetype_script(void)
|
|
|
|
{
|
2012-05-08 11:48:19 +00:00
|
|
|
SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype script");
|
2008-12-14 14:43:08 +00:00
|
|
|
ARegionType *art;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-08 11:48:19 +00:00
|
|
|
st->spaceid = SPACE_SCRIPT;
|
2009-12-19 22:37:51 +00:00
|
|
|
strncpy(st->name, "Script", BKE_ST_MAXNAME);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-08-04 14:39:53 +02:00
|
|
|
st->create = script_create;
|
2012-05-08 11:48:19 +00:00
|
|
|
st->free = script_free;
|
|
|
|
st->init = script_init;
|
|
|
|
st->duplicate = script_duplicate;
|
|
|
|
st->operatortypes = script_operatortypes;
|
|
|
|
st->keymap = script_keymap;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2008-12-14 14:43:08 +00:00
|
|
|
/* regions: main window */
|
2012-05-08 11:48:19 +00:00
|
|
|
art = MEM_callocN(sizeof(ARegionType), "spacetype script region");
|
2008-12-14 14:43:08 +00:00
|
|
|
art->regionid = RGN_TYPE_WINDOW;
|
2015-11-28 17:14:45 +01:00
|
|
|
art->init = script_main_region_init;
|
|
|
|
art->draw = script_main_region_draw;
|
|
|
|
art->listener = script_main_region_listener;
|
2019-04-22 00:18:34 +10:00
|
|
|
/* XXX: Need to further test this ED_KEYMAP_UI is needed for button interaction. */
|
|
|
|
art->keymapflag = ED_KEYMAP_VIEW2D | ED_KEYMAP_UI | ED_KEYMAP_FRAMES;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2008-12-14 14:43:08 +00:00
|
|
|
BLI_addhead(&st->regiontypes, art);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2008-12-14 14:43:08 +00:00
|
|
|
/* regions: header */
|
2012-05-08 11:48:19 +00:00
|
|
|
art = MEM_callocN(sizeof(ARegionType), "spacetype script region");
|
2008-12-14 14:43:08 +00:00
|
|
|
art->regionid = RGN_TYPE_HEADER;
|
2012-05-08 11:48:19 +00:00
|
|
|
art->prefsizey = HEADERY;
|
|
|
|
art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_HEADER;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-11-28 17:14:45 +01:00
|
|
|
art->init = script_header_region_init;
|
|
|
|
art->draw = script_header_region_draw;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2008-12-14 14:43:08 +00:00
|
|
|
BLI_addhead(&st->regiontypes, art);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2008-12-14 14:43:08 +00:00
|
|
|
BKE_spacetype_register(st);
|
|
|
|
}
|