From ab20c6fd4ca9ac6e93c3fd49ed8ec65d53d2f4c0 Mon Sep 17 00:00:00 2001 From: Ivan Epifanov Date: Mon, 14 Dec 2020 15:05:04 +0300 Subject: [PATCH] [vita] Add L2/R2 on back touch --- SourceX/controls/touch.cpp | 53 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/SourceX/controls/touch.cpp b/SourceX/controls/touch.cpp index bd4ed73be..47e5de4ca 100644 --- a/SourceX/controls/touch.cpp +++ b/SourceX/controls/touch.cpp @@ -27,6 +27,10 @@ static void init_touch(void); static void preprocess_events(SDL_Event *event); static void preprocess_finger_down(SDL_Event *event); static void preprocess_finger_up(SDL_Event *event); +#ifdef __vita__ +static void preprocess_back_finger_down(SDL_Event *event); +static void preprocess_back_finger_up(SDL_Event *event); +#endif static void preprocess_finger_motion(SDL_Event *event); static void set_mouse_button_event(SDL_Event *event, uint32_t type, uint8_t button, int32_t x, int32_t y); static void set_mouse_motion_event(SDL_Event *event, int32_t x, int32_t y, int32_t xrel, int32_t yrel); @@ -101,6 +105,16 @@ static void preprocess_events(SDL_Event *event) // front (0) or back (1) panel SDL_TouchID port = event->tfinger.touchId; if (port != 0) { +#ifdef __vita__ + switch (event->type) { + case SDL_FINGERDOWN: + preprocess_back_finger_down(event); + break; + case SDL_FINGERUP: + preprocess_back_finger_up(event); + break; + } +#endif return; } @@ -157,6 +171,45 @@ static void preprocess_finger_down(SDL_Event *event) break; } } +#ifdef __vita__ +static void preprocess_back_finger_down(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 != 1) return; + + event->type = SDL_CONTROLLERAXISMOTION; + event->caxis.value = 32767; + event->caxis.which = 0; + if (event->tfinger.x <= 0.5) {; + event->caxis.axis = SDL_CONTROLLER_AXIS_TRIGGERLEFT; + } else { + event->caxis.axis = SDL_CONTROLLER_AXIS_TRIGGERRIGHT; + } +} + +static void preprocess_back_finger_up(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 != 1) return; + + event->type = SDL_CONTROLLERAXISMOTION; + event->caxis.value = 0; + event->caxis.which = 0; + if (event->tfinger.x <= 0.5) {; + event->caxis.axis = SDL_CONTROLLER_AXIS_TRIGGERLEFT; + } else { + event->caxis.axis = SDL_CONTROLLER_AXIS_TRIGGERRIGHT; + } +} +#endif static void preprocess_finger_up(SDL_Event *event) {