From 1768bf89cac53a84ffe63b868c6540f88add15d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Co=C3=AAlho?= Date: Wed, 25 May 2016 15:42:26 -0300 Subject: [PATCH] Added axis motion state MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Carlos Coêlho --- include/joystick_event.h | 15 +++------------ kernel/sdl2/sdl2kernel.cpp | 21 ++++++++++++++++----- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/include/joystick_event.h b/include/joystick_event.h index 6bbafaa..986a934 100644 --- a/include/joystick_event.h +++ b/include/joystick_event.h @@ -13,7 +13,7 @@ namespace ijengine { class JoystickEvent : public Event { public: - typedef enum {PRESSED, RELEASED} State; + typedef enum {BUTTON_PRESSED, BUTTON_RELEASED, AXIS_MOTION} State; typedef enum { @@ -28,22 +28,13 @@ namespace ijengine { TRIGGERLEFT, TRIGGERRIGHT, AXIS_MAX } Axis; - JoystickEvent(unsigned t, State s, Button b) : - Event(t), m_state(s), m_button(b) {} + JoystickEvent(unsigned t, State s, Button b, Axis a) : + Event(t), m_state(s), m_button(b), m_axis(a) {} State state() const { return m_state; } Button button() const { return m_button; } Axis axis() const { return m_axis; } - string serialize() const - { - ostringstream os; - os << JOYSTICK_EVENT_ID << "," << (int) m_state << "," - << (int) m_button; - - return os.str(); - } - private: State m_state; Button m_button; diff --git a/kernel/sdl2/sdl2kernel.cpp b/kernel/sdl2/sdl2kernel.cpp index d8d2224..35e42ee 100644 --- a/kernel/sdl2/sdl2kernel.cpp +++ b/kernel/sdl2/sdl2kernel.cpp @@ -217,7 +217,7 @@ SDL2Kernel::init_table() m_axis_table[SDL_CONTROLLER_AXIS_MAX] = JoystickEvent::AXIS_MAX; } - +Event MouseEvent::State button_state(int button_mask, int button_id) { @@ -310,16 +310,27 @@ SDL2Kernel::pending_joystick_events(unsigned now) if (it->type == SDL_JOYBUTTONDOWN) { auto event = JoystickEvent(timestamp, - JoystickEvent::State::PRESSED, - m_button_table[it->jbutton.button]); + JoystickEvent::State::BUTTON_PRESSED, + m_button_table[it->jbutton.button], + NULL); events.push_back(event); it = m_events.erase(it); } else if (it->type == SDL_JOYBUTTONUP) { auto event = JoystickEvent(timestamp, - JoystickEvent::State::RELEASED, - m_button_table[it->jbutton.button]); + JoystickEvent::State::BUTTON_RELEASED, + m_button_table[it->jbutton.button], + NULL); + + events.push_back(event); + it = m_events.erase(it); + } else if (it->type == SDL_JOYAXISMOTION) + { + auto event = JoystickEvent(timestamp, + JoystickEvent::State::AXIS_MOTION, + NULL, + m_axis_table[it->jaxis.axis]); events.push_back(event); it = m_events.erase(it);