2009-04-08 16:40:46 +00:00
|
|
|
/**
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* ***** 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,
|
|
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* Contributor(s): Blender Foundation (2009)
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2009-06-16 00:52:21 +00:00
|
|
|
#include "DNA_screen_types.h"
|
|
|
|
|
2009-04-08 16:40:46 +00:00
|
|
|
#include "RNA_define.h"
|
|
|
|
#include "RNA_types.h"
|
|
|
|
|
|
|
|
#include "rna_internal.h"
|
2009-04-19 17:12:16 +00:00
|
|
|
#include "RNA_enum_types.h"
|
2009-04-08 16:40:46 +00:00
|
|
|
|
2009-05-28 23:37:55 +00:00
|
|
|
#include "UI_interface.h"
|
|
|
|
|
2009-06-09 10:30:11 +00:00
|
|
|
#include "WM_types.h"
|
|
|
|
|
2009-04-08 16:40:46 +00:00
|
|
|
#ifdef RNA_RUNTIME
|
|
|
|
|
2009-04-19 13:37:59 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
#include "RNA_access.h"
|
|
|
|
|
|
|
|
#include "BLI_dynstr.h"
|
|
|
|
|
|
|
|
#include "BKE_context.h"
|
|
|
|
#include "BKE_report.h"
|
|
|
|
#include "BKE_screen.h"
|
|
|
|
|
|
|
|
#include "WM_api.h"
|
|
|
|
|
2009-04-19 17:12:16 +00:00
|
|
|
static ARegionType *region_type_find(ReportList *reports, int space_type, int region_type)
|
2009-04-19 13:37:59 +00:00
|
|
|
{
|
2009-04-19 17:12:16 +00:00
|
|
|
SpaceType *st;
|
|
|
|
ARegionType *art;
|
2009-04-19 13:37:59 +00:00
|
|
|
|
2009-04-19 17:12:16 +00:00
|
|
|
st= BKE_spacetype_from_id(space_type);
|
2009-04-19 13:37:59 +00:00
|
|
|
|
2009-04-19 17:12:16 +00:00
|
|
|
for(art= (st)? st->regiontypes.first: NULL; art; art= art->next) {
|
|
|
|
if (art->regionid==region_type)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* region type not found? abort */
|
|
|
|
if (art==NULL) {
|
|
|
|
BKE_report(reports, RPT_ERROR, "Region not found in spacetype.");
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-04-19 13:37:59 +00:00
|
|
|
|
2009-04-19 17:12:16 +00:00
|
|
|
return art;
|
2009-04-19 13:37:59 +00:00
|
|
|
}
|
|
|
|
|
2009-04-19 17:12:16 +00:00
|
|
|
/* Panel */
|
|
|
|
|
2009-04-19 13:37:59 +00:00
|
|
|
static int panel_poll(const bContext *C, PanelType *pt)
|
|
|
|
{
|
|
|
|
PointerRNA ptr;
|
2009-07-17 02:31:28 +00:00
|
|
|
ParameterList list;
|
2009-04-19 13:37:59 +00:00
|
|
|
FunctionRNA *func;
|
|
|
|
void *ret;
|
|
|
|
int visible;
|
|
|
|
|
2009-07-21 20:05:16 +00:00
|
|
|
RNA_pointer_create(NULL, pt->ext.srna, NULL, &ptr); /* dummy */
|
2009-04-19 13:37:59 +00:00
|
|
|
func= RNA_struct_find_function(&ptr, "poll");
|
|
|
|
|
2009-07-17 02:31:28 +00:00
|
|
|
RNA_parameter_list_create(&list, &ptr, func);
|
|
|
|
RNA_parameter_set_lookup(&list, "context", &C);
|
2009-07-21 20:05:16 +00:00
|
|
|
pt->ext.call(&ptr, func, &list);
|
2009-04-19 13:37:59 +00:00
|
|
|
|
2009-07-17 02:31:28 +00:00
|
|
|
RNA_parameter_get_lookup(&list, "visible", &ret);
|
2009-04-19 13:37:59 +00:00
|
|
|
visible= *(int*)ret;
|
|
|
|
|
2009-07-17 02:31:28 +00:00
|
|
|
RNA_parameter_list_free(&list);
|
2009-04-19 13:37:59 +00:00
|
|
|
|
|
|
|
return visible;
|
|
|
|
}
|
|
|
|
|
2009-04-19 17:12:16 +00:00
|
|
|
static void panel_draw(const bContext *C, Panel *pnl)
|
2009-04-19 13:37:59 +00:00
|
|
|
{
|
2009-04-19 17:12:16 +00:00
|
|
|
PointerRNA ptr;
|
2009-07-17 02:31:28 +00:00
|
|
|
ParameterList list;
|
2009-04-19 17:12:16 +00:00
|
|
|
FunctionRNA *func;
|
2009-04-19 13:37:59 +00:00
|
|
|
|
2009-07-21 20:05:16 +00:00
|
|
|
RNA_pointer_create(&CTX_wm_screen(C)->id, pnl->type->ext.srna, pnl, &ptr);
|
2009-04-19 17:12:16 +00:00
|
|
|
func= RNA_struct_find_function(&ptr, "draw");
|
2009-04-19 13:37:59 +00:00
|
|
|
|
2009-07-17 02:31:28 +00:00
|
|
|
RNA_parameter_list_create(&list, &ptr, func);
|
|
|
|
RNA_parameter_set_lookup(&list, "context", &C);
|
2009-07-21 20:05:16 +00:00
|
|
|
pnl->type->ext.call(&ptr, func, &list);
|
2009-04-19 17:12:16 +00:00
|
|
|
|
2009-07-17 02:31:28 +00:00
|
|
|
RNA_parameter_list_free(&list);
|
2009-04-19 13:37:59 +00:00
|
|
|
}
|
|
|
|
|
2009-05-19 17:13:33 +00:00
|
|
|
static void panel_draw_header(const bContext *C, Panel *pnl)
|
|
|
|
{
|
|
|
|
PointerRNA ptr;
|
2009-07-17 02:31:28 +00:00
|
|
|
ParameterList list;
|
2009-05-19 17:13:33 +00:00
|
|
|
FunctionRNA *func;
|
|
|
|
|
2009-07-21 20:05:16 +00:00
|
|
|
RNA_pointer_create(&CTX_wm_screen(C)->id, pnl->type->ext.srna, pnl, &ptr);
|
2009-05-19 17:13:33 +00:00
|
|
|
func= RNA_struct_find_function(&ptr, "draw_header");
|
|
|
|
|
2009-07-17 02:31:28 +00:00
|
|
|
RNA_parameter_list_create(&list, &ptr, func);
|
|
|
|
RNA_parameter_set_lookup(&list, "context", &C);
|
2009-07-21 20:05:16 +00:00
|
|
|
pnl->type->ext.call(&ptr, func, &list);
|
2009-05-19 17:13:33 +00:00
|
|
|
|
2009-07-17 02:31:28 +00:00
|
|
|
RNA_parameter_list_free(&list);
|
2009-05-19 17:13:33 +00:00
|
|
|
}
|
|
|
|
|
2009-04-19 17:12:16 +00:00
|
|
|
static void rna_Panel_unregister(const bContext *C, StructRNA *type)
|
2009-04-19 13:37:59 +00:00
|
|
|
{
|
|
|
|
ARegionType *art;
|
2009-04-19 17:12:16 +00:00
|
|
|
PanelType *pt= RNA_struct_blender_type_get(type);
|
2009-04-19 13:37:59 +00:00
|
|
|
|
2009-04-19 17:12:16 +00:00
|
|
|
if(!pt)
|
|
|
|
return;
|
|
|
|
if(!(art=region_type_find(NULL, pt->space_type, pt->region_type)))
|
|
|
|
return;
|
2009-04-19 13:37:59 +00:00
|
|
|
|
2009-08-16 07:26:29 +00:00
|
|
|
RNA_struct_free_extension(type, &pt->ext);
|
2009-08-14 12:29:55 +00:00
|
|
|
|
2009-04-19 17:12:16 +00:00
|
|
|
BLI_freelinkN(&art->paneltypes, pt);
|
|
|
|
RNA_struct_free(&BLENDER_RNA, type);
|
2009-04-19 13:37:59 +00:00
|
|
|
|
2009-04-19 17:12:16 +00:00
|
|
|
/* update while blender is running */
|
|
|
|
if(C)
|
2009-12-08 17:23:48 +00:00
|
|
|
WM_main_add_notifier(NC_SCREEN|NA_EDITED, NULL);
|
2009-04-19 13:37:59 +00:00
|
|
|
}
|
|
|
|
|
2.5: RNA, defining enums, pointers and collections properties is now
possible from python, but it's still work in progress.
Pointers and collections are restricted to types derived from
IDPropertyGroup (same as for operators), because RNA knows how to
allocate/deallocate those.
Collections have .add() and .remove(number) functions that can be
used. The remove function should be fixed to take an other argument
than a number.
With the IDPropertyGroup restriction, pointers are more like nested
structs. They don't have add(), remove() yet, not sure where to put
them. Currently the pointer / nested struct is automatically allocated
in the get() function, this needs to be fixed, rule is that RNA get()
will not change any data for thread safety.
Also, it is only possible to add properties to structs after they have
been registered, which needs to be improved as well.
Example code:
http://www.pasteall.org/7201/python
2009-08-18 01:29:25 +00:00
|
|
|
static StructRNA *rna_Panel_register(const bContext *C, ReportList *reports, void *data, const char *identifier, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
|
2009-04-19 13:37:59 +00:00
|
|
|
{
|
|
|
|
ARegionType *art;
|
2009-04-19 20:09:31 +00:00
|
|
|
PanelType *pt, dummypt = {0};
|
|
|
|
Panel dummypanel= {0};
|
2009-04-19 13:37:59 +00:00
|
|
|
PointerRNA dummyptr;
|
2009-05-27 00:03:49 +00:00
|
|
|
int have_function[3];
|
2009-04-19 13:37:59 +00:00
|
|
|
|
|
|
|
/* setup dummy panel & panel type to store static properties in */
|
|
|
|
dummypanel.type= &dummypt;
|
|
|
|
RNA_pointer_create(NULL, &RNA_Panel, &dummypanel, &dummyptr);
|
|
|
|
|
|
|
|
/* validate the python class */
|
|
|
|
if(validate(&dummyptr, data, have_function) != 0)
|
|
|
|
return NULL;
|
2009-12-22 10:04:15 +00:00
|
|
|
|
|
|
|
if(strlen(identifier) >= sizeof(dummypt.idname)) {
|
|
|
|
BKE_reportf(reports, RPT_ERROR, "registering panel class: '%s' is too long, maximum length is %d.", identifier, sizeof(dummypt.idname));
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-04-19 13:37:59 +00:00
|
|
|
|
2009-04-19 17:12:16 +00:00
|
|
|
if(!(art=region_type_find(reports, dummypt.space_type, dummypt.region_type)))
|
2009-04-19 13:37:59 +00:00
|
|
|
return NULL;
|
|
|
|
|
2009-04-19 17:12:16 +00:00
|
|
|
/* check if we have registered this panel type before, and remove it */
|
|
|
|
for(pt=art->paneltypes.first; pt; pt=pt->next) {
|
|
|
|
if(strcmp(pt->idname, dummypt.idname) == 0) {
|
2009-07-21 20:05:16 +00:00
|
|
|
if(pt->ext.srna)
|
|
|
|
rna_Panel_unregister(C, pt->ext.srna);
|
2009-07-10 11:59:45 +00:00
|
|
|
else
|
|
|
|
BLI_freelinkN(&art->paneltypes, pt);
|
2009-04-19 13:37:59 +00:00
|
|
|
break;
|
2009-04-19 17:12:16 +00:00
|
|
|
}
|
2009-04-19 13:37:59 +00:00
|
|
|
}
|
2009-04-19 17:12:16 +00:00
|
|
|
|
|
|
|
/* create a new panel type */
|
|
|
|
pt= MEM_callocN(sizeof(PanelType), "python buttons panel");
|
|
|
|
memcpy(pt, &dummypt, sizeof(dummypt));
|
2009-04-19 13:37:59 +00:00
|
|
|
|
2009-07-21 20:05:16 +00:00
|
|
|
pt->ext.srna= RNA_def_struct(&BLENDER_RNA, pt->idname, "Panel");
|
|
|
|
pt->ext.data= data;
|
|
|
|
pt->ext.call= call;
|
|
|
|
pt->ext.free= free;
|
|
|
|
RNA_struct_blender_type_set(pt->ext.srna, pt);
|
2009-04-19 13:37:59 +00:00
|
|
|
|
|
|
|
pt->poll= (have_function[0])? panel_poll: NULL;
|
|
|
|
pt->draw= (have_function[1])? panel_draw: NULL;
|
2009-05-19 17:13:33 +00:00
|
|
|
pt->draw_header= (have_function[2])? panel_draw_header: NULL;
|
2009-04-19 13:37:59 +00:00
|
|
|
|
2009-04-19 17:12:16 +00:00
|
|
|
BLI_addtail(&art->paneltypes, pt);
|
2009-04-19 13:37:59 +00:00
|
|
|
|
|
|
|
/* update while blender is running */
|
|
|
|
if(C)
|
2009-12-08 17:23:48 +00:00
|
|
|
WM_main_add_notifier(NC_SCREEN|NA_EDITED, NULL);
|
2009-04-19 13:37:59 +00:00
|
|
|
|
2009-07-21 20:05:16 +00:00
|
|
|
return pt->ext.srna;
|
2009-04-19 13:37:59 +00:00
|
|
|
}
|
|
|
|
|
2009-07-21 01:26:17 +00:00
|
|
|
static StructRNA* rna_Panel_refine(PointerRNA *ptr)
|
2009-04-19 17:12:16 +00:00
|
|
|
{
|
|
|
|
Panel *hdr= (Panel*)ptr->data;
|
2009-07-21 20:05:16 +00:00
|
|
|
return (hdr->type && hdr->type->ext.srna)? hdr->type->ext.srna: &RNA_Panel;
|
2009-04-19 17:12:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Header */
|
|
|
|
|
|
|
|
static void header_draw(const bContext *C, Header *hdr)
|
|
|
|
{
|
|
|
|
PointerRNA htr;
|
2009-07-17 02:31:28 +00:00
|
|
|
ParameterList list;
|
2009-04-19 17:12:16 +00:00
|
|
|
FunctionRNA *func;
|
|
|
|
|
2009-07-21 20:05:16 +00:00
|
|
|
RNA_pointer_create(&CTX_wm_screen(C)->id, hdr->type->ext.srna, hdr, &htr);
|
2009-04-19 17:12:16 +00:00
|
|
|
func= RNA_struct_find_function(&htr, "draw");
|
|
|
|
|
2009-07-17 02:31:28 +00:00
|
|
|
RNA_parameter_list_create(&list, &htr, func);
|
|
|
|
RNA_parameter_set_lookup(&list, "context", &C);
|
2009-07-21 20:05:16 +00:00
|
|
|
hdr->type->ext.call(&htr, func, &list);
|
2009-04-19 17:12:16 +00:00
|
|
|
|
2009-07-17 02:31:28 +00:00
|
|
|
RNA_parameter_list_free(&list);
|
2009-04-19 17:12:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void rna_Header_unregister(const bContext *C, StructRNA *type)
|
2009-04-19 13:37:59 +00:00
|
|
|
{
|
|
|
|
ARegionType *art;
|
2009-04-19 17:12:16 +00:00
|
|
|
HeaderType *ht= RNA_struct_blender_type_get(type);
|
2009-04-19 13:37:59 +00:00
|
|
|
|
2009-04-19 17:12:16 +00:00
|
|
|
if(!ht)
|
|
|
|
return;
|
|
|
|
if(!(art=region_type_find(NULL, ht->space_type, RGN_TYPE_HEADER)))
|
2009-04-19 13:37:59 +00:00
|
|
|
return;
|
|
|
|
|
2009-08-16 07:26:29 +00:00
|
|
|
RNA_struct_free_extension(type, &ht->ext);
|
2009-08-14 12:29:55 +00:00
|
|
|
|
2009-04-19 17:12:16 +00:00
|
|
|
BLI_freelinkN(&art->headertypes, ht);
|
2009-04-19 13:37:59 +00:00
|
|
|
RNA_struct_free(&BLENDER_RNA, type);
|
|
|
|
|
|
|
|
/* update while blender is running */
|
|
|
|
if(C)
|
2009-12-08 17:23:48 +00:00
|
|
|
WM_main_add_notifier(NC_SCREEN|NA_EDITED, NULL);
|
2009-04-19 13:37:59 +00:00
|
|
|
}
|
|
|
|
|
2.5: RNA, defining enums, pointers and collections properties is now
possible from python, but it's still work in progress.
Pointers and collections are restricted to types derived from
IDPropertyGroup (same as for operators), because RNA knows how to
allocate/deallocate those.
Collections have .add() and .remove(number) functions that can be
used. The remove function should be fixed to take an other argument
than a number.
With the IDPropertyGroup restriction, pointers are more like nested
structs. They don't have add(), remove() yet, not sure where to put
them. Currently the pointer / nested struct is automatically allocated
in the get() function, this needs to be fixed, rule is that RNA get()
will not change any data for thread safety.
Also, it is only possible to add properties to structs after they have
been registered, which needs to be improved as well.
Example code:
http://www.pasteall.org/7201/python
2009-08-18 01:29:25 +00:00
|
|
|
static StructRNA *rna_Header_register(const bContext *C, ReportList *reports, void *data, const char *identifier, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
|
2009-04-19 13:37:59 +00:00
|
|
|
{
|
2009-04-19 17:12:16 +00:00
|
|
|
ARegionType *art;
|
2009-04-19 20:09:31 +00:00
|
|
|
HeaderType *ht, dummyht = {0};
|
|
|
|
Header dummyheader= {0};
|
2009-04-19 17:12:16 +00:00
|
|
|
PointerRNA dummyhtr;
|
|
|
|
int have_function[1];
|
|
|
|
|
|
|
|
/* setup dummy header & header type to store static properties in */
|
|
|
|
dummyheader.type= &dummyht;
|
|
|
|
RNA_pointer_create(NULL, &RNA_Header, &dummyheader, &dummyhtr);
|
|
|
|
|
|
|
|
/* validate the python class */
|
|
|
|
if(validate(&dummyhtr, data, have_function) != 0)
|
|
|
|
return NULL;
|
2009-12-22 10:04:15 +00:00
|
|
|
|
|
|
|
if(strlen(identifier) >= sizeof(dummyht.idname)) {
|
|
|
|
BKE_reportf(reports, RPT_ERROR, "registering header class: '%s' is too long, maximum length is %d.", identifier, sizeof(dummyht.idname));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-04-19 17:12:16 +00:00
|
|
|
if(!(art=region_type_find(reports, dummyht.space_type, RGN_TYPE_HEADER)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* check if we have registered this header type before, and remove it */
|
|
|
|
for(ht=art->headertypes.first; ht; ht=ht->next) {
|
|
|
|
if(strcmp(ht->idname, dummyht.idname) == 0) {
|
2009-07-21 20:05:16 +00:00
|
|
|
if(ht->ext.srna)
|
|
|
|
rna_Header_unregister(C, ht->ext.srna);
|
2009-04-19 17:12:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create a new header type */
|
|
|
|
ht= MEM_callocN(sizeof(HeaderType), "python buttons header");
|
|
|
|
memcpy(ht, &dummyht, sizeof(dummyht));
|
|
|
|
|
2009-07-21 20:05:16 +00:00
|
|
|
ht->ext.srna= RNA_def_struct(&BLENDER_RNA, ht->idname, "Header");
|
|
|
|
ht->ext.data= data;
|
|
|
|
ht->ext.call= call;
|
|
|
|
ht->ext.free= free;
|
|
|
|
RNA_struct_blender_type_set(ht->ext.srna, ht);
|
2009-04-19 17:12:16 +00:00
|
|
|
|
|
|
|
ht->draw= (have_function[0])? header_draw: NULL;
|
|
|
|
|
|
|
|
BLI_addtail(&art->headertypes, ht);
|
|
|
|
|
|
|
|
/* update while blender is running */
|
|
|
|
if(C)
|
2009-12-08 17:23:48 +00:00
|
|
|
WM_main_add_notifier(NC_SCREEN|NA_EDITED, NULL);
|
2009-04-19 17:12:16 +00:00
|
|
|
|
2009-07-21 20:05:16 +00:00
|
|
|
return ht->ext.srna;
|
2009-04-19 17:12:16 +00:00
|
|
|
}
|
|
|
|
|
2009-07-21 01:26:17 +00:00
|
|
|
static StructRNA* rna_Header_refine(PointerRNA *htr)
|
2009-04-19 17:12:16 +00:00
|
|
|
{
|
|
|
|
Header *hdr= (Header*)htr->data;
|
2009-07-21 20:05:16 +00:00
|
|
|
return (hdr->type && hdr->type->ext.srna)? hdr->type->ext.srna: &RNA_Header;
|
2009-04-19 13:37:59 +00:00
|
|
|
}
|
|
|
|
|
2009-04-22 18:39:44 +00:00
|
|
|
/* Menu */
|
|
|
|
|
|
|
|
static int menu_poll(const bContext *C, MenuType *pt)
|
|
|
|
{
|
|
|
|
PointerRNA ptr;
|
2009-07-17 02:31:28 +00:00
|
|
|
ParameterList list;
|
2009-04-22 18:39:44 +00:00
|
|
|
FunctionRNA *func;
|
|
|
|
void *ret;
|
|
|
|
int visible;
|
|
|
|
|
2009-07-21 20:05:16 +00:00
|
|
|
RNA_pointer_create(NULL, pt->ext.srna, NULL, &ptr); /* dummy */
|
2009-04-22 18:39:44 +00:00
|
|
|
func= RNA_struct_find_function(&ptr, "poll");
|
|
|
|
|
2009-07-17 02:31:28 +00:00
|
|
|
RNA_parameter_list_create(&list, &ptr, func);
|
|
|
|
RNA_parameter_set_lookup(&list, "context", &C);
|
2009-07-21 20:05:16 +00:00
|
|
|
pt->ext.call(&ptr, func, &list);
|
2009-04-22 18:39:44 +00:00
|
|
|
|
2009-07-17 02:31:28 +00:00
|
|
|
RNA_parameter_get_lookup(&list, "visible", &ret);
|
2009-04-22 18:39:44 +00:00
|
|
|
visible= *(int*)ret;
|
|
|
|
|
2009-07-17 02:31:28 +00:00
|
|
|
RNA_parameter_list_free(&list);
|
2009-04-22 18:39:44 +00:00
|
|
|
|
|
|
|
return visible;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void menu_draw(const bContext *C, Menu *hdr)
|
|
|
|
{
|
|
|
|
PointerRNA mtr;
|
2009-07-17 02:31:28 +00:00
|
|
|
ParameterList list;
|
2009-04-22 18:39:44 +00:00
|
|
|
FunctionRNA *func;
|
|
|
|
|
2009-07-21 20:05:16 +00:00
|
|
|
RNA_pointer_create(&CTX_wm_screen(C)->id, hdr->type->ext.srna, hdr, &mtr);
|
2009-04-22 18:39:44 +00:00
|
|
|
func= RNA_struct_find_function(&mtr, "draw");
|
|
|
|
|
2009-07-17 02:31:28 +00:00
|
|
|
RNA_parameter_list_create(&list, &mtr, func);
|
|
|
|
RNA_parameter_set_lookup(&list, "context", &C);
|
2009-07-21 20:05:16 +00:00
|
|
|
hdr->type->ext.call(&mtr, func, &list);
|
2009-04-22 18:39:44 +00:00
|
|
|
|
2009-07-17 02:31:28 +00:00
|
|
|
RNA_parameter_list_free(&list);
|
2009-04-22 18:39:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void rna_Menu_unregister(const bContext *C, StructRNA *type)
|
|
|
|
{
|
|
|
|
MenuType *mt= RNA_struct_blender_type_get(type);
|
|
|
|
|
|
|
|
if(!mt)
|
|
|
|
return;
|
|
|
|
|
2009-08-16 07:26:29 +00:00
|
|
|
RNA_struct_free_extension(type, &mt->ext);
|
2009-08-14 12:29:55 +00:00
|
|
|
|
2009-10-08 19:06:32 +00:00
|
|
|
WM_menutype_freelink(mt);
|
|
|
|
|
2009-04-22 18:39:44 +00:00
|
|
|
RNA_struct_free(&BLENDER_RNA, type);
|
|
|
|
|
|
|
|
/* update while blender is running */
|
|
|
|
if(C)
|
2009-12-08 17:23:48 +00:00
|
|
|
WM_main_add_notifier(NC_SCREEN|NA_EDITED, NULL);
|
2009-04-22 18:39:44 +00:00
|
|
|
}
|
|
|
|
|
2.5: RNA, defining enums, pointers and collections properties is now
possible from python, but it's still work in progress.
Pointers and collections are restricted to types derived from
IDPropertyGroup (same as for operators), because RNA knows how to
allocate/deallocate those.
Collections have .add() and .remove(number) functions that can be
used. The remove function should be fixed to take an other argument
than a number.
With the IDPropertyGroup restriction, pointers are more like nested
structs. They don't have add(), remove() yet, not sure where to put
them. Currently the pointer / nested struct is automatically allocated
in the get() function, this needs to be fixed, rule is that RNA get()
will not change any data for thread safety.
Also, it is only possible to add properties to structs after they have
been registered, which needs to be improved as well.
Example code:
http://www.pasteall.org/7201/python
2009-08-18 01:29:25 +00:00
|
|
|
static StructRNA *rna_Menu_register(const bContext *C, ReportList *reports, void *data, const char *identifier, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
|
2009-04-22 18:39:44 +00:00
|
|
|
{
|
|
|
|
MenuType *mt, dummymt = {0};
|
|
|
|
Menu dummymenu= {0};
|
|
|
|
PointerRNA dummymtr;
|
|
|
|
int have_function[2];
|
|
|
|
|
|
|
|
/* setup dummy menu & menu type to store static properties in */
|
|
|
|
dummymenu.type= &dummymt;
|
|
|
|
RNA_pointer_create(NULL, &RNA_Menu, &dummymenu, &dummymtr);
|
|
|
|
|
|
|
|
/* validate the python class */
|
|
|
|
if(validate(&dummymtr, data, have_function) != 0)
|
|
|
|
return NULL;
|
2009-12-22 10:04:15 +00:00
|
|
|
|
|
|
|
if(strlen(identifier) >= sizeof(dummymt.idname)) {
|
|
|
|
BKE_reportf(reports, RPT_ERROR, "registering menu class: '%s' is too long, maximum length is %d.", identifier, sizeof(dummymt.idname));
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-04-22 18:39:44 +00:00
|
|
|
|
|
|
|
/* check if we have registered this menu type before, and remove it */
|
2009-10-08 19:06:32 +00:00
|
|
|
mt= WM_menutype_find(dummymt.idname, TRUE);
|
2009-10-06 13:04:31 +00:00
|
|
|
if(mt && mt->ext.srna)
|
|
|
|
rna_Menu_unregister(C, mt->ext.srna);
|
2009-04-22 18:39:44 +00:00
|
|
|
|
|
|
|
/* create a new menu type */
|
|
|
|
mt= MEM_callocN(sizeof(MenuType), "python buttons menu");
|
|
|
|
memcpy(mt, &dummymt, sizeof(dummymt));
|
|
|
|
|
2009-07-21 20:05:16 +00:00
|
|
|
mt->ext.srna= RNA_def_struct(&BLENDER_RNA, mt->idname, "Menu");
|
|
|
|
mt->ext.data= data;
|
|
|
|
mt->ext.call= call;
|
|
|
|
mt->ext.free= free;
|
|
|
|
RNA_struct_blender_type_set(mt->ext.srna, mt);
|
2009-04-22 18:39:44 +00:00
|
|
|
|
|
|
|
mt->poll= (have_function[0])? menu_poll: NULL;
|
|
|
|
mt->draw= (have_function[1])? menu_draw: NULL;
|
|
|
|
|
2009-10-08 19:06:32 +00:00
|
|
|
WM_menutype_add(mt);
|
2009-04-22 18:39:44 +00:00
|
|
|
|
|
|
|
/* update while blender is running */
|
|
|
|
if(C)
|
2009-12-08 17:23:48 +00:00
|
|
|
WM_main_add_notifier(NC_SCREEN|NA_EDITED, NULL);
|
2009-04-22 18:39:44 +00:00
|
|
|
|
2009-07-21 20:05:16 +00:00
|
|
|
return mt->ext.srna;
|
2009-04-22 18:39:44 +00:00
|
|
|
}
|
|
|
|
|
2009-07-21 01:26:17 +00:00
|
|
|
static StructRNA* rna_Menu_refine(PointerRNA *mtr)
|
2009-04-22 18:39:44 +00:00
|
|
|
{
|
|
|
|
Menu *hdr= (Menu*)mtr->data;
|
2009-07-21 20:05:16 +00:00
|
|
|
return (hdr->type && hdr->type->ext.srna)? hdr->type->ext.srna: &RNA_Menu;
|
2009-04-22 18:39:44 +00:00
|
|
|
}
|
|
|
|
|
2009-07-21 01:26:17 +00:00
|
|
|
static int rna_UILayout_active_get(PointerRNA *ptr)
|
2009-05-28 23:37:55 +00:00
|
|
|
{
|
|
|
|
return uiLayoutGetActive(ptr->data);
|
|
|
|
}
|
|
|
|
|
2009-07-21 01:26:17 +00:00
|
|
|
static void rna_UILayout_active_set(PointerRNA *ptr, int value)
|
2009-05-28 23:37:55 +00:00
|
|
|
{
|
RNA
* Mesh.add_geometry, Mesh.update and make indices editable. This
is without checking if they are valid still, no time now to
implement this.
* Also fix warnings in rna_ui.c, and a bug in CDDM_calc_edges.
Example code:
co = [0.0, 0.0, 0.0] + [1.0, 0.0, 0.0] + [0.0, 1.0, 0.0] + [1.0, 1.0, 0.0]
faces = [0, 1, 2, 0] + [1, 3, 2, 0]
mesh.add_geometry(4, 0, 2)
mesh.verts.foreach_set("co", co)
mesh.faces.foreach_set("verts", faces)
mesh.update()
2009-07-01 12:19:00 +00:00
|
|
|
uiLayoutSetActive(ptr->data, value);
|
2009-05-28 23:37:55 +00:00
|
|
|
}
|
|
|
|
|
2009-07-21 01:26:17 +00:00
|
|
|
static void rna_UILayout_op_context_set(PointerRNA *ptr, int value)
|
2009-06-09 10:30:11 +00:00
|
|
|
{
|
RNA
* Mesh.add_geometry, Mesh.update and make indices editable. This
is without checking if they are valid still, no time now to
implement this.
* Also fix warnings in rna_ui.c, and a bug in CDDM_calc_edges.
Example code:
co = [0.0, 0.0, 0.0] + [1.0, 0.0, 0.0] + [0.0, 1.0, 0.0] + [1.0, 1.0, 0.0]
faces = [0, 1, 2, 0] + [1, 3, 2, 0]
mesh.add_geometry(4, 0, 2)
mesh.verts.foreach_set("co", co)
mesh.faces.foreach_set("verts", faces)
mesh.update()
2009-07-01 12:19:00 +00:00
|
|
|
uiLayoutSetOperatorContext(ptr->data, value);
|
2009-06-09 10:30:11 +00:00
|
|
|
}
|
|
|
|
|
2009-07-21 01:26:17 +00:00
|
|
|
static int rna_UILayout_op_context_get(PointerRNA *ptr)
|
2009-06-09 10:30:11 +00:00
|
|
|
{
|
|
|
|
return uiLayoutGetOperatorContext(ptr->data);
|
|
|
|
}
|
|
|
|
|
2009-07-21 01:26:17 +00:00
|
|
|
static int rna_UILayout_enabled_get(PointerRNA *ptr)
|
2009-05-28 23:37:55 +00:00
|
|
|
{
|
|
|
|
return uiLayoutGetEnabled(ptr->data);
|
|
|
|
}
|
|
|
|
|
2009-07-21 01:26:17 +00:00
|
|
|
static void rna_UILayout_enabled_set(PointerRNA *ptr, int value)
|
2009-05-28 23:37:55 +00:00
|
|
|
{
|
RNA
* Mesh.add_geometry, Mesh.update and make indices editable. This
is without checking if they are valid still, no time now to
implement this.
* Also fix warnings in rna_ui.c, and a bug in CDDM_calc_edges.
Example code:
co = [0.0, 0.0, 0.0] + [1.0, 0.0, 0.0] + [0.0, 1.0, 0.0] + [1.0, 1.0, 0.0]
faces = [0, 1, 2, 0] + [1, 3, 2, 0]
mesh.add_geometry(4, 0, 2)
mesh.verts.foreach_set("co", co)
mesh.faces.foreach_set("verts", faces)
mesh.update()
2009-07-01 12:19:00 +00:00
|
|
|
uiLayoutSetEnabled(ptr->data, value);
|
2009-05-28 23:37:55 +00:00
|
|
|
}
|
|
|
|
|
2009-07-21 01:26:17 +00:00
|
|
|
#if 0
|
|
|
|
static int rna_UILayout_red_alert_get(PointerRNA *ptr)
|
2009-05-28 23:37:55 +00:00
|
|
|
{
|
|
|
|
return uiLayoutGetRedAlert(ptr->data);
|
|
|
|
}
|
|
|
|
|
2009-07-21 01:26:17 +00:00
|
|
|
static void rna_UILayout_red_alert_set(PointerRNA *ptr, int value)
|
2009-05-28 23:37:55 +00:00
|
|
|
{
|
RNA
* Mesh.add_geometry, Mesh.update and make indices editable. This
is without checking if they are valid still, no time now to
implement this.
* Also fix warnings in rna_ui.c, and a bug in CDDM_calc_edges.
Example code:
co = [0.0, 0.0, 0.0] + [1.0, 0.0, 0.0] + [0.0, 1.0, 0.0] + [1.0, 1.0, 0.0]
faces = [0, 1, 2, 0] + [1, 3, 2, 0]
mesh.add_geometry(4, 0, 2)
mesh.verts.foreach_set("co", co)
mesh.faces.foreach_set("verts", faces)
mesh.update()
2009-07-01 12:19:00 +00:00
|
|
|
uiLayoutSetRedAlert(ptr->data, value);
|
2009-05-28 23:37:55 +00:00
|
|
|
}
|
|
|
|
|
2009-07-21 01:26:17 +00:00
|
|
|
static int rna_UILayout_keep_aspect_get(PointerRNA *ptr)
|
2009-05-28 23:37:55 +00:00
|
|
|
{
|
|
|
|
return uiLayoutGetKeepAspect(ptr->data);
|
|
|
|
}
|
|
|
|
|
2009-07-21 01:26:17 +00:00
|
|
|
static void rna_UILayout_keep_aspect_set(PointerRNA *ptr, int value)
|
2009-05-28 23:37:55 +00:00
|
|
|
{
|
RNA
* Mesh.add_geometry, Mesh.update and make indices editable. This
is without checking if they are valid still, no time now to
implement this.
* Also fix warnings in rna_ui.c, and a bug in CDDM_calc_edges.
Example code:
co = [0.0, 0.0, 0.0] + [1.0, 0.0, 0.0] + [0.0, 1.0, 0.0] + [1.0, 1.0, 0.0]
faces = [0, 1, 2, 0] + [1, 3, 2, 0]
mesh.add_geometry(4, 0, 2)
mesh.verts.foreach_set("co", co)
mesh.faces.foreach_set("verts", faces)
mesh.update()
2009-07-01 12:19:00 +00:00
|
|
|
uiLayoutSetKeepAspect(ptr->data, value);
|
2009-05-28 23:37:55 +00:00
|
|
|
}
|
2009-07-21 01:26:17 +00:00
|
|
|
#endif
|
2009-05-28 23:37:55 +00:00
|
|
|
|
2009-07-21 01:26:17 +00:00
|
|
|
static int rna_UILayout_alignment_get(PointerRNA *ptr)
|
2009-05-28 23:37:55 +00:00
|
|
|
{
|
|
|
|
return uiLayoutGetAlignment(ptr->data);
|
|
|
|
}
|
|
|
|
|
2009-07-21 01:26:17 +00:00
|
|
|
static void rna_UILayout_alignment_set(PointerRNA *ptr, int value)
|
2009-05-28 23:37:55 +00:00
|
|
|
{
|
RNA
* Mesh.add_geometry, Mesh.update and make indices editable. This
is without checking if they are valid still, no time now to
implement this.
* Also fix warnings in rna_ui.c, and a bug in CDDM_calc_edges.
Example code:
co = [0.0, 0.0, 0.0] + [1.0, 0.0, 0.0] + [0.0, 1.0, 0.0] + [1.0, 1.0, 0.0]
faces = [0, 1, 2, 0] + [1, 3, 2, 0]
mesh.add_geometry(4, 0, 2)
mesh.verts.foreach_set("co", co)
mesh.faces.foreach_set("verts", faces)
mesh.update()
2009-07-01 12:19:00 +00:00
|
|
|
uiLayoutSetAlignment(ptr->data, value);
|
2009-05-28 23:37:55 +00:00
|
|
|
}
|
|
|
|
|
2009-07-21 01:26:17 +00:00
|
|
|
static float rna_UILayout_scale_x_get(PointerRNA *ptr)
|
2009-05-28 23:37:55 +00:00
|
|
|
{
|
2009-06-03 00:04:48 +00:00
|
|
|
return uiLayoutGetScaleX(ptr->data);
|
2009-05-28 23:37:55 +00:00
|
|
|
}
|
|
|
|
|
2009-07-21 01:26:17 +00:00
|
|
|
static void rna_UILayout_scale_x_set(PointerRNA *ptr, float value)
|
2009-05-28 23:37:55 +00:00
|
|
|
{
|
RNA
* Mesh.add_geometry, Mesh.update and make indices editable. This
is without checking if they are valid still, no time now to
implement this.
* Also fix warnings in rna_ui.c, and a bug in CDDM_calc_edges.
Example code:
co = [0.0, 0.0, 0.0] + [1.0, 0.0, 0.0] + [0.0, 1.0, 0.0] + [1.0, 1.0, 0.0]
faces = [0, 1, 2, 0] + [1, 3, 2, 0]
mesh.add_geometry(4, 0, 2)
mesh.verts.foreach_set("co", co)
mesh.faces.foreach_set("verts", faces)
mesh.update()
2009-07-01 12:19:00 +00:00
|
|
|
uiLayoutSetScaleX(ptr->data, value);
|
2009-06-03 00:04:48 +00:00
|
|
|
}
|
|
|
|
|
2009-07-21 01:26:17 +00:00
|
|
|
static float rna_UILayout_scale_y_get(PointerRNA *ptr)
|
2009-06-03 00:04:48 +00:00
|
|
|
{
|
|
|
|
return uiLayoutGetScaleY(ptr->data);
|
|
|
|
}
|
|
|
|
|
2009-07-21 01:26:17 +00:00
|
|
|
static void rna_UILayout_scale_y_set(PointerRNA *ptr, float value)
|
2009-06-03 00:04:48 +00:00
|
|
|
{
|
RNA
* Mesh.add_geometry, Mesh.update and make indices editable. This
is without checking if they are valid still, no time now to
implement this.
* Also fix warnings in rna_ui.c, and a bug in CDDM_calc_edges.
Example code:
co = [0.0, 0.0, 0.0] + [1.0, 0.0, 0.0] + [0.0, 1.0, 0.0] + [1.0, 1.0, 0.0]
faces = [0, 1, 2, 0] + [1, 3, 2, 0]
mesh.add_geometry(4, 0, 2)
mesh.verts.foreach_set("co", co)
mesh.faces.foreach_set("verts", faces)
mesh.update()
2009-07-01 12:19:00 +00:00
|
|
|
uiLayoutSetScaleY(ptr->data, value);
|
2009-05-28 23:37:55 +00:00
|
|
|
}
|
|
|
|
|
2009-06-09 10:30:11 +00:00
|
|
|
#else // RNA_RUNTIME
|
2009-04-08 16:40:46 +00:00
|
|
|
|
|
|
|
static void rna_def_ui_layout(BlenderRNA *brna)
|
|
|
|
{
|
|
|
|
StructRNA *srna;
|
2009-05-28 23:37:55 +00:00
|
|
|
PropertyRNA *prop;
|
|
|
|
|
|
|
|
static EnumPropertyItem alignment_items[] = {
|
2009-06-16 00:52:21 +00:00
|
|
|
{UI_LAYOUT_ALIGN_EXPAND, "EXPAND", 0, "Expand", ""},
|
|
|
|
{UI_LAYOUT_ALIGN_LEFT, "LEFT", 0, "Left", ""},
|
|
|
|
{UI_LAYOUT_ALIGN_CENTER, "CENTER", 0, "Center", ""},
|
2009-10-22 16:35:51 +00:00
|
|
|
{UI_LAYOUT_ALIGN_RIGHT, "RIGHT", 0, "Right", ""},
|
2009-06-16 00:52:21 +00:00
|
|
|
{0, NULL, 0, NULL, NULL}};
|
2009-06-09 10:30:11 +00:00
|
|
|
|
|
|
|
/* see WM_types.h */
|
|
|
|
static EnumPropertyItem operator_context_items[] = {
|
2009-06-16 00:52:21 +00:00
|
|
|
{WM_OP_INVOKE_DEFAULT, "INVOKE_DEFAULT", 0, "Invoke Default", ""},
|
|
|
|
{WM_OP_INVOKE_REGION_WIN, "INVOKE_REGION_WIN", 0, "Invoke Region Window", ""},
|
|
|
|
{WM_OP_INVOKE_AREA, "INVOKE_AREA", 0, "Invoke Area", ""},
|
|
|
|
{WM_OP_INVOKE_SCREEN, "INVOKE_SCREEN", 0, "Invoke Screen", ""},
|
|
|
|
{WM_OP_EXEC_DEFAULT, "EXEC_DEFAULT", 0, "Exec Default", ""},
|
|
|
|
{WM_OP_EXEC_REGION_WIN, "EXEC_REGION_WIN", 0, "Exec Region Window", ""},
|
|
|
|
{WM_OP_EXEC_AREA, "EXEC_AREA", 0, "Exec Area", ""},
|
|
|
|
{WM_OP_EXEC_SCREEN, "EXEC_SCREEN", 0, "Exec Screen", ""},
|
|
|
|
{0, NULL, 0, NULL, NULL}};
|
2009-07-21 01:26:17 +00:00
|
|
|
|
|
|
|
/* layout */
|
2009-04-08 16:40:46 +00:00
|
|
|
|
|
|
|
srna= RNA_def_struct(brna, "UILayout", NULL);
|
|
|
|
RNA_def_struct_sdna(srna, "uiLayout");
|
|
|
|
RNA_def_struct_ui_text(srna, "UI Layout", "User interface layout in a panel or header.");
|
|
|
|
|
2009-05-28 23:37:55 +00:00
|
|
|
prop= RNA_def_property(srna, "active", PROP_BOOLEAN, PROP_NONE);
|
|
|
|
RNA_def_property_boolean_funcs(prop, "rna_UILayout_active_get", "rna_UILayout_active_set");
|
2009-06-09 10:30:11 +00:00
|
|
|
|
|
|
|
prop= RNA_def_property(srna, "operator_context", PROP_ENUM, PROP_NONE);
|
|
|
|
RNA_def_property_enum_items(prop, operator_context_items);
|
|
|
|
RNA_def_property_enum_funcs(prop, "rna_UILayout_op_context_get", "rna_UILayout_op_context_set", NULL);
|
2009-05-28 23:37:55 +00:00
|
|
|
|
|
|
|
prop= RNA_def_property(srna, "enabled", PROP_BOOLEAN, PROP_NONE);
|
|
|
|
RNA_def_property_boolean_funcs(prop, "rna_UILayout_enabled_get", "rna_UILayout_enabled_set");
|
|
|
|
|
2009-07-21 01:26:17 +00:00
|
|
|
#if 0
|
2009-05-28 23:37:55 +00:00
|
|
|
prop= RNA_def_property(srna, "red_alert", PROP_BOOLEAN, PROP_NONE);
|
|
|
|
RNA_def_property_boolean_funcs(prop, "rna_UILayout_red_alert_get", "rna_UILayout_red_alert_set");
|
2009-07-21 01:26:17 +00:00
|
|
|
#endif
|
2009-05-28 23:37:55 +00:00
|
|
|
|
|
|
|
prop= RNA_def_property(srna, "alignment", PROP_ENUM, PROP_NONE);
|
|
|
|
RNA_def_property_enum_items(prop, alignment_items);
|
|
|
|
RNA_def_property_enum_funcs(prop, "rna_UILayout_alignment_get", "rna_UILayout_alignment_set", NULL);
|
|
|
|
|
2009-07-21 01:26:17 +00:00
|
|
|
#if 0
|
2009-05-28 23:37:55 +00:00
|
|
|
prop= RNA_def_property(srna, "keep_aspect", PROP_BOOLEAN, PROP_NONE);
|
|
|
|
RNA_def_property_boolean_funcs(prop, "rna_UILayout_keep_aspect_get", "rna_UILayout_keep_aspect_set");
|
2009-07-21 01:26:17 +00:00
|
|
|
#endif
|
2009-05-28 23:37:55 +00:00
|
|
|
|
2009-06-03 00:04:48 +00:00
|
|
|
prop= RNA_def_property(srna, "scale_x", PROP_FLOAT, PROP_UNSIGNED);
|
|
|
|
RNA_def_property_float_funcs(prop, "rna_UILayout_scale_x_get", "rna_UILayout_scale_x_set", NULL);
|
|
|
|
|
|
|
|
prop= RNA_def_property(srna, "scale_y", PROP_FLOAT, PROP_UNSIGNED);
|
|
|
|
RNA_def_property_float_funcs(prop, "rna_UILayout_scale_y_get", "rna_UILayout_scale_y_set", NULL);
|
2009-05-28 23:37:55 +00:00
|
|
|
|
2009-04-08 16:40:46 +00:00
|
|
|
RNA_api_ui_layout(srna);
|
|
|
|
}
|
|
|
|
|
2009-04-19 13:37:59 +00:00
|
|
|
static void rna_def_panel(BlenderRNA *brna)
|
|
|
|
{
|
|
|
|
StructRNA *srna;
|
|
|
|
PropertyRNA *prop;
|
|
|
|
FunctionRNA *func;
|
|
|
|
|
|
|
|
srna= RNA_def_struct(brna, "Panel", NULL);
|
2009-04-19 17:12:16 +00:00
|
|
|
RNA_def_struct_ui_text(srna, "Panel", "Panel containing buttons.");
|
2009-04-19 13:37:59 +00:00
|
|
|
RNA_def_struct_sdna(srna, "Panel");
|
|
|
|
RNA_def_struct_refine_func(srna, "rna_Panel_refine");
|
|
|
|
RNA_def_struct_register_funcs(srna, "rna_Panel_register", "rna_Panel_unregister");
|
|
|
|
|
2009-04-19 17:12:16 +00:00
|
|
|
/* poll */
|
2009-04-19 13:37:59 +00:00
|
|
|
func= RNA_def_function(srna, "poll", NULL);
|
|
|
|
RNA_def_function_ui_description(func, "Test if the panel is visible or not.");
|
|
|
|
RNA_def_function_flag(func, FUNC_REGISTER|FUNC_REGISTER_OPTIONAL);
|
|
|
|
RNA_def_function_return(func, RNA_def_boolean(func, "visible", 1, "", ""));
|
|
|
|
RNA_def_pointer(func, "context", "Context", "", "");
|
|
|
|
|
2009-04-19 17:12:16 +00:00
|
|
|
/* draw */
|
2009-04-19 13:37:59 +00:00
|
|
|
func= RNA_def_function(srna, "draw", NULL);
|
|
|
|
RNA_def_function_ui_description(func, "Draw buttons into the panel UI layout.");
|
|
|
|
RNA_def_function_flag(func, FUNC_REGISTER);
|
|
|
|
RNA_def_pointer(func, "context", "Context", "", "");
|
|
|
|
|
2009-05-19 17:13:33 +00:00
|
|
|
func= RNA_def_function(srna, "draw_header", NULL);
|
|
|
|
RNA_def_function_ui_description(func, "Draw buttons into the panel header UI layout.");
|
|
|
|
RNA_def_function_flag(func, FUNC_REGISTER);
|
|
|
|
RNA_def_pointer(func, "context", "Context", "", "");
|
|
|
|
|
2009-04-19 13:37:59 +00:00
|
|
|
prop= RNA_def_property(srna, "layout", PROP_POINTER, PROP_NONE);
|
|
|
|
RNA_def_property_struct_type(prop, "UILayout");
|
|
|
|
|
2009-07-28 16:46:14 +00:00
|
|
|
prop= RNA_def_property(srna, "text", PROP_STRING, PROP_NONE);
|
|
|
|
RNA_def_property_string_sdna(prop, NULL, "drawname");
|
|
|
|
|
2009-04-19 17:12:16 +00:00
|
|
|
/* registration */
|
2009-10-31 13:31:23 +00:00
|
|
|
prop= RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE);
|
2009-04-19 17:12:16 +00:00
|
|
|
RNA_def_property_string_sdna(prop, NULL, "type->idname");
|
2009-04-19 13:37:59 +00:00
|
|
|
RNA_def_property_flag(prop, PROP_REGISTER);
|
|
|
|
|
2009-10-31 13:31:23 +00:00
|
|
|
prop= RNA_def_property(srna, "bl_label", PROP_STRING, PROP_NONE);
|
2009-04-19 17:12:16 +00:00
|
|
|
RNA_def_property_string_sdna(prop, NULL, "type->label");
|
2009-04-19 13:37:59 +00:00
|
|
|
RNA_def_property_flag(prop, PROP_REGISTER);
|
|
|
|
|
2009-10-31 13:31:23 +00:00
|
|
|
prop= RNA_def_property(srna, "bl_space_type", PROP_ENUM, PROP_NONE);
|
2009-04-19 17:12:16 +00:00
|
|
|
RNA_def_property_enum_sdna(prop, NULL, "type->space_type");
|
|
|
|
RNA_def_property_enum_items(prop, space_type_items);
|
2009-04-19 13:37:59 +00:00
|
|
|
RNA_def_property_flag(prop, PROP_REGISTER);
|
|
|
|
|
2009-10-31 13:31:23 +00:00
|
|
|
prop= RNA_def_property(srna, "bl_region_type", PROP_ENUM, PROP_NONE);
|
2009-04-19 17:12:16 +00:00
|
|
|
RNA_def_property_enum_sdna(prop, NULL, "type->region_type");
|
|
|
|
RNA_def_property_enum_items(prop, region_type_items);
|
2009-04-19 13:37:59 +00:00
|
|
|
RNA_def_property_flag(prop, PROP_REGISTER);
|
|
|
|
|
2009-10-31 13:31:23 +00:00
|
|
|
prop= RNA_def_property(srna, "bl_context", PROP_STRING, PROP_NONE);
|
2009-04-19 17:12:16 +00:00
|
|
|
RNA_def_property_string_sdna(prop, NULL, "type->context");
|
2009-10-31 18:48:58 +00:00
|
|
|
RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL); /* should this be optional? - Campbell */
|
2009-06-16 01:08:39 +00:00
|
|
|
|
2009-10-31 13:31:23 +00:00
|
|
|
prop= RNA_def_property(srna, "bl_default_closed", PROP_BOOLEAN, PROP_NONE);
|
2009-06-16 01:08:39 +00:00
|
|
|
RNA_def_property_boolean_sdna(prop, NULL, "type->flag", PNL_DEFAULT_CLOSED);
|
2009-10-31 18:48:58 +00:00
|
|
|
RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
|
2009-07-08 15:34:41 +00:00
|
|
|
|
2009-10-31 13:31:23 +00:00
|
|
|
prop= RNA_def_property(srna, "bl_show_header", PROP_BOOLEAN, PROP_NONE);
|
2009-07-26 03:54:17 +00:00
|
|
|
RNA_def_property_boolean_negative_sdna(prop, NULL, "type->flag", PNL_NO_HEADER);
|
2009-10-31 18:48:58 +00:00
|
|
|
RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
|
2009-04-19 17:12:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void rna_def_header(BlenderRNA *brna)
|
|
|
|
{
|
|
|
|
StructRNA *srna;
|
|
|
|
PropertyRNA *prop;
|
|
|
|
FunctionRNA *func;
|
|
|
|
|
|
|
|
srna= RNA_def_struct(brna, "Header", NULL);
|
|
|
|
RNA_def_struct_ui_text(srna, "Header", "Editor header containing buttons.");
|
|
|
|
RNA_def_struct_sdna(srna, "Header");
|
|
|
|
RNA_def_struct_refine_func(srna, "rna_Header_refine");
|
|
|
|
RNA_def_struct_register_funcs(srna, "rna_Header_register", "rna_Header_unregister");
|
|
|
|
|
|
|
|
/* draw */
|
|
|
|
func= RNA_def_function(srna, "draw", NULL);
|
|
|
|
RNA_def_function_ui_description(func, "Draw buttons into the header UI layout.");
|
|
|
|
RNA_def_function_flag(func, FUNC_REGISTER);
|
|
|
|
RNA_def_pointer(func, "context", "Context", "", "");
|
|
|
|
|
2009-07-21 01:14:55 +00:00
|
|
|
RNA_define_verify_sdna(0); // not in sdna
|
|
|
|
|
2009-04-19 17:12:16 +00:00
|
|
|
prop= RNA_def_property(srna, "layout", PROP_POINTER, PROP_NONE);
|
2009-07-21 01:14:55 +00:00
|
|
|
RNA_def_property_pointer_sdna(prop, NULL, "layout");
|
2009-04-19 17:12:16 +00:00
|
|
|
RNA_def_property_struct_type(prop, "UILayout");
|
|
|
|
|
|
|
|
/* registration */
|
2009-10-31 13:31:23 +00:00
|
|
|
prop= RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE);
|
2009-04-19 17:12:16 +00:00
|
|
|
RNA_def_property_string_sdna(prop, NULL, "type->idname");
|
|
|
|
RNA_def_property_flag(prop, PROP_REGISTER);
|
|
|
|
|
2009-10-31 13:31:23 +00:00
|
|
|
prop= RNA_def_property(srna, "bl_space_type", PROP_ENUM, PROP_NONE);
|
2009-04-19 17:12:16 +00:00
|
|
|
RNA_def_property_enum_sdna(prop, NULL, "type->space_type");
|
|
|
|
RNA_def_property_enum_items(prop, space_type_items);
|
2009-04-19 13:37:59 +00:00
|
|
|
RNA_def_property_flag(prop, PROP_REGISTER);
|
2009-07-21 01:14:55 +00:00
|
|
|
|
|
|
|
RNA_define_verify_sdna(1);
|
2009-04-19 13:37:59 +00:00
|
|
|
}
|
|
|
|
|
2009-04-22 18:39:44 +00:00
|
|
|
static void rna_def_menu(BlenderRNA *brna)
|
|
|
|
{
|
|
|
|
StructRNA *srna;
|
|
|
|
PropertyRNA *prop;
|
|
|
|
FunctionRNA *func;
|
|
|
|
|
|
|
|
srna= RNA_def_struct(brna, "Menu", NULL);
|
|
|
|
RNA_def_struct_ui_text(srna, "Menu", "Editor menu containing buttons.");
|
|
|
|
RNA_def_struct_sdna(srna, "Menu");
|
|
|
|
RNA_def_struct_refine_func(srna, "rna_Menu_refine");
|
|
|
|
RNA_def_struct_register_funcs(srna, "rna_Menu_register", "rna_Menu_unregister");
|
|
|
|
|
|
|
|
/* poll */
|
|
|
|
func= RNA_def_function(srna, "poll", NULL);
|
|
|
|
RNA_def_function_ui_description(func, "Test if the menu is visible or not.");
|
|
|
|
RNA_def_function_flag(func, FUNC_REGISTER|FUNC_REGISTER_OPTIONAL);
|
|
|
|
RNA_def_function_return(func, RNA_def_boolean(func, "visible", 1, "", ""));
|
|
|
|
RNA_def_pointer(func, "context", "Context", "", "");
|
|
|
|
|
|
|
|
/* draw */
|
|
|
|
func= RNA_def_function(srna, "draw", NULL);
|
|
|
|
RNA_def_function_ui_description(func, "Draw buttons into the menu UI layout.");
|
|
|
|
RNA_def_function_flag(func, FUNC_REGISTER);
|
|
|
|
RNA_def_pointer(func, "context", "Context", "", "");
|
|
|
|
|
2009-07-21 01:14:55 +00:00
|
|
|
RNA_define_verify_sdna(0); // not in sdna
|
|
|
|
|
2009-04-22 18:39:44 +00:00
|
|
|
prop= RNA_def_property(srna, "layout", PROP_POINTER, PROP_NONE);
|
2009-07-21 01:14:55 +00:00
|
|
|
RNA_def_property_pointer_sdna(prop, NULL, "layout");
|
2009-04-22 18:39:44 +00:00
|
|
|
RNA_def_property_struct_type(prop, "UILayout");
|
|
|
|
|
|
|
|
/* registration */
|
2009-10-31 13:31:23 +00:00
|
|
|
prop= RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE);
|
2009-04-22 18:39:44 +00:00
|
|
|
RNA_def_property_string_sdna(prop, NULL, "type->idname");
|
|
|
|
RNA_def_property_flag(prop, PROP_REGISTER);
|
|
|
|
|
2009-10-31 13:31:23 +00:00
|
|
|
prop= RNA_def_property(srna, "bl_label", PROP_STRING, PROP_NONE);
|
2009-04-22 18:39:44 +00:00
|
|
|
RNA_def_property_string_sdna(prop, NULL, "type->label");
|
|
|
|
RNA_def_property_flag(prop, PROP_REGISTER);
|
|
|
|
|
2009-07-21 01:14:55 +00:00
|
|
|
RNA_define_verify_sdna(1);
|
2009-04-22 18:39:44 +00:00
|
|
|
}
|
|
|
|
|
2009-04-08 16:40:46 +00:00
|
|
|
void RNA_def_ui(BlenderRNA *brna)
|
|
|
|
{
|
|
|
|
rna_def_ui_layout(brna);
|
2009-04-19 13:37:59 +00:00
|
|
|
rna_def_panel(brna);
|
2009-04-19 17:12:16 +00:00
|
|
|
rna_def_header(brna);
|
2009-04-22 18:39:44 +00:00
|
|
|
rna_def_menu(brna);
|
2009-04-08 16:40:46 +00:00
|
|
|
}
|
|
|
|
|
2009-06-09 10:30:11 +00:00
|
|
|
#endif // RNA_RUNTIME
|
2009-04-08 16:40:46 +00:00
|
|
|
|