[Scummvm-git-logs] scummvm master -> ece8dedcf4d980e2d455ef6cc6e6444ebf617c0d

rsn8887 rsn8887 at users.noreply.github.com
Sat Mar 24 02:42:32 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:
ece8dedcf4 PSP2: prevent accidental clicks when moving pointer using touch


Commit: ece8dedcf4d980e2d455ef6cc6e6444ebf617c0d
    https://github.com/scummvm/scummvm/commit/ece8dedcf4d980e2d455ef6cc6e6444ebf617c0d
Author: rsn8887 (rsn8887 at users.noreply.github.com)
Date: 2018-03-23T18:11:13-05:00

Commit Message:
PSP2: prevent accidental clicks when moving pointer using touch

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 6fc0b7d..a8a179d 100644
--- a/backends/events/psp2sdl/psp2sdl-events.cpp
+++ b/backends/events/psp2sdl/psp2sdl-events.cpp
@@ -107,6 +107,8 @@ void PSP2EventSource::preprocessFingerDown(SDL_Event *event) {
 		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;
@@ -137,28 +139,34 @@ void PSP2EventSource::preprocessFingerUp(SDL_Event *event) {
 			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
-					if (numFingersDown == 2 || numFingersDown == 1) {
-						Uint8 simulatedButton = 0;
-						if (numFingersDown == 2) {
-							simulatedButton = SDL_BUTTON_RIGHT;
-						} else if (numFingersDown == 1) {
-							simulatedButton = SDL_BUTTON_LEFT;
-							if (port == 0 && !ConfMan.getBool("frontpanel_touchpad_mode")) {
-								convertTouchXYToGameXY(event->tfinger.x, event->tfinger.y, &x, &y);
+					// but only if the finger hasn't moved since it was pressed down by more than MAX_TAP_MOTION_DISTANCE pixels
+					float xrel = ((event->tfinger.x * 960.0) - (_finger[port][i].lastDownX * 960.0));
+					float yrel = ((event->tfinger.y * 544.0) - (_finger[port][i].lastDownY * 544.0));
+					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;
+							} else if (numFingersDown == 1) {
+								simulatedButton = SDL_BUTTON_LEFT;
+								if (port == 0 && !ConfMan.getBool("frontpanel_touchpad_mode")) {
+									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;
-
-						SDL_Event ev;
-						ev.type = SDL_MOUSEBUTTONUP;
-						ev.button.button = simulatedButton;
-						ev.button.x = x;
-						ev.button.y = y;
-						SDL_PushEvent(&ev);
+							event->type = SDL_MOUSEBUTTONDOWN;
+							event->button.button = simulatedButton;
+							event->button.x = x;
+							event->button.y = y;
+
+							SDL_Event ev;
+							ev.type = SDL_MOUSEBUTTONUP;
+							ev.button.button = simulatedButton;
+							ev.button.x = x;
+							ev.button.y = y;
+							SDL_PushEvent(&ev);
+						}
 					}
 				}
 			} else if (numFingersDown == 1) {
diff --git a/backends/events/psp2sdl/psp2sdl-events.h b/backends/events/psp2sdl/psp2sdl-events.h
index 2f27208..391d03d 100644
--- a/backends/events/psp2sdl/psp2sdl-events.h
+++ b/backends/events/psp2sdl/psp2sdl-events.h
@@ -39,6 +39,7 @@ private:
 	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
 	}; // track three fingers per panel
 
 	typedef struct {
@@ -46,6 +47,8 @@ private:
 		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[SCE_TOUCH_PORT_MAX_NUM][MAX_NUM_FINGERS]; // keep track of finger status





More information about the Scummvm-git-logs mailing list