diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-08-24 04:44:28 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-08-24 04:44:28 +0300 |
commit | 7ec1a56a41953eac23e252fad9a3bf1605471abc (patch) | |
tree | 34d707f3d434a39bc08c34cbc64abfce61c9da9c /source/blender/editors | |
parent | c5206e5d2f880adf9cff8ed295be5ec160d18e0d (diff) |
RNA: avoid redundant property lookups in UI API
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/include/UI_interface.h | 2 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_layout.c | 82 |
2 files changed, 57 insertions, 27 deletions
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index f2aad249df3..a38f82bc5fc 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -1051,8 +1051,10 @@ void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int void uiItemFullR(uiLayout *layout, struct PointerRNA *ptr, struct PropertyRNA *prop, int index, int value, int flag, const char *name, int icon); void uiItemEnumR_prop(uiLayout *layout, const char *name, int icon, struct PointerRNA *ptr, PropertyRNA *prop, int value); void uiItemEnumR(uiLayout *layout, const char *name, int icon, struct PointerRNA *ptr, const char *propname, int value); +void uiItemEnumR_string_prop(uiLayout *layout, struct PointerRNA *ptr, PropertyRNA *prop, const char *value, const char *name, int icon); void uiItemEnumR_string(uiLayout *layout, struct PointerRNA *ptr, const char *propname, const char *value, const char *name, int icon); void uiItemsEnumR(uiLayout *layout, struct PointerRNA *ptr, const char *propname); +void uiItemPointerR_prop(uiLayout *layout, struct PointerRNA *ptr, PropertyRNA *prop, struct PointerRNA *searchptr, PropertyRNA *searchprop, const char *name, int icon); void uiItemPointerR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, struct PointerRNA *searchptr, const char *searchpropname, const char *name, int icon); void uiItemsFullEnumO( uiLayout *layout, const char *opname, const char *propname, diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index 5fc2dd09203..140fdbe355b 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -1545,22 +1545,26 @@ void uiItemEnumR(uiLayout *layout, const char *name, int icon, struct PointerRNA uiItemFullR(layout, ptr, prop, RNA_ENUM_VALUE, value, 0, name, icon); } -void uiItemEnumR_string(uiLayout *layout, struct PointerRNA *ptr, const char *propname, const char *value, const char *name, int icon) + +void uiItemEnumR_string_prop( + uiLayout *layout, struct PointerRNA *ptr, PropertyRNA *prop, + const char *value, const char *name, int icon) { - PropertyRNA *prop = RNA_struct_find_property(ptr, propname); const EnumPropertyItem *item; int ivalue, a; bool free; - if (!prop || RNA_property_type(prop) != PROP_ENUM) { + if (UNLIKELY(RNA_property_type(prop) != PROP_ENUM)) { + const char *propname = RNA_property_identifier(prop); ui_item_disabled(layout, propname); - RNA_warning("enum property not found: %s.%s", RNA_struct_identifier(ptr->type), propname); + RNA_warning("not an enum property: %s.%s", RNA_struct_identifier(ptr->type), propname); return; } RNA_property_enum_items(layout->root->block->evil_C, ptr, prop, &item, NULL, &free); if (!RNA_enum_value_from_id(item, value, &ivalue)) { + const char *propname = RNA_property_identifier(prop); if (free) { MEM_freeN((void *)item); } @@ -1584,6 +1588,19 @@ void uiItemEnumR_string(uiLayout *layout, struct PointerRNA *ptr, const char *pr } } +void uiItemEnumR_string( + uiLayout *layout, struct PointerRNA *ptr, const char *propname, + const char *value, const char *name, int icon) +{ + PropertyRNA *prop = RNA_struct_find_property(ptr, propname); + if (UNLIKELY(prop == NULL)) { + ui_item_disabled(layout, propname); + RNA_warning("enum property not found: %s.%s", RNA_struct_identifier(ptr->type), propname); + return; + } + uiItemEnumR_string_prop(layout, ptr, prop, value, name, icon); +} + void uiItemsEnumR(uiLayout *layout, struct PointerRNA *ptr, const char *propname) { PropertyRNA *prop; @@ -1799,9 +1816,12 @@ void ui_but_add_search(uiBut *but, PointerRNA *ptr, PropertyRNA *prop, PointerRN } } -void uiItemPointerR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, struct PointerRNA *searchptr, const char *searchpropname, const char *name, int icon) +void uiItemPointerR_prop( + uiLayout *layout, + PointerRNA *ptr, PropertyRNA *prop, + PointerRNA *searchptr, PropertyRNA *searchprop, + const char *name, int icon) { - PropertyRNA *prop, *searchprop; PropertyType type; uiBut *but; uiBlock *block; @@ -1809,32 +1829,15 @@ void uiItemPointerR(uiLayout *layout, struct PointerRNA *ptr, const char *propna int w, h; char namestr[UI_MAX_NAME_STR]; - /* validate arguments */ - prop = RNA_struct_find_property(ptr, propname); - - if (!prop) { - RNA_warning("property not found: %s.%s", - RNA_struct_identifier(ptr->type), propname); - return; - } - type = RNA_property_type(prop); if (!ELEM(type, PROP_POINTER, PROP_STRING, PROP_ENUM)) { - RNA_warning("Property %s must be a pointer, string or enum", propname); + RNA_warning("Property %s.%s must be a pointer, string or enum", + RNA_struct_identifier(ptr->type), RNA_property_identifier(prop)); return; } - - searchprop = RNA_struct_find_property(searchptr, searchpropname); - - - if (!searchprop) { - RNA_warning("search collection property not found: %s.%s", - RNA_struct_identifier(searchptr->type), searchpropname); - return; - } - else if (RNA_property_type(searchprop) != PROP_COLLECTION) { + if (RNA_property_type(searchprop) != PROP_COLLECTION) { RNA_warning("search collection property is not a collection type: %s.%s", - RNA_struct_identifier(searchptr->type), searchpropname); + RNA_struct_identifier(searchptr->type), RNA_property_identifier(searchprop)); return; } @@ -1862,6 +1865,31 @@ void uiItemPointerR(uiLayout *layout, struct PointerRNA *ptr, const char *propna ui_but_add_search(but, ptr, prop, searchptr, searchprop); } +void uiItemPointerR( + uiLayout *layout, + PointerRNA *ptr, const char *propname, + PointerRNA *searchptr, const char *searchpropname, + const char *name, int icon) +{ + PropertyRNA *prop, *searchprop; + + /* validate arguments */ + prop = RNA_struct_find_property(ptr, propname); + if (!prop) { + RNA_warning("property not found: %s.%s", + RNA_struct_identifier(ptr->type), propname); + return; + } + searchprop = RNA_struct_find_property(searchptr, searchpropname); + if (!searchprop) { + RNA_warning("search collection property not found: %s.%s", + RNA_struct_identifier(searchptr->type), searchpropname); + return; + } + + uiItemPointerR_prop(layout, ptr, prop, searchptr, searchprop, name, icon); +} + /* menu item */ static void ui_item_menutype_func(bContext *C, uiLayout *layout, void *arg_mt) { |