SPARK  0.1.0
A general purpose game engine written in C++.
Loading...
Searching...
No Matches
Event.h
1#pragma once
2
3#include "spark/events/Export.h"
4
5#include "spark/base/Macros.h"
6#include "spark/rtti/HasRtti.h"
7
8namespace spark::events
9{
10 enum class EventType
11 {
12 None = 0,
13 WindowClose,
14 WindowResize,
15 WindowFocus,
16 WindowLostFocus,
17 WindowMoved,
18 AppTick,
19 AppUpdate,
20 AppRender,
21 KeyPressed,
22 KeyReleased,
23 KeyTyped,
24 MouseButtonPressed,
25 MouseButtonReleased,
26 MouseMoved,
27 MouseScrolled
28 };
29
30 enum EventCategory
31 {
32 None = 0,
33 EventCategoryApplication = BIT(0),
34 EventCategoryInput = BIT(1),
35 EventCategoryKeyboard = BIT(2),
36 EventCategoryMouse = BIT(3),
37 EventCategoryMouseButton = BIT(4)
38 };
39
40#define DEFINE_EVENT_TYPE(type) public: \
41 static EventType StaticType() { return type; } \
42 virtual EventType eventType() const override { return StaticType(); } \
43 private:
44
45#define DEFINE_EVENT_CATEGORY(category) public: \
46 virtual int eventCategoryFlags() const override { return category; } \
47 private:
48
52 class SPARK_EVENTS_EXPORT Event : public rtti::HasRtti
53 {
54 DECLARE_SPARK_RTTI(Event)
55
56 public:
57 explicit Event() = default;
58 ~Event() override = default;
59
60 Event(const Event& other) = default;
61 Event(Event&& other) noexcept = default;
62 Event& operator=(const Event& other) = default;
63 Event& operator=(Event&& other) noexcept = default;
64
69 [[nodiscard]] virtual EventType eventType() const = 0;
70
75 [[nodiscard]] virtual int eventCategoryFlags() const = 0;
76
82 [[nodiscard]] bool isInCategory(const EventCategory& category) const;
83
84 public:
85 bool handled = false;
86 };
87}
88
89IMPLEMENT_SPARK_RTTI(spark::events::Event)
A base class for all events in SPARK.
Definition Event.h:53
virtual int eventCategoryFlags() const =0
Gets the category flags of the event.
virtual EventType eventType() const =0
Gets the type of the event.
The class anything using the RTTI should implement.
Definition HasRtti.h:16