| 
									
										
										
										
											2011-02-23 10:52:22 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2008-12-14 14:43:08 +00:00
										 |  |  |  * ***** BEGIN GPL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 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 | 
					
						
							|  |  |  |  * of the License, or (at your option) any later version.  | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 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. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  | 
					
						
							|  |  |  |  * Contributor(s): Blender Foundation | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * ***** END GPL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-27 20:29:51 +00:00
										 |  |  | /** \file blender/editors/space_script/space_script.c
 | 
					
						
							|  |  |  |  *  \ingroup spscript | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-14 14:43:08 +00:00
										 |  |  | #include <string.h>
 | 
					
						
							|  |  |  | #include <stdio.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "MEM_guardedalloc.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "BLI_blenlib.h"
 | 
					
						
							| 
									
										
										
										
											2009-11-10 20:43:45 +00:00
										 |  |  | #include "BLI_math.h"
 | 
					
						
							| 
									
										
										
										
											2008-12-14 14:43:08 +00:00
										 |  |  | #include "BLI_rand.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"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-14 17:55:27 +00:00
										 |  |  | #include "ED_space_api.h"
 | 
					
						
							| 
									
										
										
										
											2008-12-14 14:43:08 +00:00
										 |  |  | #include "ED_screen.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "BIF_gl.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "WM_api.h"
 | 
					
						
							|  |  |  | #include "WM_types.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "UI_resources.h"
 | 
					
						
							|  |  |  | #include "UI_view2d.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-31 04:11:39 +00:00
										 |  |  | #ifdef WITH_PYTHON
 | 
					
						
							| 
									
										
										
											
												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
										 |  |  | #include "BPY_extern.h"
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-08 11:48:19 +00:00
										 |  |  | #include "script_intern.h"  // own include
 | 
					
						
							| 
									
										
										
										
											2008-12-14 14:43:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-28 13:27:45 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | //static script_run_python(char *funcname, )
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-14 14:43:08 +00:00
										 |  |  | /* ******************** default callbacks for script space ***************** */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-16 08:03:28 +00:00
										 |  |  | static SpaceLink *script_new(const bContext *UNUSED(C)) | 
					
						
							| 
									
										
										
										
											2008-12-14 14:43:08 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	ARegion *ar; | 
					
						
							|  |  |  | 	SpaceScript *sscript; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-05-08 11:48:19 +00:00
										 |  |  | 	sscript = MEM_callocN(sizeof(SpaceScript), "initscript"); | 
					
						
							|  |  |  | 	sscript->spacetype = SPACE_SCRIPT; | 
					
						
							| 
									
										
										
										
											2008-12-14 14:43:08 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* header */ | 
					
						
							| 
									
										
										
										
											2012-05-08 11:48:19 +00:00
										 |  |  | 	ar = MEM_callocN(sizeof(ARegion), "header for script"); | 
					
						
							| 
									
										
										
										
											2008-12-14 14:43:08 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	BLI_addtail(&sscript->regionbase, ar); | 
					
						
							| 
									
										
										
										
											2012-05-08 11:48:19 +00:00
										 |  |  | 	ar->regiontype = RGN_TYPE_HEADER; | 
					
						
							|  |  |  | 	ar->alignment = RGN_ALIGN_BOTTOM; | 
					
						
							| 
									
										
										
										
											2008-12-14 14:43:08 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* main area */ | 
					
						
							| 
									
										
										
										
											2012-05-08 11:48:19 +00:00
										 |  |  | 	ar = MEM_callocN(sizeof(ARegion), "main area for script"); | 
					
						
							| 
									
										
										
										
											2008-12-14 14:43:08 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	BLI_addtail(&sscript->regionbase, ar); | 
					
						
							| 
									
										
										
										
											2012-05-08 11:48:19 +00:00
										 |  |  | 	ar->regiontype = RGN_TYPE_WINDOW; | 
					
						
							| 
									
										
										
										
											2008-12-14 14:43:08 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* channel list region XXX */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	return (SpaceLink *)sscript; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* not spacelink itself */ | 
					
						
							|  |  |  | static void script_free(SpaceLink *sl) | 
					
						
							|  |  |  | {	 | 
					
						
							| 
									
										
										
										
											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) { | 
					
						
							|  |  |  | // XXX		BPy_Set_DrawButtonsList(sscript->but_refs);
 | 
					
						
							|  |  |  | //		BPy_Free_DrawButtonsList();
 | 
					
						
							|  |  |  | 		sscript->but_refs = NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 	sscript->script = NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* spacetype; init callback */ | 
					
						
							| 
									
										
										
										
											2010-10-16 08:03:28 +00:00
										 |  |  | static void script_init(struct wmWindowManager *UNUSED(wm), ScrArea *UNUSED(sa)) | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							| 
									
										
										
										
											2008-12-14 14:43:08 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* clear or remove stuff from old */ | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	return (SpaceLink *)sscriptn; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* add handlers, stuff you only do once or on area/region changes */ | 
					
						
							|  |  |  | static void script_main_area_init(wmWindowManager *wm, ARegion *ar) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-09-17 21:36:02 +00:00
										 |  |  | 	wmKeyMap *keymap; | 
					
						
							| 
									
										
										
										
											2008-12-14 14:43:08 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2008-12-17 10:25:02 +00:00
										 |  |  | 	UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_STANDARD, ar->winx, ar->winy); | 
					
						
							| 
									
										
										
										
											2008-12-14 14:43:08 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* own keymap */ | 
					
						
							| 
									
										
										
										
											2012-03-24 02:51:46 +00:00
										 |  |  | 	keymap = WM_keymap_find(wm->defaultconf, "Script", SPACE_SCRIPT, 0); | 
					
						
							| 
									
										
										
										
											2008-12-14 14:43:08 +00:00
										 |  |  | 	WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void script_main_area_draw(const bContext *C, ARegion *ar) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* draw entirely, view changes should be handled here */ | 
					
						
							| 
									
										
										
										
											2012-05-08 11:48:19 +00:00
										 |  |  | 	SpaceScript *sscript = (SpaceScript *)CTX_wm_space_data(C); | 
					
						
							|  |  |  | 	View2D *v2d = &ar->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); | 
					
						
							| 
									
										
										
										
											2008-12-14 14:43:08 +00:00
										 |  |  | 	glClear(GL_COLOR_BUFFER_BIT); | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2010-10-14 01:22:14 +00:00
										 |  |  | 	UI_view2d_view_ortho(v2d); | 
					
						
							| 
									
										
										
										
											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);
 | 
					
						
							| 
									
										
										
										
											2008-12-14 14:43:08 +00: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
 | 
					
						
							| 
									
										
										
										
											2008-12-14 14:43:08 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* reset view matrix */ | 
					
						
							|  |  |  | 	UI_view2d_view_restore(C); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* scrollers? */ | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* add handlers, stuff you only do once or on area/region changes */ | 
					
						
							| 
									
										
										
										
											2010-10-16 08:03:28 +00:00
										 |  |  | static void script_header_area_init(wmWindowManager *UNUSED(wm), ARegion *ar) | 
					
						
							| 
									
										
										
										
											2008-12-14 14:43:08 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-06-18 19:48:55 +00:00
										 |  |  | 	ED_region_header_init(ar); | 
					
						
							| 
									
										
										
										
											2008-12-14 14:43:08 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void script_header_area_draw(const bContext *C, ARegion *ar) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-06-18 19:48:55 +00:00
										 |  |  | 	ED_region_header(C, ar); | 
					
						
							| 
									
										
										
										
											2008-12-14 14:43:08 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-16 08:03:28 +00:00
										 |  |  | static void script_main_area_listener(ARegion *UNUSED(ar), wmNotifier *UNUSED(wmn)) | 
					
						
							| 
									
										
										
										
											2008-12-14 14:43:08 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	/* context changes */ | 
					
						
							| 
									
										
										
										
											2009-02-28 13:27:45 +00:00
										 |  |  | 	// XXX - Todo, need the ScriptSpace accessible to get the python script to run.
 | 
					
						
							|  |  |  | 	// BPY_run_script_space_listener()
 | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							| 
									
										
										
										
											2008-12-14 14:43:08 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-05-08 11:48:19 +00:00
										 |  |  | 	st->new = script_new; | 
					
						
							|  |  |  | 	st->free = script_free; | 
					
						
							|  |  |  | 	st->init = script_init; | 
					
						
							|  |  |  | 	st->duplicate = script_duplicate; | 
					
						
							|  |  |  | 	st->operatortypes = script_operatortypes; | 
					
						
							|  |  |  | 	st->keymap = script_keymap; | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							| 
									
										
										
										
											2012-05-08 11:48:19 +00:00
										 |  |  | 	art->init = script_main_area_init; | 
					
						
							|  |  |  | 	art->draw = script_main_area_draw; | 
					
						
							|  |  |  | 	art->listener = script_main_area_listener; | 
					
						
							|  |  |  | 	art->keymapflag = ED_KEYMAP_VIEW2D |   ED_KEYMAP_UI | ED_KEYMAP_FRAMES; // XXX need to further test this ED_KEYMAP_UI is needed for button interaction
 | 
					
						
							| 
									
										
										
										
											2008-12-14 14:43:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	BLI_addhead(&st->regiontypes, art); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* 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; | 
					
						
							| 
									
										
										
										
											2008-12-14 14:43:08 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-05-08 11:48:19 +00:00
										 |  |  | 	art->init = script_header_area_init; | 
					
						
							|  |  |  | 	art->draw = script_header_area_draw; | 
					
						
							| 
									
										
										
										
											2008-12-14 14:43:08 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	BLI_addhead(&st->regiontypes, art); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	BKE_spacetype_register(st); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 |