1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-27 21:49:10 +02:00

Merge pull request #5401 from Laserlicht/touch_overlay

[1.6.6] overlay for touch screens & pinch fix
This commit is contained in:
Ivan Savenko 2025-02-09 19:40:45 +02:00 committed by GitHub
commit 640f654fe0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 29 additions and 6 deletions

View File

@ -389,6 +389,13 @@ bool InputHandler::hasTouchInputDevice() const
return fingerHandler->hasTouchInputDevice();
}
int InputHandler::getNumTouchFingers() const
{
if(currentInputMode != InputMode::TOUCH)
return 0;
return fingerHandler->getNumTouchFingers();
}
void InputHandler::dispatchMainThread(const std::function<void()> & functor)
{
auto heapFunctor = new std::function<void()>(functor);

View File

@ -90,6 +90,9 @@ public:
/// returns true if system has active touchscreen
bool hasTouchInputDevice() const;
/// returns number of fingers on touchscreen
int getNumTouchFingers() const;
/// Calls provided functor in main thread on next execution frame
void dispatchMainThread(const std::function<void()> & functor);

View File

@ -35,7 +35,7 @@
#include <SDL_timer.h>
InputSourceTouch::InputSourceTouch()
: lastTapTimeTicks(0), lastLeftClickTimeTicks(0)
: lastTapTimeTicks(0), lastLeftClickTimeTicks(0), numTouchFingers(0)
{
params.useRelativeMode = settings["general"]["userRelativePointer"].Bool();
params.relativeModeSpeedFactor = settings["general"]["relativePointerSpeedMultiplier"].Float();
@ -116,6 +116,8 @@ void InputSourceTouch::handleEventFingerMotion(const SDL_TouchFingerEvent & tfin
void InputSourceTouch::handleEventFingerDown(const SDL_TouchFingerEvent & tfinger)
{
numTouchFingers = SDL_GetNumTouchFingers(tfinger.touchId);
// FIXME: better place to update potentially changed settings?
params.longTouchTimeMilliseconds = settings["general"]["longTouchTimeMilliseconds"].Float();
params.hapticFeedbackEnabled = settings["general"]["hapticFeedback"].Bool();
@ -174,6 +176,8 @@ void InputSourceTouch::handleEventFingerDown(const SDL_TouchFingerEvent & tfinge
void InputSourceTouch::handleEventFingerUp(const SDL_TouchFingerEvent & tfinger)
{
numTouchFingers = SDL_GetNumTouchFingers(tfinger.touchId);
switch(state)
{
case TouchState::RELATIVE_MODE:
@ -282,6 +286,11 @@ bool InputSourceTouch::hasTouchInputDevice() const
return SDL_GetNumTouchDevices() > 0;
}
int InputSourceTouch::getNumTouchFingers() const
{
return numTouchFingers;
}
void InputSourceTouch::emitPanningEvent(const SDL_TouchFingerEvent & tfinger)
{
Point distance = convertTouchToMouse(-tfinger.dx, -tfinger.dy);
@ -326,8 +335,8 @@ void InputSourceTouch::emitPinchEvent(const SDL_TouchFingerEvent & tfinger)
float newX = thisX - otherX;
float newY = thisY - otherY;
double distanceOld = std::sqrt(oldX * oldX + oldY + oldY);
double distanceNew = std::sqrt(newX * newX + newY + newY);
double distanceOld = std::sqrt(oldX * oldX + oldY * oldY);
double distanceNew = std::sqrt(newX * newX + newY * newY);
if (distanceOld > params.pinchSensitivityThreshold)
GH.events().dispatchGesturePinch(lastTapPosition, distanceNew / distanceOld);

View File

@ -108,6 +108,7 @@ class InputSourceTouch
uint32_t lastLeftClickTimeTicks;
Point lastLeftClickPosition;
int numTouchFingers;
Point convertTouchToMouse(const SDL_TouchFingerEvent & current);
Point convertTouchToMouse(float x, float y);
@ -127,4 +128,6 @@ public:
void handleUpdate();
bool hasTouchInputDevice() const;
int getNumTouchFingers() const;
};

View File

@ -224,7 +224,7 @@ void MapViewController::updateState()
adventureContext->settingShowVisitable = settings["session"]["showVisitable"].Bool();
adventureContext->settingShowBlocked = settings["session"]["showBlocked"].Bool();
adventureContext->settingSpellRange = settings["session"]["showSpellRange"].Bool();
adventureContext->settingTextOverlay = GH.isKeyboardAltDown();
adventureContext->settingTextOverlay = GH.isKeyboardAltDown() || GH.input().getNumTouchFingers() == 2;
}
}

View File

@ -20,6 +20,7 @@
#include "../CGameInfo.h"
#include "../CPlayerInterface.h"
#include "../PlayerLocalState.h"
#include "../eventsSDL/InputHandler.h"
#include "../gui/CGuiHandler.h"
#include "../gui/Shortcut.h"
#include "../gui/WindowHandler.h"
@ -175,7 +176,7 @@ void CBuildingRect::show(Canvas & to)
{
uint32_t stageDelay = BUILDING_APPEAR_TIMEPOINT;
bool showTextOverlay = GH.isKeyboardAltDown();
bool showTextOverlay = GH.isKeyboardAltDown() || GH.input().getNumTouchFingers() == 2;
if(stateTimeCounter < BUILDING_APPEAR_TIMEPOINT)
{
@ -692,7 +693,7 @@ void CCastleBuildings::show(Canvas & to)
{
CIntObject::show(to);
bool showTextOverlay = GH.isKeyboardAltDown();
bool showTextOverlay = GH.isKeyboardAltDown() || GH.input().getNumTouchFingers() == 2;
if(showTextOverlay)
drawOverlays(to, buildings);
}