diff options
author | rsn8887 | 2018-03-23 18:07:47 -0500 |
---|---|---|
committer | rsn8887 | 2018-03-23 18:11:13 -0500 |
commit | ece8dedcf4d980e2d455ef6cc6e6444ebf617c0d (patch) | |
tree | a4a47a442309b9de6d44a9f12792bc2b7ce5594b /backends/events | |
parent | 41592302ebb5a998e0ea0ddc1174791d2fbc0f3c (diff) | |
download | scummvm-rg350-ece8dedcf4d980e2d455ef6cc6e6444ebf617c0d.tar.gz scummvm-rg350-ece8dedcf4d980e2d455ef6cc6e6444ebf617c0d.tar.bz2 scummvm-rg350-ece8dedcf4d980e2d455ef6cc6e6444ebf617c0d.zip |
PSP2: prevent accidental clicks when moving pointer using touch
Diffstat (limited to 'backends/events')
-rw-r--r-- | backends/events/psp2sdl/psp2sdl-events.cpp | 48 | ||||
-rw-r--r-- | backends/events/psp2sdl/psp2sdl-events.h | 3 |
2 files changed, 31 insertions, 20 deletions
diff --git a/backends/events/psp2sdl/psp2sdl-events.cpp b/backends/events/psp2sdl/psp2sdl-events.cpp index 6fc0b7dede..a8a179d170 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 2f27208f61..391d03dd3f 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 |