1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00

support double tap

This commit is contained in:
Laserlicht 2023-09-18 16:05:39 +02:00 committed by GitHub
parent d225bdb1cd
commit 7321bb1d25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 3 deletions

View File

@ -33,7 +33,7 @@
#include <SDL_timer.h>
InputSourceTouch::InputSourceTouch()
: lastTapTimeTicks(0)
: lastTapTimeTicks(0), lastLeftClickTimeTicks(0)
{
params.useRelativeMode = settings["general"]["userRelativePointer"].Bool();
params.relativeModeSpeedFactor = settings["general"]["relativePointerSpeedMultiplier"].Float();
@ -181,8 +181,15 @@ void InputSourceTouch::handleEventFingerUp(const SDL_TouchFingerEvent & tfinger)
case TouchState::TAP_DOWN_SHORT:
{
GH.input().setCursorPosition(convertTouchToMouse(tfinger));
GH.events().dispatchMouseLeftButtonPressed(convertTouchToMouse(tfinger), params.touchToleranceDistance);
GH.events().dispatchMouseLeftButtonReleased(convertTouchToMouse(tfinger), params.touchToleranceDistance);
if(tfinger.timestamp - lastLeftClickTimeTicks < doubleTouchTimeMilliseconds && (convertTouchToMouse(tfinger) - lastLeftClickPosition).distance < doubleTouchToleranceDistance)
GH.events().dispatchMouseDoubleClick(convertTouchToMouse(tfinger);
else
{
GH.events().dispatchMouseLeftButtonPressed(convertTouchToMouse(tfinger), params.touchToleranceDistance);
GH.events().dispatchMouseLeftButtonReleased(convertTouchToMouse(tfinger), params.touchToleranceDistance);
}
lastLeftClickTimeTicks = tfinger.timestamp;
lastLeftClickPosition = convertTouchToMouse(tfinger);
state = TouchState::IDLE;
break;
}

View File

@ -72,6 +72,12 @@ struct TouchInputParameters
/// tap for period longer than specified here will be qualified as "long tap", triggering corresponding gesture
uint32_t longTouchTimeMilliseconds = 750;
/// time span in where the second tap has to happen for qualifing as "double click"
uint32_t doubleTouchTimeMilliseconds = 500;
/// max distance in where the second tap has to happen for qualifing as "double click"
uint32_t doubleTouchToleranceDistance = 50;
/// moving finger for distance larger than specified will be qualified as panning gesture instead of long press
uint32_t panningSensitivityThreshold = 10;
@ -94,6 +100,9 @@ class InputSourceTouch
uint32_t lastTapTimeTicks;
Point lastTapPosition;
uint32_t lastLeftClickTimeTicks;
Point lastLeftClickPosition;
Point convertTouchToMouse(const SDL_TouchFingerEvent & current);
Point convertTouchToMouse(float x, float y);