diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-09-18 07:38:05 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-09-18 07:38:05 +0300 |
commit | 2b57222ecea2e73ce28027373c0f3b57c75011a9 (patch) | |
tree | f20f1938d3d4efce461c3304198b653dc2eb526d /source/blender | |
parent | f677ff274c6815d9aa8e0e16fe0dbbdd3d33990c (diff) |
Gizmo: add snap & tweak to the dial widget
Allows holding Ctrl to snap w/ the spin tool.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/editors/gizmo_library/gizmo_types/dial3d_gizmo.c | 19 | ||||
-rw-r--r-- | source/blender/editors/gizmo_library/gizmo_types/value2d_gizmo.c | 4 |
2 files changed, 17 insertions, 6 deletions
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 a47474e6e85..4acd033a6e2 100644 --- a/source/blender/editors/gizmo_library/gizmo_types/dial3d_gizmo.c +++ b/source/blender/editors/gizmo_library/gizmo_types/dial3d_gizmo.c @@ -80,9 +80,9 @@ typedef struct DialInteraction { /* only for when using properties */ float prop_angle; } init; - struct { /* Cache the last angle to detect rotations bigger than -/+ PI. */ + eWM_GizmoFlagTweak tweak_flag; float angle; } prev; @@ -398,12 +398,12 @@ static void gizmo_dial_draw(const bContext *C, wmGizmo *gz) static int gizmo_dial_modal( bContext *C, wmGizmo *gz, const wmEvent *event, - eWM_GizmoFlagTweak UNUSED(tweak_flag)) + eWM_GizmoFlagTweak tweak_flag) { - if (event->type != MOUSEMOVE) { + DialInteraction *inter = gz->interaction_data; + if ((event->type != MOUSEMOVE) && (inter->prev.tweak_flag == tweak_flag)) { return OPERATOR_RUNNING_MODAL; } - const float co_outer[4] = {0.0f, DIAL_WIDTH, 0.0f}; /* coordinate at which the arc drawing will be started */ float angle_ofs, angle_delta; @@ -415,8 +415,14 @@ static int gizmo_dial_modal( CTX_data_depsgraph(C), gz, event, CTX_wm_region(C), CTX_wm_view3d(C), matrix, co_outer, &angle_ofs, &angle_delta); - DialInteraction *inter = gz->interaction_data; + if (tweak_flag & WM_GIZMO_TWEAK_SNAP) { + const double snap = DEG2RAD(5); + angle_delta = (float)roundf((double)angle_delta / snap) * snap; + } + if (tweak_flag & WM_GIZMO_TWEAK_PRECISE) { + angle_delta *= 0.1f; + } inter->output.angle_delta = angle_delta; inter->output.angle_ofs = angle_ofs; @@ -425,6 +431,9 @@ static int gizmo_dial_modal( if (WM_gizmo_target_property_is_valid(gz_prop)) { WM_gizmo_target_property_float_set(C, gz, gz_prop, inter->init.prop_angle + angle_delta); } + + inter->prev.tweak_flag = tweak_flag; + return OPERATOR_RUNNING_MODAL; } diff --git a/source/blender/editors/gizmo_library/gizmo_types/value2d_gizmo.c b/source/blender/editors/gizmo_library/gizmo_types/value2d_gizmo.c index 0f83e9a3514..46a6b8f3a5f 100644 --- a/source/blender/editors/gizmo_library/gizmo_types/value2d_gizmo.c +++ b/source/blender/editors/gizmo_library/gizmo_types/value2d_gizmo.c @@ -92,7 +92,9 @@ static int gizmo_value_modal( if (tweak_flag & WM_GIZMO_TWEAK_SNAP) { - value_delta = floorf((value_delta * 10.0f) + 0.5f) / 10.0f; + const double snap = 0.1; + value_delta = (float)roundf((double)value_delta / snap) * snap; + } if (tweak_flag & WM_GIZMO_TWEAK_PRECISE) { value_delta *= 0.1f; |