[Scummvm-git-logs] scummvm master -> 5189dbb7ba7d3db8a7e78906e5bc5ab8d1677955

rsn8887 rsn8887 at users.noreply.github.com
Tue Jan 23 14:28:13 CET 2018


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

Summary:
5189dbb7ba PSP2: Implement touch controls (front and back panel)


Commit: 5189dbb7ba7d3db8a7e78906e5bc5ab8d1677955
    https://github.com/scummvm/scummvm/commit/5189dbb7ba7d3db8a7e78906e5bc5ab8d1677955
Author: rsn8887 (rsn8887 at users.noreply.github.com)
Date: 2018-01-23T07:27:11-06:00

Commit Message:
PSP2: Implement touch controls (front and back panel)

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 4ea528b..b774b9e 100644
--- a/backends/events/psp2sdl/psp2sdl-events.cpp
+++ b/backends/events/psp2sdl/psp2sdl-events.cpp
@@ -36,11 +36,99 @@
 
 #include "math.h"
 
+PSP2EventSource::PSP2EventSource() {
+	for (int i = 0; i < SCE_TOUCH_PORT_MAX_NUM; i++) {
+		for (int j = 0; j < 2; j++) {
+			_finger[i][j].id = -1;
+		}
+	}
+}
+
 void PSP2EventSource::preprocessEvents(SDL_Event *event) {
 
 	// prevent suspend (scummvm games contains a lot of cutscenes..)
 	sceKernelPowerTick(SCE_KERNEL_POWER_TICK_DISABLE_AUTO_SUSPEND);
 	sceKernelPowerTick(SCE_KERNEL_POWER_TICK_DISABLE_OLED_OFF);
+
+	// left mouse click gesture: single finger short tap
+	// right mouse click gesture: second finger short tap while first finger is still down
+	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;
+		// which touchID (for multitouch)?
+		SDL_FingerID id = event->tfinger.fingerId;
+
+		int numFingersDown = 0;
+		for (int j = 0; j < 2; j++) {
+			if (_finger[port][j].id >= 0) {
+				numFingersDown++;
+			}
+		}
+
+		if (port < SCE_TOUCH_PORT_MAX_NUM && port >= 0) {
+			if (event->type == SDL_FINGERDOWN) {
+				for (int i = 0; i < 2; i++) {
+					if (_finger[port][i].id == -1 || i == 1) {
+						_finger[port][i].id = id;
+						_finger[port][i].timeLastDown = event->tfinger.timestamp;
+						break;
+					}
+				}
+			} else if (event->type == SDL_FINGERUP) {
+				// 250 ms long tap is interpreted as right/left mouse click depending on number of fingers down
+				for (int i = 0; i < 2; i++) {
+					if (_finger[port][i].id == id) {
+
+						_finger[port][i].id = -1;
+
+						if ((event->tfinger.timestamp - _finger[port][i].timeLastDown) <= 250) {
+							if (numFingersDown == 2 || numFingersDown == 1) {
+								Uint8 simulatedButton = 0;
+								if (numFingersDown == 2) {
+									simulatedButton = SDL_BUTTON_RIGHT;
+								} else if (numFingersDown == 1) {
+									simulatedButton = SDL_BUTTON_LEFT;
+								}
+
+								// simulate button click due to tap gesture
+								event->type = SDL_MOUSEBUTTONDOWN;
+								event->button.button = simulatedButton;
+								event->button.x = _km.x / MULTIPLIER;
+								event->button.y = _km.y / MULTIPLIER;
+
+								SDL_Event ev;
+								ev.type = SDL_MOUSEBUTTONUP;
+								ev.button.button = simulatedButton;
+								ev.button.x = _km.x / MULTIPLIER;
+								ev.button.y = _km.y / MULTIPLIER;
+								SDL_PushEvent(&ev);
+							}
+						}
+					}
+				}
+			} else if (event->type == SDL_FINGERMOTION && numFingersDown == 1) {
+
+				// convert touch events to relative mouse pointer events
+				Sint32 mouse_x = _km.x / MULTIPLIER + (event->tfinger.dx * _km.x_max);
+				Sint32 mouse_y = _km.y / MULTIPLIER + (event->tfinger.dy * _km.y_max);
+
+				if (mouse_x > _km.x_max) {
+					mouse_x = _km.x_max;
+				} else if (mouse_x < 0) {
+					mouse_x = 0;
+				}
+				if (mouse_y > _km.y_max) {
+					mouse_y = _km.y_max;
+				} else if (mouse_y < 0) {
+					mouse_y = 0;
+				}
+
+				event->type = SDL_MOUSEMOTION;
+				event->motion.x = mouse_x;
+				event->motion.y = mouse_y;
+			}
+		}
+	}
 }
 
 #endif
diff --git a/backends/events/psp2sdl/psp2sdl-events.h b/backends/events/psp2sdl/psp2sdl-events.h
index 5593e8a..a715536 100644
--- a/backends/events/psp2sdl/psp2sdl-events.h
+++ b/backends/events/psp2sdl/psp2sdl-events.h
@@ -24,13 +24,21 @@
 #define BACKEND_EVENTS_PSP2_H
 
 #include "backends/events/sdl/sdl-events.h"
+#include <psp2/touch.h>
 
 /**
  * SDL Events manager for the PSP2.
  */
 class PSP2EventSource : public SdlEventSource {
+public:
+	PSP2EventSource();
 protected:
-	void preprocessEvents(SDL_Event *event);
+	void preprocessEvents(SDL_Event *event) override;
+	typedef struct {
+		int id; // -1: no touch
+		int timeLastDown;
+	} Touch;
+	Touch _finger[SCE_TOUCH_PORT_MAX_NUM][2]; // track only two fingers per panel
 };
 
 #endif /* BACKEND_EVENTS_PSP2_H */





More information about the Scummvm-git-logs mailing list