[Scummvm-git-logs] scummvm master -> 9fea178445ce46bdf68a13a960a3e07f12087653

bluegr noreply at scummvm.org
Fri Sep 27 00:26:53 UTC 2024


This automated email contains information about 4 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
d4369c5666 SDL: Move finger handling to common SDL code
b2c4468aae SDL: Enable touchpad mode option on generic SDL
4609ad13f9 SWITCH: Remove useless override
9fea178445 VITA: Remove useless override


Commit: d4369c5666ac493508015f9844e81847ebec19f5
    https://github.com/scummvm/scummvm/commit/d4369c5666ac493508015f9844e81847ebec19f5
Author: Vladimir Serbinenko (phcoder at gmail.com)
Date: 2024-09-27T03:26:47+03:00

Commit Message:
SDL: Move finger handling to common SDL code

It's also useful on Linux be it on desktop with touchscreen or mobile Linux

Changed paths:
  R backends/events/sdl/finger-sdl-events.cpp
  R backends/events/sdl/finger-sdl-events.h
    backends/events/psp2sdl/psp2sdl-events.cpp
    backends/events/psp2sdl/psp2sdl-events.h
    backends/events/sdl/sdl-events.cpp
    backends/events/sdl/sdl-events.h
    backends/events/switchsdl/switchsdl-events.cpp
    backends/events/switchsdl/switchsdl-events.h
    backends/module.mk


diff --git a/backends/events/psp2sdl/psp2sdl-events.cpp b/backends/events/psp2sdl/psp2sdl-events.cpp
index b145dfe4650..fa962b1c8d6 100644
--- a/backends/events/psp2sdl/psp2sdl-events.cpp
+++ b/backends/events/psp2sdl/psp2sdl-events.cpp
@@ -36,8 +36,6 @@
 
 #include "math.h"
 
-PSP2EventSource::PSP2EventSource() : FingerSdlEventSource() {}
-
 Common::Point PSP2EventSource::getTouchscreenSize() {
 	return Common::Point(960, 544);
 }
@@ -48,14 +46,44 @@ void PSP2EventSource::preprocessEvents(SDL_Event *event) {
 	sceKernelPowerTick(SCE_KERNEL_POWER_TICK_DISABLE_AUTO_SUSPEND);
 	sceKernelPowerTick(SCE_KERNEL_POWER_TICK_DISABLE_OLED_OFF);
 
-	FingerSdlEventSource::preprocessEvents(event);
+	SdlEventSource::preprocessEvents(event);
 }
 
