From c8cf37787bc1c90ee2bced0d7dcd1cf735402fff Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Mon, 30 Dec 2013 15:41:52 +0100 Subject: [PATCH] InputManager: Handle joystick hat events --- src/inputmanager.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/inputmanager.cpp b/src/inputmanager.cpp index 970564d..8994847 100644 --- a/src/inputmanager.cpp +++ b/src/inputmanager.cpp @@ -151,6 +151,23 @@ bool InputManager::getButton(Button *button, bool wait) { source = KEYBOARD; break; #ifndef SDL_JOYSTICK_DISABLED + case SDL_JOYHATMOTION: + switch (event.jhat.value) { + case SDL_HAT_CENTERED: + return false; + case SDL_HAT_UP: + *button = UP; + break; + case SDL_HAT_DOWN: + *button = DOWN; + break; + case SDL_HAT_LEFT: + *button = LEFT; + break; + case SDL_HAT_RIGHT: + *button = RIGHT; + break; + } case SDL_JOYBUTTONDOWN: source = JOYSTICK; break; @@ -222,7 +239,7 @@ bool InputManager::getButton(Button *button, bool wait) { } } #ifndef SDL_JOYSTICK_DISABLED - } else if (source == JOYSTICK && event.type != SDL_JOYAXISMOTION) { + } else if (source == JOYSTICK && event.type == SDL_JOYBUTTONDOWN) { for (i = 0; i < BUTTON_TYPE_SIZE; i++) { if (buttonMap[i].source == JOYSTICK && (unsigned int)event.jbutton.button == buttonMap[i].code) {