aboutsummaryrefslogtreecommitdiff
path: root/backends/events
diff options
context:
space:
mode:
authorrsn88872018-01-23 07:14:39 -0600
committerrsn88872018-01-23 07:27:11 -0600
commit5189dbb7ba7d3db8a7e78906e5bc5ab8d1677955 (patch)
tree717852b8832fdd98931819ba2a19d65de25ea8c7 /backends/events
parenta06bf756c609e03892e3c5bdec1ef18276250389 (diff)
downloadscummvm-rg350-5189dbb7ba7d3db8a7e78906e5bc5ab8d1677955.tar.gz
scummvm-rg350-5189dbb7ba7d3db8a7e78906e5bc5ab8d1677955.tar.bz2
scummvm-rg350-5189dbb7ba7d3db8a7e78906e5bc5ab8d1677955.zip
PSP2: Implement touch controls (front and back panel)
Diffstat (limited to 'backends/events')
-rw-r--r--backends/events/psp2sdl/psp2sdl-events.cpp88
-rw-r--r--backends/events/psp2sdl/psp2sdl-events.h10
2 files changed, 97 insertions, 1 deletions
diff --git a/backends/events/psp2sdl/psp2sdl-events.cpp b/backends/events/psp2sdl/psp2sdl-events.cpp
index 4ea528b00f..b774b9eda1 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 5593e8a504..a71553681a 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 */