UI: Decrease Tablet Drag Threshold With Pen Pressure

We have separate drag movement thresholds, and one is specifically for
tablet pen movement. A movement is not considered a drag (when using
left click select) until this amount is detected. This PR decreases
that amount with pen pressure. This results in more immediate and
responsive behavior that feels quite natural. Whether using RCS or
LCS this also similarly reduces the lag when dragging on numerical
inputs and sliders.

Pull Request: https://projects.blender.org/blender/blender/pulls/136685
This commit is contained in:
Harley Acheson
2025-04-15 02:51:15 +02:00
committed by Harley Acheson
parent 4794cbe0bf
commit 5102880f51
2 changed files with 24 additions and 7 deletions

View File

@@ -208,8 +208,6 @@ static int ui_handle_region_semi_modal_buttons(bContext *C, const wmEvent *event
#define MENU_TOWARDS_MARGIN 20
/** Tolerance for closing menus (in pixels). */
#define MENU_TOWARDS_WIGGLE_ROOM 64
/** Drag-lock distance threshold (in pixels). */
#define BUTTON_DRAGLOCK_THRESH 3
enum uiButtonActivateType {
BUTTON_ACTIVATE_OVER,
@@ -685,6 +683,18 @@ static void ui_mouse_scale_warp(uiHandleButtonData *data,
/** \name UI Utilities
* \{ */
#ifdef USE_DRAG_MULTINUM
static bool ui_multibut_drag_wait(const uiHandleButtonMulti &multi_data)
{
const bool initializing = ELEM(
multi_data.init, uiHandleButtonMulti::INIT_UNSET, uiHandleButtonMulti::INIT_SETUP);
const bool vertical_dragging = abs(multi_data.drag_dir[1]) > abs(multi_data.drag_dir[0]);
/* Continue waiting if we are dragging vertically but have not yet detected gesture. */
return (initializing && vertical_dragging);
}
#endif /* USE_DRAG_MULTINUM */
/**
* Ignore mouse movements within some horizontal pixel threshold before starting to drag
*/
@@ -695,14 +705,13 @@ static bool ui_but_dragedit_update_mval(uiHandleButtonData *data, int mx)
}
if (data->draglock) {
if (abs(mx - data->dragstartx) <= BUTTON_DRAGLOCK_THRESH) {
const int threshold = WM_event_drag_threshold(data->window->event_last_handled);
if (abs(mx - data->dragstartx) < threshold) {
return false;
}
#ifdef USE_DRAG_MULTINUM
if (ELEM(data->multi_data.init,
uiHandleButtonMulti::INIT_UNSET,
uiHandleButtonMulti::INIT_SETUP))
{
/* Continue to wait for multibut drag initialization if dragging vertically. */
if (ui_multibut_drag_wait(data->multi_data)) {
return false;
}
#endif

View File

@@ -406,6 +406,14 @@ int WM_event_drag_threshold(const wmEvent *event)
* The `event->type` would include #MOUSEMOVE which is always the case when dragging
* and does not help us know which threshold to use. */
if (WM_event_is_tablet(event)) {
/* Decrease threshold as pen pressure is increased. */
if (event->tablet.pressure > 0.0f && event->tablet.pressure < 1.0f) {
/* Pressure 0 results in max threshold, pressure 0.5 and above results in 0 pixels. */
const float bias = 1.0f - std::min(event->tablet.pressure * 2.0f, 1.0f);
drag_threshold = std::max(int(bias * float(U.drag_threshold_tablet)), 0);
/* Return without multiplying by resolution scale. */
return drag_threshold;
}
drag_threshold = U.drag_threshold_tablet;
}
else {