From 518451757e3a809978417e1ef30cf85a725dae86 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 25 Sep 2018 15:14:17 +1000 Subject: Gizmo: dial support for a click setting a value Useful for click w/o drag to spin a full revolution. --- .../gizmo_library/gizmo_types/dial3d_gizmo.c | 31 +++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'source/blender/editors/gizmo_library') diff --git a/source/blender/editors/gizmo_library/gizmo_types/dial3d_gizmo.c b/source/blender/editors/gizmo_library/gizmo_types/dial3d_gizmo.c index d09acfa8761..48ac16290df 100644 --- a/source/blender/editors/gizmo_library/gizmo_types/dial3d_gizmo.c +++ b/source/blender/editors/gizmo_library/gizmo_types/dial3d_gizmo.c @@ -88,6 +88,7 @@ typedef struct DialInteraction { /* Number of full rotations. */ int rotations; + bool has_drag; /* Final output values, used for drawing. */ struct { @@ -445,6 +446,10 @@ static int gizmo_dial_modal( if (tweak_flag & WM_GIZMO_TWEAK_PRECISE) { angle_delta *= 0.1f; } + if (angle_delta != 0.0f) { + inter->has_drag = true; + } + inter->output.angle_delta = angle_delta; inter->output.angle_ofs = angle_ofs; @@ -462,13 +467,33 @@ static int gizmo_dial_modal( static void gizmo_dial_exit(bContext *C, wmGizmo *gz, const bool cancel) { DialInteraction *inter = gz->interaction_data; + bool use_reset_value = false; + float reset_value = 0.0f; if (cancel) { /* Set the property for the operator and call its modal function. */ wmGizmoProperty *gz_prop = WM_gizmo_target_property_find(gz, "offset"); if (WM_gizmo_target_property_is_valid(gz_prop)) { - WM_gizmo_target_property_float_set(C, gz, gz_prop, inter->init.prop_angle); + use_reset_value = true; + reset_value = inter->init.prop_angle; + } + } + else { + if (inter->has_drag == false) { + PropertyRNA *prop = RNA_struct_find_property(gz->ptr, "click_value"); + if (RNA_property_is_set(gz->ptr, prop)) { + use_reset_value = true; + reset_value = RNA_property_float_get(gz->ptr, prop); + } + } + } + + if (use_reset_value) { + wmGizmoProperty *gz_prop = WM_gizmo_target_property_find(gz, "offset"); + if (WM_gizmo_target_property_is_valid(gz_prop)) { + WM_gizmo_target_property_float_set(C, gz, gz_prop, reset_value); } } + } @@ -531,6 +556,10 @@ static void GIZMO_GT_dial_3d(wmGizmoType *gzt) RNA_def_boolean(gzt->srna, "wrap_angle", true, "Wrap Angle", ""); RNA_def_float_factor(gzt->srna, "arc_inner_factor", 0.0f, 0.0f, 1.0f, "Arc Inner Factor", "", 0.0f, 1.0f); RNA_def_float_factor(gzt->srna, "arc_partial_angle", 0.0f, 0.0f, M_PI * 2, "Show Partial Dial", "", 0.0f, M_PI * 2); + RNA_def_float( + gzt->srna, "click_value", 0.0f, -FLT_MAX, FLT_MAX, + "Click Value", "Value to use for a single click action", + -FLT_MAX, FLT_MAX); WM_gizmotype_target_property_def(gzt, "offset", PROP_FLOAT, 1); } -- cgit v1.2.3