Pārlūkot izejas kodu

implement overlay for touch screens

Laserlicht 8 mēneši atpakaļ
vecāks
revīzija
1f61f22122

+ 7 - 0
client/eventsSDL/InputHandler.cpp

@@ -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);

+ 3 - 0
client/eventsSDL/InputHandler.h

@@ -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);
 

+ 10 - 1
client/eventsSDL/InputSourceTouch.cpp

@@ -34,7 +34,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();
@@ -114,6 +114,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();
@@ -172,6 +174,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:
@@ -280,6 +284,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);

+ 3 - 0
client/eventsSDL/InputSourceTouch.h

@@ -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;
 };

+ 1 - 1
client/mapView/MapViewController.cpp

@@ -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;
 	}
 }
 

+ 3 - 2
client/windows/CCastleInterface.cpp

@@ -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);
 }