diff --git a/src/input_buttons_desktop.cpp b/src/input_buttons_desktop.cpp index 0a9bd8a4975..8f31c99be9a 100644 --- a/src/input_buttons_desktop.cpp +++ b/src/input_buttons_desktop.cpp @@ -131,6 +131,11 @@ void Input::InitButtons() { buttons[UP].push_back(Keys::JOY_AXIS_Y_UP); #endif +#if defined(USE_TOUCH) && defined(SUPPORT_TOUCH) + buttons[DECISION].push_back(Keys::ONE_FINGER); + buttons[CANCEL].push_back(Keys::TWO_FINGERS); +#endif + dir_buttons.resize(10); dir_buttons[2].push_back(DOWN); dir_buttons[4].push_back(LEFT); diff --git a/src/keys.h b/src/keys.h index 7a2c9553f82..2cd0ffd772d 100644 --- a/src/keys.h +++ b/src/keys.h @@ -191,6 +191,11 @@ namespace Input { JOY_AXIS_Y_UP, #endif +#if defined(USE_TOUCH) && defined(SUPPORT_TOUCH) + ONE_FINGER, + TWO_FINGERS, +#endif + KEYS_COUNT }; } diff --git a/src/options.h b/src/options.h index cb13a53d2fa..5f30428c968 100644 --- a/src/options.h +++ b/src/options.h @@ -90,6 +90,7 @@ #define USE_JOYSTICK #define USE_JOYSTICK_HAT #define USE_JOYSTICK_AXIS +#define USE_TOUCH //#define USE_FIXED_TIMESTEP_FPS diff --git a/src/sdl_ui.cpp b/src/sdl_ui.cpp index 97cd782f70e..c57a3bd6d0c 100644 --- a/src/sdl_ui.cpp +++ b/src/sdl_ui.cpp @@ -672,11 +672,9 @@ void SdlUi::ProcessEvent(SDL_Event &evnt) { #if SDL_MAJOR_VERSION>1 case SDL_FINGERDOWN: - ProcessFingerDownEvent(evnt); - return; - case SDL_FINGERUP: - ProcessFingerUpEvent(evnt); + case SDL_FINGERMOTION: + ProcessFingerEvent(evnt); return; #endif } @@ -941,17 +939,29 @@ void SdlUi::ProcessJoystickAxisEvent(SDL_Event &evnt) { } #if SDL_MAJOR_VERSION>1 -void SdlUi::ProcessFingerDownEvent(SDL_Event& evnt) { - ProcessFingerEvent(evnt, true); -} - -void SdlUi::ProcessFingerUpEvent(SDL_Event& evnt) { - ProcessFingerEvent(evnt, false); -} - -void SdlUi::ProcessFingerEvent(SDL_Event& evnt, bool finger_down) { - (void)finger_down; - (void)evnt; +void SdlUi::ProcessFingerEvent(SDL_Event& evnt) { +#if defined(USE_TOUCH) && defined(SUPPORT_TOUCH) + SDL_TouchID touchid; + int fingers = 0; + + // We currently ignore swipe gestures + if (evnt.type != SDL_FINGERMOTION) { + /* FIXME: To simplify things, we lazily only get the current number of + fingers touching the first device (hoping nobody actually uses + multiple devices). This way we do not need to keep track on finger + IDs and deal with the timing. + */ + touchid = SDL_GetTouchDevice(0); + if (touchid != 0) + fingers = SDL_GetNumTouchFingers(touchid); + + keys[Input::Keys::ONE_FINGER] = fingers > 0; + keys[Input::Keys::TWO_FINGERS] = fingers > 1; + } +#else + /* unused */ + (void) evnt; +#endif } void SdlUi::SetAppIcon() { diff --git a/src/sdl_ui.h b/src/sdl_ui.h index febe364304b..8651a15a917 100644 --- a/src/sdl_ui.h +++ b/src/sdl_ui.h @@ -112,10 +112,7 @@ class SdlUi : public BaseUi { void ProcessJoystickAxisEvent(SDL_Event &evnt); #if SDL_MAJOR_VERSION>1 void ProcessMouseWheelEvent(SDL_Event &evnt); - - void ProcessFingerDownEvent(SDL_Event & evnt); - void ProcessFingerUpEvent(SDL_Event & evnt); - void ProcessFingerEvent(SDL_Event & evnt, bool finger_down); + void ProcessFingerEvent(SDL_Event & evnt); /** @} */ diff --git a/src/system.h b/src/system.h index f8bcce6a36e..c559d9085b1 100644 --- a/src/system.h +++ b/src/system.h @@ -79,6 +79,11 @@ # if !defined(OPENDINGUX) && !defined(GEKKO) # define SUPPORT_KEYBOARD # define SUPPORT_MOUSE + + // We have our own touch input solution on Android +# if !defined(__ANDROID__) +# define SUPPORT_TOUCH +# endif # endif # if !defined(OPENDINGUX)