Pārlūkot izejas kodu

Fix movement of cursor when software cursor is on and touch input in use

Ivan Savenko 4 mēneši atpakaļ
vecāks
revīzija
851c9304b5

+ 2 - 0
client/eventsSDL/InputHandler.cpp

@@ -289,12 +289,14 @@ void InputHandler::preprocessEvent(const SDL_Event & ev)
 		return;
 	}
 
+#ifndef VCMI_EMULATE_TOUCHSCREEN_WITH_MOUSE
 	//preprocessing
 	if(ev.type == SDL_MOUSEMOTION)
 	{
 		std::scoped_lock interfaceLock(ENGINE->interfaceMutex);
 		ENGINE->cursor().cursorMove(ev.motion.x, ev.motion.y);
 	}
+#endif
 
 	{
 		std::unique_lock<std::mutex> lock(eventsMutex);

+ 14 - 3
client/eventsSDL/InputSourceTouch.cpp

@@ -65,15 +65,18 @@ void InputSourceTouch::handleEventFingerMotion(const SDL_TouchFingerEvent & tfin
 	if(std::abs(motionAccumulatedX[tfinger.fingerId]) < motionThreshold && std::abs(motionAccumulatedY[tfinger.fingerId]) < motionThreshold)
 		return;
 
+	int scalingFactor = ENGINE->screenHandler().getScalingFactor();
+
 	if (settings["video"]["cursor"].String() == "software" && state != TouchState::RELATIVE_MODE)
-		ENGINE->cursor().cursorMove(ENGINE->getCursorPosition().x, ENGINE->getCursorPosition().y);
+	{
+		Point cursorPosition = Point(tfinger.x * screenSize.x, tfinger.y * screenSize.y) * scalingFactor;
+		ENGINE->cursor().cursorMove(cursorPosition.x, cursorPosition.y);
+	}
 
 	switch(state)
 	{
 		case TouchState::RELATIVE_MODE:
 		{
-			int scalingFactor = ENGINE->screenHandler().getScalingFactor();
-
 			Point moveDistance {
 				static_cast<int>(screenSize.x * params.relativeModeSpeedFactor * motionAccumulatedX[tfinger.fingerId]),
 				static_cast<int>(screenSize.y * params.relativeModeSpeedFactor * motionAccumulatedY[tfinger.fingerId])
@@ -134,6 +137,14 @@ void InputSourceTouch::handleEventFingerDown(const SDL_TouchFingerEvent & tfinge
 
 	lastTapTimeTicks = tfinger.timestamp;
 
+	if (settings["video"]["cursor"].String() == "software" && state != TouchState::RELATIVE_MODE)
+	{
+		int scalingFactor = ENGINE->screenHandler().getScalingFactor();
+		Point screenSize = ENGINE->screenDimensions();
+		Point cursorPosition = Point(tfinger.x * screenSize.x, tfinger.y * screenSize.y) * scalingFactor;
+		ENGINE->cursor().cursorMove(cursorPosition.x, cursorPosition.y);
+	}
+
 	switch(state)
 	{
 		case TouchState::RELATIVE_MODE: