diff options
author | Julian Eisel <eiseljulian@gmail.com> | 2015-09-29 20:56:09 +0300 |
---|---|---|
committer | Julian Eisel <eiseljulian@gmail.com> | 2015-09-30 02:58:59 +0300 |
commit | 32365bb06c15b8fecaf2d50a45851f8a256ffcf0 (patch) | |
tree | 601edd6571226927a2facd45d2af2d171182afbe /source/blender | |
parent | 7d2a62ef65e075d10ac57aaf170f5c08e2e5b267 (diff) |
Add drag-threshold for number slider buttons
Was already used for normal number buttons for ages, makes sense to use here too.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/editors/interface/interface_handlers.c | 50 |
1 files changed, 34 insertions, 16 deletions
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index fe5a5031725..c4457f45dde 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -138,6 +138,8 @@ static bool ui_mouse_motion_keynav_test(struct uiKeyNavLock *keynav, const wmEve #define MENU_TOWARDS_MARGIN 20 /* margin in pixels */ #define MENU_TOWARDS_WIGGLE_ROOM 64 /* tolerance in pixels */ +/* drag-lock distance threshold in pixels */ +#define BUTTON_DRAGLOCK_THRESH 3 typedef enum uiButtonActivateType { BUTTON_ACTIVATE_OVER, @@ -529,6 +531,30 @@ static bool ui_but_is_cursor_warp(uiBut *but) return false; } +/** + * Ignore mouse movements within some horizontal pixel threshold before starting to drag + */ +static bool ui_but_dragedit_poll(uiHandleButtonData *data, int mx) +{ + if (mx == data->draglastx) + return false; + + if (data->draglock) { + if (ABS(mx - data->dragstartx) <= BUTTON_DRAGLOCK_THRESH) { + return false; + } +#ifdef USE_DRAG_MULTINUM + if (ELEM(data->multi_data.init, BUTTON_MULTI_INIT_UNSET, BUTTON_MULTI_INIT_SETUP)) { + return false; + } +#endif + data->draglock = false; + data->dragstartx = mx; /* ignore mouse movement within drag-lock */ + } + + return true; +} + static float ui_mouse_scale_warp_factor(const bool shift) { return shift ? 0.05f : 1.0f; @@ -3993,23 +4019,10 @@ static bool ui_numedit_but_NUM( int lvalue, temp; bool changed = false; const bool is_float = ui_but_is_float(but); - - if (mx == data->draglastx) - return changed; - - /* drag-lock - prevent unwanted scroll adjustments */ - /* change value (now 3) to adjust threshold in pixels */ - if (data->draglock) { - if (abs(mx - data->dragstartx) <= 3) - return changed; -#ifdef USE_DRAG_MULTINUM - if (ELEM(data->multi_data.init, BUTTON_MULTI_INIT_UNSET, BUTTON_MULTI_INIT_SETUP)) { - return changed; - } -#endif - data->draglock = false; - data->dragstartx = mx; /* ignore mouse movement within drag-lock */ + /* prevent unwanted drag adjustments */ + if (ui_but_dragedit_poll(data, mx) == false) { + return changed; } softmin = but->softmin; @@ -4332,6 +4345,11 @@ static bool ui_numedit_but_SLI( /* note, 'offs' is really from the widget drawing rounded corners see 'widget_numslider' */ float offs; + /* prevent unwanted drag adjustments */ + if (ui_but_dragedit_poll(data, mx) == false) { + return changed; + } + softmin = but->softmin; softmax = but->softmax; softrange = softmax - softmin; |