SDOM - Simple SDL Document Object Model
A lightweight, extensible Document Object Model for SDL-based applications.
Loading...
Searching...
No Matches
SDOM_EventManager.hpp
Go to the documentation of this file.
1/*** SDOM_EventManager.hpp ****************************
2 * ___ ___ ___ __ __ ___ _ __ __ _
3 * / __| \ / _ \| \/ | | __|_ _____ _ _| |_| \/ |__ _ _ _ __ _ __ _ ___ _ _ | |_ _ __ _ __
4 * \__ \ |) | (_) | |\/| | | _|\ V / -_) ' \ _| |\/| / _` | ' \/ _` / _` / -_) '_|| ' \| '_ \ '_ \
5 * |___/___/ \___/|_| |_|_|___|\_/\___|_||_\__|_| |_\__,_|_||_\__,_\__, \___|_|(_)_||_| .__/ .__/
6 * |___| |___/ |_| |_|
7 *
8 * The SDOM_EventManager class is responsible for managing the event queue and dispatching
9 * events throughout the SDOM display object hierarchy. It provides methods for queuing,
10 * translating, and dispatching both SDOM and SDL events, ensuring that user input and
11 * system events are delivered efficiently and in the correct order. The EventManager
12 * supports event propagation to individual nodes, all nodes on a stage, or all event
13 * listeners, and includes utility functions for hit-testing and mouse interaction. By
14 * centralizing event management, the EventManager enables robust, flexible, and scalable
15 * event-driven programming 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#pragma once
39#ifndef __SDOM_EVENT_MANAGER_HPP__
40#define __SDOM_EVENT_MANAGER_HPP__
41
42// #include <SDOM/SDOM.hpp>
43
44// #include <queue>
45// #include <memory>
46// #include "SDOM/SDOM_Event.hpp"
47// #include "SDOM/SDOM_IDisplayObject.hpp"
48
49namespace SDOM
50{
51 class IDisplayObject;
52 class Event;
53 class EventType;
54
56 {
57 public:
58 EventManager() = default;
59 ~EventManager() = default;
60
61 // Add an event to the queue
62 void addEvent(std::unique_ptr<Event> event);
63
64 // Queue an SDL_Event as an SDOM::Event
65 void Queue_SDL_Event(SDL_Event& sdlEvent);
66
67 // Dispatch all queued events
69
70 // Dispatch a single event to the target node
71 void dispatchEvent(std::unique_ptr<Event> event, DisplayHandle rootNode);
72 // Dispatch an event to all nodes on the same stage
73 void dispatchEventToAllNodesOnStage(std::unique_ptr<Event> event);
74
75 // Dispatch an event to all event listeners on the same stage
76 void dispatchEventToAllEventListenersOnStage(std::unique_ptr<Event> event);
77
78 // Returns true if there are any listeners (or node-default handlers)
79 // registered that would receive events of the given type on the current stage.
80 bool hasListeners(const EventType& type) const;
81
82 // Utility methods
83 bool isMouseWithinBounds(IDisplayObject& target) const;
85
86 int getEventQueueSize() const { return static_cast<int>(eventQueue.size()); }
87
88 // Event popEvent() { if (!eventQueue.empty()) return std::move(*eventQueue.front()); return Event(); }
89
90 private:
91 std::queue<std::unique_ptr<Event>> eventQueue; // Queue for storing events
92 };
93
94} // namespace SDOM
95
96#endif // __EVENT_MANAGER_HPP__
Definition SDOM_DisplayHandle.hpp:24
Definition SDOM_EventManager.hpp:56
void dispatchEventToAllEventListenersOnStage(std::unique_ptr< Event > event)
Definition SDOM_EventManager.cpp:238
EventManager()=default
bool isMouseWithinBounds(IDisplayObject &target) const
Definition SDOM_EventManager.cpp:256
void DispatchQueuedEvents()
Definition SDOM_EventManager.cpp:62
~EventManager()=default
void Queue_SDL_Event(SDL_Event &sdlEvent)
Definition SDOM_EventManager.cpp:333
bool hasListeners(const EventType &type) const
void dispatchEventToAllNodesOnStage(std::unique_ptr< Event > event)
Definition SDOM_EventManager.cpp:215
int getEventQueueSize() const
Definition SDOM_EventManager.hpp:86
void addEvent(std::unique_ptr< Event > event)
Definition SDOM_EventManager.cpp:56
void dispatchEvent(std::unique_ptr< Event > event, DisplayHandle rootNode)
Definition SDOM_EventManager.cpp:74
DisplayHandle findTopObjectUnderMouse(DisplayHandle rootNode, DisplayHandle excludeNode=DisplayHandle()) const
Definition SDOM_EventManager.cpp:276
Definition SDOM_EventType.hpp:49
Definition SDOM_IDisplayObject.hpp:153
Contains all core classes and utilities for the SDOM library.
Definition lua_BindHelpers.hpp:7