Skip to content

Commit

Permalink
Add minimal touch support for decision/cancel
Browse files Browse the repository at this point in the history
Related: EasyRPG#634
This is a very naive implementation, as it only checks whether fingers
touch the screen and not where they touch and in which direction swipes
are done or if there are gestures, etc.
  • Loading branch information
carstene1ns committed Oct 9, 2016
1 parent 9d348aa commit cf2d4dd
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 19 deletions.
5 changes: 5 additions & 0 deletions src/input_buttons_desktop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions src/keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
}
Expand Down
1 change: 1 addition & 0 deletions src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
#define USE_JOYSTICK
#define USE_JOYSTICK_HAT
#define USE_JOYSTICK_AXIS
#define USE_TOUCH

//#define USE_FIXED_TIMESTEP_FPS

Expand Down
40 changes: 25 additions & 15 deletions src/sdl_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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() {
Expand Down
5 changes: 1 addition & 4 deletions src/sdl_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/** @} */

Expand Down
5 changes: 5 additions & 0 deletions src/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit cf2d4dd

Please sign in to comment.