improved code to handle special game controller buttons
authorHolger Schemel <info@artsoft.org>
Tue, 12 Jun 2018 18:23:32 +0000 (20:23 +0200)
committerHolger Schemel <info@artsoft.org>
Tue, 12 Jun 2018 18:45:50 +0000 (20:45 +0200)
src/events.c

index c1a5cbc18eb15c9abdc60b8a0a5ff36468a71ee2..000744c9e177a90e8dff21dcd2f7ffc78ae66ff1 100644 (file)
@@ -2423,24 +2423,38 @@ void HandleJoystick()
 void HandleSpecialGameControllerButtons(Event *event)
 {
 #if defined(TARGET_SDL2)
 void HandleSpecialGameControllerButtons(Event *event)
 {
 #if defined(TARGET_SDL2)
+  int key_status;
+  Key key;
+
   switch (event->type)
   {
     case SDL_CONTROLLERBUTTONDOWN:
   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);
-
+      key_status = KEY_PRESSED;
       break;
 
     case SDL_CONTROLLERBUTTONUP:
       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);
+      key_status = KEY_RELEASED;
+      break;
+
+    default:
+      return;
+  }
 
 
+  switch (event->cbutton.button)
+  {
+    case SDL_CONTROLLER_BUTTON_START:
+      key = KSYM_space;
+      break;
+
+    case SDL_CONTROLLER_BUTTON_BACK:
+      key = KSYM_Escape;
       break;
       break;
+
+    default:
+      return;
   }
   }
+
+  HandleKey(key, key_status);
 #endif
 }
 
 #endif
 }