mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
support double tap
This commit is contained in:
parent
d225bdb1cd
commit
7321bb1d25
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user