hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/src/core/event.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/event.h')
-rw-r--r--src/core/event.h134
1 files changed, 67 insertions, 67 deletions
diff --git a/src/core/event.h b/src/core/event.h
index a1e30e9..1891206 100644
--- a/src/core/event.h
+++ b/src/core/event.h
@@ -46,40 +46,40 @@ 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 get_event_type() const = 0;
- virtual const char* get_name() const = 0;
- virtual int get_category_flags() const = 0;
- virtual std::string to_string() const { return get_name(); }
+ auto is_in_category(EventCategory category) -> bool { return get_category_flags() & category; }
- bool is_in_category(EventCategory category) { return get_category_flags() & category; }
+ bool handled = false;
};
- #define EVENT_CLASS_TYPE(type) \
- static EventType get_static_type() { return EventType::type; } \
- virtual EventType get_event_type() const override { return get_static_type(); } \
- virtual const char* get_name() 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 get_category_flags() 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 get_category_flags() 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 get_category_flags() 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 get_category_flags() const override { return EventCategoryKeyboard | \
- EventCategoryInput; }
+ virtual auto get_category_flags() const -> int override { return EventCategoryKeyboard | \
+ EventCategoryInput; }
class WindowResizeEvent
: public Event
@@ -88,10 +88,10 @@ namespace Donut
WindowResizeEvent(unsigned int width, unsigned int height)
: m_width(width), m_height(height) { }
- unsigned int get_width() const { return m_width; }
- unsigned int get_height() const { return m_height; }
+ auto get_width() const -> unsigned int { return m_width; }
+ auto get_height() const -> unsigned int { return m_height; }
- std::string to_string() const override
+ auto to_string() const -> std::string override
{
return "WindowResizeEvent: " + std::to_string(m_width) + ", " + std::to_string(m_height);
}
@@ -102,7 +102,7 @@ namespace Donut
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,17 +126,17 @@ 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) { }
- int get_x() const { return m_x; }
- int get_y() const { return m_y; }
+ auto get_x() const -> int { return m_x; }
+ auto get_y() const -> int { return m_y; }
- std::string to_string() const override
+ auto to_string() const -> std::string override
{
return "WindowMovedEvent: " + std::to_string(m_x) + ", " + std::to_string(m_y);
}
@@ -147,13 +147,13 @@ namespace Donut
int m_x, m_y;
};
- class KeyEvent
+ class KeyEvent
: public Event
{
public:
- int get_key_code() const { return m_key_code; }
- virtual int get_category_flags() 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)
@@ -161,18 +161,18 @@ namespace Donut
int m_key_code;
};
- class KeyPressedEvent
+ class KeyPressedEvent
: public KeyEvent
{
public:
KeyPressedEvent(int keycode, bool is_repeat = false)
: KeyEvent(keycode), m_is_repeat(is_repeat) { }
- bool is_repeat() const { return m_is_repeat; }
+ auto is_repeat() const -> bool { return m_is_repeat; }
- std::string to_string() const override
+ auto to_string() const -> std::string override
{
- return "KeyPressedEvent: " + std::to_string(m_key_code) +
+ return "KeyPressedEvent: " + std::to_string(m_key_code) +
" (repeat = " + std::to_string(m_is_repeat) + ")";
}
@@ -182,14 +182,14 @@ namespace Donut
bool m_is_repeat;
};
- class KeyReleasedEvent
+ class KeyReleasedEvent
: public KeyEvent
{
public:
KeyReleasedEvent(int keycode)
: KeyEvent(keycode) { }
- std::string to_string() const override
+ auto to_string() const -> std::string override
{
return "KeyReleasedEvent: " + std::to_string(m_key_code);
}
@@ -197,14 +197,14 @@ namespace Donut
KEYBOARD_EVENT_CLASS_TYPE(KeyReleased)
};
- class KeyTypedEvent
+ class KeyTypedEvent
: public KeyEvent
{
public:
KeyTypedEvent(int keycode)
: KeyEvent(keycode) { }
- std::string to_string() const override
+ auto to_string() const -> std::string override
{
return "KeyTypedEvent: " + std::to_string(m_key_code);
}
@@ -212,17 +212,17 @@ namespace Donut
KEYBOARD_EVENT_CLASS_TYPE(KeyTyped)
};
- class MouseMovedEvent
+ class MouseMovedEvent
: public Event
{
public:
MouseMovedEvent(float x, float y)
: m_mouse_x(x), m_mouse_y(y) { }
- float get_x() const { return m_mouse_x; }
- float get_y() const { return m_mouse_y; }
+ auto get_x() const -> float { return m_mouse_x; }
+ auto get_y() const -> float { return m_mouse_y; }
- std::string to_string() const override
+ auto to_string() const -> std::string override
{
return "MouseMovedEvent: " + std::to_string(m_mouse_x) + ", " + std::to_string(m_mouse_y);
}
@@ -233,17 +233,17 @@ namespace Donut
float m_mouse_x, m_mouse_y;
};
- class MouseScrolledEvent
+ class MouseScrolledEvent
: public Event
{
public:
MouseScrolledEvent(float x_offset, float y_offset)
: m_x_offset(x_offset), m_y_offset(y_offset) { }
- float get_x_offset() const { return m_x_offset; }
- float get_y_offset() const { return m_y_offset; }
+ auto get_x_offset() const -> float { return m_x_offset; }
+ auto get_y_offset() const -> float { return m_y_offset; }
- std::string to_string() const override
+ auto to_string() const -> std::string override
{
return "MouseScrolledEvent: " + std::to_string(m_x_offset) +
", " + std::to_string(m_y_offset);
@@ -255,14 +255,14 @@ namespace Donut
float m_x_offset, m_y_offset;
};
- class MouseButtonEvent
+ class MouseButtonEvent
: public Event
{
public:
- int get_mouse_button() const { return m_button; }
- virtual int get_category_flags() 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)
@@ -270,14 +270,14 @@ namespace Donut
int m_button;
};
- class MouseButtonPressedEvent
+ class MouseButtonPressedEvent
: public MouseButtonEvent
{
public:
MouseButtonPressedEvent(int button)
: MouseButtonEvent(button) { }
- std::string to_string() const override
+ auto to_string() const -> std::string override
{
return "MouseButtonPressedEvent: " + std::to_string(m_button);
}
@@ -285,14 +285,14 @@ namespace Donut
MOUSE_BUTTON_EVENT_CLASS_TYPE(MouseButtonPressed)
};
- class MouseButtonReleasedEvent
+ class MouseButtonReleasedEvent
: public MouseButtonEvent
{
public:
MouseButtonReleasedEvent(int button)
: MouseButtonEvent(button) { }
- std::string to_string() const override
+ auto to_string() const -> std::string override
{
return "MouseButtonReleasedEvent: " + std::to_string(m_button);
}
@@ -303,11 +303,11 @@ namespace Donut
class EventDispatcher
{
public:
- EventDispatcher(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.get_event_type() == T::get_static_type())
{
@@ -329,21 +329,21 @@ namespace Donut
EventHandler() = default;
~EventHandler() = default;
- void set_event_callback(const EventCallbackFn& callback)
+ auto set_event_callback(const EventCallbackFn& callback) -> void
{
m_event_callback = callback;
}
- void on_event(Event& event)
+ auto on_event(Event& event) -> void
{
if (m_event_callback)
m_event_callback(event);
}
template<typename T>
- void bind_event(const std::function<void(T&)>& callback)
+ auto bind_event(const std::function<void(T&)>& callback) -> void
{
- m_event_callback = [callback](Event& event)
+ m_event_callback = [callback](Event& event)
{
if (event.get_event_type() == T::get_static_type())
callback(static_cast<T&>(event));