From b29141048a7d8980431ecd234d398c699403b652 Mon Sep 17 00:00:00 2001 From: staphen Date: Sun, 12 Sep 2021 21:02:38 -0400 Subject: [PATCH] Move existing touch control logic to Vita platform --- CMakeLists.txt | 4 ++-- Source/diablo.cpp | 7 +++++-- Source/miniwin/misc_msg.cpp | 9 ++++++--- Source/{controls => platform/vita}/touch.cpp | 9 +-------- Source/{controls => platform/vita}/touch.h | 7 +++++-- 5 files changed, 19 insertions(+), 17 deletions(-) rename Source/{controls => platform/vita}/touch.cpp (96%) rename Source/{controls => platform/vita}/touch.h (60%) diff --git a/CMakeLists.txt b/CMakeLists.txt index dc37ce492..62c07ec00 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -396,7 +396,6 @@ set(libdevilutionx_SRCS Source/controls/menu_controls.cpp Source/controls/modifier_hints.cpp Source/controls/plrctrls.cpp - Source/controls/touch.cpp Source/controls/keymapper.cpp Source/engine/animationinfo.cpp Source/engine/demomode.cpp @@ -501,7 +500,8 @@ endif() if(VITA) list(APPEND libdevilutionx_SRCS - Source/platform/vita/keyboard.cpp) + Source/platform/vita/keyboard.cpp + Source/platform/vita/touch.cpp) endif() if(NINTENDO_3DS) diff --git a/Source/diablo.cpp b/Source/diablo.cpp index 02b4bb76a..60558ba71 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -65,6 +65,10 @@ #include "utils/language.h" #include "utils/paths.h" +#ifdef __vita__ +#include "platform/vita/touch.h" +#endif + #ifdef GPERF_HEAP_FIRST_GAME_ITERATION #include #endif @@ -118,7 +122,6 @@ MouseActionType LastMouseButtonAction = MouseActionType::None; // Controller support: Actions to run after updating the cursor state. // Defined in SourceX/controls/plctrls.cpp. -extern void finish_simulated_mouse_clicks(int currentMouseX, int currentMouseY); extern void plrctrls_after_check_curs_move(); extern void plrctrls_every_frame(); extern void plrctrls_after_game_logic(); @@ -192,7 +195,7 @@ bool ProcessInput() } if (!gmenu_is_active() && sgnTimeoutCurs == CURSOR_NONE) { -#ifndef USE_SDL1 +#ifdef __vita__ finish_simulated_mouse_clicks(MousePosition.x, MousePosition.y); #endif CheckCursMove(); diff --git a/Source/miniwin/misc_msg.cpp b/Source/miniwin/misc_msg.cpp index 0e6b686c2..6e003c610 100644 --- a/Source/miniwin/misc_msg.cpp +++ b/Source/miniwin/misc_msg.cpp @@ -9,7 +9,6 @@ #include "controls/game_controls.h" #include "controls/plrctrls.h" #include "controls/remap_keyboard.h" -#include "controls/touch.h" #include "cursor.h" #include "engine/demomode.h" #include "engine/rectangle.hpp" @@ -24,6 +23,10 @@ #include "utils/sdl_compat.h" #include "utils/stubs.h" +#ifdef __vita__ +#include "platform/vita/touch.h" +#endif + #ifdef __SWITCH__ #include "platform/switch/docking.h" #include @@ -311,7 +314,7 @@ bool FetchMessage_Real(tagMSG *lpMsg) return true; } -#ifndef USE_SDL1 +#ifdef __vita__ handle_touch(&e, MousePosition.x, MousePosition.y); #endif @@ -434,7 +437,7 @@ bool FetchMessage_Real(tagMSG *lpMsg) break; } return true; -#ifndef USE_SDL1 +#ifdef __vita__ } if (e.type < SDL_JOYAXISMOTION || (e.type >= SDL_FINGERDOWN && e.type < SDL_DOLLARGESTURE)) { #else diff --git a/Source/controls/touch.cpp b/Source/platform/vita/touch.cpp similarity index 96% rename from Source/controls/touch.cpp rename to Source/platform/vita/touch.cpp index 21b6abe1f..58c20f713 100644 --- a/Source/controls/touch.cpp +++ b/Source/platform/vita/touch.cpp @@ -1,4 +1,3 @@ -#ifndef USE_SDL1 #include #include "options.h" @@ -29,10 +28,8 @@ static void InitTouch(); static void PreprocessEvents(SDL_Event *event); static void PreprocessFingerDown(SDL_Event *event); static void PreprocessFingerUp(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 PreprocessFingerMotion(SDL_Event *event); static void SetMouseButtonEvent(SDL_Event *event, uint32_t type, uint8_t button, int32_t x, int32_t y); static void SetMouseMotionEvent(SDL_Event *event, int32_t x, int32_t y, int32_t xrel, int32_t yrel); @@ -109,7 +106,6 @@ static void PreprocessEvents(SDL_Event *event) // front (0) or back (1) panel SDL_TouchID port = event->tfinger.touchId; if (port != 0) { -#ifdef __vita__ if (devilution::sgOptions.Controller.bRearTouch) { switch (event->type) { case SDL_FINGERDOWN: @@ -120,7 +116,6 @@ static void PreprocessEvents(SDL_Event *event) break; } } -#endif return; } @@ -177,7 +172,7 @@ static void PreprocessFingerDown(SDL_Event *event) break; } } -#ifdef __vita__ + static void preprocess_back_finger_down(SDL_Event *event) { // front (0) or back (1) panel @@ -215,7 +210,6 @@ static void preprocess_back_finger_up(SDL_Event *event) event->caxis.axis = SDL_CONTROLLER_AXIS_TRIGGERRIGHT; } } -#endif static void PreprocessFingerUp(SDL_Event *event) { @@ -487,4 +481,3 @@ static void SetMouseMotionEvent(SDL_Event *event, int32_t x, int32_t y, int32_t event->motion.xrel = xrel; event->motion.yrel = yrel; } -#endif diff --git a/Source/controls/touch.h b/Source/platform/vita/touch.h similarity index 60% rename from Source/controls/touch.h rename to Source/platform/vita/touch.h index b621c5916..6e96f0ea6 100644 --- a/Source/controls/touch.h +++ b/Source/platform/vita/touch.h @@ -1,11 +1,14 @@ #pragma once +#ifdef __vita__ + #include namespace devilution { -#ifndef USE_SDL1 void handle_touch(SDL_Event *event, int currentMouseX, int currentMouseY); -#endif +void finish_simulated_mouse_clicks(int currentMouseX, int currentMouseY); } // namespace devilution + +#endif