Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2018-09-13 15:03:52 +0300
committerCampbell Barton <ideasman42@gmail.com>2018-09-13 15:04:54 +0300
commit8326fe7aa5e12a0057c075eb5ecfd91f44a58d95 (patch)
treea04b541962c662077702e532aef6a123a8693f5c /source
parent3b8251664eb7b64a04391463ca9793fee9c1a1e9 (diff)
Gizmo: value2d cancel, snap & precise support
Diffstat (limited to 'source')
-rw-r--r--source/blender/editors/gizmo_library/gizmo_types/value2d_gizmo.c26
1 files changed, 24 insertions, 2 deletions
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 c0c53523ea9..1212d0e0839 100644
--- a/source/blender/editors/gizmo_library/gizmo_types/value2d_gizmo.c
+++ b/source/blender/editors/gizmo_library/gizmo_types/value2d_gizmo.c
@@ -35,6 +35,8 @@
* So we can use a single gizmo to make redoing an operator seem modal.
*/
+#include <math.h>
+
#include "MEM_guardedalloc.h"
#include "BKE_context.h"
@@ -66,16 +68,24 @@ static void gizmo_value_draw(const bContext *UNUSED(C), wmGizmo *UNUSED(gz))
static int gizmo_value_modal(
bContext *C, wmGizmo *gz, const wmEvent *event,
- eWM_GizmoFlagTweak UNUSED(tweak_flag))
+ eWM_GizmoFlagTweak tweak_flag)
{
ARegion *ar = CTX_wm_region(C);
ValueInteraction *inter = gz->interaction_data;
const float value_scale = 4.0f; /* Could be option. */
const float value_range = inter->range[1] - inter->range[0];
- const float value_delta = (
+ float value_delta = (
inter->init_prop_value +
(((event->mval[0] - inter->init_mval[0]) / ar->winx) * value_range)) * value_scale;
+
+ if (tweak_flag & WM_GIZMO_TWEAK_SNAP) {
+ value_delta = floorf((value_delta * 10.0f) + 0.5f) / 10.0f;
+ }
+ if (tweak_flag & WM_GIZMO_TWEAK_PRECISE) {
+ value_delta *= 0.1f;
+ }
+
/* 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)) {
@@ -107,6 +117,17 @@ static int gizmo_value_invoke(
return OPERATOR_RUNNING_MODAL;
}
+static void gizmo_value_exit(bContext *C, wmGizmo *gz, const bool cancel)
+{
+ if (cancel) {
+ ValueInteraction *inter = gz->interaction_data;
+ 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_value);
+ }
+ }
+}
+
static int gizmo_value_test_select(
bContext *UNUSED(C), wmGizmo *UNUSED(gz), const int UNUSED(mval[2]))
{
@@ -128,6 +149,7 @@ static void GIZMO_GT_value_2d(wmGizmoType *gzt)
/* api callbacks */
gzt->draw = gizmo_value_draw;
gzt->invoke = gizmo_value_invoke;
+ gzt->exit = gizmo_value_exit;
gzt->modal = gizmo_value_modal;
gzt->test_select = gizmo_value_test_select;