This class manages event listener subscriptions and event dispatching.
More...
#include <EventDispatcher.h>
Inherits Object.
|
void | addEventListenerWithSceneGraphPriority (EventListener *listener, Node *node) |
| Adds a event listener for a specified event with the priority of scene graph.
|
|
void | addEventListenerWithFixedPriority (EventListener *listener, int fixedPriority) |
| Adds a event listener for a specified event with the fixed priority.
|
|
EventListenerCustom * | addCustomEventListener (std::string_view eventName, const std::function< void(EventCustom *)> &callback) |
| Adds a Custom event listener.
|
|
void | removeEventListener (EventListener *listener) |
| Remove a listener.
|
|
void | removeEventListenersForType (EventListener::Type listenerType) |
| Removes all listeners with the same event listener type.
|
|
void | removeEventListenersForTarget (Node *target, bool recursive=false) |
| Removes all listeners which are associated with the specified target.
|
|
void | removeCustomEventListeners (std::string_view customEventName) |
| Removes all custom listeners with the same event name.
|
|
void | removeAllEventListeners () |
| Removes all listeners.
|
|
void | pauseEventListenersForTarget (Node *target, bool recursive=false) |
| Pauses all listeners which are associated the specified target.
|
|
void | resumeEventListenersForTarget (Node *target, bool recursive=false) |
| Resumes all listeners which are associated the specified target.
|
|
void | setPriority (EventListener *listener, int fixedPriority) |
| Sets listener's priority with fixed value.
|
|
void | setEnabled (bool isEnabled) |
| Whether to enable dispatching events.
|
|
bool | isEnabled () const |
| Checks whether dispatching events is enabled.
|
|
void | dispatchEvent (Event *event, bool forced=false) |
| Dispatches the event.
|
|
void | dispatchCustomEvent (std::string_view eventName, void *optionalUserData=nullptr, bool forced=false) |
| Dispatches a Custom Event with a event name an optional user data.
|
|
bool | hasEventListener (std::string_view listenerID) const |
| Query whether the specified event listener id has been added.
|
|
| EventDispatcher () |
| Constructor of EventDispatcher.
|
|
| ~EventDispatcher () |
| Destructor of EventDispatcher.
|
|
void | retain () |
| Retains the ownership.
|
|
void | release () |
| Releases the ownership immediately.
|
|
Object * | autorelease () |
| Releases the ownership sometime soon automatically.
|
|
unsigned int | getReferenceCount () const |
| Returns the Object's current reference count.
|
|
virtual | ~Object () |
| Destructor.
|
|
|
unsigned int | _ID |
| object id, ScriptSupport need public _ID
|
|
int | _luaID |
| Lua reference id.
|
|
This class manages event listener subscriptions and event dispatching.
The EventListener list is managed in such a way that event listeners can be added and removed even from within an EventListener, while events are being dispatched. @js NA
◆ addEventListenerWithSceneGraphPriority()
void addEventListenerWithSceneGraphPriority |
( |
EventListener * | listener, |
|
|
Node * | node ) |
Adds a event listener for a specified event with the priority of scene graph.
- Parameters
-
listener | The listener of a specified event. |
node | The priority of the listener is based on the draw order of this node. |
- Note
- The priority of scene graph will be fixed value 0. So the order of listener item in the vector will be ' <0, scene graph (0 priority), >0'.
◆ addEventListenerWithFixedPriority()
void addEventListenerWithFixedPriority |
( |
EventListener * | listener, |
|
|
int | fixedPriority ) |
Adds a event listener for a specified event with the fixed priority.
- Parameters
-
listener | The listener of a specified event. |
fixedPriority | The fixed priority of the listener. |
- Note
- A lower priority will be called before the ones that have a higher value. 0 priority is forbidden for fixed priority since it's used for scene graph based priority.
◆ addCustomEventListener()
Adds a Custom event listener.
It will use a fixed priority of 1.
- Parameters
-
eventName | A given name of the event. |
callback | A given callback method that associated the event name. |
- Returns
- the generated event. Needed in order to remove the event from the dispatcher
◆ removeEventListener()
Remove a listener.
- Parameters
-
listener | The specified event listener which needs to be removed. |
◆ removeEventListenersForType()
Removes all listeners with the same event listener type.
- Parameters
-
listenerType | A given event listener type which needs to be removed. |
◆ removeEventListenersForTarget()
void removeEventListenersForTarget |
( |
Node * | target, |
|
|
bool | recursive = false ) |
Removes all listeners which are associated with the specified target.
- Parameters
-
target | A given target node. |
recursive | True if remove recursively, the default value is false. |
◆ removeCustomEventListeners()
void removeCustomEventListeners |
( |
std::string_view | customEventName | ) |
|
Removes all custom listeners with the same event name.
- Parameters
-
customEventName | A given event listener name which needs to be removed. |
◆ pauseEventListenersForTarget()
void pauseEventListenersForTarget |
( |
Node * | target, |
|
|
bool | recursive = false ) |
Pauses all listeners which are associated the specified target.
- Parameters
-
target | A given target node. |
recursive | True if pause recursively, the default value is false. |
◆ resumeEventListenersForTarget()
void resumeEventListenersForTarget |
( |
Node * | target, |
|
|
bool | recursive = false ) |
Resumes all listeners which are associated the specified target.
- Parameters
-
target | A given target node. |
recursive | True if resume recursively, the default value is false. |
◆ setPriority()
Sets listener's priority with fixed value.
- Parameters
-
listener | A given listener. |
fixedPriority | The fixed priority value. |
◆ setEnabled()
void setEnabled |
( |
bool | isEnabled | ) |
|
Whether to enable dispatching events.
- Parameters
-
isEnabled | True if enable dispatching events. |
◆ isEnabled()
Checks whether dispatching events is enabled.
- Returns
- True if dispatching events is enabled.
◆ dispatchEvent()
void dispatchEvent |
( |
Event * | event, |
|
|
bool | forced = false ) |
Dispatches the event.
Also removes all EventListeners marked for deletion from the event dispatcher list.
- Parameters
-
event | The event needs to be dispatched. |
forced | If the event should be sent out regardless of enabled state |
◆ dispatchCustomEvent()
void dispatchCustomEvent |
( |
std::string_view | eventName, |
|
|
void * | optionalUserData = nullptr, |
|
|
bool | forced = false ) |
Dispatches a Custom Event with a event name an optional user data.
- Parameters
-
eventName | The name of the event which needs to be dispatched. |
optionalUserData | The optional user data, it's a void*, the default value is nullptr. |
forced | If the event should be sent out regardless of enabled state |
◆ hasEventListener()
bool hasEventListener |
( |
std::string_view | listenerID | ) |
const |
Query whether the specified event listener id has been added.
- Parameters
-
listenerID | The listenerID of the event listener id. |
- Returns
- True if dispatching events is exist
The documentation for this class was generated from the following file: