SDOM - Simple SDL Document Object Model
A lightweight, extensible Document Object Model for SDL-based applications.
Loading...
Searching...
No Matches
SDOM_IDisplayObject.hpp
Go to the documentation of this file.
1/*** SDOM_IDisplayObject.hpp ****************************
2 * ___ ___ ___ __ __ ___ _ _ ___ _ _ _ _
3 * / __| \ / _ \| \/ | | \‍(_)____ __| |__ _ _ _ / _ \| |__ (_)___ __| |_ | |_ _ __ _ __
4 * \__ \ |) | (_) | |\/| | | |) | (_-< '_ \ / _` | || | (_) | '_ \| / -_) _| _|_| ' \| '_ \ '_ \
5 * |___/___/ \___/|_| |_|_|___/|_/__/ .__/_\__,_|\_, |\___/|_.__// \___\__|\__(_)_||_| .__/ .__/
6 * |___| |_| |__/ |__/ |_| |_|
7 *
8 * The SDOM_IDisplayObject class is the abstract base class for all visual and interactive
9 * elements in the SDOM framework. It defines the core interface and behavior for display
10 * objects, including rendering, event handling, parent-child hierarchy, anchoring, layout,
11 * and property management. IDisplayObject supports flexible positioning and sizing, z-ordering,
12 * visibility, and interactivity, as well as integration with the event system for robust user
13 * input and event-driven programming. Through its extensible design, it enables the creation of
14 * complex, nested GUI structures and serves as the foundation for all concrete display
15 * objects—such as panels, buttons, images, and labels—within SDOM-based applications.
16 *
17 *
18 * This software is provided 'as-is', without any express or implied
19 * warranty. In no event will the authors be held liable for any damages
20 * arising from the use of this software.
21 *
22 * Permission is granted to anyone to use this software for any purpose,
23 * including commercial applications, and to alter it and redistribute it
24 * freely, subject to the following restrictions:
25 *
26 * 1. The origin of this software must not be misrepresented; you must not
27 * claim that you wrote the original software. If you use this software
28 * in a product, an acknowledgment in the product documentation would be
29 * appreciated but is not required.
30 * 2. Altered source versions must be plainly marked as such, and must not be
31 * misrepresented as being the original software.
32 * 3. This notice may not be removed or altered from any source distribution.
33 *
34 * Released under the ZLIB License.
35 * Original Author: Jay Faries (warte67)
36 *
37 ******************/
38/*
39================================================================================
40SDOM::IDisplayObject Contract
41
42Intent:
43 - IDisplayObject is the abstract base class for all visual and interactive elements in SDOM.
44 - Defines the core interface and behavior for display objects, including rendering, event handling, parent-child hierarchy, anchoring, layout, and property management.
45 - Enables creation of complex, nested GUI structures and serves as the foundation for all concrete display objects (panels, buttons, images, labels, etc.).
46
47Requirements:
48 1. Rendering
49 - Must provide a method to render itself to a display surface.
50 - Supports z-ordering and visibility toggling.
51
52 2. Event Handling
53 - Must handle user input and system events.
54 - Supports event listener registration, removal, and event propagation (capture/bubble).
55
56 3. Hierarchy Management
57 - Supports parent-child relationships for nested GUI structures.
58 - Provides methods to add, remove, and query children and parent.
59 - Supports sorting and prioritizing children.
60
61 4. Layout and Anchoring
62 - Supports flexible positioning, sizing, and anchoring to edges.
63 - Provides accessors and mutators for coordinates, dimensions, and anchor points.
64
65 5. Property Management
66 - Supports dynamic property registration and introspection (via IDataObject).
67 - Properties are accessible for runtime modification and editor integration.
68
69 6. Interactivity
70 - Supports enabling/disabling, hiding/showing, and click/tab focus management.
71
72 7. Extensibility
73 - Designed for inheritance and composition.
74 - Allows derived classes to extend or override core behavior.
75
76 8. Type Identity and Verification
77 - Must expose a public static type name (e.g., TypeName) for each concrete display object.
78 - Must verify its type during construction (from InitStruct or Lua config) and report errors if mismatched.
79 - Enables safe, consistent creation and identification of display object types across the SDOM framework.
80
81Non-Requirements:
82 - Does not directly manage rendering resources (handled by other systems).
83 - Does not implement concrete rendering or event logic (must be provided by derived classes).
84 - Not responsible for serialization format (delegated to IDataObject).
85
86Summary:
87 IDisplayObject is a visual, interactive, and extensible interface for SDOM GUI elements, focused on:
88 - Rendering and event handling
89 - Hierarchical layout and anchoring
90 - Dynamic property management
91 - Interactivity and extensibility
92================================================================================
93*/
94
95
96#ifndef __SDOM_IDISPLAY_OBJECT_HPP__
97#define __SDOM_IDISPLAY_OBJECT_HPP__
98
99// #include <SDOM/SDOM.hpp>
101#include <iostream>
102
104
105#include <SDOM/SDOM.hpp>
106
107
108
109namespace SDOM
110{
111
112 class Event;
113 class EventType;
114 class EventTypeHash;
115 class Stage;
116
117/*
118## Garbage Collection / Orphan Retention
119
120Proposed approach: add an `OrphanRetentionPolicy` enum (or a smaller `retainOnOrphan` boolean for a quick
121win) on `IDisplayObject` and make the Factory's orphan collector respect each object's policy. This supports
122editor/templates that should not be destroyed immediately and gives a clear migration path to more
123sophisticated GC.
124
125Recommended enum (suggested values):
126- `OrphanRetentionPolicy::AutoDestroy` — object is eligible for destruction immediately when orphaned.
127 (fast, default for ephemeral runtime objects)
128- `OrphanRetentionPolicy::GracePeriod` — object is eligible only after a configurable grace period has
129 elapsed since it became orphaned; allows reparenting via DisplayHandle within the grace window.
130- `OrphanRetentionPolicy::RetainUntilManual` — object is never auto-destroyed; requires explicit Factory
131 or user code to destroy. (useful for editor templates and long-lived resources)
132- `OrphanRetentionPolicy::RetainWhenReferenced` — object is retained while any DisplayHandle or external
133 reference exists; destroyed only once all references are gone and policy conditions met. (optional
134 advanced mode)
135
136Minimal API hints:
137- in `IDisplayObject`: add `OrphanRetentionPolicy orphanPolicy = OrphanRetentionPolicy::GracePeriod;`
138 and `std::chrono::milliseconds orphanGrace{5000};`
139- convenience setters/getters: `setOrphanPolicy(...)`, `getOrphanPolicy()`, `setOrphanGrace(...)`
140- in the Factory: track an `optional<steady_clock::time_point> orphanedAt` per object and implement
141 `collectOrphans()` which checks policy+elapsed time and destroys accordingly.
142
143Notes & test ideas:
144- Reparent before grace expiry should clear `orphanedAt` and prevent destruction.
145- `RetainUntilManual` objects should be visible in `Factory::listOrphanedObjects()` and only removed by
146 explicit destroy.
147- Add unit tests for each policy (auto destroy, grace window reparenting, retained objects resisting
148 collection).
149
150*/
151
153 {
154 using SUPER = IDataObject;
155
156 public:
157 // --- Orphan Retention --- //
158 enum class OrphanRetentionPolicy : int
159 {
160 RetainUntilManual, // object is never auto-destroyed; requires explicit Factory or user code to destroy.
161 AutoDestroy, // object is eligible for destruction immediately when orphaned.
162 GracePeriod // allows reparenting via DisplayHandle within the grace window.
163 };
164 OrphanRetentionPolicy getOrphanRetentionPolicy() const { return orphanPolicy_; }
165 IDisplayObject& setOrphanRetentionPolicy(OrphanRetentionPolicy policy) { orphanPolicy_ = policy; return *this; }
166 std::chrono::milliseconds getOrphanGrace() const { return orphanGrace; }
167 IDisplayObject& setOrphanGrace(std::chrono::milliseconds grace) { orphanGrace = grace; return *this; }
168
169 private:
170 std::chrono::milliseconds orphanGrace{ORPHAN_GRACE_PERIOD};
171 std::chrono::steady_clock::time_point orphanedAt_ = std::chrono::steady_clock::now(); // Time when the object became orphaned
172 OrphanRetentionPolicy orphanPolicy_ = OrphanRetentionPolicy::RetainUntilManual; // Default policy
173
174
175 public:
176 // --- Comparison Operators (for Sol2/Lua) --- //
177 bool operator==(const IDisplayObject& other) const { return this == &other; }
178 bool operator<(const IDisplayObject& other) const { return this < &other; }
179 bool operator!=(const IDisplayObject& other) const { return !(*this == other); }
180 bool operator>(const IDisplayObject& other) const { return other < *this; }
181 bool operator<=(const IDisplayObject& other) const { return !(other < *this); }
182 bool operator>=(const IDisplayObject& other) const { return !(*this < other); }
183
184 static constexpr const char* TypeName = "IDisplayObject";
185
186 // --- Construction & Initialization --- //
187 struct InitStruct {
188 std::string name = TypeName;
189 std::string type = TypeName;
190 float x = 0.0f;
191 float y = 0.0f;
192 float width = 0.0f;
193 float height = 0.0f;
194 SDL_Color color = {255, 0, 255, 255};
195
196 SDL_Color foregroundColor = {255, 255, 255, 255}; // white
197 SDL_Color backgroundColor = {255, 255, 255, 128}; // transparent white
198 SDL_Color borderColor = {0, 0, 0, 128}; // transparent black
199 SDL_Color outlineColor = {0, 0, 0, 255}; // black
200 SDL_Color dropshadowColor = {0, 0, 0, 128}; // semi-transparent black
201
206 int z_order = 0;
207 int priority = 0;
208 bool isClickable = true;
209 bool isEnabled = true;
210 bool isHidden = false;
211 int tabPriority = 0;
212 bool tabEnabled = false;
213 };
214
215 friend class Factory;
216
217 protected:
218 IDisplayObject(const InitStruct& init);
219 IDisplayObject(const sol::table& config);
221
222 public:
223
224 virtual ~IDisplayObject();
225
226 // --- Lifecycle & Core Virtuals --- //
227 virtual bool onInit() override;
228 virtual void onQuit() override;
229 virtual void onUpdate(float fElapsedTime);
230 virtual void onEvent(const Event& event);
231 virtual void onRender() = 0;
232 virtual bool onUnitTest() { return true; }
233
234 // --- Dirty/State Management --- //
235 void cleanAll();
236 bool getDirty() const { return bIsDirty_; }
238 {
239 bIsDirty_ = true;
240 return *this;
241 }
243 {
244 bIsDirty_ = grime;
245 return *this;
246 }
247 bool isDirty() const { return bIsDirty_; }
248
249 // --- Debug/Utility --- //
250 void printTree(int depth = 0, bool isLast = true, const std::vector<bool>& hasMoreSiblings = {}) const;
251
252 // --- Event Handling --- //
253 void addEventListener(EventType& type, std::function<void(Event&)> listener, bool useCapture = false, int priority = 0);
254 void removeEventListener(EventType& type, std::function<void(Event&)> listener, bool useCapture = false);
255 void triggerEventListeners(Event& event, bool useCapture);
256 bool hasEventListeners(const EventType& type, bool useCapture) const;
257 void queue_event(const EventType& type, std::function<void(Event&)> init_payload);
258
259 // --- Hierarchy Management --- //
260 void addChild(DisplayHandle child, bool useWorld = false, int worldX = 0, int worldY = 0);
261 DisplayHandle getChild(std::string name) const;
262 bool removeChild(DisplayHandle child);
263 bool removeChild(const std::string& name);
264 const std::vector<DisplayHandle>& getChildren() const;
265 DisplayHandle getParent() const;
266 IDisplayObject& setParent(const DisplayHandle& parent);
267 bool hasChild(DisplayHandle child) const;
268
269 // Ancestor/Descendant helpers
270 bool isAncestorOf(DisplayHandle descendant) const;
271 bool isAncestorOf(const std::string& name) const;
272 bool isDescendantOf(DisplayHandle ancestor) const;
273 bool isDescendantOf(const std::string& name) const;
274 // Remove this object from its parent (convenience). Returns true if removed.
275 bool removeFromParent();
276 // Recursive descendant removal: search depth-first and remove first match. Returns true if removed.
277 bool removeDescendant(DisplayHandle descendant);
278 bool removeDescendant(const std::string& descendantName);
279
280 // --- Type & Property Access --- //
281 std::string getType() const { return type_; }
282 IDisplayObject& setType(const std::string& newType) { type_ = newType; return *this; }
283 Bounds getBounds() const { return { getLeft(), getTop(), getRight(), getBottom() }; }
284 IDisplayObject& setBounds(const Bounds& b) { setLeft(b.left); setTop(b.top); setRight(b.right); setBottom(b.bottom); return *this; } // **NEW**
285 SDL_Color getColor() const { return color_; }
286 IDisplayObject& setColor(const SDL_Color& color) { color_ = color; return *this; }
287
288 // --- Priority & Z-Order --- //
289 int getMaxPriority() const;
290 int getMinPriority() const;
291 int getPriority() const { return priority_; }
295 IDisplayObject& setPriority(int priority);
296 std::vector<int> getChildrenPriorities() const;
298 int getZOrder() const { return z_order_; }
299 IDisplayObject& setZOrder(int z_order) { z_order_ = z_order; return *this; }
300
301 // --- Focus & Interactivity --- //
302 void setKeyboardFocus();
303 bool isKeyboardFocused() const;
304 bool isMouseHovered() const;
305 bool isClickable() const { return isClickable_; }
306 IDisplayObject& setClickable(bool clickable) { isClickable_ = clickable; setDirty(); return *this; }
307 bool isEnabled() const { return isEnabled_; }
308 IDisplayObject& setEnabled(bool enabled) { isEnabled_ = enabled; setDirty(); return *this; }
309 bool isHidden() const { return isHidden_; }
310 IDisplayObject& setHidden(bool hidden) { isHidden_ = hidden; setDirty(); return *this; }
311 bool isVisible() const { return !isHidden_; }
312 IDisplayObject& setVisible(bool visible) { isHidden_ = !visible; setDirty(); return *this; }
313
314 // --- Tab Management --- //
315 int getTabPriority() const;
316 IDisplayObject& setTabPriority(int index);
317 bool isTabEnabled() const;
318 IDisplayObject& setTabEnabled(bool enabled);
319
320 // --- Geometry & Layout (In World Coordinates) --- //
321 int getX() const;
322 int getY() const;
323 int getWidth() const;
324 int getHeight() const;
325 IDisplayObject& setX(int p_x);
326 IDisplayObject& setY(int p_y);
327 IDisplayObject& setWidth(int width);
328 IDisplayObject& setHeight(int height);
329
330 // --- Edge Anchors --- //
335 void setAnchorTop(AnchorPoint ap);
336 void setAnchorLeft(AnchorPoint ap);
339
340 // --- Edge Positions (In World Coordinates)--- //
341 float getLeft() const;
342 float getRight() const;
343 float getTop() const;
344 float getBottom() const;
345 IDisplayObject& setLeft(float p_left);
346 IDisplayObject& setRight(float p_right);
347 IDisplayObject& setTop(float p_top);
348 IDisplayObject& setBottom(float p_bottom);
349
350 // --- Local Offset Accessors --- //
351 float getLocalX() const { return left_; }
352 float getLocalY() const { return top_; }
353 float getLocalWidth() const { return right_ - left_; }
354 float getLocalHeight() const { return bottom_ - top_; }
355
356 float getLocalLeft() const { return left_; }
357 float getLocalRight() const { return right_; }
358 float getLocalTop() const { return top_; }
359 float getLocalBottom() const { return bottom_; }
360
361 IDisplayObject& setLocalLeft(float value) { left_ = value; return *this; }
362 IDisplayObject& setLocalRight(float value) { right_ = value; return *this; }
363 IDisplayObject& setLocalTop(float value) { top_ = value; return *this; }
364 IDisplayObject& setLocalBottom(float value) { bottom_ = value; return *this; }
365
366 protected: // --- Member Variables --- //
367 // std::string name_; // defined in IDataObject
368 float left_ = 0.0f, top_ = 0.0f, right_ = 0.0f, bottom_ = 0.0f; // these are in terms of local not world coordinates
369 std::string type_; // Type identifier (e.g., "Button", "Panel", etc.)
370 bool bIsDirty_ = false;
371 SDL_Color color_ = {255, 255, 255, 255};
372
373 SDL_Color foregroundColor_ = {255, 255, 255, 255}; // white
374 SDL_Color backgroundColor_ = {255, 255, 255, 128}; // transparent
375 SDL_Color borderColor_ = {0, 0, 0, 128}; // transparent
376 SDL_Color outlineColor_ = {0, 0, 0, 255}; // black
377 SDL_Color dropshadowColor_ = {0, 0, 0, 128}; // semi-transparent black
378
383 int z_order_ = 0;
384 int priority_ = 0;
385 bool isClickable_ = false;
386 bool isEnabled_ = true;
387 bool isHidden_ = false;
388 int tabPriority_ = -1;
389 bool tabEnabled_ = false;
391 std::vector<DisplayHandle> children_;
392
393 // --- Event Listener Containers --- //
395 std::function<void(Event&)> listener;
398 };
399 std::unordered_map<EventType, std::vector<ListenerEntry>, EventTypeHash> captureEventListeners;
400 std::unordered_map<EventType, std::vector<ListenerEntry>, EventTypeHash> bubblingEventListeners;
401
402 // --- Internal/Utility --- //
403 IDisplayObject(const IDisplayObject& other) = delete;
404 void attachChild_(DisplayHandle child, DisplayHandle parent, bool useWorld = false, int worldX = 0, int worldY = 0);
405 void removeOrphan_(const DisplayHandle& orphan);
406
407 protected:
408
409 // --- Lua Registration --- //
410 virtual void _registerLuaBindings(const std::string& typeName, sol::state_view lua);
411 sol::usertype<IDisplayObject> objHandleType_;
412
413 }; // END: class IDisplayObject
414
415} // namespace SDOM
416
417// // include the LUA wrappers for IDisplayObject
418// #include "lua_IDisplayObject.hpp"
419
420#endif // __SDOM_IDISPLAY_OBJECT_HPP__
constexpr int ORPHAN_GRACE_PERIOD
Definition SDOM.hpp:78
Definition SDOM_DisplayHandle.hpp:24
Definition SDOM_EventType.hpp:49
Definition SDOM_Event.hpp:55
Definition SDOM_Factory.hpp:43
Definition SDOM_IDataObject.hpp:107
Definition SDOM_IDisplayObject.hpp:153
float getLocalWidth() const
Definition SDOM_IDisplayObject.hpp:353
bool operator>=(const IDisplayObject &other) const
Definition SDOM_IDisplayObject.hpp:182
std::vector< int > getChildrenPriorities() const
Definition SDOM_IDisplayObject.cpp:773
virtual void _registerLuaBindings(const std::string &typeName, sol::state_view lua)
Definition SDOM_IDisplayObject.cpp:1314
IDisplayObject & setPriority(int priority)
Definition SDOM_IDisplayObject.cpp:761
AnchorPoint getAnchorBottom() const
Definition SDOM_IDisplayObject.hpp:333
Bounds getBounds() const
Definition SDOM_IDisplayObject.hpp:283
void addEventListener(EventType &type, std::function< void(Event &)> listener, bool useCapture=false, int priority=0)
Definition SDOM_IDisplayObject.cpp:572
float getLocalY() const
Definition SDOM_IDisplayObject.hpp:352
IDisplayObject & setTop(float p_top)
Definition SDOM_IDisplayObject.cpp:1248
SDL_Color backgroundColor_
Definition SDOM_IDisplayObject.hpp:374
IDisplayObject & setColor(const SDL_Color &color)
Definition SDOM_IDisplayObject.hpp:286
void triggerEventListeners(Event &event, bool useCapture)
Definition SDOM_IDisplayObject.cpp:589
float bottom_
Definition SDOM_IDisplayObject.hpp:368
bool isHidden_
Definition SDOM_IDisplayObject.hpp:387
int getMinPriority() const
Definition SDOM_IDisplayObject.cpp:643
sol::usertype< IDisplayObject > objHandleType_
Definition SDOM_IDisplayObject.hpp:411
IDisplayObject & setParent(const DisplayHandle &parent)
Definition SDOM_IDisplayObject.cpp:443
IDisplayObject & setBounds(const Bounds &b)
Definition SDOM_IDisplayObject.hpp:284
bool removeDescendant(DisplayHandle descendant)
Definition SDOM_IDisplayObject.cpp:880
IDisplayObject & setToLowestPriority()
Definition SDOM_IDisplayObject.cpp:674
bool hasChild(DisplayHandle child) const
Definition SDOM_IDisplayObject.cpp:801
bool isAncestorOf(DisplayHandle descendant) const
Definition SDOM_IDisplayObject.cpp:808
int getHeight() const
Definition SDOM_IDisplayObject.cpp:974
int getMaxPriority() const
Definition SDOM_IDisplayObject.cpp:625
float getTop() const
Definition SDOM_IDisplayObject.cpp:1132
IDisplayObject & setY(int p_y)
Definition SDOM_IDisplayObject.cpp:1023
IDisplayObject & setType(const std::string &newType)
Definition SDOM_IDisplayObject.hpp:282
static constexpr const char * TypeName
Definition SDOM_IDisplayObject.hpp:184
float getLocalBottom() const
Definition SDOM_IDisplayObject.hpp:359
IDisplayObject & setTabEnabled(bool enabled)
Definition SDOM_IDisplayObject.cpp:931
void setKeyboardFocus()
Definition SDOM_IDisplayObject.cpp:951
bool getDirty() const
Definition SDOM_IDisplayObject.hpp:236
bool isClickable_
Definition SDOM_IDisplayObject.hpp:385
IDisplayObject & setLeft(float p_left)
Definition SDOM_IDisplayObject.cpp:1184
std::chrono::milliseconds getOrphanGrace() const
Definition SDOM_IDisplayObject.hpp:166
SDL_Color borderColor_
Definition SDOM_IDisplayObject.hpp:375
bool isDescendantOf(DisplayHandle ancestor) const
Definition SDOM_IDisplayObject.cpp:839
int getZOrder() const
Definition SDOM_IDisplayObject.hpp:298
float right_
Definition SDOM_IDisplayObject.hpp:368
void cleanAll()
Definition SDOM_IDisplayObject.cpp:516
float getLocalX() const
Definition SDOM_IDisplayObject.hpp:351
bool removeChild(DisplayHandle child)
Definition SDOM_IDisplayObject.cpp:397
bool isVisible() const
Definition SDOM_IDisplayObject.hpp:311
void setAnchorLeft(AnchorPoint ap)
Definition SDOM_IDisplayObject.cpp:1043
AnchorPoint anchorRight_
Definition SDOM_IDisplayObject.hpp:382
AnchorPoint anchorLeft_
Definition SDOM_IDisplayObject.hpp:380
float top_
Definition SDOM_IDisplayObject.hpp:368
bool operator==(const IDisplayObject &other) const
Definition SDOM_IDisplayObject.hpp:177
bool tabEnabled_
Definition SDOM_IDisplayObject.hpp:389
bool isEnabled_
Definition SDOM_IDisplayObject.hpp:386
std::unordered_map< EventType, std::vector< ListenerEntry >, EventTypeHash > captureEventListeners
Definition SDOM_IDisplayObject.hpp:399
std::unordered_map< EventType, std::vector< ListenerEntry >, EventTypeHash > bubblingEventListeners
Definition SDOM_IDisplayObject.hpp:400
int getY() const
Definition SDOM_IDisplayObject.cpp:1000
AnchorPoint getAnchorRight() const
Definition SDOM_IDisplayObject.hpp:334
IDisplayObject & moveToTop()
Definition SDOM_IDisplayObject.cpp:783
int getTabPriority() const
Definition SDOM_IDisplayObject.cpp:915
void setAnchorBottom(AnchorPoint ap)
Definition SDOM_IDisplayObject.cpp:1067
bool operator>(const IDisplayObject &other) const
Definition SDOM_IDisplayObject.hpp:180
float getLocalLeft() const
Definition SDOM_IDisplayObject.hpp:356
float getLocalHeight() const
Definition SDOM_IDisplayObject.hpp:354
IDisplayObject & setToHighestPriority()
Definition SDOM_IDisplayObject.cpp:661
float getLeft() const
Definition SDOM_IDisplayObject.cpp:1078
IDisplayObject & setZOrder(int z_order)
Definition SDOM_IDisplayObject.hpp:299
bool bIsDirty_
Definition SDOM_IDisplayObject.hpp:370
IDisplayObject & setLocalTop(float value)
Definition SDOM_IDisplayObject.hpp:363
IDisplayObject & setClickable(bool clickable)
Definition SDOM_IDisplayObject.hpp:306
IDisplayObject & setX(int p_x)
Definition SDOM_IDisplayObject.cpp:1006
IDisplayObject & setOrphanRetentionPolicy(OrphanRetentionPolicy policy)
Definition SDOM_IDisplayObject.hpp:165
void setAnchorRight(AnchorPoint ap)
Definition SDOM_IDisplayObject.cpp:1051
void printTree(int depth=0, bool isLast=true, const std::vector< bool > &hasMoreSiblings={}) const
Definition SDOM_IDisplayObject.cpp:528
std::string type_
Definition SDOM_IDisplayObject.hpp:369
SDL_Color foregroundColor_
Definition SDOM_IDisplayObject.hpp:373
IDisplayObject & setRight(float p_right)
Definition SDOM_IDisplayObject.cpp:1216
IDisplayObject & setDirty()
Definition SDOM_IDisplayObject.hpp:237
float getLocalRight() const
Definition SDOM_IDisplayObject.hpp:357
virtual bool onUnitTest()
Runs unit tests for this object.
Definition SDOM_IDisplayObject.hpp:232
void queue_event(const EventType &type, std::function< void(Event &)> init_payload)
Definition SDOM_IDisplayObject.cpp:612
IDisplayObject & setOrphanGrace(std::chrono::milliseconds grace)
Definition SDOM_IDisplayObject.hpp:167
IDisplayObject & setDirty(bool grime)
Definition SDOM_IDisplayObject.hpp:242
std::string getType() const
Definition SDOM_IDisplayObject.hpp:281
void removeOrphan_(const DisplayHandle &orphan)
Definition SDOM_IDisplayObject.cpp:304
bool operator!=(const IDisplayObject &other) const
Definition SDOM_IDisplayObject.hpp:179
OrphanRetentionPolicy
Definition SDOM_IDisplayObject.hpp:159
OrphanRetentionPolicy getOrphanRetentionPolicy() const
Definition SDOM_IDisplayObject.hpp:164
int priority_
Definition SDOM_IDisplayObject.hpp:384
void addChild(DisplayHandle child, bool useWorld=false, int worldX=0, int worldY=0)
Definition SDOM_IDisplayObject.cpp:357
virtual bool onInit() override
Definition SDOM_IDisplayObject.cpp:195
virtual void onRender()=0
virtual void onUpdate(float fElapsedTime)
Definition SDOM_IDisplayObject.cpp:207
bool removeFromParent()
Definition SDOM_IDisplayObject.cpp:865
const std::vector< DisplayHandle > & getChildren() const
Definition SDOM_IDisplayObject.cpp:440
bool operator<=(const IDisplayObject &other) const
Definition SDOM_IDisplayObject.hpp:181
AnchorPoint anchorTop_
Definition SDOM_IDisplayObject.hpp:379
bool isClickable() const
Definition SDOM_IDisplayObject.hpp:305
IDisplayObject & setEnabled(bool enabled)
Definition SDOM_IDisplayObject.hpp:308
IDisplayObject(const IDisplayObject &other)=delete
DisplayHandle parent_
Definition SDOM_IDisplayObject.hpp:390
AnchorPoint anchorBottom_
Definition SDOM_IDisplayObject.hpp:381
bool operator<(const IDisplayObject &other) const
Definition SDOM_IDisplayObject.hpp:178
IDisplayObject & setLocalRight(float value)
Definition SDOM_IDisplayObject.hpp:362
IDisplayObject & setHidden(bool hidden)
Definition SDOM_IDisplayObject.hpp:310
IDisplayObject & setLocalBottom(float value)
Definition SDOM_IDisplayObject.hpp:364
bool hasEventListeners(const EventType &type, bool useCapture) const
Definition SDOM_IDisplayObject.cpp:603
int getPriority() const
Definition SDOM_IDisplayObject.hpp:291
bool isKeyboardFocused() const
Definition SDOM_IDisplayObject.cpp:955
bool isEnabled() const
Definition SDOM_IDisplayObject.hpp:307
bool isTabEnabled() const
Definition SDOM_IDisplayObject.cpp:926
DisplayHandle getParent() const
Definition SDOM_IDisplayObject.cpp:441
void removeEventListener(EventType &type, std::function< void(Event &)> listener, bool useCapture=false)
Definition SDOM_IDisplayObject.cpp:554
std::vector< DisplayHandle > children_
Definition SDOM_IDisplayObject.hpp:391
SDL_Color color_
Definition SDOM_IDisplayObject.hpp:371
SDL_Color dropshadowColor_
Definition SDOM_IDisplayObject.hpp:377
int getWidth() const
Definition SDOM_IDisplayObject.cpp:967
DisplayHandle getChild(std::string name) const
Definition SDOM_IDisplayObject.cpp:376
IDisplayObject & setBottom(float p_bottom)
Definition SDOM_IDisplayObject.cpp:1280
virtual void onEvent(const Event &event)
Definition SDOM_IDisplayObject.cpp:213
SDL_Color outlineColor_
Definition SDOM_IDisplayObject.hpp:376
float getBottom() const
Definition SDOM_IDisplayObject.cpp:1157
AnchorPoint getAnchorLeft() const
Definition SDOM_IDisplayObject.hpp:332
int z_order_
Definition SDOM_IDisplayObject.hpp:383
IDisplayObject & setVisible(bool visible)
Definition SDOM_IDisplayObject.hpp:312
float getLocalTop() const
Definition SDOM_IDisplayObject.hpp:358
void setAnchorTop(AnchorPoint ap)
Definition SDOM_IDisplayObject.cpp:1059
IDisplayObject & setLocalLeft(float value)
Definition SDOM_IDisplayObject.hpp:361
int getX() const
Definition SDOM_IDisplayObject.cpp:994
IDisplayObject & sortChildrenByPriority()
Definition SDOM_IDisplayObject.cpp:687
int tabPriority_
Definition SDOM_IDisplayObject.hpp:388
IDisplayObject & setWidth(int width)
Definition SDOM_IDisplayObject.cpp:981
bool isDirty() const
Definition SDOM_IDisplayObject.hpp:247
void attachChild_(DisplayHandle child, DisplayHandle parent, bool useWorld=false, int worldX=0, int worldY=0)
Definition SDOM_IDisplayObject.cpp:219
bool isHidden() const
Definition SDOM_IDisplayObject.hpp:309
float getRight() const
Definition SDOM_IDisplayObject.cpp:1107
SDL_Color getColor() const
Definition SDOM_IDisplayObject.hpp:285
AnchorPoint getAnchorTop() const
Definition SDOM_IDisplayObject.hpp:331
IDisplayObject & setTabPriority(int index)
Definition SDOM_IDisplayObject.cpp:920
virtual ~IDisplayObject()
Definition SDOM_IDisplayObject.cpp:189
float left_
Definition SDOM_IDisplayObject.hpp:368
bool isMouseHovered() const
Definition SDOM_IDisplayObject.cpp:961
virtual void onQuit() override
Definition SDOM_IDisplayObject.cpp:202
IDisplayObject & setHeight(int height)
Definition SDOM_IDisplayObject.cpp:987
Contains all core classes and utilities for the SDOM library.
Definition lua_BindHelpers.hpp:7
AnchorPoint
Reference points for anchoring child edges to a parent.
Definition SDOM.hpp:137
@ TOP_LEFT
Top-left corner of the parent.
Represents a rectangle's position and size in 2D space.
Definition SDOM.hpp:307
float left
Left edge coordinate.
Definition SDOM.hpp:308
float top
Top edge coordinate.
Definition SDOM.hpp:309
float right
Right edge coordinate.
Definition SDOM.hpp:310
float bottom
Bottom edge coordinate.
Definition SDOM.hpp:311
Definition SDOM_EventTypeHash.hpp:49
Definition SDOM_IDisplayObject.hpp:187
SDL_Color foregroundColor
Definition SDOM_IDisplayObject.hpp:196
SDL_Color dropshadowColor
Definition SDOM_IDisplayObject.hpp:200
std::string type
Definition SDOM_IDisplayObject.hpp:189
AnchorPoint anchorLeft
Definition SDOM_IDisplayObject.hpp:203
float height
Definition SDOM_IDisplayObject.hpp:193
bool tabEnabled
Definition SDOM_IDisplayObject.hpp:212
std::string name
Definition SDOM_IDisplayObject.hpp:188
AnchorPoint anchorBottom
Definition SDOM_IDisplayObject.hpp:204
AnchorPoint anchorTop
Definition SDOM_IDisplayObject.hpp:202
SDL_Color backgroundColor
Definition SDOM_IDisplayObject.hpp:197
float width
Definition SDOM_IDisplayObject.hpp:192
int z_order
Definition SDOM_IDisplayObject.hpp:206
SDL_Color color
Definition SDOM_IDisplayObject.hpp:194
float x
Definition SDOM_IDisplayObject.hpp:190
int priority
Definition SDOM_IDisplayObject.hpp:207
SDL_Color outlineColor
Definition SDOM_IDisplayObject.hpp:199
float y
Definition SDOM_IDisplayObject.hpp:191
int tabPriority
Definition SDOM_IDisplayObject.hpp:211
bool isClickable
Definition SDOM_IDisplayObject.hpp:208
bool isEnabled
Definition SDOM_IDisplayObject.hpp:209
SDL_Color borderColor
Definition SDOM_IDisplayObject.hpp:198
AnchorPoint anchorRight
Definition SDOM_IDisplayObject.hpp:205
bool isHidden
Definition SDOM_IDisplayObject.hpp:210
Definition SDOM_IDisplayObject.hpp:394
EventType eventType
Definition SDOM_IDisplayObject.hpp:397
std::function< void(Event &)> listener
Definition SDOM_IDisplayObject.hpp:395
int priority
Definition SDOM_IDisplayObject.hpp:396