-bool PSP2EventSource::isTouchpadMode(int port) {
+bool PSP2EventSource::isTouchPortTouchpadMode(SDL_TouchID port) {
 	return port != 0 || ConfMan.getBool("frontpanel_touchpad_mode");
 }
 
-bool PSP2EventSource::isPortActive(int port) {
+bool PSP2EventSource::isTouchPortActive(SDL_TouchID port) {
 	return port == 0 || ConfMan.getBool("touchpad_mouse_mode");
 }
+
+void PSP2EventSource::convertTouchXYToGameXY(float touchX, float touchY, int *gameX, int *gameY) {
+	int screenH = _graphicsManager->getWindowHeight();
+	int screenW = _graphicsManager->getWindowWidth();
+	Common::Point touchscreenSize = getTouchscreenSize();
+
+	const int dispW = touchscreenSize.x;
+	const int dispH = touchscreenSize.y;
+
+	int x, y, w, h;
+	float sx, sy;
+	float ratio = (float)screenW / (float)screenH;
+
+	h = dispH;
+	w = h * ratio;
+
+	x = (dispW - w) / 2;
+	y = (dispH - h) / 2;
+
+	sy = (float)h / (float)screenH;
+	sx = (float)w / (float)screenW;
+
+	// Find touch coordinates in terms of screen pixels
+	float dispTouchX = (touchX * (float)dispW);
+	float dispTouchY = (touchY * (float)dispH);
+
+	*gameX = CLIP((int)((dispTouchX - x) / sx), 0, screenW - 1);
+	*gameY = CLIP((int)((dispTouchY - y) / sy), 0, screenH - 1);
+}
+
 #endif
diff --git a/backends/events/psp2sdl/psp2sdl-events.h b/backends/events/psp2sdl/psp2sdl-events.h
index 0dd80db1f20..e14c3d33b9c 100644
--- a/backends/events/psp2sdl/psp2sdl-events.h
+++ b/backends/events/psp2sdl/psp2sdl-events.h
@@ -22,21 +22,20 @@
 #if !defined(DISABLE_DEFAULT_EVENTMANAGER)
 #define BACKEND_EVENTS_PSP2_H
 
-#include "backends/events/sdl/finger-sdl-events.h"
 #include "backends/events/sdl/sdl-events.h"
-#include <psp2/touch.h>
 
 /**
  * SDL Events manager for the PSP2.
  */
-class PSP2EventSource : public FingerSdlEventSource {
+class PSP2EventSource : public SdlEventSource {
 public:
-	PSP2EventSource();
+	PSP2EventSource() {}
 protected:
 	void preprocessEvents(SDL_Event *event) override;
-	bool isTouchpadMode(int port) override;
-	bool isPortActive(int port) override;
+	bool isTouchPortTouchpadMode(SDL_TouchID port) override;
+	bool isTouchPortActive(SDL_TouchID port) override;
 	Common::Point getTouchscreenSize() override;
+	void convertTouchXYToGameXY(float touchX, float touchY, int *gameX, int *gameY) override;
 };
 
 #endif /* BACKEND_EVENTS_PSP2_H */
diff --git a/backends/events/sdl/finger-sdl-events.cpp b/backends/events/sdl/finger-sdl-events.cpp
deleted file mode 100644
index 17823b99719..00000000000
--- a/backends/events/sdl/finger-sdl-events.cpp
+++ /dev/null
@@ -1,431 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#include "common/scummsys.h"
-
-#include "backends/events/sdl/finger-sdl-events.h"
-#include "backends/platform/sdl/sdl.h"
-#include "engines/engine.h"
-
-#include "common/util.h"
-#include "common/events.h"
-#include "common/config-manager.h"
-
-#include "math.h"
-
-FingerSdlEventSource::FingerSdlEventSource() {
-	for (int port = 0; port < MAX_NUM_PORTS; port++) {
-		for (int i = 0; i < MAX_NUM_FINGERS; i++) {
-			_finger[port][i].id = -1;
-			_finger[port][i].timeLastDown = 0;
-			_finger[port][i].lastX = 0;
-			_finger[port][i].lastY = 0;
-			_finger[port][i].lastDownX = 0;
-			_finger[port][i].lastDownY = 0;
-		}
-		_multiFingerDragging[port] = DRAG_NONE;
-	}
-
-	for (int port = 0; port < MAX_NUM_PORTS; port++) {
-		for (int i = 0; i < 2; i++) {
-			_simulatedClickStartTime[port][i] = 0;
-		}
-	}
-
-	_hiresDX = 0;
-	_hiresDY = 0;
-
-#if SDL_VERSION_ATLEAST(2,0,10)
-	// ensure that touch doesn't create double-events
-	SDL_SetHint(SDL_HINT_TOUCH_MOUSE_EVENTS, "0");
-#endif
-}
-
-bool FingerSdlEventSource::pollEvent(Common::Event &event) {
-	finishSimulatedMouseClicks();
-	return SdlEventSource::pollEvent(event);
-}
-
-void FingerSdlEventSource::preprocessEvents(SDL_Event *event) {
-
-	// Supported touch gestures:
-	// left mouse click: single finger short tap
-	// right mouse click: second finger short tap while first finger is still down
-	// pointer motion: single finger drag
-	if (event->type == SDL_FINGERDOWN || event->type == SDL_FINGERUP || event->type == SDL_FINGERMOTION) {
-		// front (0) or back (1) panel
-		SDL_TouchID port = event->tfinger.touchId;
-		if (port < MAX_NUM_PORTS && port >= 0) {
-			// touchpad_mouse_mode off: use only front panel for direct touch control of pointer
-			// touchpad_mouse_mode on: also enable rear touch with indirect touch control
-			// where the finger can be somewhere else than the pointer and still move it
-			if (isPortActive(port)) {
-				switch (event->type) {
-				case SDL_FINGERDOWN:
-					preprocessFingerDown(event);
-					break;
-				case SDL_FINGERUP:
-					preprocessFingerUp(event);
-					break;
-				case SDL_FINGERMOTION:
-					preprocessFingerMotion(event);
-					break;
-				}
-			}
-		}
-	}
-}
-
-void FingerSdlEventSource::preprocessFingerDown(SDL_Event *event) {
-	// front (0) or back (1) panel
-	SDL_TouchID port = event->tfinger.touchId;
-	// id (for multitouch)
-	SDL_FingerID id = event->tfinger.fingerId;
-
-	int x = _mouseX;
-	int y = _mouseY;
-
-	if (port >= MAX_NUM_PORTS) {
-		return;
-	}
-
-	if (!isTouchpadMode(port)) {
-		convertTouchXYToGameXY(event->tfinger.x, event->tfinger.y, &x, &y);
-	}
-
-	// make sure each finger is not reported down multiple times
-	for (int i = 0; i < MAX_NUM_FINGERS; i++) {
-		if (_finger[port][i].id == id) {
-			_finger[port][i].id = -1;
-		}
-	}
-
-	// we need the timestamps to decide later if the user performed a short tap (click)
-	// or a long tap (drag)
-	// we also need the last coordinates for each finger to keep track of dragging
-	for (int i = 0; i < MAX_NUM_FINGERS; i++) {
-		if (_finger[port][i].id == -1) {
-			_finger[port][i].id = id;
-			_finger[port][i].timeLastDown = event->tfinger.timestamp;
-			_finger[port][i].lastDownX = event->tfinger.x;
-			_finger[port][i].lastDownY = event->tfinger.y;
-			_finger[port][i].lastX = x;
-			_finger[port][i].lastY = y;
-			break;
-		}
-	}
-}
-
-void FingerSdlEventSource::preprocessFingerUp(SDL_Event *event) {
-	// front (0) or back (1) panel
-	SDL_TouchID port = event->tfinger.touchId;
-	// id (for multitouch)
-	SDL_FingerID id = event->tfinger.fingerId;
-
-	if (port >= MAX_NUM_PORTS) {
-		return;
-	}
-
-	// find out how many fingers were down before this event
-	int numFingersDown = 0;
-	for (int i = 0; i < MAX_NUM_FINGERS; i++) {
-		if (_finger[port][i].id >= 0) {
-			numFingersDown++;
-		}
-	}
-
-	int x = _mouseX;
-	int y = _mouseY;
-
-	for (int i = 0; i < MAX_NUM_FINGERS; i++) {
-		if (_finger[port][i].id == id) {
-			_finger[port][i].id = -1;
-			if (!_multiFingerDragging[port]) {
-				if ((event->tfinger.timestamp - _finger[port][i].timeLastDown) <= MAX_TAP_TIME) {
-					// short (<MAX_TAP_TIME ms) tap is interpreted as right/left mouse click depending on # fingers already down
-					// but only if the finger hasn't moved since it was pressed down by more than MAX_TAP_MOTION_DISTANCE pixels
-				  	Common::Point touchscreenSize = getTouchscreenSize();
-					float xrel = ((event->tfinger.x * (float) touchscreenSize.x) - (_finger[port][i].lastDownX * (float) touchscreenSize.x));
-					float yrel = ((event->tfinger.y * (float) touchscreenSize.y) - (_finger[port][i].lastDownY * (float) touchscreenSize.y));
-					float maxRSquared = (float) (MAX_TAP_MOTION_DISTANCE * MAX_TAP_MOTION_DISTANCE);
-					if ((xrel * xrel + yrel * yrel) < maxRSquared) {
-						if (numFingersDown == 2 || numFingersDown == 1) {
-							Uint8 simulatedButton = 0;
-							if (numFingersDown == 2) {
-								simulatedButton = SDL_BUTTON_RIGHT;
-								// need to raise the button later
-								_simulatedClickStartTime[port][1] = event->tfinger.timestamp;
-							} else if (numFingersDown == 1) {
-								simulatedButton = SDL_BUTTON_LEFT;
-								// need to raise the button later
-								_simulatedClickStartTime[port][0] = event->tfinger.timestamp;
-								if (!isTouchpadMode(port)) {
-									convertTouchXYToGameXY(event->tfinger.x, event->tfinger.y, &x, &y);
-								}
-							}
-
-							event->type = SDL_MOUSEBUTTONDOWN;
-							event->button.button = simulatedButton;
-							event->button.x = x;
-							event->button.y = y;
-						}
-					}
-				}
-			} else if (numFingersDown == 1) {
-				// when dragging, and the last finger is lifted, the drag is over
-				if (!isTouchpadMode(port)) {
-					convertTouchXYToGameXY(event->tfinger.x, event->tfinger.y, &x, &y);
-				}
-				Uint8 simulatedButton = 0;
-				if (_multiFingerDragging[port] == DRAG_THREE_FINGER)
-					simulatedButton = SDL_BUTTON_RIGHT;
-				else {
-					simulatedButton = SDL_BUTTON_LEFT;
-				}
-				event->type = SDL_MOUSEBUTTONUP;
-				event->button.button = simulatedButton;
-				event->button.x = x;
-				event->button.y = y;
-				_multiFingerDragging[port] = DRAG_NONE;
-			}
-		}
-	}
-}
-
-void FingerSdlEventSource::preprocessFingerMotion(SDL_Event *event) {
-	// front (0) or back (1) panel
-	SDL_TouchID port = event->tfinger.touchId;
-	// id (for multitouch)
-	SDL_FingerID id = event->tfinger.fingerId;
-
-	if (port >= MAX_NUM_PORTS) {
-		return;
-	}
-
-	// find out how many fingers were down before this event
-	int numFingersDown = 0;
-	for (int i = 0; i < MAX_NUM_FINGERS; i++) {
-		if (_finger[port][i].id >= 0) {
-			numFingersDown++;
-		}
-	}
-
-	if (numFingersDown >= 1) {
-		int x = _mouseX;
-		int y = _mouseY;
-		int xMax = _graphicsManager->getWindowWidth() - 1;
-		int yMax = _graphicsManager->getWindowHeight() - 1;
-
-		if (!isTouchpadMode(port)) {
-			convertTouchXYToGameXY(event->tfinger.x, event->tfinger.y, &x, &y);
-		}	else {
-			// for relative mode, use the pointer speed setting
-			float speedFactor = 1.0;
-
-			switch (ConfMan.getInt("kbdmouse_speed")) {
-			// 0.25 keyboard pointer speed
-			case 0:
-				speedFactor = 0.25;
-				break;
-			// 0.5 speed
-			case 1:
-				speedFactor = 0.5;
-				break;
-			// 0.75 speed
-			case 2:
-				speedFactor = 0.75;
-				break;
-			// 1.0 speed
-			case 3:
-				speedFactor = 1.0;
-				break;
-			// 1.25 speed
-			case 4:
-				speedFactor = 1.25;
-				break;
-			// 1.5 speed
-			case 5:
-				speedFactor = 1.5;
-				break;
-			// 1.75 speed
-			case 6:
-				speedFactor = 1.75;
-				break;
-			// 2.0 speed
-			case 7:
-				speedFactor = 2.0;
-				break;
-			default:
-				speedFactor = 1.0;
-			}
-
-			// convert touch events to relative mouse pointer events
-			// track sub-pixel relative finger motion using the FINGER_SUBPIXEL_MULTIPLIER
-			_hiresDX += (event->tfinger.dx * 1.25 * speedFactor * xMax * FINGER_SUBPIXEL_MULTIPLIER);
-			_hiresDY += (event->tfinger.dy * 1.25 * speedFactor * yMax * FINGER_SUBPIXEL_MULTIPLIER);
-			int xRel = _hiresDX / FINGER_SUBPIXEL_MULTIPLIER;
-			int yRel = _hiresDY / FINGER_SUBPIXEL_MULTIPLIER;
-			x = _mouseX + xRel;
-			y = _mouseY + yRel;
-			_hiresDX %= FINGER_SUBPIXEL_MULTIPLIER;
-			_hiresDY %= FINGER_SUBPIXEL_MULTIPLIER;
-		}
-
-		x = CLIP(x, 0, xMax);
-		y = CLIP(y, 0, yMax);
-
-		// update the current finger's coordinates so we can track it later
-		for (int i = 0; i < MAX_NUM_FINGERS; i++) {
-			if (_finger[port][i].id == id) {
-				_finger[port][i].lastX = x;
-				_finger[port][i].lastY = y;
-			}
-		}
-
-		// If we are starting a multi-finger drag, start holding down the mouse button
-		if (numFingersDown >= 2) {
-			if (!_multiFingerDragging[port]) {
-				// only start a multi-finger drag if at least two fingers have been down long enough
-				int numFingersDownLong = 0;
-				for (int i = 0; i < MAX_NUM_FINGERS; i++) {
-					if (_finger[port][i].id >= 0) {
-						if (event->tfinger.timestamp - _finger[port][i].timeLastDown > MAX_TAP_TIME) {
-							numFingersDownLong++;
-						}
-					}
-				}
-				if (numFingersDownLong >= 2) {
-					// starting drag, so push mouse down at current location (back)
-					// or location of "oldest" finger (front)
-					int mouseDownX = _mouseX;
-					int mouseDownY = _mouseY;
-					if (!isTouchpadMode(port)) {
-						for (int i = 0; i < MAX_NUM_FINGERS; i++) {
-							if (_finger[port][i].id == id) {
-								Uint32 earliestTime = _finger[port][i].timeLastDown;
-								for (int j = 0; j < MAX_NUM_FINGERS; j++) {
-									if (_finger[port][j].id >= 0 && (i != j) ) {
-										if (_finger[port][j].timeLastDown < earliestTime) {
-											mouseDownX = _finger[port][j].lastX;
-											mouseDownY = _finger[port][j].lastY;
-											earliestTime = _finger[port][j].timeLastDown;
-										}
-									}
-								}
-								break;
-							}
-						}
-					}
-					Uint8 simulatedButton = 0;
-					if (numFingersDownLong == 2) {
-						simulatedButton = SDL_BUTTON_LEFT;
-						_multiFingerDragging[port] = DRAG_TWO_FINGER;
-					} else {
-						simulatedButton = SDL_BUTTON_RIGHT;
-						_multiFingerDragging[port] = DRAG_THREE_FINGER;
-					}
-					SDL_Event ev;
-					ev.type = SDL_MOUSEBUTTONDOWN;
-					ev.button.button = simulatedButton;
-					ev.button.x = mouseDownX;
-					ev.button.y = mouseDownY;
-					SDL_PushEvent(&ev);
-				}
-			}
-		}
-
-		//check if this is the "oldest" finger down (or the only finger down), otherwise it will not affect mouse motion
-		bool updatePointer = true;
-		if (numFingersDown > 1) {
-			for (int i = 0; i < MAX_NUM_FINGERS; i++) {
-				if (_finger[port][i].id == id) {
-					for (int j = 0; j < MAX_NUM_FINGERS; j++) {
-						if (_finger[port][j].id >= 0 && (i != j) ) {
-							if (_finger[port][j].timeLastDown < _finger[port][i].timeLastDown) {
-								updatePointer = false;
-							}
-						}
-					}
-				}
-			}
-		}
-		if (updatePointer) {
-			event->type = SDL_MOUSEMOTION;
-			event->motion.x = x;
-			event->motion.y = y;
-		}
-	}
-}
-
-void FingerSdlEventSource::convertTouchXYToGameXY(float touchX, float touchY, int *gameX, int *gameY) {
-	int screenH = _graphicsManager->getWindowHeight();
-	int screenW = _graphicsManager->getWindowWidth();
-	Common::Point touchscreenSize = getTouchscreenSize();
-
-	const int dispW = touchscreenSize.x;
-	const int dispH = touchscreenSize.y;
-
-	int x, y, w, h;
-	float sx, sy;
-	float ratio = (float)screenW / (float)screenH;
-
-	h = dispH;
-	w = h * ratio;
-
-	x = (dispW - w) / 2;
-	y = (dispH - h) / 2;
-
-	sy = (float)h / (float)screenH;
-	sx = (float)w / (float)screenW;
-
-	// Find touch coordinates in terms of screen pixels
-	float dispTouchX = (touchX * (float)dispW);
-	float dispTouchY = (touchY * (float)dispH);
-
-	*gameX = CLIP((int)((dispTouchX - x) / sx), 0, screenW - 1);
-	*gameY = CLIP((int)((dispTouchY - y) / sy), 0, screenH - 1);
-}
-
-void FingerSdlEventSource::finishSimulatedMouseClicks() {
-	for (int port = 0; port < MAX_NUM_PORTS; port++) {
-		for (int i = 0; i < 2; i++) {
-			if (_simulatedClickStartTime[port][i] != 0) {
-				Uint32 currentTime = SDL_GetTicks();
-				if (currentTime - _simulatedClickStartTime[port][i] >= SIMULATED_CLICK_DURATION) {
-					int simulatedButton;
-					if (i == 0) {
-						simulatedButton = SDL_BUTTON_LEFT;
-					} else {
-						simulatedButton = SDL_BUTTON_RIGHT;
-					}
-					SDL_Event ev;
-					ev.type = SDL_MOUSEBUTTONUP;
-					ev.button.button = simulatedButton;
-					ev.button.x = _mouseX;
-					ev.button.y = _mouseY;
-					SDL_PushEvent(&ev);
-
-					_simulatedClickStartTime[port][i] = 0;
-				}
-			}
-		}
-	}
-}
diff --git a/backends/events/sdl/finger-sdl-events.h b/backends/events/sdl/finger-sdl-events.h
deleted file mode 100644
index b5f452521bf..00000000000
--- a/backends/events/sdl/finger-sdl-events.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#if !defined(DISABLE_DEFAULT_EVENTMANAGER)
-#define BACKEND_EVENTS_FINGER_H
-
-#include "backends/events/sdl/sdl-events.h"
-
-/**
- * SDL Events manager for the touchscreen.
- */
-class FingerSdlEventSource : public SdlEventSource {
-public:
-	FingerSdlEventSource();
-	bool pollEvent(Common::Event &event) override;
-protected:
-	void preprocessEvents(SDL_Event *event) override;
-	virtual bool isTouchpadMode(int port) = 0;
-	virtual bool isPortActive(int port) = 0;
-	virtual Common::Point getTouchscreenSize() = 0;
-	virtual void convertTouchXYToGameXY(float touchX, float touchY, int *gameX, int *gameY);
-
-private:
-	enum {
-		MAX_NUM_FINGERS = 3, // number of fingers to track per panel
-		MAX_NUM_PORTS = 5, // maximum number of supported ports
-		MAX_TAP_TIME = 250, // taps longer than this will not result in mouse click events
-		MAX_TAP_MOTION_DISTANCE = 10, // max distance finger motion in Vita screen pixels to be considered a tap
-		SIMULATED_CLICK_DURATION = 50, // time in ms how long simulated mouse clicks should be
-		FINGER_SUBPIXEL_MULTIPLIER = 16 // multiplier for sub-pixel resolution
-	};
-
-	typedef struct {
-		int id; // -1: no touch
-		uint32 timeLastDown;
-		int lastX; // last known screen coordinates
-		int lastY; // last known screen coordinates
-		float lastDownX; // SDL touch coordinates when last pressed down
-		float lastDownY; // SDL touch coordinates when last pressed down
-	} Touch;
-
-	Touch _finger[MAX_NUM_PORTS][MAX_NUM_FINGERS]; // keep track of finger status
-
-	typedef enum DraggingType {
-		DRAG_NONE = 0,
-		DRAG_TWO_FINGER,
-		DRAG_THREE_FINGER,
-	} DraggingType;
-
-	DraggingType _multiFingerDragging[MAX_NUM_PORTS]; // keep track whether we are currently drag-and-dropping
-
-	unsigned int _simulatedClickStartTime[MAX_NUM_PORTS][2]; // initiation time of last simulated left or right click (zero if no click)
-
-	int _hiresDX; // keep track of slow, sub-pixel, finger motion across multiple frames
-	int _hiresDY;
-
-	void preprocessFingerDown(SDL_Event *event);
-	void preprocessFingerUp(SDL_Event *event);
-	void preprocessFingerMotion(SDL_Event *event);
-	void finishSimulatedMouseClicks(void);
-};
-
-#endif /* BACKEND_EVENTS_FINGER_H */
diff --git a/backends/events/sdl/sdl-events.cpp b/backends/events/sdl/sdl-events.cpp
index bef0ef75bc6..1fd797c18d9 100644
--- a/backends/events/sdl/sdl-events.cpp
+++ b/backends/events/sdl/sdl-events.cpp
@@ -99,6 +99,12 @@ SdlEventSource::SdlEventSource()
 
 		openJoystick(joystick_num);
 	}
+
+#if SDL_VERSION_ATLEAST(2,0,10)
+	// ensure that touch doesn't create double-events
+	SDL_SetHint(SDL_HINT_TOUCH_MOUSE_EVENTS, "0");
+#endif
+
 }
 
 SdlEventSource::~SdlEventSource() {
@@ -409,9 +415,329 @@ Common::KeyCode SdlEventSource::SDLToOSystemKeycode(const SDL_Keycode key) {
 	}
 }
 
-bool SdlEventSource::pollEvent(Common::Event &event) {
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+void SdlEventSource::preprocessFingerDown(SDL_Event *event) {
+	// front (0) or back (1) panel
+	SDL_TouchID port = event->tfinger.touchId;
+	// id (for multitouch)
+	SDL_FingerID id = event->tfinger.fingerId;
+
+	int x = _mouseX;
+	int y = _mouseY;
+
+	if (!isTouchPortTouchpadMode(port)) {
+		convertTouchXYToGameXY(event->tfinger.x, event->tfinger.y, &x, &y);
+	}
+
+	// make sure each finger is not reported down multiple times
+	for (int i = 0; i < MAX_NUM_FINGERS; i++) {
+		if (_touchPanels[port]._finger[i].id == id) {
+			_touchPanels[port]._finger[i].id = -1;
+		}
+	}
+
+	// we need the timestamps to decide later if the user performed a short tap (click)
+	// or a long tap (drag)
+	// we also need the last coordinates for each finger to keep track of dragging
+	for (int i = 0; i < MAX_NUM_FINGERS; i++) {
+		if (_touchPanels[port]._finger[i].id == -1) {
+			_touchPanels[port]._finger[i].id = id;
+			_touchPanels[port]._finger[i].timeLastDown = event->tfinger.timestamp;
+			_touchPanels[port]._finger[i].lastDownX = event->tfinger.x;
+			_touchPanels[port]._finger[i].lastDownY = event->tfinger.y;
+			_touchPanels[port]._finger[i].lastX = x;
+			_touchPanels[port]._finger[i].lastY = y;
+			break;
+		}
+	}
+}
+
+Common::Point SdlEventSource::getTouchscreenSize() {
+	int windowWidth, windowHeight;
+	SDL_GetWindowSize((dynamic_cast<SdlGraphicsManager*>(_graphicsManager))->getWindow()->getSDLWindow(), &windowWidth, &windowHeight);
+	return Common::Point(windowWidth, windowHeight);
+}
+
+bool SdlEventSource::isTouchPortTouchpadMode(SDL_TouchID port) {
+       return g_system->getFeatureState(OSystem::kFeatureTouchpadMode);
+}
+
+bool SdlEventSource::isTouchPortActive(SDL_TouchID port) {
+	return true;
+}
+
+void SdlEventSource::convertTouchXYToGameXY(float touchX, float touchY, int *gameX, int *gameY) {
+	int windowWidth, windowHeight;
+	SDL_GetWindowSize((dynamic_cast<SdlGraphicsManager*>(_graphicsManager))->getWindow()->getSDLWindow(), &windowWidth, &windowHeight);
+
+	*gameX = windowWidth * touchX;
+	*gameY = windowHeight * touchY;
+}
+
+void SdlEventSource::finishSimulatedMouseClicks() {
+	for (auto &panel : _touchPanels) {
+		for (int i = 0; i < 2; i++) {
+			if (panel._value._simulatedClickStartTime[i] != 0) {
+				Uint32 currentTime = SDL_GetTicks();
+				if (currentTime - panel._value._simulatedClickStartTime[i] >= SIMULATED_CLICK_DURATION) {
+					int simulatedButton;
+					if (i == 0) {
+						simulatedButton = SDL_BUTTON_LEFT;
+					} else {
+						simulatedButton = SDL_BUTTON_RIGHT;
+					}
+					SDL_Event ev;
+					ev.type = SDL_MOUSEBUTTONUP;
+					ev.button.button = simulatedButton;
+					ev.button.x = _mouseX;
+					ev.button.y = _mouseY;
+					SDL_PushEvent(&ev);
+
+					panel._value._simulatedClickStartTime[i] = 0;
+				}
+			}
+		}
+	}
+}
+
+void SdlEventSource::preprocessFingerUp(SDL_Event *event) {
+	// front (0) or back (1) panel
+	SDL_TouchID port = event->tfinger.touchId;
+	// id (for multitouch)
+	SDL_FingerID id = event->tfinger.fingerId;
+
+	// find out how many fingers were down before this event
+	int numFingersDown = 0;
+	for (int i = 0; i < MAX_NUM_FINGERS; i++) {
+		if (_touchPanels[port]._finger[i].id >= 0) {
+			numFingersDown++;
+		}
+	}
 
+	int x = _mouseX;
+	int y = _mouseY;
+
+	for (int i = 0; i < MAX_NUM_FINGERS; i++) {
+		if (_touchPanels[port]._finger[i].id == id) {
+			_touchPanels[port]._finger[i].id = -1;
+			if (!_touchPanels[port]._multiFingerDragging) {
+				if ((event->tfinger.timestamp - _touchPanels[port]._finger[i].timeLastDown) <= MAX_TAP_TIME) {
+					// short (<MAX_TAP_TIME ms) tap is interpreted as right/left mouse click depending on # fingers already down
+					// but only if the finger hasn't moved since it was pressed down by more than MAX_TAP_MOTION_DISTANCE pixels
+					Common::Point touchscreenSize = getTouchscreenSize();
+					float xrel = ((event->tfinger.x * (float) touchscreenSize.x) - (_touchPanels[port]._finger[i].lastDownX * (float) touchscreenSize.x));
+					float yrel = ((event->tfinger.y * (float) touchscreenSize.y) - (_touchPanels[port]._finger[i].lastDownY * (float) touchscreenSize.y));
+					float maxRSquared = (float) (MAX_TAP_MOTION_DISTANCE * MAX_TAP_MOTION_DISTANCE);
+					if ((xrel * xrel + yrel * yrel) < maxRSquared) {
+						if (numFingersDown == 2 || numFingersDown == 1) {
+							Uint8 simulatedButton = 0;
+							if (numFingersDown == 2) {
+								simulatedButton = SDL_BUTTON_RIGHT;
+								// need to raise the button later
+								_touchPanels[port]._simulatedClickStartTime[1] = event->tfinger.timestamp;
+							} else if (numFingersDown == 1) {
+								simulatedButton = SDL_BUTTON_LEFT;
+								// need to raise the button later
+								_touchPanels[port]._simulatedClickStartTime[0] = event->tfinger.timestamp;
+								if (!isTouchPortTouchpadMode(port)) {
+									convertTouchXYToGameXY(event->tfinger.x, event->tfinger.y, &x, &y);
+								}
+							}
+
+							event->type = SDL_MOUSEBUTTONDOWN;
+							event->button.button = simulatedButton;
+							event->button.x = x;
+							event->button.y = y;
+						}
+					}
+				}
+			} else if (numFingersDown == 1) {
+				// when dragging, and the last finger is lifted, the drag is over
+				if (!isTouchPortTouchpadMode(port)) {
+					convertTouchXYToGameXY(event->tfinger.x, event->tfinger.y, &x, &y);
+				}
+				Uint8 simulatedButton = 0;
+				if (_touchPanels[port]._multiFingerDragging == DRAG_THREE_FINGER)
+					simulatedButton = SDL_BUTTON_RIGHT;
+				else {
+					simulatedButton = SDL_BUTTON_LEFT;
+				}
+				event->type = SDL_MOUSEBUTTONUP;
+				event->button.button = simulatedButton;
+				event->button.x = x;
+				event->button.y = y;
+				_touchPanels[port]._multiFingerDragging = DRAG_NONE;
+			}
+		}
+	}
+}
+
+void SdlEventSource::preprocessFingerMotion(SDL_Event *event) {
+	// front (0) or back (1) panel
+	SDL_TouchID port = event->tfinger.touchId;
+	// id (for multitouch)
+	SDL_FingerID id = event->tfinger.fingerId;
+
+	// find out how many fingers were down before this event
+	int numFingersDown = 0;
+	for (int i = 0; i < MAX_NUM_FINGERS; i++) {
+		if (_touchPanels[port]._finger[i].id >= 0) {
+			numFingersDown++;
+		}
+	}
+
+	if (numFingersDown >= 1) {
+		int x = _mouseX;
+		int y = _mouseY;
+		int xMax = _graphicsManager->getWindowWidth() - 1;
+		int yMax = _graphicsManager->getWindowHeight() - 1;
+
+		if (!isTouchPortTouchpadMode(port)) {
+			convertTouchXYToGameXY(event->tfinger.x, event->tfinger.y, &x, &y);
+		}	else {
+			// for relative mode, use the pointer speed setting
+			float speedFactor = 1.0;
+
+			switch (ConfMan.getInt("kbdmouse_speed")) {
+			// 0.25 keyboard pointer speed
+			case 0:
+				speedFactor = 0.25;
+				break;
+			// 0.5 speed
+			case 1:
+				speedFactor = 0.5;
+				break;
+			// 0.75 speed
+			case 2:
+				speedFactor = 0.75;
+				break;
+			// 1.0 speed
+			case 3:
+				speedFactor = 1.0;
+				break;
+			// 1.25 speed
+			case 4:
+				speedFactor = 1.25;
+				break;
+			// 1.5 speed
+			case 5:
+				speedFactor = 1.5;
+				break;
+			// 1.75 speed
+			case 6:
+				speedFactor = 1.75;
+				break;
+			// 2.0 speed
+			case 7:
+				speedFactor = 2.0;
+				break;
+			default:
+				speedFactor = 1.0;
+			}
+
+			// convert touch events to relative mouse pointer events
+			// track sub-pixel relative finger motion using the FINGER_SUBPIXEL_MULTIPLIER
+			_touchPanels[port]._hiresDX += (event->tfinger.dx * 1.25 * speedFactor * xMax * FINGER_SUBPIXEL_MULTIPLIER);
+			_touchPanels[port]._hiresDY += (event->tfinger.dy * 1.25 * speedFactor * yMax * FINGER_SUBPIXEL_MULTIPLIER);
+			int xRel = _touchPanels[port]._hiresDX / FINGER_SUBPIXEL_MULTIPLIER;
+			int yRel = _touchPanels[port]._hiresDY / FINGER_SUBPIXEL_MULTIPLIER;
+			x = _mouseX + xRel;
+			y = _mouseY + yRel;
+			_touchPanels[port]._hiresDX %= FINGER_SUBPIXEL_MULTIPLIER;
+			_touchPanels[port]._hiresDY %= FINGER_SUBPIXEL_MULTIPLIER;
+		}
+
+		x = CLIP(x, 0, xMax);
+		y = CLIP(y, 0, yMax);
+
+		// update the current finger's coordinates so we can track it later
+		for (int i = 0; i < MAX_NUM_FINGERS; i++) {
+			if (_touchPanels[port]._finger[i].id == id) {
+				_touchPanels[port]._finger[i].lastX = x;
+				_touchPanels[port]._finger[i].lastY = y;
+			}
+		}
+
+		// If we are starting a multi-finger drag, start holding down the mouse button
+		if (numFingersDown >= 2) {
+			if (!_touchPanels[port]._multiFingerDragging) {
+				// only start a multi-finger drag if at least two fingers have been down long enough
+				int numFingersDownLong = 0;
+				for (int i = 0; i < MAX_NUM_FINGERS; i++) {
+					if (_touchPanels[port]._finger[i].id >= 0) {
+						if (event->tfinger.timestamp - _touchPanels[port]._finger[i].timeLastDown > MAX_TAP_TIME) {
+							numFingersDownLong++;
+						}
+					}
+				}
+				if (numFingersDownLong >= 2) {
+					// starting drag, so push mouse down at current location (back)
+					// or location of "oldest" finger (front)
+					int mouseDownX = _mouseX;
+					int mouseDownY = _mouseY;
+					if (!isTouchPortTouchpadMode(port)) {
+						for (int i = 0; i < MAX_NUM_FINGERS; i++) {
+							if (_touchPanels[port]._finger[i].id == id) {
+								Uint32 earliestTime = _touchPanels[port]._finger[i].timeLastDown;
+								for (int j = 0; j < MAX_NUM_FINGERS; j++) {
+									if (_touchPanels[port]._finger[j].id >= 0 && (i != j) ) {
+										if (_touchPanels[port]._finger[j].timeLastDown < earliestTime) {
+											mouseDownX = _touchPanels[port]._finger[j].lastX;
+											mouseDownY = _touchPanels[port]._finger[j].lastY;
+											earliestTime = _touchPanels[port]._finger[j].timeLastDown;
+										}
+									}
+								}
+								break;
+							}
+						}
+					}
+					Uint8 simulatedButton = 0;
+					if (numFingersDownLong == 2) {
+						simulatedButton = SDL_BUTTON_LEFT;
+						_touchPanels[port]._multiFingerDragging = DRAG_TWO_FINGER;
+					} else {
+						simulatedButton = SDL_BUTTON_RIGHT;
+						_touchPanels[port]._multiFingerDragging = DRAG_THREE_FINGER;
+					}
+					SDL_Event ev;
+					ev.type = SDL_MOUSEBUTTONDOWN;
+					ev.button.button = simulatedButton;
+					ev.button.x = mouseDownX;
+					ev.button.y = mouseDownY;
+					SDL_PushEvent(&ev);
+				}
+			}
+		}
+
+		//check if this is the "oldest" finger down (or the only finger down), otherwise it will not affect mouse motion
+		bool updatePointer = true;
+		if (numFingersDown > 1) {
+			for (int i = 0; i < MAX_NUM_FINGERS; i++) {
+				if (_touchPanels[port]._finger[i].id == id) {
+					for (int j = 0; j < MAX_NUM_FINGERS; j++) {
+						if (_touchPanels[port]._finger[j].id >= 0 && (i != j) ) {
+							if (_touchPanels[port]._finger[j].timeLastDown < _touchPanels[port]._finger[i].timeLastDown) {
+								updatePointer = false;
+							}
+						}
+					}
+				}
+			}
+		}
+		if (updatePointer) {
+			event->type = SDL_MOUSEMOTION;
+			event->motion.x = x;
+			event->motion.y = y;
+		}
+	}
+}
+#endif
+
+bool SdlEventSource::pollEvent(Common::Event &event) {
 #if SDL_VERSION_ATLEAST(2, 0, 0)
+	finishSimulatedMouseClicks();
+
 	// In case we still need to send a key up event for a key down from a
 	// TEXTINPUT event we do this immediately.
 	if (_queuedFakeKeyUp) {
@@ -438,6 +764,34 @@ bool SdlEventSource::pollEvent(Common::Event &event) {
 	SDL_Event ev;
 	while (SDL_PollEvent(&ev)) {
 		preprocessEvents(&ev);
+
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+		// Supported touch gestures:
+		// left mouse click: single finger short tap
+		// right mouse click: second finger short tap while first finger is still down
+		// pointer motion: single finger drag
+		if (ev.type == SDL_FINGERDOWN || ev.type == SDL_FINGERUP || ev.type == SDL_FINGERMOTION) {
+			// front (0) or back (1) panel
+			SDL_TouchID port = ev.tfinger.touchId;
+			// touchpad_mouse_mode off: use only front panel for direct touch control of pointer
+			// touchpad_mouse_mode on: also enable rear touch with indirect touch control
+			// where the finger can be somewhere else than the pointer and still move it
+			if (isTouchPortActive(port)) {
+				switch (ev.type) {
+				case SDL_FINGERDOWN:
+					preprocessFingerDown(&ev);
+					break;
+				case SDL_FINGERUP:
+					preprocessFingerUp(&ev);
+					break;
+				case SDL_FINGERMOTION:
+					preprocessFingerMotion(&ev);
+					break;
+				}
+			}
+		}
+#endif
+
 #if defined(USE_IMGUI) && SDL_VERSION_ATLEAST(2, 0, 0)
 		if (ImGui_ImplSDL2_Ready()) {
 			ImGui_ImplSDL2_ProcessEvent(&ev);
diff --git a/backends/events/sdl/sdl-events.h b/backends/events/sdl/sdl-events.h
index b3f722dffd3..753836e1b4d 100644
--- a/backends/events/sdl/sdl-events.h
+++ b/backends/events/sdl/sdl-events.h
@@ -143,6 +143,11 @@ protected:
 	virtual int mapSDLControllerButtonToOSystem(Uint8 sdlButton);
 	virtual bool handleControllerButton(const SDL_Event &ev, Common::Event &event, bool buttonUp);
 	virtual bool handleControllerAxisMotion(const SDL_Event &ev, Common::Event &event);
+
+	virtual bool isTouchPortTouchpadMode(SDL_TouchID port);
+	virtual bool isTouchPortActive(SDL_TouchID port);
+	virtual Common::Point getTouchscreenSize();
+	virtual void convertTouchXYToGameXY(float touchX, float touchY, int *gameX, int *gameY);
 #endif
 
 	//@}
@@ -216,6 +221,45 @@ protected:
 	 * KEYDOWN event.
 	 */
 	Common::Event _fakeKeyUp;
+
+	enum {
+		MAX_NUM_FINGERS = 3, // number of fingers to track per panel
+		MAX_TAP_TIME = 250, // taps longer than this will not result in mouse click events
+		MAX_TAP_MOTION_DISTANCE = 10, // max distance finger motion in Vita screen pixels to be considered a tap
+		SIMULATED_CLICK_DURATION = 50, // time in ms how long simulated mouse clicks should be
+		FINGER_SUBPIXEL_MULTIPLIER = 16 // multiplier for sub-pixel resolution
+	};
+
+	typedef struct {
+		int id = -1; // -1: no touch
+		uint32 timeLastDown = 0;
+		int lastX = 0; // last known screen coordinates
+		int lastY = 0; // last known screen coordinates
+		float lastDownX = 0; // SDL touch coordinates when last pressed down
+		float lastDownY = 0; // SDL touch coordinates when last pressed down
+	} TouchFinger;
+
+	typedef enum DraggingType {
+		DRAG_NONE = 0,
+		DRAG_TWO_FINGER,
+		DRAG_THREE_FINGER,
+	} DraggingType;
+
+	typedef struct {
+		TouchFinger _finger[MAX_NUM_FINGERS]; // keep track of finger status
+		DraggingType _multiFingerDragging = DRAG_NONE; // keep track whether we are currently drag-and-dropping
+		unsigned int _simulatedClickStartTime[2] = {0, 0}; // initiation time of last simulated left or right click (zero if no click)
+		int _hiresDX = 0; // keep track of slow, sub-pixel, finger motion across multiple frames
+		int _hiresDY = 0;
+	} TouchPanelState;
+
+	Common::HashMap<unsigned long, TouchPanelState> _touchPanels;
+
+private:
+	void preprocessFingerDown(SDL_Event *event);
+	void preprocessFingerUp(SDL_Event *event);
+	void preprocessFingerMotion(SDL_Event *event);
+	void finishSimulatedMouseClicks(void);
 #endif
 };
 
diff --git a/backends/events/switchsdl/switchsdl-events.cpp b/backends/events/switchsdl/switchsdl-events.cpp
index e1f0e6543de..8b23ebe34b2 100644
--- a/backends/events/switchsdl/switchsdl-events.cpp
+++ b/backends/events/switchsdl/switchsdl-events.cpp
@@ -35,24 +35,42 @@
 #include "common/events.h"
 #include "common/config-manager.h"
 
-SwitchEventSource::SwitchEventSource() : FingerSdlEventSource() {}
-
 Common::Point SwitchEventSource::getTouchscreenSize() {
 	return Common::Point(1280, 720);
 }
 
 bool SwitchEventSource::pollEvent(Common::Event &event) {
 	((DefaultTimerManager *) g_system->getTimerManager())->handler();
-	return FingerSdlEventSource::pollEvent(event);
+	return SdlEventSource::pollEvent(event);
 }
 
+void SwitchEventSource::convertTouchXYToGameXY(float touchX, float touchY, int *gameX, int *gameY) {
+	int screenH = _graphicsManager->getWindowHeight();
+	int screenW = _graphicsManager->getWindowWidth();
+	Common::Point touchscreenSize = getTouchscreenSize();
 
-bool SwitchEventSource::isTouchpadMode(int port) {
-	return ConfMan.getBool("touchpad_mouse_mode");
-}
+	const int dispW = touchscreenSize.x;
+	const int dispH = touchscreenSize.y;
+
+	int x, y, w, h;
+	float sx, sy;
+	float ratio = (float)screenW / (float)screenH;
+
+	h = dispH;
+	w = h * ratio;
+
+	x = (dispW - w) / 2;
+	y = (dispH - h) / 2;
+
+	sy = (float)h / (float)screenH;
+	sx = (float)w / (float)screenW;
+
+	// Find touch coordinates in terms of screen pixels
+	float dispTouchX = (touchX * (float)dispW);
+	float dispTouchY = (touchY * (float)dispH);
 
-bool SwitchEventSource::isPortActive(int port) {
-	return true;
+	*gameX = CLIP((int)((dispTouchX - x) / sx), 0, screenW - 1);
+	*gameY = CLIP((int)((dispTouchY - y) / sy), 0, screenH - 1);
 }
 
 #endif
diff --git a/backends/events/switchsdl/switchsdl-events.h b/backends/events/switchsdl/switchsdl-events.h
index 10f6d50bac4..e594b91aa32 100644
--- a/backends/events/switchsdl/switchsdl-events.h
+++ b/backends/events/switchsdl/switchsdl-events.h
@@ -23,20 +23,18 @@
 #define BACKEND_EVENTS_SWITCH_H
 
 #include "backends/events/sdl/sdl-events.h"
-#include "backends/events/sdl/finger-sdl-events.h"
 
 /**
  * SDL Events manager for the SWITCH.
  */
-class SwitchEventSource : public FingerSdlEventSource {
+class SwitchEventSource : public SdlEventSource {
 public:
-	SwitchEventSource();
+	SwitchEventSource() {}
 
 protected:
 	bool pollEvent(Common::Event &event) override;
-	bool isPortActive(int port) override;
-	bool isTouchpadMode(int port) override;
 	Common::Point getTouchscreenSize() override;
+	void convertTouchXYToGameXY(float touchX, float touchY, int *gameX, int *gameY) override;
 };
 
 #endif /* BACKEND_EVENTS_SWITCH_H */
diff --git a/backends/module.mk b/backends/module.mk
index ac9afaecdf4..8cb79e3601e 100644
--- a/backends/module.mk
+++ b/backends/module.mk
@@ -463,8 +463,7 @@ MODULE_OBJS += \
 	fs/posix-drives/posix-drives-fs.o \
 	fs/posix-drives/posix-drives-fs-factory.o \
 	plugins/psp2/psp2-provider.o \
-	events/psp2sdl/psp2sdl-events.o \
-	events/sdl/finger-sdl-events.o
+	events/psp2sdl/psp2sdl-events.o
 endif
 
 ifeq ($(BACKEND),samsungtv)
@@ -482,8 +481,7 @@ endif
 
 ifeq ($(BACKEND),switch)
 MODULE_OBJS += \
-	events/switchsdl/switchsdl-events.o \
-	events/sdl/finger-sdl-events.o
+	events/switchsdl/switchsdl-events.o
 endif
 
 ifdef ENABLE_EVENTRECORDER


Commit: b2c4468aaefea9b3607d5358f2029196b9256862
    https://github.com/scummvm/scummvm/commit/b2c4468aaefea9b3607d5358f2029196b9256862
Author: Vladimir Serbinenko (phcoder at gmail.com)
Date: 2024-09-27T03:26:47+03:00

Commit Message:
SDL: Enable touchpad mode option on generic SDL

Touchscreen is present on Linux phones and can be present on generic Linux.
Allow to configure it in touchpad mode. Think of Raspberry pi connected to
a touchscreen

Changed paths:
    backends/platform/sdl/psp2/psp2.cpp
    backends/platform/sdl/psp2/psp2.h
    backends/platform/sdl/sdl.cpp
    backends/platform/sdl/sdl.h
    backends/platform/sdl/switch/switch.cpp
    backends/platform/sdl/switch/switch.h


diff --git a/backends/platform/sdl/psp2/psp2.cpp b/backends/platform/sdl/psp2/psp2.cpp
index 9c7e6d9cbfd..fef88d3a1b6 100644
--- a/backends/platform/sdl/psp2/psp2.cpp
+++ b/backends/platform/sdl/psp2/psp2.cpp
@@ -155,28 +155,6 @@ bool OSystem_PSP2::hasFeature(Feature f) {
 		OSystem_SDL::hasFeature(f));
 }
 
-void OSystem_PSP2::setFeatureState(Feature f, bool enable) {
-	switch (f) {
-	case kFeatureTouchpadMode:
-		ConfMan.setBool("touchpad_mouse_mode", enable);
-		break;
-	default:
-		OSystem_SDL::setFeatureState(f, enable);
-		break;
-	}
-}
-
-bool OSystem_PSP2::getFeatureState(Feature f) {
-	switch (f) {
-	case kFeatureTouchpadMode:
-		return ConfMan.getBool("touchpad_mouse_mode");
-		break;
-	default:
-		return OSystem_SDL::getFeatureState(f);
-		break;
-	}
-}
-
 void OSystem_PSP2::logMessage(LogMessageType::Type type, const char *message) {
 #if __PSP2_DEBUG__
 	psp2shell_print(message);
diff --git a/backends/platform/sdl/psp2/psp2.h b/backends/platform/sdl/psp2/psp2.h
index 09a76a29013..646ae0203d4 100644
--- a/backends/platform/sdl/psp2/psp2.h
+++ b/backends/platform/sdl/psp2/psp2.h
@@ -32,8 +32,6 @@ public:
 	void init() override;
 	void initBackend() override;
 	bool hasFeature(Feature f) override;
-	void setFeatureState(Feature f, bool enable) override;
-	bool getFeatureState(Feature f) override;
 	void logMessage(LogMessageType::Type type, const char *message) override;
 	Common::HardwareInputSet *getHardwareInputSet() override;
 
diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index a9ebb363b97..20d2579f299 100644
--- a/backends/platform/sdl/sdl.cpp
+++ b/backends/platform/sdl/sdl.cpp
@@ -209,10 +209,38 @@ bool OSystem_SDL::hasFeature(Feature f) {
 #endif
 #if defined(USE_SCUMMVMDLC) && defined(USE_LIBCURL)
 	if (f == kFeatureDLC) return true;
+#endif
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+	if (f == kFeatureTouchpadMode) {
+		return SDL_GetNumTouchDevices() > 0;
+	}
 #endif
 	return ModularGraphicsBackend::hasFeature(f);
 }
 
+
+void OSystem_SDL::setFeatureState(Feature f, bool enable) {
+	switch (f) {
+	case kFeatureTouchpadMode:
+		ConfMan.setBool("touchpad_mouse_mode", enable);
+		break;
+	default:
+		ModularGraphicsBackend::setFeatureState(f, enable);
+		break;
+	}
+}
+
+bool OSystem_SDL::getFeatureState(Feature f) {
+	switch (f) {
+	case kFeatureTouchpadMode:
+		return ConfMan.getBool("touchpad_mouse_mode");
+		break;
+	default:
+		return ModularGraphicsBackend::getFeatureState(f);
+		break;
+	}
+}
+
 void OSystem_SDL::initBackend() {
 	// Check if backend has not been initialized
 	assert(!_inited);
diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h
index 9383f88f29b..c177b2efb54 100644
--- a/backends/platform/sdl/sdl.h
+++ b/backends/platform/sdl/sdl.h
@@ -52,6 +52,8 @@ public:
 	void init() override;
 
 	bool hasFeature(Feature f) override;
+	void setFeatureState(Feature f, bool enable) override;
+	bool getFeatureState(Feature f) override;
 
 	// Override functions from ModularBackend and OSystem
 	void initBackend() override;
diff --git a/backends/platform/sdl/switch/switch.cpp b/backends/platform/sdl/switch/switch.cpp
index 023d4b7bafd..8d6fb126e99 100644
--- a/backends/platform/sdl/switch/switch.cpp
+++ b/backends/platform/sdl/switch/switch.cpp
@@ -124,28 +124,6 @@ bool OSystem_Switch::hasFeature(Feature f) {
 		OSystem_SDL::hasFeature(f));
 }
 
-void OSystem_Switch::setFeatureState(Feature f, bool enable) {
-	switch (f) {
-	case kFeatureTouchpadMode:
-		ConfMan.setBool("touchpad_mouse_mode", enable);
-		break;
-	default:
-		OSystem_SDL::setFeatureState(f, enable);
-		break;
-	}
-}
-
-bool OSystem_Switch::getFeatureState(Feature f) {
-	switch (f) {
-	case kFeatureTouchpadMode:
-		return ConfMan.getBool("touchpad_mouse_mode");
-		break;
-	default:
-		return OSystem_SDL::getFeatureState(f);
-		break;
-	}
-}
-
 void OSystem_Switch::logMessage(LogMessageType::Type type, const char *message) {
 	printf("%s\n", message);
 }
diff --git a/backends/platform/sdl/switch/switch.h b/backends/platform/sdl/switch/switch.h
index 73f539593e3..034b9c6a9eb 100644
--- a/backends/platform/sdl/switch/switch.h
+++ b/backends/platform/sdl/switch/switch.h
@@ -29,8 +29,6 @@ public:
 	void init() override;
 	void initBackend() override;
 	bool hasFeature(Feature f) override;
-	void setFeatureState(Feature f, bool enable) override;
-	bool getFeatureState(Feature f) override;
 	void logMessage(LogMessageType::Type type, const char *message) override;
 	Common::HardwareInputSet *getHardwareInputSet() override;
 	virtual Common::String getSystemLanguage() const;


Commit: 4609ad13f9349f9f2d65c27cc7bfbd5114fe08f7
    https://github.com/scummvm/scummvm/commit/4609ad13f9349f9f2d65c27cc7bfbd5114fe08f7
Author: Vladimir Serbinenko (phcoder at gmail.com)
Date: 2024-09-27T03:26:47+03:00

Commit Message:
SWITCH: Remove useless override

This does basically the same as the base class but in a more complicated
way. Just remove it

Changed paths:
    backends/events/switchsdl/switchsdl-events.cpp
    backends/events/switchsdl/switchsdl-events.h


diff --git a/backends/events/switchsdl/switchsdl-events.cpp b/backends/events/switchsdl/switchsdl-events.cpp
index 8b23ebe34b2..0aeb0870e8e 100644
--- a/backends/events/switchsdl/switchsdl-events.cpp
+++ b/backends/events/switchsdl/switchsdl-events.cpp
@@ -35,42 +35,9 @@
 #include "common/events.h"
 #include "common/config-manager.h"
 
-Common::Point SwitchEventSource::getTouchscreenSize() {
-	return Common::Point(1280, 720);
-}
-
 bool SwitchEventSource::pollEvent(Common::Event &event) {
 	((DefaultTimerManager *) g_system->getTimerManager())->handler();
 	return SdlEventSource::pollEvent(event);
 }
 
-void SwitchEventSource::convertTouchXYToGameXY(float touchX, float touchY, int *gameX, int *gameY) {
-	int screenH = _graphicsManager->getWindowHeight();
-	int screenW = _graphicsManager->getWindowWidth();
-	Common::Point touchscreenSize = getTouchscreenSize();
-
-	const int dispW = touchscreenSize.x;
-	const int dispH = touchscreenSize.y;
-
-	int x, y, w, h;
-	float sx, sy;
-	float ratio = (float)screenW / (float)screenH;
-
-	h = dispH;
-	w = h * ratio;
-
-	x = (dispW - w) / 2;
-	y = (dispH - h) / 2;
-
-	sy = (float)h / (float)screenH;
-	sx = (float)w / (float)screenW;
-
-	// Find touch coordinates in terms of screen pixels
-	float dispTouchX = (touchX * (float)dispW);
-	float dispTouchY = (touchY * (float)dispH);
-
-	*gameX = CLIP((int)((dispTouchX - x) / sx), 0, screenW - 1);
-	*gameY = CLIP((int)((dispTouchY - y) / sy), 0, screenH - 1);
-}
-
 #endif
diff --git a/backends/events/switchsdl/switchsdl-events.h b/backends/events/switchsdl/switchsdl-events.h
index e594b91aa32..2637247db4f 100644
--- a/backends/events/switchsdl/switchsdl-events.h
+++ b/backends/events/switchsdl/switchsdl-events.h
@@ -33,8 +33,6 @@ public:
 
 protected:
 	bool pollEvent(Common::Event &event) override;
-	Common::Point getTouchscreenSize() override;
-	void convertTouchXYToGameXY(float touchX, float touchY, int *gameX, int *gameY) override;
 };
 
 #endif /* BACKEND_EVENTS_SWITCH_H */


Commit: 9fea178445ce46bdf68a13a960a3e07f12087653
    https://github.com/scummvm/scummvm/commit/9fea178445ce46bdf68a13a960a3e07f12087653
Author: Vladimir Serbinenko (phcoder at gmail.com)
Date: 2024-09-27T03:26:47+03:00

Commit Message:
VITA: Remove useless override

This does basically the same as the base class but in a more complicated
way. Just remove it

Changed paths:
    backends/events/psp2sdl/psp2sdl-events.cpp
    backends/events/psp2sdl/psp2sdl-events.h


diff --git a/backends/events/psp2sdl/psp2sdl-events.cpp b/backends/events/psp2sdl/psp2sdl-events.cpp
index fa962b1c8d6..b7f2ebc2662 100644
--- a/backends/events/psp2sdl/psp2sdl-events.cpp
+++ b/backends/events/psp2sdl/psp2sdl-events.cpp
@@ -36,10 +36,6 @@
 
 #include "math.h"
 
-Common::Point PSP2EventSource::getTouchscreenSize() {
-	return Common::Point(960, 544);
-}
-
 void PSP2EventSource::preprocessEvents(SDL_Event *event) {
 
 	// prevent suspend (scummvm games contain a lot of cutscenes..)
@@ -57,33 +53,4 @@ bool PSP2EventSource::isTouchPortActive(SDL_TouchID port) {
 	return port == 0 || ConfMan.getBool("touchpad_mouse_mode");
 }
 
-void PSP2EventSource::convertTouchXYToGameXY(float touchX, float touchY, int *gameX, int *gameY) {
-	int screenH = _graphicsManager->getWindowHeight();
-	int screenW = _graphicsManager->getWindowWidth();
-	Common::Point touchscreenSize = getTouchscreenSize();
-
-	const int dispW = touchscreenSize.x;
-	const int dispH = touchscreenSize.y;
-
-	int x, y, w, h;
-	float sx, sy;
-	float ratio = (float)screenW / (float)screenH;
-
-	h = dispH;
-	w = h * ratio;
-
-	x = (dispW - w) / 2;
-	y = (dispH - h) / 2;
-
-	sy = (float)h / (float)screenH;
-	sx = (float)w / (float)screenW;
-
-	// Find touch coordinates in terms of screen pixels
-	float dispTouchX = (touchX * (float)dispW);
-	float dispTouchY = (touchY * (float)dispH);
-
-	*gameX = CLIP((int)((dispTouchX - x) / sx), 0, screenW - 1);
-	*gameY = CLIP((int)((dispTouchY - y) / sy), 0, screenH - 1);
-}
-
 #endif
diff --git a/backends/events/psp2sdl/psp2sdl-events.h b/backends/events/psp2sdl/psp2sdl-events.h
index e14c3d33b9c..20ebeed301c 100644
--- a/backends/events/psp2sdl/psp2sdl-events.h
+++ b/backends/events/psp2sdl/psp2sdl-events.h
@@ -34,8 +34,6 @@ protected:
 	void preprocessEvents(SDL_Event *event) override;
 	bool isTouchPortTouchpadMode(SDL_TouchID port) override;
 	bool isTouchPortActive(SDL_TouchID port) override;
-	Common::Point getTouchscreenSize() override;
-	void convertTouchXYToGameXY(float touchX, float touchY, int *gameX, int *gameY) override;
 };
 
 #endif /* BACKEND_EVENTS_PSP2_H */




More information about the Scummvm-git-logs mailing list