From 11883bd17be207f3512b9b60cc81c0b9f7348eba Mon Sep 17 00:00:00 2001 From: Riyyi Date: Sun, 22 Dec 2019 17:00:38 +0100 Subject: [PATCH] Add joystick connected event --- inferno/src/inferno/event/event.h | 5 +++ inferno/src/inferno/event/joystickevent.h | 55 +++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 inferno/src/inferno/event/joystickevent.h diff --git a/inferno/src/inferno/event/event.h b/inferno/src/inferno/event/event.h index a674d6b..b8b9947 100644 --- a/inferno/src/inferno/event/event.h +++ b/inferno/src/inferno/event/event.h @@ -21,6 +21,9 @@ namespace Inferno { MouseButtonRelease, MousePosition, MouseScroll, + + JoystickConnected, + JoystickDisconnected, }; enum EventCategory { @@ -33,6 +36,8 @@ namespace Inferno { MouseEventCategory = BIT(3), MouseButtonEventCategory = BIT(4), + + JoystickEventCatergory = BIT(5), }; class Event { diff --git a/inferno/src/inferno/event/joystickevent.h b/inferno/src/inferno/event/joystickevent.h new file mode 100644 index 0000000..6056e93 --- /dev/null +++ b/inferno/src/inferno/event/joystickevent.h @@ -0,0 +1,55 @@ +#ifndef JOYSTICKEVENT_H +#define JOYSTICKEVENT_H + +#include "inferno/event/event.h" + +namespace Inferno { + + class JoystickEvent : public Event { + public: + inline int getID() const { return m_id; } + + EVENT_CLASS_CATEGORY(InputEventCategory | JoystickEventCatergory) + + protected: + JoystickEvent(int id) : + m_id(id) {} + + private: + int m_id; + }; + + class JoystickConnectedEvent : public JoystickEvent { + public: + JoystickConnectedEvent(int id) : + JoystickEvent(id) {} + + virtual std::string toString() const override + { + std::stringstream ss; + ss << "JoystickConnected: " << getID(); + return ss.str(); + } + + EVENT_CLASS_TYPE(JoystickConnected) + }; + + class JoystickDisconnectedEvent : public JoystickEvent { + public: + JoystickDisconnectedEvent(int id) : + JoystickEvent(id) {} + + virtual std::string toString() const override + { + std::stringstream ss; + ss << "JoystickDisconnected: " << getID(); + return ss.str(); + } + + EVENT_CLASS_TYPE(JoystickDisconnected) + }; + +} + + +#endif // JOYSTICKEVENT_H