UI: expose gizmo orientation as a single enum
Avoids awkward logic from the popover, by faking an extra item in the enum.
This commit is contained in:
parent
2bc27d3dc5
commit
1ce9a142b6
Notes:
blender-bot
2023-02-14 01:52:41 +01:00
Referenced by commit7d8f57e0c0
, Correct own error in1ce9a142b6
|
@ -69,23 +69,7 @@ class _template_widget:
|
|||
def draw_settings_with_index(context, layout, index):
|
||||
scene = context.scene
|
||||
orient_slot = scene.transform_orientation_slots[index]
|
||||
use_global = orient_slot.use_global
|
||||
row = layout.row(align=True)
|
||||
|
||||
row.label(text="Orientation:")
|
||||
|
||||
popover_kw = {
|
||||
"panel": "VIEW3D_PT_transform_orientations_gizmo_" f"{index}",
|
||||
}
|
||||
|
||||
if use_global:
|
||||
popover_kw["text"], popover_kw["icon"] = "Scene", 'OBJECT_ORIGIN'
|
||||
else:
|
||||
popover_kw["text"], popover_kw["icon_value"] = orient_slot.ui_info()
|
||||
|
||||
sub = layout.row()
|
||||
sub.ui_units_x = 4
|
||||
sub.popover(**popover_kw)
|
||||
layout.prop(orient_slot, "type")
|
||||
|
||||
|
||||
class _defs_view3d_generic:
|
||||
|
|
|
@ -5270,40 +5270,6 @@ class VIEW3D_PT_transform_orientations(Panel):
|
|||
row.operator("transform.delete_orientation", text="", icon='X', emboss=False)
|
||||
|
||||
|
||||
# XXX, each panel needs to access a different orientation index.
|
||||
# look into a way to pass this from the UI that draws it.
|
||||
def VIEW3D_PT_transform_orientations_gizmo_factory(index):
|
||||
class VIEW3D_PT_transform_orientations_other_n(Panel):
|
||||
bl_space_type = 'VIEW_3D'
|
||||
bl_region_type = 'HEADER'
|
||||
bl_label = "Transform Orientations"
|
||||
bl_ui_units_x = 8
|
||||
bl_idname = "VIEW3D_PT_transform_orientations_gizmo_" + str(index)
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
layout.label(text="Transform Orientations")
|
||||
|
||||
scene = context.scene
|
||||
orient_slot = scene.transform_orientation_slots[index]
|
||||
|
||||
layout.prop(orient_slot, "use_global", text="Scene Orientation", icon='OBJECT_ORIGIN')
|
||||
use_global = orient_slot.use_global
|
||||
|
||||
col = layout.column()
|
||||
col.active = not use_global
|
||||
col.column().prop(orient_slot, "type", expand=True)
|
||||
|
||||
# Only 'VIEW3D_PT_transform_orientations' can edit
|
||||
|
||||
return VIEW3D_PT_transform_orientations_other_n
|
||||
|
||||
VIEW3D_PT_transform_orientations_gizmo_1 = VIEW3D_PT_transform_orientations_gizmo_factory(1)
|
||||
VIEW3D_PT_transform_orientations_gizmo_2 = VIEW3D_PT_transform_orientations_gizmo_factory(2)
|
||||
VIEW3D_PT_transform_orientations_gizmo_3 = VIEW3D_PT_transform_orientations_gizmo_factory(3)
|
||||
|
||||
|
||||
class VIEW3D_PT_gpencil_origin(Panel):
|
||||
bl_space_type = 'VIEW_3D'
|
||||
bl_region_type = 'HEADER'
|
||||
|
@ -5816,9 +5782,6 @@ classes = (
|
|||
VIEW3D_PT_gpencil_origin,
|
||||
VIEW3D_PT_gpencil_lock,
|
||||
VIEW3D_PT_transform_orientations,
|
||||
VIEW3D_PT_transform_orientations_gizmo_1,
|
||||
VIEW3D_PT_transform_orientations_gizmo_2,
|
||||
VIEW3D_PT_transform_orientations_gizmo_3,
|
||||
VIEW3D_PT_overlay_gpencil_options,
|
||||
VIEW3D_PT_context_properties,
|
||||
TOPBAR_PT_gpencil_materials,
|
||||
|
|
|
@ -1242,10 +1242,10 @@ static void gizmo_xform_message_subscribe(
|
|||
RNA_pointer_create(&scene->id, &RNA_TransformOrientationSlot, orient_slot, &orient_ref_ptr);
|
||||
{
|
||||
extern PropertyRNA rna_TransformOrientationSlot_type;
|
||||
extern PropertyRNA rna_TransformOrientationSlot_use_global;
|
||||
extern PropertyRNA rna_TransformOrientationSlot_use;
|
||||
const PropertyRNA *props[] = {
|
||||
&rna_TransformOrientationSlot_type,
|
||||
&rna_TransformOrientationSlot_use_global,
|
||||
&rna_TransformOrientationSlot_use,
|
||||
};
|
||||
for (int i = 0; i < ARRAY_SIZE(props); i++) {
|
||||
if (props[i]) {
|
||||
|
|
|
@ -1975,15 +1975,36 @@ static void rna_ViewLayer_remove(
|
|||
}
|
||||
}
|
||||
|
||||
/* Fake value, used internally (not saved to DNA). */
|
||||
#define V3D_MANIP_DEFAULT -1
|
||||
|
||||
static int rna_TransformOrientationSlot_type_get(PointerRNA *ptr)
|
||||
{
|
||||
Scene *scene = ptr->id.data;
|
||||
TransformOrientationSlot *orient_slot = ptr->data;
|
||||
if (orient_slot != &scene->orientation_slots[SCE_ORIENT_DEFAULT]) {
|
||||
if ((orient_slot->flag & SELECT) == 0) {
|
||||
return V3D_MANIP_DEFAULT;
|
||||
}
|
||||
}
|
||||
return BKE_scene_orientation_slot_get_index(orient_slot);
|
||||
}
|
||||
|
||||
void rna_TransformOrientationSlot_type_set(PointerRNA *ptr, int value)
|
||||
{
|
||||
Scene *scene = ptr->id.data;
|
||||
TransformOrientationSlot *orient_slot = ptr->data;
|
||||
|
||||
if (orient_slot != &scene->orientation_slots[SCE_ORIENT_DEFAULT]) {
|
||||
if (value == V3D_MANIP_DEFAULT) {
|
||||
orient_slot->flag &= ~SELECT;
|
||||
return;
|
||||
}
|
||||
else {
|
||||
orient_slot->flag |= SELECT;
|
||||
}
|
||||
}
|
||||
|
||||
BKE_scene_orientation_slot_set_index(orient_slot, value);
|
||||
}
|
||||
|
||||
|
@ -2001,13 +2022,27 @@ static PointerRNA rna_TransformOrientationSlot_get(PointerRNA *ptr)
|
|||
return rna_pointer_inherit_refine(ptr, &RNA_TransformOrientation, orientation);
|
||||
}
|
||||
|
||||
const EnumPropertyItem *rna_TransformOrientation_itemf(
|
||||
bContext *C, PointerRNA *ptr, PropertyRNA *UNUSED(prop), bool *r_free)
|
||||
static const EnumPropertyItem *rna_TransformOrientation_impl_itemf(
|
||||
bContext *C, PointerRNA *ptr,
|
||||
const bool with_scene,
|
||||
bool *r_free)
|
||||
{
|
||||
EnumPropertyItem tmp = {0, "", 0, "", ""};
|
||||
EnumPropertyItem *item = NULL;
|
||||
int i = V3D_MANIP_CUSTOM, totitem = 0;
|
||||
|
||||
if (with_scene) {
|
||||
tmp.identifier = "DEFAULT";
|
||||
tmp.name = "Default";
|
||||
tmp.description = "Use the scene orientation";
|
||||
tmp.value = V3D_MANIP_DEFAULT;
|
||||
tmp.icon = ICON_OBJECT_ORIGIN;
|
||||
RNA_enum_item_add(&item, &totitem, &tmp);
|
||||
tmp.icon = 0;
|
||||
|
||||
RNA_enum_item_add_separator(&item, &totitem);
|
||||
}
|
||||
|
||||
RNA_enum_items_add(&item, &totitem, rna_enum_transform_orientation_items);
|
||||
|
||||
Scene *scene;
|
||||
|
@ -2035,6 +2070,19 @@ const EnumPropertyItem *rna_TransformOrientation_itemf(
|
|||
|
||||
return item;
|
||||
}
|
||||
const EnumPropertyItem *rna_TransformOrientation_itemf(
|
||||
bContext *C, PointerRNA *ptr, PropertyRNA *UNUSED(prop), bool *r_free)
|
||||
{
|
||||
return rna_TransformOrientation_impl_itemf(C, ptr, false, r_free);
|
||||
}
|
||||
|
||||
const EnumPropertyItem *rna_TransformOrientation_with_scene_itemf(
|
||||
bContext *C, PointerRNA *ptr, PropertyRNA *UNUSED(prop), bool *r_free)
|
||||
{
|
||||
return rna_TransformOrientation_impl_itemf(C, ptr, true, r_free);
|
||||
}
|
||||
|
||||
#undef V3D_MANIP_DEFAULT
|
||||
|
||||
void rna_TransformOrientationSlot_ui_info(
|
||||
ID *scene_id, TransformOrientationSlot *orient_slot,
|
||||
|
@ -2227,8 +2275,8 @@ static void rna_def_transform_orientation_slot(BlenderRNA *brna)
|
|||
prop,
|
||||
"rna_TransformOrientationSlot_type_get",
|
||||
"rna_TransformOrientationSlot_type_set",
|
||||
"rna_TransformOrientation_itemf");
|
||||
RNA_def_property_ui_text(prop, "Transform Orientation", "Transformation orientation");
|
||||
"rna_TransformOrientation_with_scene_itemf");
|
||||
RNA_def_property_ui_text(prop, "Orientation", "Transformation orientation");
|
||||
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
|
||||
|
||||
prop = RNA_def_property(srna, "custom_orientation", PROP_POINTER, PROP_NONE);
|
||||
|
@ -2237,8 +2285,8 @@ static void rna_def_transform_orientation_slot(BlenderRNA *brna)
|
|||
RNA_def_property_ui_text(prop, "Current Transform Orientation", "");
|
||||
|
||||
/* flag */
|
||||
prop = RNA_def_property(srna, "use_global", PROP_BOOLEAN, PROP_NONE);
|
||||
RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", SELECT);
|
||||
prop = RNA_def_property(srna, "use", PROP_BOOLEAN, PROP_NONE);
|
||||
RNA_def_property_boolean_sdna(prop, NULL, "flag", SELECT);
|
||||
RNA_def_property_ui_text(prop, "Use", "Use scene orientation instead of a custom setting");
|
||||
RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL);
|
||||
|
||||
|
|
Loading…
Reference in New Issue