SDOM - Simple SDL Document Object Model
A lightweight, extensible Document Object Model for SDL-based applications.
Loading...
Searching...
No Matches
SDOM_EventType.hpp
Go to the documentation of this file.
1/*** SDOM_EventType.hpp ****************************
2 * ___ ___ ___ __ __ ___ _ _____ _
3 * / __| \ / _ \| \/ | | __|_ _____ _ _| ||_ _| _ _ __ ___ | |_ _ __ _ __
4 * \__ \ |) | (_) | |\/| | | _|\ V / -_) ' \ _|| || || | '_ \/ -_)_| ' \| '_ \ '_ \
5 * |___/___/ \___/|_| |_|_|___|\_/\___|_||_\__||_| \_, | .__/\___(_)_||_| .__/ .__/
6 * |___| |__/|_| |_| |_|
7 *
8 * The SDOM_EventType class defines and manages the various types of events that can
9 * be dispatched and handled within the SDOM framework. It provides a flexible system
10 * for registering both predefined and custom event types, each with configurable
11 * propagation properties such as capturing, bubbling, target-only, and global scope.
12 * EventType instances are used to categorize and identify events throughout the event
13 * system, enabling robust event-driven programming and fine-grained control over event
14 * flow. By supporting both standard UI events (mouse, keyboard, window, etc.) and
15 * user-defined events, the EventType class forms the foundation for extensible and
16 * scalable event handling in SDOM-based applications.
17 *
18 *
19 * This software is provided 'as-is', without any express or implied
20 * warranty. In no event will the authors be held liable for any damages
21 * arising from the use of this software.
22 *
23 * Permission is granted to anyone to use this software for any purpose,
24 * including commercial applications, and to alter it and redistribute it
25 * freely, subject to the following restrictions:
26 *
27 * 1. The origin of this software must not be misrepresented; you must not
28 * claim that you wrote the original software. If you use this software
29 * in a product, an acknowledgment in the product documentation would be
30 * appreciated but is not required.
31 * 2. Altered source versions must be plainly marked as such, and must not be
32 * misrepresented as being the original software.
33 * 3. This notice may not be removed or altered from any source distribution.
34 *
35 * Released under the ZLIB License.
36 * Original Author: Jay Faries (warte67)
37 *
38 ******************/
39
40#ifndef __SDOM_EVENTTYPE_HPP__
41#define __SDOM_EVENTTYPE_HPP__
42
43#include <unordered_set>
44
45
46namespace SDOM
47{
49 {
50 public:
51 // Predefined event types (* denotes completed)
52 static EventType None; // * for no event
53 static EventType SDL_Event; // * for raw SDL events
54 static EventType Quit; // * for application quit events
55 static EventType EnterFrame; // * called every frame (consider dispatching for EventListeners only)
56 // Mouse event types
57 static EventType MouseButtonUp; // * for mouse button up events
58 static EventType MouseButtonDown; // * for mouse button down events
59 static EventType MouseWheel; // * for mouse wheel
60 static EventType MouseMove; // * for mouse movement
61 static EventType MouseClick; // * for single mouse clicks
62 static EventType MouseDoubleClick; // * for double mouse clicks
63 static EventType MouseEnter; // * for mouse entering an object
64 static EventType MouseLeave; // * for mouse leaving an object
65 // Stage event types
66 static EventType StageClosed; // * for when a stage is closed
67 // Keyboard event types
68 static EventType KeyDown; // for when a key is pressed down (includes IME or Shift Modified ascii)
69 static EventType KeyUp; // for when a key is released
70 // Timer event types
71 static EventType Timer; // generic timer event
72 static EventType Tick; // periodic update
73 static EventType Timeout; // one-shot timer expiration event
74 // Window event types
75 static EventType FocusGained; // * for widgets, windows, or controls
76 static EventType FocusLost; // * for widgets, windows, or controls
77 static EventType Resize; // * for window or control size changes
78 static EventType Move; // * for IDisplayObject position changes
79 static EventType Show; // * for visibility changes
80 static EventType Hide; // * for visibility changes
81 static EventType EnterFullscreen; // * for entering fullscreen mode
82 static EventType LeaveFullscreen; // * for leaving fullscreen mode
83 // General UI event types
84 static EventType ValueChanged; // for sliders, text fields, etc.
85 static EventType StateChanged; // for checkboxes, radio buttons, etc.
86 static EventType SelectionChanged; // for list boxes, combo boxes, etc.
87 static EventType Enabled; // when IDisplayObjects become enabled
88 static EventType Disabled; // when IDisplayObjects become disabled
89 static EventType Active; // REMOVE ACTIVE
90 static EventType Inactive; // REMOVE INACTIVE
91 static EventType Visible; // when a IDisplayObject becomes visible
92 static EventType Hidden; // when a IDisplayObject becomes hidden
93 // Drag & Drop event types
94 static EventType Drag; // * when a drag operation starts
95 static EventType Dragging; // * when a drag operation is ongoing
96 static EventType Drop; // * when an item is dropped
97 // Clipboard event types
98 static EventType ClipboardCopy; // when content is copied to the clipboard
99 static EventType ClipboardPaste; // when content is pasted from the clipboard
100
101 // Main DisplayHandle event types (NEW EventTypes to be added)
102
103 // Application lifecycle event types
104 static EventType Added; // when a DisplayHandle is added to the display list
105 static EventType Removed; // when a DisplayHandle is removed from the display list
106 static EventType AddedToStage; // when a DisplayHandle is added to the stage
107 static EventType RemovedFromStage; // when a DisplayHandle is removed from the stage
108 // Event Listener Only Events
109 static EventType OnInit; // OnInit is Dispatched to EventListeners
110 static EventType OnQuit; // OnQuit is Dispatched to EventListeners
111 static EventType OnEvent; // OnEvent is Dispatched to EventListeners
112 static EventType OnUpdate; // OnUpdate is Dispatched to EventListeners
113 static EventType OnRender; // OnRender is Dispatched to EventListeners
114 static EventType OnPreRender; // OnPreRender is Dispatched to EventListeners
115 // (before stage children render)
116
117 // Custom User event types
118 static EventType User; // custom user event type
119
120 explicit EventType(const std::string& name)
121 : name(name), captures_(true), bubbles_(true), targetOnly_(false), global_(false)
122 { registerEventType(name, this); }
123
124 explicit EventType(const std::string& name, bool captures, bool bubbles, bool targetOnly, bool global)
125 : name(name), captures_(captures), bubbles_(bubbles), targetOnly_(targetOnly), global_(global)
126 {
127 registerEventType(name, this);
128 }
129
130 const std::string& getName() const { return name; }
131
132 bool operator==(const EventType& other) const { return name == other.name; }
133 bool operator!=(const EventType& other) const { return name != other.name; }
134 bool operator<(const EventType& other) const { return name < other.name; }
135
136 static void registerEventType(const std::string& name, EventType* ptr) {
137 if (registry.find(name) == registry.end()) {
138 registry.insert({name, ptr});
139 }
140 }
141
142 static bool isRegistered(const std::string& name) {
143 return registry.find(name) != registry.end();
144 }
145
146 // Return the internal registry mapping event name -> EventType*
147 static const std::unordered_map<std::string, EventType*>& getRegistry() { return registry; }
148
149 // // Ensure all predefined EventType static instances are inserted into
150 // // the registry. Calling this from startup code avoids static
151 // // initialization order issues on some platforms.
152 // // NOTE: Each EventType constructor already registers itself via
153 // // registerEventType(name, this). This helper is therefore
154 // // usually redundant, but is retained here to force initialization
155 // ///ODR-use of the predefined statics in cases where static
156 // // initialization order across translation units could lead to an
157 // // empty registry. It is kept for backward-compatibility and safety.
158 // static void registerAll();
159
160 // Register EventType usertype/table in a Lua state so scripts can
161 // access EventType constants and query properties.
162 static void registerLua(sol::state_view lua);
163
164 // -- Getters -- //
165 bool getCaptures() const;
166 bool getBubbles() const;
167 bool getTargetOnly() const;
168 bool getGlobal() const;
169
170 // -- Setters -- //
171 EventType& setCaptures(bool captures);
172 EventType& setBubbles(bool bubbles);
173 EventType& setTargetOnly(bool targetOnly);
174 EventType& setGlobal(bool global);
175
176 // -- Public Lua support -- //
177
178 private:
179 std::string name;
180 static inline std::unordered_map<std::string, EventType*> registry;
181
182 bool captures_ = true;
183 bool bubbles_ = true;
184 bool targetOnly_ = false;
185 bool global_ = false;
186
187 };
188
189} // namespace SDOM
190
191#endif // __SDOM_EVENTTYPE_HPP__
Definition SDOM_EventType.hpp:49
bool getCaptures() const
Definition SDOM_EventType.cpp:189
static EventType Dragging
Definition SDOM_EventType.hpp:95
bool operator<(const EventType &other) const
Definition SDOM_EventType.hpp:134
bool operator==(const EventType &other) const
Definition SDOM_EventType.hpp:132
static EventType Timer
Definition SDOM_EventType.hpp:71
static EventType RemovedFromStage
Definition SDOM_EventType.hpp:107
static EventType ClipboardPaste
Definition SDOM_EventType.hpp:99
static EventType OnQuit
Definition SDOM_EventType.hpp:110
static EventType MouseDoubleClick
Definition SDOM_EventType.hpp:62
static EventType FocusGained
Definition SDOM_EventType.hpp:75
static EventType Timeout
Definition SDOM_EventType.hpp:73
static EventType MouseButtonDown
Definition SDOM_EventType.hpp:58
static EventType OnEvent
Definition SDOM_EventType.hpp:111
EventType & setGlobal(bool global)
Definition SDOM_EventType.cpp:224
static bool isRegistered(const std::string &name)
Definition SDOM_EventType.hpp:142
static const std::unordered_map< std::string, EventType * > & getRegistry()
Definition SDOM_EventType.hpp:147
static EventType EnterFullscreen
Definition SDOM_EventType.hpp:81
static EventType Active
Definition SDOM_EventType.hpp:89
static EventType MouseEnter
Definition SDOM_EventType.hpp:63
EventType & setBubbles(bool bubbles)
Definition SDOM_EventType.cpp:214
static EventType MouseClick
Definition SDOM_EventType.hpp:61
static EventType AddedToStage
Definition SDOM_EventType.hpp:106
static EventType StateChanged
Definition SDOM_EventType.hpp:85
static EventType Visible
Definition SDOM_EventType.hpp:91
static EventType StageClosed
Definition SDOM_EventType.hpp:66
static EventType SelectionChanged
Definition SDOM_EventType.hpp:86
EventType & setCaptures(bool captures)
Definition SDOM_EventType.cpp:209
static EventType KeyUp
Definition SDOM_EventType.hpp:69
static EventType Drag
Definition SDOM_EventType.hpp:94
EventType(const std::string &name, bool captures, bool bubbles, bool targetOnly, bool global)
Definition SDOM_EventType.hpp:124
bool getBubbles() const
Definition SDOM_EventType.cpp:193
static EventType Enabled
Definition SDOM_EventType.hpp:87
static EventType Removed
Definition SDOM_EventType.hpp:105
static EventType MouseWheel
Definition SDOM_EventType.hpp:59
static EventType FocusLost
Definition SDOM_EventType.hpp:76
static EventType None
Definition SDOM_EventType.hpp:52
static EventType MouseLeave
Definition SDOM_EventType.hpp:64
bool operator!=(const EventType &other) const
Definition SDOM_EventType.hpp:133
static EventType Resize
Definition SDOM_EventType.hpp:77
static EventType Hidden
Definition SDOM_EventType.hpp:92
static EventType OnInit
Definition SDOM_EventType.hpp:109
static EventType Move
Definition SDOM_EventType.hpp:78
static void registerEventType(const std::string &name, EventType *ptr)
Definition SDOM_EventType.hpp:136
static EventType Disabled
Definition SDOM_EventType.hpp:88
static EventType Hide
Definition SDOM_EventType.hpp:80
static EventType MouseButtonUp
Definition SDOM_EventType.hpp:57
static EventType Quit
Definition SDOM_EventType.hpp:54
static EventType OnUpdate
Definition SDOM_EventType.hpp:112
const std::string & getName() const
Definition SDOM_EventType.hpp:130
static EventType Added
Definition SDOM_EventType.hpp:104
bool getTargetOnly() const
Definition SDOM_EventType.cpp:197
static EventType Drop
Definition SDOM_EventType.hpp:96
EventType(const std::string &name)
Definition SDOM_EventType.hpp:120
static EventType OnPreRender
Definition SDOM_EventType.hpp:114
static EventType OnRender
Definition SDOM_EventType.hpp:113
EventType & setTargetOnly(bool targetOnly)
Definition SDOM_EventType.cpp:219
static EventType MouseMove
Definition SDOM_EventType.hpp:60
static EventType ClipboardCopy
Definition SDOM_EventType.hpp:98
static EventType Show
Definition SDOM_EventType.hpp:79
static EventType EnterFrame
Definition SDOM_EventType.hpp:55
static EventType SDL_Event
Definition SDOM_EventType.hpp:53
static EventType ValueChanged
Definition SDOM_EventType.hpp:84
static EventType Tick
Definition SDOM_EventType.hpp:72
static EventType KeyDown
Definition SDOM_EventType.hpp:68
static EventType User
Definition SDOM_EventType.hpp:118
static EventType LeaveFullscreen
Definition SDOM_EventType.hpp:82
static EventType Inactive
Definition SDOM_EventType.hpp:90
bool getGlobal() const
Definition SDOM_EventType.cpp:201
static void registerLua(sol::state_view lua)
Definition SDOM_EventType.cpp:113
Contains all core classes and utilities for the SDOM library.
Definition lua_BindHelpers.hpp:7