diff options
Diffstat (limited to 'backends/events/sdl')
-rw-r--r-- | backends/events/sdl/sdl-events.cpp | 37 | ||||
-rw-r--r-- | backends/events/sdl/sdl-events.h | 3 |
2 files changed, 39 insertions, 1 deletions
diff --git a/backends/events/sdl/sdl-events.cpp b/backends/events/sdl/sdl-events.cpp index 494e1bf8cd..c3c316e334 100644 --- a/backends/events/sdl/sdl-events.cpp +++ b/backends/events/sdl/sdl-events.cpp @@ -101,7 +101,7 @@ void SdlEventSource::loadGameControllerMappingFile() { #endif SdlEventSource::SdlEventSource() - : EventSource(), _scrollLock(false), _joystick(0), _lastScreenID(0), _graphicsManager(0), _queuedFakeMouseMove(false) + : EventSource(), _scrollLock(false), _joystick(0), _lastScreenID(0), _graphicsManager(0), _queuedFakeMouseMove(false), _lastHatPosition(SDL_HAT_CENTERED) #if SDL_VERSION_ATLEAST(2, 0, 0) , _queuedFakeKeyUp(false), _fakeKeyUp(), _controller(nullptr) #endif @@ -674,6 +674,8 @@ bool SdlEventSource::dispatchSDLEvent(SDL_Event &ev, Common::Event &event) { return handleJoyButtonUp(ev, event); case SDL_JOYAXISMOTION: return handleJoyAxisMotion(ev, event); + case SDL_JOYHATMOTION: + return handleJoyHatMotion(ev, event); } } @@ -1042,6 +1044,39 @@ bool SdlEventSource::handleJoyAxisMotion(SDL_Event &ev, Common::Event &event) { return false; } +#define HANDLE_HAT_UP(new, old, mask, joybutton) \ + if ((old & mask) && !(new & mask)) { \ + event.joystick.button = joybutton; \ + g_system->getEventManager()->pushEvent(event); \ + } + +#define HANDLE_HAT_DOWN(new, old, mask, joybutton) \ + if ((new & mask) && !(old & mask)) { \ + event.joystick.button = joybutton; \ + g_system->getEventManager()->pushEvent(event); \ + } + +bool SdlEventSource::handleJoyHatMotion(SDL_Event &ev, Common::Event &event) { + if (shouldGenerateMouseEvents()) + return false; + + event.type = Common::EVENT_JOYBUTTON_UP; + HANDLE_HAT_UP(ev.jhat.value, _lastHatPosition, SDL_HAT_UP, Common::JOYSTICK_BUTTON_DPAD_UP) + HANDLE_HAT_UP(ev.jhat.value, _lastHatPosition, SDL_HAT_DOWN, Common::JOYSTICK_BUTTON_DPAD_DOWN) + HANDLE_HAT_UP(ev.jhat.value, _lastHatPosition, SDL_HAT_LEFT, Common::JOYSTICK_BUTTON_DPAD_LEFT) + HANDLE_HAT_UP(ev.jhat.value, _lastHatPosition, SDL_HAT_RIGHT, Common::JOYSTICK_BUTTON_DPAD_RIGHT) + + event.type = Common::EVENT_JOYBUTTON_DOWN; + HANDLE_HAT_DOWN(ev.jhat.value, _lastHatPosition, SDL_HAT_UP, Common::JOYSTICK_BUTTON_DPAD_UP) + HANDLE_HAT_DOWN(ev.jhat.value, _lastHatPosition, SDL_HAT_DOWN, Common::JOYSTICK_BUTTON_DPAD_DOWN) + HANDLE_HAT_DOWN(ev.jhat.value, _lastHatPosition, SDL_HAT_LEFT, Common::JOYSTICK_BUTTON_DPAD_LEFT) + HANDLE_HAT_DOWN(ev.jhat.value, _lastHatPosition, SDL_HAT_RIGHT, Common::JOYSTICK_BUTTON_DPAD_RIGHT) + + _lastHatPosition = ev.jhat.value; + + return false; +} + #if SDL_VERSION_ATLEAST(2, 0, 0) bool SdlEventSource::handleJoystickAdded(const SDL_JoyDeviceEvent &device) { debug(5, "SdlEventSource: Received joystick added event for index '%d'", device.which); diff --git a/backends/events/sdl/sdl-events.h b/backends/events/sdl/sdl-events.h index 6050c80297..bf17cc918f 100644 --- a/backends/events/sdl/sdl-events.h +++ b/backends/events/sdl/sdl-events.h @@ -143,6 +143,7 @@ protected: virtual bool handleJoyButtonDown(SDL_Event &ev, Common::Event &event); virtual bool handleJoyButtonUp(SDL_Event &ev, Common::Event &event); virtual bool handleJoyAxisMotion(SDL_Event &ev, Common::Event &event); + virtual bool handleJoyHatMotion(SDL_Event &ev, Common::Event &event); virtual void updateKbdMouse(); virtual bool handleKbdMouse(Common::Event &event); @@ -224,6 +225,8 @@ protected: */ Common::Event _fakeMouseMove; + uint8 _lastHatPosition; + #if SDL_VERSION_ATLEAST(2, 0, 0) /** * Whether _fakeKeyUp contains an event we need to send. |