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 87011a9732167f4aafd2c45b73f4d1e61b6e9a96..a870bf7433f4156337d627d82632ecf2ebf53a14 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 e5d2dcc393c143ccca73e4a76bc37cb1326ce62c..b4c9c3214880fd6b0ddca0f1c04a7d4946a7472a 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 f907d5dd2bf39816a2bc8ef2a8bbb78eef83147f..84afef183185e8b37eed8454fb71879f9b059cbd 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;