mirror of
https://github.com/vcmi/vcmi.git
synced 2025-04-23 12:08:45 +02:00
Merge pull request #5461 from Laserlicht/touch_improve
[1.6.7?] Improve touch motion
This commit is contained in:
commit
bc90f4f4aa
@ -58,6 +58,15 @@ InputSourceTouch::InputSourceTouch()
|
|||||||
|
|
||||||
void InputSourceTouch::handleEventFingerMotion(const SDL_TouchFingerEvent & tfinger)
|
void InputSourceTouch::handleEventFingerMotion(const SDL_TouchFingerEvent & tfinger)
|
||||||
{
|
{
|
||||||
|
Point screenSize = GH.screenDimensions();
|
||||||
|
|
||||||
|
motionAccumulatedX[tfinger.fingerId] += tfinger.dx;
|
||||||
|
motionAccumulatedY[tfinger.fingerId] += tfinger.dy;
|
||||||
|
|
||||||
|
float motionThreshold = 1.0 / std::min(screenSize.x, screenSize.y);
|
||||||
|
if(std::abs(motionAccumulatedX[tfinger.fingerId]) < motionThreshold && std::abs(motionAccumulatedY[tfinger.fingerId]) < motionThreshold)
|
||||||
|
return;
|
||||||
|
|
||||||
if (CCS && CCS->curh && settings["video"]["cursor"].String() == "software" && state != TouchState::RELATIVE_MODE)
|
if (CCS && CCS->curh && settings["video"]["cursor"].String() == "software" && state != TouchState::RELATIVE_MODE)
|
||||||
CCS->curh->cursorMove(GH.getCursorPosition().x, GH.getCursorPosition().y);
|
CCS->curh->cursorMove(GH.getCursorPosition().x, GH.getCursorPosition().y);
|
||||||
|
|
||||||
@ -65,12 +74,11 @@ void InputSourceTouch::handleEventFingerMotion(const SDL_TouchFingerEvent & tfin
|
|||||||
{
|
{
|
||||||
case TouchState::RELATIVE_MODE:
|
case TouchState::RELATIVE_MODE:
|
||||||
{
|
{
|
||||||
Point screenSize = GH.screenDimensions();
|
|
||||||
int scalingFactor = GH.screenHandler().getScalingFactor();
|
int scalingFactor = GH.screenHandler().getScalingFactor();
|
||||||
|
|
||||||
Point moveDistance {
|
Point moveDistance {
|
||||||
static_cast<int>(screenSize.x * params.relativeModeSpeedFactor * tfinger.dx),
|
static_cast<int>(screenSize.x * params.relativeModeSpeedFactor * motionAccumulatedX[tfinger.fingerId]),
|
||||||
static_cast<int>(screenSize.y * params.relativeModeSpeedFactor * tfinger.dy)
|
static_cast<int>(screenSize.y * params.relativeModeSpeedFactor * motionAccumulatedY[tfinger.fingerId])
|
||||||
};
|
};
|
||||||
|
|
||||||
GH.input().moveCursorPosition(moveDistance);
|
GH.input().moveCursorPosition(moveDistance);
|
||||||
@ -112,6 +120,11 @@ void InputSourceTouch::handleEventFingerMotion(const SDL_TouchFingerEvent & tfin
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(std::abs(motionAccumulatedX[tfinger.fingerId]) >= motionThreshold)
|
||||||
|
motionAccumulatedX[tfinger.fingerId] = 0;
|
||||||
|
if(std::abs(motionAccumulatedY[tfinger.fingerId]) >= motionThreshold)
|
||||||
|
motionAccumulatedY[tfinger.fingerId] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputSourceTouch::handleEventFingerDown(const SDL_TouchFingerEvent & tfinger)
|
void InputSourceTouch::handleEventFingerDown(const SDL_TouchFingerEvent & tfinger)
|
||||||
@ -293,7 +306,7 @@ int InputSourceTouch::getNumTouchFingers() const
|
|||||||
|
|
||||||
void InputSourceTouch::emitPanningEvent(const SDL_TouchFingerEvent & tfinger)
|
void InputSourceTouch::emitPanningEvent(const SDL_TouchFingerEvent & tfinger)
|
||||||
{
|
{
|
||||||
Point distance = convertTouchToMouse(-tfinger.dx, -tfinger.dy);
|
Point distance = convertTouchToMouse(-motionAccumulatedX[tfinger.fingerId], -motionAccumulatedY[tfinger.fingerId]);
|
||||||
|
|
||||||
GH.events().dispatchGesturePanning(lastTapPosition, convertTouchToMouse(tfinger), distance);
|
GH.events().dispatchGesturePanning(lastTapPosition, convertTouchToMouse(tfinger), distance);
|
||||||
}
|
}
|
||||||
@ -327,8 +340,8 @@ void InputSourceTouch::emitPinchEvent(const SDL_TouchFingerEvent & tfinger)
|
|||||||
|
|
||||||
float thisX = tfinger.x * GH.screenDimensions().x;
|
float thisX = tfinger.x * GH.screenDimensions().x;
|
||||||
float thisY = tfinger.y * GH.screenDimensions().y;
|
float thisY = tfinger.y * GH.screenDimensions().y;
|
||||||
float deltaX = tfinger.dx * GH.screenDimensions().x;
|
float deltaX = motionAccumulatedX[tfinger.fingerId] * GH.screenDimensions().x;
|
||||||
float deltaY = tfinger.dy * GH.screenDimensions().y;
|
float deltaY = motionAccumulatedY[tfinger.fingerId] * GH.screenDimensions().y;
|
||||||
|
|
||||||
float oldX = thisX - deltaX - otherX;
|
float oldX = thisX - deltaX - otherX;
|
||||||
float oldY = thisY - deltaY - otherY;
|
float oldY = thisY - deltaY - otherY;
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "SDL_touch.h"
|
||||||
#include "../../lib/Point.h"
|
#include "../../lib/Point.h"
|
||||||
|
|
||||||
// Debug option. If defined, mouse events will instead generate touch events, allowing testing of touch input on desktop
|
// Debug option. If defined, mouse events will instead generate touch events, allowing testing of touch input on desktop
|
||||||
@ -110,6 +111,9 @@ class InputSourceTouch
|
|||||||
Point lastLeftClickPosition;
|
Point lastLeftClickPosition;
|
||||||
int numTouchFingers;
|
int numTouchFingers;
|
||||||
|
|
||||||
|
std::map<SDL_FingerID, float> motionAccumulatedX;
|
||||||
|
std::map<SDL_FingerID, float> motionAccumulatedY;
|
||||||
|
|
||||||
Point convertTouchToMouse(const SDL_TouchFingerEvent & current);
|
Point convertTouchToMouse(const SDL_TouchFingerEvent & current);
|
||||||
Point convertTouchToMouse(float x, float y);
|
Point convertTouchToMouse(float x, float y);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user