Skip to content

Commit

Permalink
Added axis motion state
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Coêlho <[email protected]>
  • Loading branch information
chocoelho committed May 25, 2016
1 parent dd73770 commit 1768bf8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
15 changes: 3 additions & 12 deletions include/joystick_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down
21 changes: 16 additions & 5 deletions kernel/sdl2/sdl2kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 1768bf8

Please sign in to comment.