[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [17887] branches/blender2.5/blender/source /blender/editors: UI: added the following functions to create buttons for RNA properties and for
Brecht Van Lommel
brecht at blender.org
Tue Dec 16 08:55:43 CET 2008
Revision: 17887
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=17887
Author: blendix
Date: 2008-12-16 08:55:43 +0100 (Tue, 16 Dec 2008)
Log Message:
-----------
UI: added the following functions to create buttons for RNA properties and for
operators. RNA property buttons will automatically fill in the label, min/max,
etc if they are not specified. Operator menu buttons will look up the key
combination in the handlers and add it automatically.
uiDefButR, uiDefIconButR, uiDefIconTextButR
uiDefButO, uiDefIconButO, uiDefIconTextButO
uiDefButO takes a context pointer to do the key lookup, don't really like this..
Modified Paths:
--------------
branches/blender2.5/blender/source/blender/editors/include/UI_interface.h
branches/blender2.5/blender/source/blender/editors/interface/interface.c
branches/blender2.5/blender/source/blender/editors/interface/interface.h
branches/blender2.5/blender/source/blender/editors/interface/interface_handlers.c
branches/blender2.5/blender/source/blender/editors/space_outliner/space_outliner.c
branches/blender2.5/blender/source/blender/editors/space_time/time_header.c
Modified: branches/blender2.5/blender/source/blender/editors/include/UI_interface.h
===================================================================
--- branches/blender2.5/blender/source/blender/editors/include/UI_interface.h 2008-12-16 07:53:59 UTC (rev 17886)
+++ branches/blender2.5/blender/source/blender/editors/include/UI_interface.h 2008-12-16 07:55:43 UTC (rev 17887)
@@ -258,6 +258,8 @@
uiBut *uiDefButBitS(uiBlock *block, int type, int bit, int retval, char *str, short x1, short y1, short x2, short y2, short *poin, float min, float max, float a1, float a2, char *tip);
uiBut *uiDefButC(uiBlock *block, int type, int retval, char *str, short x1, short y1, short x2, short y2, char *poin, float min, float max, float a1, float a2, char *tip);
uiBut *uiDefButBitC(uiBlock *block, int type, int bit, int retval, char *str, short x1, short y1, short x2, short y2, char *poin, float min, float max, float a1, float a2, char *tip);
+uiBut *uiDefButR(uiBlock *block, int type, int retval, char *str, short x1, short y1, short x2, short y2, struct PointerRNA *ptr, const char *propname, int index, float min, float max, float a1, float a2, char *tip);
+uiBut *uiDefButO(struct bContext *C, uiBlock *block, int type, char *opname, int opcontext, char *str, short x1, short y1, short x2, short y2, char *tip);
uiBut *uiDefIconBut(uiBlock *block,
int type, int retval, int icon,
@@ -274,9 +276,16 @@
uiBut *uiDefIconButBitS(uiBlock *block, int type, int bit, int retval, int icon, short x1, short y1, short x2, short y2, short *poin, float min, float max, float a1, float a2, char *tip);
uiBut *uiDefIconButC(uiBlock *block, int type, int retval, int icon, short x1, short y1, short x2, short y2, char *poin, float min, float max, float a1, float a2, char *tip);
uiBut *uiDefIconButBitC(uiBlock *block, int type, int bit, int retval, int icon, short x1, short y1, short x2, short y2, char *poin, float min, float max, float a1, float a2, char *tip);
+uiBut *uiDefIconButR(uiBlock *block, int type, int retval, int icon, short x1, short y1, short x2, short y2, struct PointerRNA *ptr, const char *propname, int index, float min, float max, float a1, float a2, char *tip);
+uiBut *uiDefIconButO(struct bContext *C, uiBlock *block, int type, char *opname, int opcontext, int icon, short x1, short y1, short x2, short y2, char *tip);
-uiBut *uiDefIconTextBut(uiBlock *block, int type, int retval, int icon, char *str, short x1, short y1, short x2, short y2, void *poin, float min, float max, float a1, float a2, char *tip);
-
+uiBut *uiDefIconTextBut(uiBlock *block,
+ int type, int retval, int icon, char *str,
+ short x1, short y1,
+ short x2, short y2,
+ void *poin,
+ float min, float max,
+ float a1, float a2, char *tip);
uiBut *uiDefIconTextButF(uiBlock *block, int type, int retval, int icon, char *str, short x1, short y1, short x2, short y2, float *poin, float min, float max, float a1, float a2, char *tip);
uiBut *uiDefIconTextButBitF(uiBlock *block, int type, int bit, int retval, int icon, char *str, short x1, short y1, short x2, short y2, float *poin, float min, float max, float a1, float a2, char *tip);
uiBut *uiDefIconTextButI(uiBlock *block, int type, int retval, int icon, char *str, short x1, short y1, short x2, short y2, int *poin, float min, float max, float a1, float a2, char *tip);
@@ -285,6 +294,8 @@
uiBut *uiDefIconTextButBitS(uiBlock *block, int type, int bit, int retval, int icon, char *str, short x1, short y1, short x2, short y2, short *poin, float min, float max, float a1, float a2, char *tip);
uiBut *uiDefIconTextButC(uiBlock *block, int type, int retval, int icon, char *str, short x1, short y1, short x2, short y2, char *poin, float min, float max, float a1, float a2, char *tip);
uiBut *uiDefIconTextButBitC(uiBlock *block, int type, int bit, int retval, int icon, char *str, short x1, short y1, short x2, short y2, char *poin, float min, float max, float a1, float a2, char *tip);
+uiBut *uiDefIconTextButR(uiBlock *block, int type, int retval, int icon, char *str, short x1, short y1, short x2, short y2, struct PointerRNA *ptr, const char *propname, int index, float min, float max, float a1, float a2, char *tip);
+uiBut *uiDefIconTextButO(struct bContext *C, uiBlock *block, int type, char *opname, int opcontext, int icon, char *str, short x1, short y1, short x2, short y2, char *tip);
typedef void (*uiIDPoinFuncFP) (struct bContext *C, char *str, struct ID **idpp);
uiBut *uiDefIDPoinBut(struct uiBlock *block, uiIDPoinFuncFP func, short blocktype, int retval, char *str,
@@ -298,8 +309,6 @@
void uiDefKeyevtButS(uiBlock *block, int retval, char *str, short x1, short y1, short x2, short y2, short *spoin, char *tip);
-uiBut *uiDefRNABut(uiBlock *block, int retval, struct PointerRNA *ptr, struct PropertyRNA *prop, int index, short x1, short y1, short x2, short y2);
-
void uiAutoBlock(struct uiBlock *block,
float minx, float miny,
float sizex, float sizey, int flag);
Modified: branches/blender2.5/blender/source/blender/editors/interface/interface.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/interface/interface.c 2008-12-16 07:53:59 UTC (rev 17886)
+++ branches/blender2.5/blender/source/blender/editors/interface/interface.c 2008-12-16 07:55:43 UTC (rev 17887)
@@ -1986,6 +1986,124 @@
return but;
}
+uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, char *str, short x1, short y1, short x2, short y2, PointerRNA *ptr, const char *propname, int index, float min, float max, float a1, float a2, char *tip)
+{
+ uiBut *but;
+ PropertyRNA *prop;
+ PropertyType proptype;
+ int freestr= 0;
+
+ prop= RNA_struct_find_property(ptr, propname);
+ if(!prop)
+ return NULL;
+
+ proptype= RNA_property_type(ptr, prop);
+
+ /* use rna values if parameters are not specified */
+ if(!str) {
+ if(type == MENU && proptype == PROP_ENUM) {
+ const EnumPropertyItem *item;
+ DynStr *dynstr;
+ int i, totitem;
+
+ RNA_property_enum_items(ptr, prop, &item, &totitem);
+
+ dynstr= BLI_dynstr_new();
+ BLI_dynstr_appendf(dynstr, "%s%%t", RNA_property_ui_name(ptr, prop));
+ for(i=0; i<totitem; i++)
+ BLI_dynstr_appendf(dynstr, "|%s %%x%d", item[i].name, item[i].value);
+ str= BLI_dynstr_get_cstring(dynstr);
+ BLI_dynstr_free(dynstr);
+
+ freestr= 1;
+ }
+ else
+ str= (char*)RNA_property_ui_name(ptr, prop);
+ }
+
+ if(!tip)
+ tip= (char*)RNA_property_ui_description(ptr, prop);
+
+ if(min == max || a1 == -1 || a2 == -1) {
+ if(proptype == PROP_INT) {
+ int softmin, softmax, step;
+
+ RNA_property_int_ui_range(ptr, prop, &softmin, &softmax, &step);
+
+ if(min == max) {
+ min= softmin;
+ max= softmax;
+ }
+ if(a1 == -1)
+ a1= step;
+ if(a2 == -1)
+ a2= 0;
+ }
+ else if(proptype == PROP_FLOAT) {
+ float softmin, softmax, step, precision;
+
+ RNA_property_float_ui_range(ptr, prop, &softmin, &softmax, &step, &precision);
+
+ if(min == max) {
+ min= softmin;
+ max= softmax;
+ }
+ if(a1 == -1)
+ a1= step;
+ if(a2 == -1)
+ a2= precision;
+ }
+ else if(proptype == PROP_STRING) {
+ min= 0;
+ max= RNA_property_string_maxlength(ptr, prop);
+ if(max == 0) /* interface code should ideally support unlimited length */
+ max= UI_MAX_DRAW_STR;
+ }
+ }
+
+ /* now create button */
+ but= ui_def_but(block, type, retval, str, x1, y1, x2, y2, NULL, min, max, a1, a2, tip);
+ but->rnapoin= *ptr;
+ but->rnaprop= prop;
+ but->rnaindex= index;
+
+ if(freestr)
+ MEM_freeN(str);
+
+ return but;
+}
+
+uiBut *ui_def_but_operator(bContext *C, uiBlock *block, int type, char *opname, int opcontext, char *str, short x1, short y1, short x2, short y2, char *tip)
+{
+ uiBut *but;
+ char buf[100], *butstr;
+
+ if(!str) {
+ wmOperatorType *ot= WM_operatortype_find(opname);
+ str= (ot)? ot->name: "";
+ }
+
+ if(type == BUTM) {
+ if(WM_key_event_operator_string(C, opname, opcontext, buf, sizeof(buf))) {
+ butstr= MEM_mallocN(strlen(str)+strlen(buf)+2, "ui_def_but_operator");
+ strcpy(butstr, str);
+ strcat(butstr, "|");
+ strcat(butstr, buf);
+ }
+ else
+ butstr= str;
+ }
+
+ but= ui_def_but(block, type, -1, butstr, x1, y1, x2, y2, NULL, 0, 0, 0, 0, tip);
+ but->opname= opname;
+ but->opcontext= opcontext;
+
+ if(butstr != str)
+ MEM_freeN(butstr);
+
+ return but;
+}
+
uiBut *uiDefBut(uiBlock *block, int type, int retval, char *str, short x1, short y1, short x2, short y2, void *poin, float min, float max, float a1, float a2, char *tip)
{
uiBut *but= ui_def_but(block, type, retval, str, x1, y1, x2, y2, poin, min, max, a1, a2, tip);
@@ -2131,7 +2249,27 @@
{
return uiDefButBit(block, type|CHA, bit, retval, str, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
}
+uiBut *uiDefButR(uiBlock *block, int type, int retval, char *str, short x1, short y1, short x2, short y2, PointerRNA *ptr, const char *propname, int index, float min, float max, float a1, float a2, char *tip)
+{
+ uiBut *but;
+ but= ui_def_but_rna(block, type, retval, str, x1, y1, x2, y2, ptr, propname, index, min, max, a1, a2, tip);
+ if(but)
+ ui_check_but(but);
+
+ return but;
+}
+uiBut *uiDefButO(bContext *C, uiBlock *block, int type, char *opname, int opcontext, char *str, short x1, short y1, short x2, short y2, char *tip)
+{
+ uiBut *but;
+
+ but= ui_def_but_operator(C, block, type, opname, opcontext, str, x1, y1, x2, y2, tip);
+ if(but)
+ ui_check_but(but);
+
+ return but;
+}
+
uiBut *uiDefIconBut(uiBlock *block, int type, int retval, int icon, short x1, short y1, short x2, short y2, void *poin, float min, float max, float a1, float a2, char *tip)
{
uiBut *but= ui_def_but(block, type, retval, "", x1, y1, x2, y2, poin, min, max, a1, a2, tip);
@@ -2185,7 +2323,33 @@
{
return uiDefIconButBit(block, type|CHA, bit, retval, icon, x1, y1, x2, y2, (void*) poin, min, max, a1, a2, tip);
}
+uiBut *uiDefIconButR(uiBlock *block, int type, int retval, int icon, short x1, short y1, short x2, short y2, PointerRNA *ptr, const char *propname, int index, float min, float max, float a1, float a2, char *tip)
+{
+ uiBut *but;
+ but= ui_def_but_rna(block, type, retval, "", x1, y1, x2, y2, ptr, propname, index, min, max, a1, a2, tip);
+ if(but) {
+ but->icon= (BIFIconID) icon;
+ but->flag|= UI_HAS_ICON;
+ ui_check_but(but);
+ }
+
+ return but;
+}
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list