Enigma 3.2.2
A Simple, Reliable and Efficient Encryption Tool
Loading...
Searching...
No Matches
Event.hpp
Go to the documentation of this file.
1#pragma once
2#ifndef ENIGMA_EVENT_H
3#define ENIGMA_EVENT_H
4
5#include <Core/Core.hpp>
6
7
9enum class EventType : std::uint32_t {
10 NONE = 0,
11
12 //WINDOW
20
21 //FRAME BUFFER
23
24 //APPLICATION
28
29 //KEYBOARD
33
34 //MOUSE
39
40 //JOYSTICK
43};
44inline std::uint32_t operator|(const EventType a, const EventType b) { return static_cast<std::uint32_t>(a) | static_cast<std::uint32_t>(b); }
45inline std::uint32_t operator&(const EventType a, const EventType b) { return static_cast<std::uint32_t>(a) & static_cast<std::uint32_t>(b); }
46
47enum class EventCategory : std::uint32_t {
48 NONE = 0,
49 APPLICATION = BIT(0),
50 INPUT = BIT(1),
51 KEYBOARD = BIT(2),
52 MOUSE = BIT(3),
53 MOUSE_BUTTON = BIT(4),
54 JOYSTICK = BIT(5)
55};
56inline std::uint32_t operator|(const EventCategory a, const EventCategory b) { return static_cast<std::uint32_t>(a) | static_cast<std::uint32_t>(b); }
57inline std::uint32_t operator&(const EventCategory a, const EventCategory b) { return static_cast<std::uint32_t>(a) & static_cast<std::uint32_t>(b); }
58
59#define EVENT_CLASS_TYPE(type) \
60 static EventType GetStaticType() { return type; } \
61 virtual EventType GetEventType() const override { return GetStaticType(); } \
62 virtual const char *GetName() const override { return #type; }
63#define EVENT_CLASS_CATEGORY(category) \
64 virtual std::uint32_t GetCategoryFlags() const override { return static_cast<std::uint32_t>(category); }
65
66class Event {
67 public:
68 virtual EventType GetEventType() const = 0;
69 virtual const char *GetName() const = 0;
70 virtual std::uint32_t GetCategoryFlags() const = 0;
71 virtual std::string ToString() const { return GetName(); }
72
73 bool IsInCategory(EventCategory category) const noexcept {
74 return GetCategoryFlags() & static_cast<std::uint32_t>(category);
75 }
76
77 bool IsHandled() const noexcept { return m_isHandled; }
78 void SetHandled(const bool handled) noexcept { m_isHandled = handled; }
79
80 protected:
81 bool m_isHandled{false};
82};
83
84
85inline std::ostream& operator<<(std::ostream& os, const Event& e) {
86 return os << e.ToString();
87}
89
90#endif // !ENIGMA_EVENT_H
std::uint32_t operator|(const EventType a, const EventType b)
Definition Event.hpp:44
std::uint32_t operator&(const EventType a, const EventType b)
Definition Event.hpp:45
EventCategory
Definition Event.hpp:47
EventType
Definition Event.hpp:9
@ WINDOW_LOST_FOCUS
@ JOYSTICK_CONNECTED
@ FRAME_BUFFER_RESIZE
@ JOYSTICK_DISCONNECTED
@ WINDOW_FILE_DROP
@ MOUSE_BUTTON_PRESSED
@ MOUSE_BUTTON_RELEASED
@ WINDOW_MAXIMIZED
std::ostream & operator<<(std::ostream &os, const Event &e)
Definition Event.hpp:85
#define NS_ENIGMA_BEGIN
Enable/Disable Assertions.
Definition Macros.hpp:13
#define NS_ENIGMA_END
Definition Macros.hpp:14
#define BIT(x)
Bit Shift.
Definition Macros.hpp:74
virtual std::string ToString() const
Definition Event.hpp:71
virtual const char * GetName() const =0
void SetHandled(const bool handled) noexcept
Definition Event.hpp:78
bool IsHandled() const noexcept
Definition Event.hpp:77
bool m_isHandled
Definition Event.hpp:81
bool IsInCategory(EventCategory category) const noexcept
Definition Event.hpp:73
virtual std::uint32_t GetCategoryFlags() const =0
virtual EventType GetEventType() const =0