From: Holger Schemel Date: Sun, 2 Jul 2017 21:22:13 +0000 (+0200) Subject: added handling 'back' and 'start' buttons on game controllers X-Git-Tag: 4.0.1.0~36 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=b62e4322b0b7d01aac9340adaddba753e04c9c51;p=rocksndiamonds.git added handling 'back' and 'start' buttons on game controllers --- diff --git a/src/events.c b/src/events.c index 87011a97..a870bf74 100644 --- a/src/events.c +++ b/src/events.c @@ -248,11 +248,13 @@ void HandleOtherEvents(Event *event) #if defined(TARGET_SDL) #if defined(TARGET_SDL2) + case SDL_CONTROLLERBUTTONDOWN: + case SDL_CONTROLLERBUTTONUP: + HandleSpecialGameControllerButtons(event); + /* FALL THROUGH */ case SDL_CONTROLLERDEVICEADDED: case SDL_CONTROLLERDEVICEREMOVED: case SDL_CONTROLLERAXISMOTION: - case SDL_CONTROLLERBUTTONDOWN: - case SDL_CONTROLLERBUTTONUP: #endif case SDL_JOYAXISMOTION: case SDL_JOYBUTTONDOWN: @@ -350,6 +352,12 @@ void ClearEventQueue() ClearPlayerAction(); break; +#if defined(TARGET_SDL2) + case SDL_CONTROLLERBUTTONUP: + ClearPlayerAction(); + break; +#endif + default: HandleOtherEvents(&event); break; @@ -389,6 +397,12 @@ void SleepWhileUnmapped() key_joystick_mapping = 0; break; +#if defined(TARGET_SDL2) + case SDL_CONTROLLERBUTTONUP: + key_joystick_mapping = 0; + break; +#endif + case EVENT_MAPNOTIFY: window_unmapped = FALSE; break; @@ -2031,9 +2045,39 @@ void HandleJoystick() return; } + if (tape.recording && tape.pausing) + { + if (joystick & JOY_ACTION) + TapeTogglePause(TAPE_TOGGLE_MANUAL); + } + break; default: break; } } + +void HandleSpecialGameControllerButtons(Event *event) +{ +#if defined(TARGET_SDL2) + switch (event->type) + { + case SDL_CONTROLLERBUTTONDOWN: + if (event->cbutton.button == SDL_CONTROLLER_BUTTON_START) + HandleKey(KSYM_space, KEY_PRESSED); + else if (event->cbutton.button == SDL_CONTROLLER_BUTTON_BACK) + HandleKey(KSYM_Escape, KEY_PRESSED); + + break; + + case SDL_CONTROLLERBUTTONUP: + if (event->cbutton.button == SDL_CONTROLLER_BUTTON_START) + HandleKey(KSYM_space, KEY_RELEASED); + else if (event->cbutton.button == SDL_CONTROLLER_BUTTON_BACK) + HandleKey(KSYM_Escape, KEY_RELEASED); + + break; + } +#endif +} diff --git a/src/events.h b/src/events.h index e5d2dcc3..b4c9c321 100644 --- a/src/events.h +++ b/src/events.h @@ -44,5 +44,6 @@ void HandleToonAnimations(void); void HandleButton(int, int, int, int); void HandleKey(Key, int); void HandleJoystick(); +void HandleSpecialGameControllerButtons(Event *); #endif diff --git a/src/tools.c b/src/tools.c index f907d5dd..84afef18 100644 --- a/src/tools.c +++ b/src/tools.c @@ -3939,6 +3939,34 @@ static int RequestHandleEvents(unsigned int req_state) ClearPlayerAction(); break; +#if defined(TARGET_SDL2) + case SDL_CONTROLLERBUTTONDOWN: + switch (event.cbutton.button) + { + case SDL_CONTROLLER_BUTTON_A: + case SDL_CONTROLLER_BUTTON_X: + case SDL_CONTROLLER_BUTTON_LEFTSHOULDER: + result = 1; + break; + + case SDL_CONTROLLER_BUTTON_B: + case SDL_CONTROLLER_BUTTON_Y: + case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER: + case SDL_CONTROLLER_BUTTON_BACK: + result = 0; + break; + } + + if (req_state & REQ_PLAYER) + result = 0; + + break; + + case SDL_CONTROLLERBUTTONUP: + ClearPlayerAction(); + break; +#endif + default: HandleOtherEvents(&event); break;