added handling 'back' and 'start' buttons on game controllers
authorHolger Schemel <info@artsoft.org>
Sun, 2 Jul 2017 21:22:13 +0000 (23:22 +0200)
committerHolger Schemel <info@artsoft.org>
Sun, 2 Jul 2017 21:22:13 +0000 (23:22 +0200)
src/events.c
src/events.h
src/tools.c

index 87011a9..a870bf7 100644 (file)
@@ -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
+}
index e5d2dcc..b4c9c32 100644 (file)
@@ -44,5 +44,6 @@ void HandleToonAnimations(void);
 void HandleButton(int, int, int, int);
 void HandleKey(Key, int);
 void HandleJoystick();
+void HandleSpecialGameControllerButtons(Event *);
 
 #endif
index f907d5d..84afef1 100644 (file)
@@ -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;