Enigma  3.2.0
A Simple, Reliable and Efficient Encryption Tool
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 
9 enum class EventType : std::uint32_t {
10  NONE = 0,
11 
12  //WINDOW
20 
21  //FRAME BUFFER
23 
24  //APPLICATION
25  APP_TICK,
26  APP_UPDATE,
27  APP_RENDER,
28 
29  //KEYBOARD
32  KEY_TYPED,
33 
34  //MOUSE
39 
40  //JOYSTICK
43 };
44 inline std::uint32_t operator|(const EventType a, const EventType b) { return static_cast<std::uint32_t>(a) | static_cast<std::uint32_t>(b); }
45 inline std::uint32_t operator&(const EventType a, const EventType b) { return static_cast<std::uint32_t>(a) & static_cast<std::uint32_t>(b); }
46 
47 enum 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 };
56 inline std::uint32_t operator|(const EventCategory a, const EventCategory b) { return static_cast<std::uint32_t>(a) | static_cast<std::uint32_t>(b); }
57 inline 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 
66 class 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 
85 inline 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
std::ostream & operator<<(std::ostream &os, const Event &e)
Definition: Event.hpp:85
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
#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
Definition: Event.hpp:66
virtual std::string ToString() const
Definition: Event.hpp:71
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 const char * GetName() const =0
virtual EventType GetEventType() const =0