RNA: convenience method for orientation name & icon
authorCampbell Barton <ideasman42@gmail.com>
Wed, 19 Dec 2018 10:40:06 +0000 (21:40 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 19 Dec 2018 10:41:39 +0000 (21:41 +1100)
Avoids RNA introspection at draw time
which is relatively slow (approx 5x).

release/scripts/startup/bl_ui/space_view3d.py
source/blender/makesrna/intern/rna_scene.c

index 8f3132f690fbdad8497c3961f00101dec48730f6..fa58fed61027b15a63f8b0e134758bf503b799fe 100644 (file)
@@ -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
index 58bde16344250e8875cd3b39b8f95ec5c7615a3d..3a8cfbff3a199cda1bf7532ac1c87d4647eb0e5c 100644 (file)
@@ -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);
 }