From e0114e297ab1cd4674bea23f260ce5ec05376a78 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Sat, 20 Mar 2021 22:06:12 +0200 Subject: Touch: Adjusted tap-and-hold gesture After the hold has been detected, require a larger motion to begin dragging. --- src/ui/touch.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/ui/touch.c b/src/ui/touch.c index c369c5a5..40e5c5d0 100644 --- a/src/ui/touch.c +++ b/src/ui/touch.c @@ -118,8 +118,12 @@ iLocalDef float distance_Touch_(const iTouch *d) { return length_F3(sub_F3(d->pos[0], d->startPos)); } +static iBool isStationaryDistance_Touch_(const iTouch *d, int distance) { + return !d->hasMoved && distance_Touch_(d) < distance * get_Window()->pixelRatio; +} + static iBool isStationary_Touch_(const iTouch *d) { - return !d->hasMoved && distance_Touch_(d) < tapRadiusPt_ * get_Window()->pixelRatio; + return isStationaryDistance_Touch_(d, tapRadiusPt_); } static void dispatchMotion_Touch_(iFloat3 pos, int buttonState) { @@ -372,10 +376,12 @@ iBool processEvent_Touch(const SDL_Event *ev) { } if (touch->isTapAndHold) { pushPos_Touch_(touch, pos, fing->timestamp); - if (!touch->hasMoved && !isStationary_Touch_(touch)) { + if (!touch->hasMoved && !isStationaryDistance_Touch_(touch, tapRadiusPt_ * 3)) { touch->hasMoved = iTrue; } - dispatchMotion_Touch_(pos, 0); + if (touch->hasMoved) { + dispatchMotion_Touch_(pos, 0); + } return iTrue; } /* Update touch position. */ -- cgit v1.2.3