Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-08-06 18:57:55 +0400
committerCampbell Barton <ideasman42@gmail.com>2011-08-06 18:57:55 +0400
commit2f5809d8317e8dd7a3e4edc30a6f709fb632bb83 (patch)
treeaa5b7bf6325c0bc5c69d182f0874af8f8e391703 /source
parentdc4dede8029801580683551b39f967c206720736 (diff)
make ui_def_but_rna into 2 functions, once which takes a prop, another which takes a propname, no functional change yet but lets us avoid duplicate hash lookups.
Diffstat (limited to 'source')
-rw-r--r--source/blender/editors/interface/interface.c238
1 files changed, 128 insertions, 110 deletions
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 8aed0d58a07..78e24c3bccb 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -2490,138 +2490,141 @@ static uiBut *ui_def_but(uiBlock *block, int type, int retval, const char *str,
return but;
}
-static uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, const char *str, int x1, int y1, short x2, short y2, PointerRNA *ptr, const char *propname, int index, float min, float max, float a1, float a2, const char *tip)
+/* ui_def_but_rna_propname and ui_def_but_rna
+ * both take the same args except for propname vs prop, this is done so we can
+ * avoid an extra lookup on 'prop' when its already available.
+ *
+ * When this kind of change won't disrupt branches, best look into making more
+ * of our UI functions take prop rather then propname.
+ */
+
+#define UI_DEF_BUT_RNA_DISABLE(but) \
+ but->flag |= UI_BUT_DISABLED; \
+ but->lock = 1; \
+ but->lockstr = ""
+
+
+static uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, const char *str, int x1, int y1, short x2, short y2, PointerRNA *ptr, PropertyRNA *prop, int index, float min, float max, float a1, float a2, const char *tip)
{
uiBut *but;
- PropertyRNA *prop;
PropertyType proptype;
int freestr= 0, icon= 0;
- prop= RNA_struct_find_property(ptr, propname);
+ proptype= RNA_property_type(prop);
- if(prop) {
- proptype= RNA_property_type(prop);
-
- /* use rna values if parameters are not specified */
- if(!str) {
- if(type == MENU && proptype == PROP_ENUM) {
- EnumPropertyItem *item;
- DynStr *dynstr;
- int i, totitem, value, free;
-
- RNA_property_enum_items(block->evil_C, ptr, prop, &item, &totitem, &free);
- value= RNA_property_enum_get(ptr, prop);
-
- dynstr= BLI_dynstr_new();
- BLI_dynstr_appendf(dynstr, "%s%%t", RNA_property_ui_name(prop));
- for(i=0; i<totitem; i++) {
- if(!item[i].identifier[0]) {
- if(item[i].name)
- BLI_dynstr_appendf(dynstr, "|%s%%l", item[i].name);
- else
- BLI_dynstr_append(dynstr, "|%l");
- }
- else if(item[i].icon)
- BLI_dynstr_appendf(dynstr, "|%s %%i%d %%x%d", item[i].name, item[i].icon, item[i].value);
+ /* use rna values if parameters are not specified */
+ if(!str) {
+ if(type == MENU && proptype == PROP_ENUM) {
+ EnumPropertyItem *item;
+ DynStr *dynstr;
+ int i, totitem, value, free;
+
+ RNA_property_enum_items(block->evil_C, ptr, prop, &item, &totitem, &free);
+ value= RNA_property_enum_get(ptr, prop);
+
+ dynstr= BLI_dynstr_new();
+ BLI_dynstr_appendf(dynstr, "%s%%t", RNA_property_ui_name(prop));
+ for(i=0; i<totitem; i++) {
+ if(!item[i].identifier[0]) {
+ if(item[i].name)
+ BLI_dynstr_appendf(dynstr, "|%s%%l", item[i].name);
else
- BLI_dynstr_appendf(dynstr, "|%s %%x%d", item[i].name, item[i].value);
+ BLI_dynstr_append(dynstr, "|%l");
+ }
+ else if(item[i].icon)
+ BLI_dynstr_appendf(dynstr, "|%s %%i%d %%x%d", item[i].name, item[i].icon, item[i].value);
+ else
+ BLI_dynstr_appendf(dynstr, "|%s %%x%d", item[i].name, item[i].value);
- if(value == item[i].value) {
- icon= item[i].icon;
- if(!tip)
- tip= item[i].description;
- }
+ if(value == item[i].value) {
+ icon= item[i].icon;
+ if(!tip)
+ tip= item[i].description;
}
- str= BLI_dynstr_get_cstring(dynstr);
- BLI_dynstr_free(dynstr);
+ }
+ str= BLI_dynstr_get_cstring(dynstr);
+ BLI_dynstr_free(dynstr);
- if(free)
- MEM_freeN(item);
+ if(free)
+ MEM_freeN(item);
- freestr= 1;
- }
- else if(ELEM(type, ROW, LISTROW) && proptype == PROP_ENUM) {
- EnumPropertyItem *item;
- int i, totitem, free;
-
- RNA_property_enum_items(block->evil_C, ptr, prop, &item, &totitem, &free);
- for(i=0; i<totitem; i++) {
- if(item[i].identifier[0] && item[i].value == (int)max) {
- str= item[i].name;
- icon= item[i].icon;
- }
- }
+ freestr= 1;
+ }
+ else if(ELEM(type, ROW, LISTROW) && proptype == PROP_ENUM) {
+ EnumPropertyItem *item;
+ int i, totitem, free;
- if(!str)
- str= RNA_property_ui_name(prop);
- if(free)
- MEM_freeN(item);
+ RNA_property_enum_items(block->evil_C, ptr, prop, &item, &totitem, &free);
+ for(i=0; i<totitem; i++) {
+ if(item[i].identifier[0] && item[i].value == (int)max) {
+ str= item[i].name;
+ icon= item[i].icon;
+ }
}
- else {
+
+ if(!str)
str= RNA_property_ui_name(prop);
- icon= RNA_property_ui_icon(prop);
- }
+ if(free)
+ MEM_freeN(item);
}
-
- if(!tip && proptype != PROP_ENUM)
- tip= RNA_property_ui_description(prop);
+ else {
+ str= RNA_property_ui_name(prop);
+ icon= RNA_property_ui_icon(prop);
+ }
+ }
- if(min == max || a1 == -1 || a2 == -1) {
- if(proptype == PROP_INT) {
- int hardmin, hardmax, softmin, softmax, step;
+ if(!tip && proptype != PROP_ENUM)
+ tip= RNA_property_ui_description(prop);
- RNA_property_int_range(ptr, prop, &hardmin, &hardmax);
- RNA_property_int_ui_range(ptr, prop, &softmin, &softmax, &step);
+ if(min == max || a1 == -1 || a2 == -1) {
+ if(proptype == PROP_INT) {
+ int hardmin, hardmax, softmin, softmax, step;
- if(!ELEM(type, ROW, LISTROW) && min == max) {
- min= hardmin;
- max= hardmax;
- }
- if(a1 == -1)
- a1= step;
- if(a2 == -1)
- a2= 0;
+ RNA_property_int_range(ptr, prop, &hardmin, &hardmax);
+ RNA_property_int_ui_range(ptr, prop, &softmin, &softmax, &step);
+
+ if(!ELEM(type, ROW, LISTROW) && min == max) {
+ min= hardmin;
+ max= hardmax;
}
- else if(proptype == PROP_FLOAT) {
- float hardmin, hardmax, softmin, softmax, step, precision;
+ if(a1 == -1)
+ a1= step;
+ if(a2 == -1)
+ a2= 0;
+ }
+ else if(proptype == PROP_FLOAT) {
+ float hardmin, hardmax, softmin, softmax, step, precision;
- RNA_property_float_range(ptr, prop, &hardmin, &hardmax);
- RNA_property_float_ui_range(ptr, prop, &softmin, &softmax, &step, &precision);
+ RNA_property_float_range(ptr, prop, &hardmin, &hardmax);
+ RNA_property_float_ui_range(ptr, prop, &softmin, &softmax, &step, &precision);
- if(!ELEM(type, ROW, LISTROW) && min == max) {
- min= hardmin;
- max= hardmax;
- }
- if(a1 == -1)
- a1= step;
- if(a2 == -1)
- a2= precision;
- }
- else if(proptype == PROP_STRING) {
- min= 0;
- max= RNA_property_string_maxlength(prop);
- if(max == 0) /* interface code should ideally support unlimited length */
- max= UI_MAX_DRAW_STR;
+ if(!ELEM(type, ROW, LISTROW) && min == max) {
+ min= hardmin;
+ max= hardmax;
}
+ if(a1 == -1)
+ a1= step;
+ if(a2 == -1)
+ a2= precision;
+ }
+ else if(proptype == PROP_STRING) {
+ min= 0;
+ max= RNA_property_string_maxlength(prop);
+ if(max == 0) /* interface code should ideally support unlimited length */
+ max= UI_MAX_DRAW_STR;
}
- }
- else {
- RNA_warning("ui_def_but_rna: property not found: %s.%s\n", RNA_struct_identifier(ptr->type), propname);
- str= propname;
}
/* now create button */
but= ui_def_but(block, type, retval, str, x1, y1, x2, y2, NULL, min, max, a1, a2, tip);
- if(prop) {
- but->rnapoin= *ptr;
- but->rnaprop= prop;
+ but->rnapoin= *ptr;
+ but->rnaprop= prop;
- if(RNA_property_array_length(&but->rnapoin, but->rnaprop))
- but->rnaindex= index;
- else
- but->rnaindex= 0;
- }
+ if(RNA_property_array_length(&but->rnapoin, but->rnaprop))
+ but->rnaindex= index;
+ else
+ but->rnaindex= 0;
if(icon) {
but->icon= (BIFIconID)icon;
@@ -2629,10 +2632,8 @@ static uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, const char *s
but->flag|= UI_ICON_LEFT;
}
- if (!prop || !RNA_property_editable(&but->rnapoin, prop)) {
- but->flag |= UI_BUT_DISABLED;
- but->lock = 1;
- but->lockstr = "";
+ if (!RNA_property_editable(&but->rnapoin, prop)) {
+ UI_DEF_BUT_RNA_DISABLE(but);
}
/* If this button uses units, calculate the step from this */
@@ -2645,6 +2646,23 @@ static uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, const char *s
return but;
}
+static uiBut *ui_def_but_rna_propname(uiBlock *block, int type, int retval, const char *str, int x1, int y1, short x2, short y2, PointerRNA *ptr, const char *propname, int index, float min, float max, float a1, float a2, const char *tip)
+{
+ PropertyRNA *prop= RNA_struct_find_property(ptr, propname);
+ uiBut *but;
+
+ if(prop) {
+ but= ui_def_but_rna(block, type, retval, str, x1, y1, x2, y2, ptr, prop, index, min, max, a1, a2, tip);
+ }
+ else {
+ but= ui_def_but(block, type, retval, propname, x1, y1, x2, y2, NULL, min, max, a1, a2, tip);
+
+ UI_DEF_BUT_RNA_DISABLE(but);
+ }
+
+ return but;
+}
+
static uiBut *ui_def_but_operator(uiBlock *block, int type, const char *opname, int opcontext, const char *str, int x1, int y1, short x2, short y2, const char *tip)
{
uiBut *but;
@@ -2857,7 +2875,7 @@ uiBut *uiDefButR(uiBlock *block, int type, int retval, const char *str, int x1,
{
uiBut *but;
- but= ui_def_but_rna(block, type, retval, str, x1, y1, x2, y2, ptr, propname, index, min, max, a1, a2, tip);
+ but= ui_def_but_rna_propname(block, type, retval, str, x1, y1, x2, y2, ptr, propname, index, min, max, a1, a2, tip);
if(but)
ui_check_but(but);
@@ -2942,7 +2960,7 @@ uiBut *uiDefIconButR(uiBlock *block, int type, int retval, int icon, int x1, int
{
uiBut *but;
- but= ui_def_but_rna(block, type, retval, "", x1, y1, x2, y2, ptr, propname, index, min, max, a1, a2, tip);
+ but= ui_def_but_rna_propname(block, type, retval, "", x1, y1, x2, y2, ptr, propname, index, min, max, a1, a2, tip);
if(but) {
if(icon) {
but->icon= (BIFIconID) icon;
@@ -3027,7 +3045,7 @@ uiBut *uiDefIconTextButR(uiBlock *block, int type, int retval, int icon, const c
{
uiBut *but;
- but= ui_def_but_rna(block, type, retval, str, x1, y1, x2, y2, ptr, propname, index, min, max, a1, a2, tip);
+ but= ui_def_but_rna_propname(block, type, retval, str, x1, y1, x2, y2, ptr, propname, index, min, max, a1, a2, tip);
if(but) {
if(icon) {
but->icon= (BIFIconID) icon;