diff --git a/Engine/src/Engine/Events/Event.h b/Engine/src/Engine/Events/Event.h new file mode 100644 index 0000000..9a0ecba --- /dev/null +++ b/Engine/src/Engine/Events/Event.h @@ -0,0 +1,40 @@ +#pragma once + +#include "Base.h" + +#include + +namespace Light { + + enum EventType + { + None = 0, + + // input + MouseMoved, ButtonPressed, ButtonReleased, // mouse + KeyPressed, KeyReleased, // keyboard + + // window + WindowMoved, WindowResized, WindowClosed, + }; + +#define EVENT_TYPE(x) virtual EventType GetType() override { return x; } + + class Event + { + private: + bool b_Handled; + + public: + virtual EventType GetType() = 0; + virtual std::string GetInfoLog() const = 0; + + inline bool IsHandled() const { return b_Handled; } + + friend std::ostream & operator<<(std::ostream & os, const Event& e) + { + return os << e.GetInfoLog(); + } + }; + +} \ No newline at end of file diff --git a/Engine/src/Engine/Events/KeyboardEvent.h b/Engine/src/Engine/Events/KeyboardEvent.h new file mode 100644 index 0000000..393ddac --- /dev/null +++ b/Engine/src/Engine/Events/KeyboardEvent.h @@ -0,0 +1,48 @@ +#pragma once + +#include "Base.h" + +#include "Event.h" + +#include + +namespace Light { + + class KeyPressedEvent : public Event + { + private: + const int m_Key; + + public: + KeyPressedEvent(int key): m_Key(key) {} + + inline int GetKey() const { return m_Key; } + + virtual std::string GetInfoLog() const override + { + std::stringstream ss; + ss << "KeyPressed: " << m_Key; + } + EVENT_TYPE(KeyPressed) + }; + + class KeyReleasedEvent : public Event + { + private: + const int m_Key; + + public: + KeyReleasedEvent(int key): m_Key(key) {} + + inline int GetKey() const { return m_Key; } + + virtual std::string GetInfoLog() const override + { + std::stringstream ss; + ss << "KeyReleased: " << m_Key; + } + EVENT_TYPE(KeyReleased) + }; + + +} \ No newline at end of file diff --git a/Engine/src/Engine/Events/MouseEvents.h b/Engine/src/Engine/Events/MouseEvents.h new file mode 100644 index 0000000..b9030e0 --- /dev/null +++ b/Engine/src/Engine/Events/MouseEvents.h @@ -0,0 +1,69 @@ +#pragma once + +#include "Base.h" + +#include "Event.h" + +#include + +namespace Light { + + class MouseMovedEvent : public Event + { + private: + const float m_PositionX, m_PositionY; + + public: + MouseMovedEvent(float x, float y) : m_PositionX(x), m_PositionY(y) {} + + inline float GetX() const { return m_PositionX; } + inline float GetY() const { return m_PositionY; } + + virtual std::string GetInfoLog() const override + { + std::stringstream ss; + ss << "MouseMoved: " << m_PositionX << ", " << m_PositionY; + return ss.str(); + } + EVENT_TYPE(MouseMoved) + }; + + class ButtonPressedEvent : public Event + { + private: + const int m_Button; + + public: + ButtonPressedEvent(int button): m_Button(button) {} + + inline int GetButton() const { return m_Button; } + + virtual std::string GetInfoLog() const override + { + std::stringstream ss; + ss << "ButtonPressed: " << m_Button; + return ss.str(); + } + EVENT_TYPE(ButtonPressed) + }; + + class ButtonReleasedEvent : public Event + { + private: + const int m_Button; + + public: + ButtonReleasedEvent(int button) : m_Button(button) {} + + inline int GetButton() const { return m_Button; } + + virtual std::string GetInfoLog() const override + { + std::stringstream ss; + ss << "ButtonReleased: " << m_Button; + return ss.str(); + } + EVENT_TYPE(ButtonReleased) + }; + +} \ No newline at end of file