RNA: convenience method for orientation name & icon
Avoids RNA introspection at draw time which is relatively slow (approx 5x).
This commit is contained in:
parent
f7dc6a63fb
commit
543a34a021
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue