]> git.mxchange.org Git - quix0rs-blobwars.git/commitdiff
Handle joystick hat (aka digital pad) events.
authorGuus Sliepen <guus@debian.org>
Sat, 21 Nov 2015 16:35:14 +0000 (17:35 +0100)
committerGuus Sliepen <guus@debian.org>
Sat, 21 Nov 2015 16:35:14 +0000 (17:35 +0100)
src/CEngine.cpp

index 0f4721fd7c8cbe05704eb82770ba46abee65516c..6f0cc752a598da6d8d4dbc13d38e229a2b5ea75e 100644 (file)
@@ -275,6 +275,35 @@ void Engine::getInput()
                                joykeyFire = false;
                                break;
 
+                       case SDL_JOYHATMOTION:
+                               switch (event.jhat.value) {
+                               case SDL_HAT_CENTERED:
+                                       joyX = 0,      joyY = 0;      break;
+                               case SDL_HAT_LEFT:
+                                       joyX = -32768, joyY = 0;      break;
+                               case SDL_HAT_LEFTUP:
+                                       joyX = -32768, joyY = -32768; break;
+                               case SDL_HAT_UP:
+                                       joyX = 0,      joyY = -32768; break;
+                               case SDL_HAT_RIGHTUP:
+                                       joyX = 32767,  joyY = -32768; break;
+                               case SDL_HAT_RIGHT:
+                                       joyX = 32767,  joyY = 0;      break;
+                               case SDL_HAT_RIGHTDOWN:
+                                       joyX = 32767,  joyY = 32767;  break;
+                               case SDL_HAT_DOWN:
+                                       joyX = 0,      joyY = 32767;  break;
+                               case SDL_HAT_LEFTDOWN:
+                                       joyX = -32768, joyY = 32767;  break;
+                               }
+
+                               if (joyX != joyprevX)
+                                       joykeyX = joyprevX = joyX;
+                               if (joyY != joyprevY)
+                                       joykeyY = joyprevY = joyY;
+
+                               break;
+
                        case SDL_WINDOWEVENT:
                                if (event.window.event == SDL_WINDOWEVENT_FOCUS_LOST)
                                        paused = true;