diff options
| author | hachem <im@hachem.wtf> | 2026-08-20 02:27:02 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2026-08-20 02:40:07 +0200 |
| commit | 5b361d81dbd2af0d0e99b9eb1adebea76ff05db0 (patch) | |
| tree | 34db1df17e8c7248aeeb92156d635d31c2484e3f /src/Core/Event.h | |
| parent | e3abaaf59777258ba06705135a0cafcb5918ad12 (diff) | |
[chore]: MASSIVE refactor + more vulkan bs
Diffstat (limited to 'src/Core/Event.h')
| -rw-r--r-- | src/Core/Event.h | 206 |
1 files changed, 103 insertions, 103 deletions
diff --git a/src/Core/Event.h b/src/Core/Event.h index 23d92fd..1891206 100644 --- a/src/Core/Event.h +++ b/src/Core/Event.h @@ -46,63 +46,63 @@ namespace Donut public: virtual ~Event() = default; - bool Handled = false; + virtual auto get_event_type() const -> EventType = 0; + virtual auto get_name() const -> const char* = 0; + virtual auto get_category_flags() const -> int = 0; + virtual auto to_string() const -> std::string { return get_name(); } - virtual EventType GetEventType() const = 0; - virtual const char* GetName() const = 0; - virtual int GetCategoryFlags() const = 0; - virtual std::string ToString() const { return GetName(); } + auto is_in_category(EventCategory category) -> bool { return get_category_flags() & category; } - bool IsInCategory(EventCategory category) { return GetCategoryFlags() & category; } + bool handled = false; }; - #define EVENT_CLASS_TYPE(type) \ - static EventType GetStaticType() { return EventType::type; } \ - virtual EventType GetEventType() const override { return GetStaticType(); } \ - virtual const char* GetName() const override { return #type; } - + #define EVENT_CLASS_TYPE(type) \ + static auto get_static_type() -> EventType { return EventType::type; } \ + virtual auto get_event_type() const -> EventType override { return get_static_type(); } \ + virtual auto get_name() const -> const char* override { return #type; } + #define APPLICATION_EVENT_CLASS_TYPE(type) \ EVENT_CLASS_TYPE(type) \ - virtual int GetCategoryFlags() const override { return EventCategoryApplication; } - + virtual auto get_category_flags() const -> int override { return EventCategoryApplication; } + #define MOUSE_EVENT_CLASS_TYPE(type) \ EVENT_CLASS_TYPE(type) \ - virtual int GetCategoryFlags() const override { return EventCategoryMouse | \ - EventCategoryInput; } - + virtual auto get_category_flags() const -> int override { return EventCategoryMouse | \ + EventCategoryInput; } + #define MOUSE_BUTTON_EVENT_CLASS_TYPE(type) \ EVENT_CLASS_TYPE(type) \ - virtual int GetCategoryFlags() const override { return EventCategoryMouseButton | \ - EventCategoryMouse | \ - EventCategoryInput; } - + virtual auto get_category_flags() const -> int override { return EventCategoryMouseButton | \ + EventCategoryMouse | \ + EventCategoryInput; } + #define KEYBOARD_EVENT_CLASS_TYPE(type) \ EVENT_CLASS_TYPE(type) \ - virtual int GetCategoryFlags() const override { return EventCategoryKeyboard | \ - EventCategoryInput; } + virtual auto get_category_flags() const -> int override { return EventCategoryKeyboard | \ + EventCategoryInput; } class WindowResizeEvent : public Event { public: WindowResizeEvent(unsigned int width, unsigned int height) - : m_Width(width), m_Height(height) { } + : m_width(width), m_height(height) { } - unsigned int GetWidth() const { return m_Width; } - unsigned int GetHeight() const { return m_Height; } + auto get_width() const -> unsigned int { return m_width; } + auto get_height() const -> unsigned int { return m_height; } - std::string ToString() const override + auto to_string() const -> std::string override { - return "WindowResizeEvent: " + std::to_string(m_Width) + ", " + std::to_string(m_Height); + return "WindowResizeEvent: " + std::to_string(m_width) + ", " + std::to_string(m_height); } APPLICATION_EVENT_CLASS_TYPE(WindowResize) private: - unsigned int m_Width, m_Height; + unsigned int m_width, m_height; }; - class WindowCloseEvent + class WindowCloseEvent : public Event { public: @@ -110,7 +110,7 @@ namespace Donut APPLICATION_EVENT_CLASS_TYPE(WindowClose) }; - class WindowFocusEvent + class WindowFocusEvent : public Event { public: @@ -118,7 +118,7 @@ namespace Donut APPLICATION_EVENT_CLASS_TYPE(WindowFocus) }; - class WindowLostFocusEvent + class WindowLostFocusEvent : public Event { public: @@ -126,175 +126,175 @@ namespace Donut APPLICATION_EVENT_CLASS_TYPE(WindowLostFocus) }; - class WindowMovedEvent + class WindowMovedEvent : public Event { public: WindowMovedEvent(int x, int y) - : m_X(x), m_Y(y) { } + : m_x(x), m_y(y) { } - int GetX() const { return m_X; } - int GetY() const { return m_Y; } + auto get_x() const -> int { return m_x; } + auto get_y() const -> int { return m_y; } - std::string ToString() const override + auto to_string() const -> std::string override { - return "WindowMovedEvent: " + std::to_string(m_X) + ", " + std::to_string(m_Y); + return "WindowMovedEvent: " + std::to_string(m_x) + ", " + std::to_string(m_y); } APPLICATION_EVENT_CLASS_TYPE(WindowMoved) private: - int m_X, m_Y; + int m_x, m_y; }; - class KeyEvent + class KeyEvent : public Event { public: - int GetKeyCode() const { return m_KeyCode; } - virtual int GetCategoryFlags() const override { return EventCategoryKeyboard | - EventCategoryInput; } + auto get_key_code() const -> int { return m_key_code; } + virtual auto get_category_flags() const -> int override { return EventCategoryKeyboard | + EventCategoryInput; } protected: KeyEvent(int keycode) - : m_KeyCode(keycode) { } - int m_KeyCode; + : m_key_code(keycode) { } + int m_key_code; }; - class KeyPressedEvent + class KeyPressedEvent : public KeyEvent { public: - KeyPressedEvent(int keycode, bool isRepeat = false) - : KeyEvent(keycode), m_IsRepeat(isRepeat) { } + KeyPressedEvent(int keycode, bool is_repeat = false) + : KeyEvent(keycode), m_is_repeat(is_repeat) { } - bool IsRepeat() const { return m_IsRepeat; } + auto is_repeat() const -> bool { return m_is_repeat; } - std::string ToString() const override + auto to_string() const -> std::string override { - return "KeyPressedEvent: " + std::to_string(m_KeyCode) + - " (repeat = " + std::to_string(m_IsRepeat) + ")"; + return "KeyPressedEvent: " + std::to_string(m_key_code) + + " (repeat = " + std::to_string(m_is_repeat) + ")"; } KEYBOARD_EVENT_CLASS_TYPE(KeyPressed) private: - bool m_IsRepeat; + bool m_is_repeat; }; - class KeyReleasedEvent + class KeyReleasedEvent : public KeyEvent { public: KeyReleasedEvent(int keycode) : KeyEvent(keycode) { } - std::string ToString() const override + auto to_string() const -> std::string override { - return "KeyReleasedEvent: " + std::to_string(m_KeyCode); + return "KeyReleasedEvent: " + std::to_string(m_key_code); } KEYBOARD_EVENT_CLASS_TYPE(KeyReleased) }; - class KeyTypedEvent + class KeyTypedEvent : public KeyEvent { public: KeyTypedEvent(int keycode) : KeyEvent(keycode) { } - std::string ToString() const override + auto to_string() const -> std::string override { - return "KeyTypedEvent: " + std::to_string(m_KeyCode); + return "KeyTypedEvent: " + std::to_string(m_key_code); } KEYBOARD_EVENT_CLASS_TYPE(KeyTyped) }; - class MouseMovedEvent + class MouseMovedEvent : public Event { public: MouseMovedEvent(float x, float y) - : m_MouseX(x), m_MouseY(y) { } + : m_mouse_x(x), m_mouse_y(y) { } - float GetX() const { return m_MouseX; } - float GetY() const { return m_MouseY; } + auto get_x() const -> float { return m_mouse_x; } + auto get_y() const -> float { return m_mouse_y; } - std::string ToString() const override + auto to_string() const -> std::string override { - return "MouseMovedEvent: " + std::to_string(m_MouseX) + ", " + std::to_string(m_MouseY); + return "MouseMovedEvent: " + std::to_string(m_mouse_x) + ", " + std::to_string(m_mouse_y); } MOUSE_EVENT_CLASS_TYPE(MouseMoved) private: - float m_MouseX, m_MouseY; + float m_mouse_x, m_mouse_y; }; - class MouseScrolledEvent + class MouseScrolledEvent : public Event { public: - MouseScrolledEvent(float xOffset, float yOffset) - : m_XOffset(xOffset), m_YOffset(yOffset) { } + MouseScrolledEvent(float x_offset, float y_offset) + : m_x_offset(x_offset), m_y_offset(y_offset) { } - float GetXOffset() const { return m_XOffset; } - float GetYOffset() const { return m_YOffset; } + auto get_x_offset() const -> float { return m_x_offset; } + auto get_y_offset() const -> float { return m_y_offset; } - std::string ToString() const override + auto to_string() const -> std::string override { - return "MouseScrolledEvent: " + std::to_string(m_XOffset) + - ", " + std::to_string(m_YOffset); + return "MouseScrolledEvent: " + std::to_string(m_x_offset) + + ", " + std::to_string(m_y_offset); } MOUSE_EVENT_CLASS_TYPE(MouseScrolled) private: - float m_XOffset, m_YOffset; + float m_x_offset, m_y_offset; }; - class MouseButtonEvent + class MouseButtonEvent : public Event { public: - int GetMouseButton() const { return m_Button; } - virtual int GetCategoryFlags() const override { return EventCategoryMouseButton | - EventCategoryMouse | - EventCategoryInput; } + auto get_mouse_button() const -> int { return m_button; } + virtual auto get_category_flags() const -> int override { return EventCategoryMouseButton | + EventCategoryMouse | + EventCategoryInput; } protected: MouseButtonEvent(int button) - : m_Button(button) { } - int m_Button; + : m_button(button) { } + int m_button; }; - class MouseButtonPressedEvent + class MouseButtonPressedEvent : public MouseButtonEvent { public: MouseButtonPressedEvent(int button) : MouseButtonEvent(button) { } - std::string ToString() const override + auto to_string() const -> std::string override { - return "MouseButtonPressedEvent: " + std::to_string(m_Button); + return "MouseButtonPressedEvent: " + std::to_string(m_button); } MOUSE_BUTTON_EVENT_CLASS_TYPE(MouseButtonPressed) }; - class MouseButtonReleasedEvent + class MouseButtonReleasedEvent : public MouseButtonEvent { public: MouseButtonReleasedEvent(int button) : MouseButtonEvent(button) { } - std::string ToString() const override + auto to_string() const -> std::string override { - return "MouseButtonReleasedEvent: " + std::to_string(m_Button); + return "MouseButtonReleasedEvent: " + std::to_string(m_button); } MOUSE_BUTTON_EVENT_CLASS_TYPE(MouseButtonReleased) @@ -303,22 +303,22 @@ namespace Donut class EventDispatcher { public: - EventDispatcher(Event& event) - : m_Event(event) { } + EventDispatcher(Event& event) + : m_event(event) { } template<typename T, typename F> - bool Dispatch(const F& func) + auto dispatch(const F& func) -> bool { - if (m_Event.GetEventType() == T::GetStaticType()) + if (m_event.get_event_type() == T::get_static_type()) { - m_Event.Handled = func(static_cast<T&>(m_Event)); + m_event.handled = func(static_cast<T&>(m_event)); return true; } return false; } private: - Event& m_Event; + Event& m_event; }; class EventHandler @@ -329,29 +329,29 @@ namespace Donut EventHandler() = default; ~EventHandler() = default; - void SetEventCallback(const EventCallbackFn& callback) + auto set_event_callback(const EventCallbackFn& callback) -> void { - m_EventCallback = callback; + m_event_callback = callback; } - void OnEvent(Event& event) + auto on_event(Event& event) -> void { - if (m_EventCallback) - m_EventCallback(event); + if (m_event_callback) + m_event_callback(event); } template<typename T> - void BindEvent(const std::function<void(T&)>& callback) + auto bind_event(const std::function<void(T&)>& callback) -> void { - m_EventCallback = [callback](Event& event) + m_event_callback = [callback](Event& event) { - if (event.GetEventType() == T::GetStaticType()) + if (event.get_event_type() == T::get_static_type()) callback(static_cast<T&>(event)); }; } private: - EventCallbackFn m_EventCallback; + EventCallbackFn m_event_callback; }; #undef EVENT_CLASS_TYPE @@ -359,4 +359,4 @@ namespace Donut #undef MOUSE_EVENT_CLASS_TYPE #undef MOUSE_BUTTON_EVENT_CLASS_TYPE #undef KEYBOARD_EVENT_CLASS_TYPE -}
\ No newline at end of file +} |
