diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-12-19 13:40:06 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-12-19 13:41:39 +0300 |
commit | 543a34a0212411271054ced45fae416b1982156a (patch) | |
tree | ae71704a0487503fc4c597ce47440cf847135c74 | |
parent | f7dc6a63fb5a62eb6141fee375e30d94c1d83fa8 (diff) |
RNA: convenience method for orientation name & icon
Avoids RNA introspection at draw time
which is relatively slow (approx 5x).
-rw-r--r-- | release/scripts/startup/bl_ui/space_view3d.py | 11 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_scene.c | 36 |
2 files changed, 37 insertions, 10 deletions
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py index 8f3132f690f..fa58fed6102 100644 --- a/release/scripts/startup/bl_ui/space_view3d.py +++ b/release/scripts/startup/bl_ui/space_view3d.py @@ -123,14 +123,7 @@ class VIEW3D_HT_header(Header): if object_mode in {'OBJECT', 'EDIT', 'POSE', 'EDIT_GPENCIL'}: orient_slot = scene.transform_orientation_slots[0] custom_orientation = orient_slot.custom_orientation - - if custom_orientation is None: - trans_orientation = bpy.types.TransformOrientationSlot.bl_rna.properties["type"].enum_items[orient_slot.type] - trans_icon = getattr(trans_orientation, "icon", 'BLANK1') - trans_name = getattr(trans_orientation, "name", "Orientation") - else: - trans_icon = 'OBJECT_ORIGIN' - trans_name = getattr(custom_orientation, "name", "Orientation") + trans_name, trans_icon = orient_slot.ui_info() row = layout.row(align=True) @@ -139,7 +132,7 @@ class VIEW3D_HT_header(Header): sub.popover( panel="VIEW3D_PT_transform_orientations", text=trans_name, - icon=trans_icon, + icon_value=trans_icon, ) # Snap diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index 58bde163442..3a8cfbff3a1 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -1567,7 +1567,7 @@ static void rna_Scene_use_persistent_data_update(Main *UNUSED(bmain), Scene *UNU RE_FreePersistentData(); } -/* Scene.orientation_slots */ +/* Scene.transform_orientation_slots */ static void rna_Scene_transform_orientation_slots_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) { Scene *scene = (Scene *)ptr->id.data; @@ -2036,6 +2036,26 @@ const EnumPropertyItem *rna_TransformOrientation_itemf( return item; } +void rna_TransformOrientationSlot_ui_info( + ID *scene_id, TransformOrientationSlot *orient_slot, + char *r_name, int *r_icon_value) +{ + Scene *scene = (Scene *)scene_id; + + if (orient_slot->type < V3D_MANIP_CUSTOM) { + const EnumPropertyItem *items = rna_enum_transform_orientation_items; + const int i = RNA_enum_from_value(items, orient_slot->type); + strcpy(r_name, items[i].name); + *r_icon_value = items[i].icon; + } + else { + TransformOrientation *orientation = BKE_scene_transform_orientation_find( + scene, orient_slot->index_custom); + strcpy(r_name, orientation->name); + *r_icon_value = ICON_OBJECT_ORIGIN; + } +} + static const EnumPropertyItem *get_unit_enum_items(int system, int type, bool *r_free) { const void *usys; @@ -2221,6 +2241,20 @@ static void rna_def_transform_orientation_slot(BlenderRNA *brna) RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", SELECT); RNA_def_property_ui_text(prop, "Use", "Disable to unlink the orientation from the scene-setting"); RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL); + + FunctionRNA *func; + PropertyRNA *parm; + + /* UI access only (avoid slow RNA introspection). */ + func = RNA_def_function(srna, "ui_info", "rna_TransformOrientationSlot_ui_info"); + RNA_def_function_ui_description(func, ""); + RNA_def_function_flag(func, FUNC_USE_SELF_ID); + parm = RNA_def_string(func, "name", NULL, sizeof(((TransformOrientation *)NULL)->name), "name", ""); + RNA_def_parameter_flags(parm, PROP_THICK_WRAP, 0); + RNA_def_function_output(func, parm); + parm = RNA_def_property(func, "icon_value", PROP_INT, PROP_NONE); + RNA_def_property_ui_text(parm, "", ""); + RNA_def_function_output(func, parm); } |