mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-24 08:32:34 +02:00
Implemented panning gesture via touch input
This commit is contained in:
parent
48859e186e
commit
26fd651917
@ -54,14 +54,14 @@ void InputHandler::handleCurrentEvent(const SDL_Event & current)
|
||||
return mouseHandler->handleEventMouseMotion(current.motion);
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
return mouseHandler->handleEventMouseButtonDown(current.button);
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
return mouseHandler->handleEventMouseButtonUp(current.button);
|
||||
case SDL_MOUSEWHEEL:
|
||||
return mouseHandler->handleEventMouseWheel(current.wheel);
|
||||
case SDL_TEXTINPUT:
|
||||
return textHandler->handleEventTextInput(current.text);
|
||||
case SDL_TEXTEDITING:
|
||||
return textHandler->handleEventTextEditing(current.edit);
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
return mouseHandler->handleEventMouseButtonUp(current.button);
|
||||
case SDL_FINGERMOTION:
|
||||
return fingerHandler->handleEventFingerMotion(current.tfinger);
|
||||
case SDL_FINGERDOWN:
|
||||
|
@ -30,7 +30,6 @@ void InputSourceMouse::handleEventMouseMotion(const SDL_MouseMotionEvent & motio
|
||||
GH.events().dispatchGesturePanning(distance);
|
||||
|
||||
mouseButtonsMask = motion.state;
|
||||
|
||||
}
|
||||
|
||||
void InputSourceMouse::handleEventMouseButtonDown(const SDL_MouseButtonEvent & button)
|
||||
|
@ -61,17 +61,21 @@ void InputSourceTouch::handleEventFingerMotion(const SDL_TouchFingerEvent & tfin
|
||||
}
|
||||
case TouchState::TAP_DOWN_SHORT:
|
||||
{
|
||||
state = TouchState::TAP_DOWN_PANNING;
|
||||
GH.input().setCursorPosition(convertTouchToMouse(tfinger));
|
||||
|
||||
Point distance = GH.getCursorPosition() - lastTapPosition;
|
||||
if ( std::abs(distance.x) > params.panningSensitivityThreshold || std::abs(distance.y) > params.panningSensitivityThreshold)
|
||||
state = TouchState::TAP_DOWN_PANNING;
|
||||
break;
|
||||
}
|
||||
case TouchState::TAP_DOWN_PANNING:
|
||||
{
|
||||
emitPanningEvent();
|
||||
emitPanningEvent(tfinger);
|
||||
break;
|
||||
}
|
||||
case TouchState::TAP_DOWN_DOUBLE:
|
||||
{
|
||||
emitPinchEvent();
|
||||
emitPinchEvent(tfinger);
|
||||
break;
|
||||
}
|
||||
case TouchState::TAP_DOWN_LONG:
|
||||
@ -100,6 +104,7 @@ void InputSourceTouch::handleEventFingerDown(const SDL_TouchFingerEvent & tfinge
|
||||
case TouchState::IDLE:
|
||||
{
|
||||
GH.input().setCursorPosition(convertTouchToMouse(tfinger));
|
||||
lastTapPosition = GH.getCursorPosition();
|
||||
state = TouchState::TAP_DOWN_SHORT;
|
||||
break;
|
||||
}
|
||||
@ -200,12 +205,14 @@ bool InputSourceTouch::isMouseButtonPressed(MouseButton button) const
|
||||
return false;
|
||||
}
|
||||
|
||||
void InputSourceTouch::emitPanningEvent()
|
||||
void InputSourceTouch::emitPanningEvent(const SDL_TouchFingerEvent & tfinger)
|
||||
{
|
||||
// TODO
|
||||
Point distance(-tfinger.dx * GH.screenDimensions().x, -tfinger.dy * GH.screenDimensions().y);
|
||||
|
||||
GH.events().dispatchGesturePanning(distance);
|
||||
}
|
||||
|
||||
void InputSourceTouch::emitPinchEvent()
|
||||
void InputSourceTouch::emitPinchEvent(const SDL_TouchFingerEvent & tfinger)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
@ -10,9 +10,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
class Point;
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
#include "../../lib/Point.h"
|
||||
|
||||
enum class MouseButton;
|
||||
struct SDL_TouchFingerEvent;
|
||||
@ -69,8 +67,13 @@ enum class TouchState
|
||||
struct TouchInputParameters
|
||||
{
|
||||
double relativeModeSpeedFactor = 1.0;
|
||||
|
||||
/// tap for period longer than specified here will be qualified as "long tap", triggering corresponding gesture
|
||||
uint32_t longPressTimeMilliseconds = 500;
|
||||
|
||||
/// moving finger for distance larger than specified will be qualified as panning gesture instead of long press
|
||||
uint32_t panningSensitivityThreshold = 16;
|
||||
|
||||
bool useHoldGesture = true;
|
||||
bool usePanGesture = true;
|
||||
bool usePinchGesture = true;
|
||||
@ -83,11 +86,12 @@ class InputSourceTouch
|
||||
TouchInputParameters params;
|
||||
TouchState state;
|
||||
uint32_t lastTapTimeTicks;
|
||||
Point lastTapPosition;
|
||||
|
||||
Point convertTouchToMouse(const SDL_TouchFingerEvent & current);
|
||||
|
||||
void emitPanningEvent();
|
||||
void emitPinchEvent();
|
||||
void emitPanningEvent(const SDL_TouchFingerEvent & tfinger);
|
||||
void emitPinchEvent(const SDL_TouchFingerEvent & tfinger);
|
||||
|
||||
public:
|
||||
InputSourceTouch();
|
||||
|
Loading…
Reference in New Issue
Block a user