[Bf-blender-cvs] [2b57222ecea] blender2.8: Gizmo: add snap & tweak to the dial widget
Campbell Barton
noreply at git.blender.org
Tue Sep 18 06:26:30 CEST 2018
Commit: 2b57222ecea2e73ce28027373c0f3b57c75011a9
Author: Campbell Barton
Date: Tue Sep 18 14:38:05 2018 +1000
Branches: blender2.8
https://developer.blender.org/rB2b57222ecea2e73ce28027373c0f3b57c75011a9
Gizmo: add snap & tweak to the dial widget
Allows holding Ctrl to snap w/ the spin tool.
===================================================================
M source/blender/editors/gizmo_library/gizmo_types/dial3d_gizmo.c
M source/blender/editors/gizmo_library/gizmo_types/value2d_gizmo.c
===================================================================
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;
More information about the Bf-blender-cvs
mailing list