diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-09-13 15:25:15 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-09-13 15:25:15 +0300 |
commit | 80f083f993d4f62a7e9c35ab946e031ca70b09cd (patch) | |
tree | cef8282d290ba47b19695d65b33b040f6df89f1d | |
parent | 00bdd0457023aa1ebc7fcf7891171d6ff373b6ac (diff) |
Gizmo: avoid redundant value2d updates
-rw-r--r-- | source/blender/editors/gizmo_library/gizmo_types/value2d_gizmo.c | 49 |
1 files changed, 29 insertions, 20 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 fd695eec2ba..c6090250db7 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,7 @@ * So we can use a single gizmo to make redoing an operator seem modal. */ +#include <float.h> #include <math.h> #include "MEM_guardedalloc.h" @@ -58,8 +59,13 @@ * \{ */ typedef struct ValueInteraction { - float init_mval[2]; - float init_prop_value; + struct { + float mval[2]; + float prop_value; + } init; + struct { + float prop_value; + } prev; float range[2]; } ValueInteraction; @@ -77,8 +83,8 @@ static int gizmo_value_modal( const float value_scale = 4.0f; /* Could be option. */ const float value_range = inter->range[1] - inter->range[0]; float value_delta = ( - inter->init_prop_value + - (((event->mval[0] - inter->init_mval[0]) / ar->winx) * value_range)) * value_scale; + inter->init.prop_value + + (((event->mval[0] - inter->init.mval[0]) / ar->winx) * value_range)) * value_scale; if (tweak_flag & WM_GIZMO_TWEAK_SNAP) { @@ -87,21 +93,23 @@ static int gizmo_value_modal( if (tweak_flag & WM_GIZMO_TWEAK_PRECISE) { value_delta *= 0.1f; } - const float value_final = inter->init_prop_value + value_delta; + const float value_final = inter->init.prop_value + value_delta; - /* 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, value_final); - } + if (value_final != inter->prev.prop_value) { + /* 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, value_final); + } - { - ScrArea *sa = CTX_wm_area(C); - char str[64]; - SNPRINTF(str, "%.4f", value_final); - ED_area_status_text(sa, str); + { + ScrArea *sa = CTX_wm_area(C); + char str[64]; + SNPRINTF(str, "%.4f", value_final); + ED_area_status_text(sa, str); + } + inter->prev.prop_value = value_final; } - return OPERATOR_RUNNING_MODAL; } @@ -111,12 +119,13 @@ static int gizmo_value_invoke( { ValueInteraction *inter = MEM_callocN(sizeof(ValueInteraction), __func__); - inter->init_mval[0] = event->mval[0]; - inter->init_mval[1] = event->mval[1]; + inter->init.mval[0] = event->mval[0]; + inter->init.mval[1] = event->mval[1]; + inter->prev.prop_value = -FLT_MAX; wmGizmoProperty *gz_prop = WM_gizmo_target_property_find(gz, "offset"); if (WM_gizmo_target_property_is_valid(gz_prop)) { - inter->init_prop_value = WM_gizmo_target_property_float_get(gz, gz_prop); + inter->init.prop_value = WM_gizmo_target_property_float_get(gz, gz_prop); if (!WM_gizmo_target_property_float_range_get(gz, gz_prop, inter->range)) { inter->range[0] = 0.0f; inter->range[1] = 1.0f; @@ -136,7 +145,7 @@ static void gizmo_value_exit(bContext *C, wmGizmo *gz, const bool 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); + WM_gizmo_target_property_float_set(C, gz, gz_prop, inter->init.prop_value); } } } |