This class manages event listener subscriptions and event dispatching. More...
#include <CCEventDispatcher.h>
Classes | |
class | EventListenerVector |
The vector to store event listeners with scene graph based priority and fixed priority. More... | |
Public Member Functions | |
void | addEventListenerWithSceneGraphPriority (EventListener *listener, Node *node) |
Adds a event listener for a specified event with the priority of scene graph. More... | |
void | addEventListenerWithFixedPriority (EventListener *listener, int fixedPriority) |
Adds a event listener for a specified event with the fixed priority. More... | |
EventListenerCustom * | addCustomEventListener (const std::string &eventName, const std::function< void(EventCustom *)> &callback) |
Adds a Custom event listener. More... | |
var | addCustomEventListener ( var eventName, var callback) |
Adds a Custom event listener. More... | |
local | addCustomEventListener ( local eventName, local callback) |
Adds a Custom event listener. More... | |
void | removeEventListener (EventListener *listener) |
Remove a listener. More... | |
void | removeEventListenersForType (EventListener::Type listenerType) |
Removes all listeners with the same event listener type. More... | |
void | removeEventListenersForTarget (Node *target, bool recursive=false) |
Removes all listeners which are associated with the specified target. More... | |
void | removeCustomEventListeners (const std::string &customEventName) |
Removes all custom listeners with the same event name. More... | |
void | removeAllEventListeners () |
Removes all listeners. More... | |
void | pauseEventListenersForTarget (Node *target, bool recursive=false) |
Pauses all listeners which are associated the specified target. More... | |
var | pauseEventListenersForTarget ( var target, var false) |
Pauses all listeners which are associated the specified target. More... | |
local | pauseEventListenersForTarget ( local target, local false) |
Pauses all listeners which are associated the specified target. More... | |
void | resumeEventListenersForTarget (Node *target, bool recursive=false) |
Resumes all listeners which are associated the specified target. More... | |
void | setPriority (EventListener *listener, int fixedPriority) |
Sets listener's priority with fixed value. More... | |
void | setEnabled (bool isEnabled) |
Whether to enable dispatching events. More... | |
bool | isEnabled () const |
Checks whether dispatching events is enabled. More... | |
void | dispatchEvent (Event *event) |
Dispatches the event Also removes all EventListeners marked for deletion from the event dispatcher list. More... | |
void | dispatchCustomEvent (const std::string &eventName, void *optionalUserData=nullptr) |
Dispatches a Custom Event with a event name an optional user data. More... | |
var | dispatchCustomEvent ( var eventName, var nullptr) |
Dispatches a Custom Event with a event name an optional user data. More... | |
local | dispatchCustomEvent ( local eventName, local nullptr) |
Dispatches a Custom Event with a event name an optional user data. More... | |
EventDispatcher () | |
Constructor of EventDispatcher. More... | |
~EventDispatcher () | |
Destructor of EventDispatcher. More... | |
Public Member Functions inherited from Ref | |
void | retain () |
Retains the ownership. More... | |
void | release () |
Release the ownership immediately. More... | |
Ref * | autorelease () |
Release the ownership sometime soon automatically. More... | |
unsigned int | getReferenceCount () const |
Returns the Ref's current reference count. More... | |
virtual | ~Ref () |
Protected Types | |
enum | DirtyFlag { NONE = 0, FIXED_PRIORITY = 1 << 0, SCENE_GRAPH_PRIORITY = 1 << 1, ALL = FIXED_PRIORITY | SCENE_GRAPH_PRIORITY } |
Priority dirty flag. More... | |
Protected Member Functions | |
void | setDirtyForNode (Node *node) |
Sets the dirty flag for a node. More... | |
local | setDirtyForNode ( local node) |
Sets the dirty flag for a node. More... | |
void | addEventListener (EventListener *listener) |
Adds an event listener with item. More... | |
void | forceAddEventListener (EventListener *listener) |
Force adding an event listener. More... | |
EventListenerVector * | getListeners (const EventListener::ListenerID &listenerID) |
Gets event the listener list for the event listener type. More... | |
local | getListeners ( local listenerID) |
Gets event the listener list for the event listener type. More... | |
void | updateDirtyFlagForSceneGraph () |
Update dirty flag. More... | |
void | removeEventListenersForListenerID (const EventListener::ListenerID &listenerID) |
Removes all listeners with the same event listener ID. More... | |
var | removeEventListenersForListenerID ( var listenerID) |
Removes all listeners with the same event listener ID. More... | |
local | removeEventListenersForListenerID ( local listenerID) |
Removes all listeners with the same event listener ID. More... | |
void | sortEventListeners (const EventListener::ListenerID &listenerID) |
Sort event listener. More... | |
void | sortEventListenersOfSceneGraphPriority (const EventListener::ListenerID &listenerID) |
Sorts the listeners of specified type by scene graph priority. More... | |
local | sortEventListenersOfSceneGraphPriority ( local listenerID) |
Sorts the listeners of specified type by scene graph priority. More... | |
void | sortEventListenersOfFixedPriority (const EventListener::ListenerID &listenerID) |
Sorts the listeners of specified type by fixed priority. More... | |
void | updateListeners (Event *event) |
Updates all listeners 1) Removes all listener items that have been marked as 'removed' when dispatching event. More... | |
void | dispatchTouchEvent (EventTouch *event) |
Touch event needs to be processed different with other events since it needs support ALL_AT_ONCE and ONE_BY_NONE mode. More... | |
void | associateNodeAndEventListener (Node *node, EventListener *listener) |
Associates node with event listener. More... | |
var | associateNodeAndEventListener ( var node, var listener) |
Associates node with event listener. More... | |
local | associateNodeAndEventListener ( local node, local listener) |
Associates node with event listener. More... | |
void | dissociateNodeAndEventListener (Node *node, EventListener *listener) |
Dissociates node with event listener. More... | |
var | dissociateNodeAndEventListener ( var node, var listener) |
Dissociates node with event listener. More... | |
local | dissociateNodeAndEventListener ( local node, local listener) |
Dissociates node with event listener. More... | |
void | dispatchEventToListeners (EventListenerVector *listeners, const std::function< bool(EventListener *)> &onEvent) |
Dispatches event to listeners with a specified listener type. More... | |
void | setDirty (const EventListener::ListenerID &listenerID, DirtyFlag flag) |
Sets the dirty flag for a specified listener ID. More... | |
void | visitTarget (Node *node, bool isRootNode) |
Walks though scene graph to get the draw order for each node, it's called before sorting event listener with scene graph priority. More... | |
Protected Member Functions inherited from Ref | |
Ref () | |
Constructor. More... | |
Protected Attributes | |
std::unordered_map < EventListener::ListenerID, EventListenerVector * > | _listenerMap |
Listeners map. More... | |
std::unordered_map < EventListener::ListenerID, DirtyFlag > | _priorityDirtyFlagMap |
The map of dirty flag. More... | |
std::unordered_map< Node *, std::vector< EventListener * > * > | _nodeListenersMap |
The map of node and event listeners. More... | |
std::unordered_map< Node *, int > | _nodePriorityMap |
The map of node and its event priority. More... | |
std::unordered_map< float, std::vector< Node * > > | _globalZOrderNodeMap |
key: Global Z Order, value: Sorted Nodes More... | |
std::vector< EventListener * > | _toAddedListeners |
The listeners to be added after dispatching event. More... | |
var | _toAddedListeners |
The listeners to be added after dispatching event. More... | |
local | _toAddedListeners |
The listeners to be added after dispatching event. More... | |
std::set< Node * > | _dirtyNodes |
The nodes were associated with scene graph based priority listeners. More... | |
int | _inDispatch |
Whether the dispatcher is dispatching event. More... | |
var | _inDispatch |
Whether the dispatcher is dispatching event. More... | |
local | _inDispatch |
Whether the dispatcher is dispatching event. More... | |
bool | _isEnabled |
Whether to enable dispatching event. More... | |
int | _nodePriorityIndex |
std::set< std::string > | _internalCustomListenerIDs |
var | _internalCustomListenerIDs |
local | _internalCustomListenerIDs |
Protected Attributes inherited from Ref | |
unsigned int | _referenceCount |
count of references More... | |
Friends | |
class | Node |
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.
|
strongprotected |
|
strongprotected |
|
strongprotected |
EventDispatcher | ( | ) |
Constructor of EventDispatcher.
var EventDispatcher | ( | ) |
Constructor of EventDispatcher.
local EventDispatcher | ( | ) |
Constructor of EventDispatcher.
~EventDispatcher | ( | ) |
Destructor of EventDispatcher.
var ~EventDispatcher | ( | ) |
Destructor of EventDispatcher.
local ~EventDispatcher | ( | ) |
Destructor of EventDispatcher.
EventListenerCustom* addCustomEventListener |
( | const std::string & | eventName, |
const std::function< void(EventCustom *)> & | callback | ||
) |
Adds a Custom event listener.
It will use a fixed priority of 1.
var addCustomEventListener | ( | var | eventName, |
var | callback | ||
) |
Adds a Custom event listener.
It will use a fixed priority of 1.
local addCustomEventListener | ( | local | eventName, |
local | callback | ||
) |
Adds a Custom event listener.
It will use a fixed priority of 1.
|
protected |
Adds an event listener with item.
|
protected |
Adds an event listener with item.
|
protected |
Adds an event listener with item.
void addEventListenerWithFixedPriority |
( | EventListener * | listener, |
int | fixedPriority | ||
) |
Adds a event listener for a specified event with the fixed priority.
listener | The listener of a specified event. |
fixedPriority | The fixed priority of the listener. |
var addEventListenerWithFixedPriority |
( | var | listener, |
var | fixedPriority | ||
) |
Adds a event listener for a specified event with the fixed priority.
listener | The listener of a specified event. |
fixedPriority | The fixed priority of the listener. |
local addEventListenerWithFixedPriority |
( | local | listener, |
local | fixedPriority | ||
) |
Adds a event listener for a specified event with the fixed priority.
listener | The listener of a specified event. |
fixedPriority | The fixed priority of the listener. |
void addEventListenerWithSceneGraphPriority |
( | EventListener * | listener, |
Node * | node | ||
) |
Adds a event listener for a specified event with the priority of scene graph.
listener | The listener of a specified event. |
node | The priority of the listener is based on the draw order of this node. |
var addEventListenerWithSceneGraphPriority |
( | var | listener, |
var | node | ||
) |
Adds a event listener for a specified event with the priority of scene graph.
listener | The listener of a specified event. |
node | The priority of the listener is based on the draw order of this node. |
local addEventListenerWithSceneGraphPriority |
( | local | listener, |
local | node | ||
) |
Adds a event listener for a specified event with the priority of scene graph.
listener | The listener of a specified event. |
node | The priority of the listener is based on the draw order of this node. |
|
protected |
Associates node with event listener.
|
protected |
Associates node with event listener.
|
protected |
Associates node with event listener.
void dispatchCustomEvent | ( | const std::string & | eventName, |
void * | optionalUserData = nullptr |
||
) |
Dispatches a Custom Event with a event name an optional user data.
var dispatchCustomEvent | ( | var | eventName, |
var | optionalUserData = nullptr |
||
) |
Dispatches a Custom Event with a event name an optional user data.
local dispatchCustomEvent | ( | local | eventName, |
local | optionalUserData = nullptr |
||
) |
Dispatches a Custom Event with a event name an optional user data.
void dispatchEvent | ( | Event * | event) |
Dispatches the event Also removes all EventListeners marked for deletion from the event dispatcher list.
var dispatchEvent | ( | var | event) |
Dispatches the event Also removes all EventListeners marked for deletion from the event dispatcher list.
local dispatchEvent | ( | local | event) |
Dispatches the event Also removes all EventListeners marked for deletion from the event dispatcher list.
|
protected |
Dispatches event to listeners with a specified listener type.
|
protected |
Dispatches event to listeners with a specified listener type.
|
protected |
Dispatches event to listeners with a specified listener type.
|
protected |
Touch event needs to be processed different with other events since it needs support ALL_AT_ONCE and ONE_BY_NONE mode.
|
protected |
Touch event needs to be processed different with other events since it needs support ALL_AT_ONCE and ONE_BY_NONE mode.
|
protected |
Touch event needs to be processed different with other events since it needs support ALL_AT_ONCE and ONE_BY_NONE mode.
|
protected |
Dissociates node with event listener.
|
protected |
Dissociates node with event listener.
|
protected |
Dissociates node with event listener.
|
protected |
Force adding an event listener.
|
protected |
Force adding an event listener.
|
protected |
Force adding an event listener.
|
protected |
Gets event the listener list for the event listener type.
|
protected |
Gets event the listener list for the event listener type.
|
protected |
Gets event the listener list for the event listener type.
bool isEnabled | ( | ) | const |
Checks whether dispatching events is enabled.
var isEnabled | ( | ) |
Checks whether dispatching events is enabled.
local isEnabled | ( | ) |
Checks whether dispatching events is enabled.
void pauseEventListenersForTarget | ( | Node * | target, |
bool | recursive = false |
||
) |
Pauses all listeners which are associated the specified target.
var pauseEventListenersForTarget | ( | var | target, |
var | recursive = false |
||
) |
Pauses all listeners which are associated the specified target.
local pauseEventListenersForTarget | ( | local | target, |
local | recursive = false |
||
) |
Pauses all listeners which are associated the specified target.
void removeAllEventListeners | ( | ) |
Removes all listeners.
var removeAllEventListeners | ( | ) |
Removes all listeners.
local removeAllEventListeners | ( | ) |
Removes all listeners.
void removeCustomEventListeners | ( | const std::string & | customEventName) |
Removes all custom listeners with the same event name.
var removeCustomEventListeners | ( | var | customEventName) |
Removes all custom listeners with the same event name.
local removeCustomEventListeners | ( | local | customEventName) |
Removes all custom listeners with the same event name.
void removeEventListener | ( | EventListener * | listener) |
Remove a listener.
listener | The specified event listener which needs to be removed. |
var removeEventListener | ( | var | listener) |
Remove a listener.
listener | The specified event listener which needs to be removed. |
local removeEventListener | ( | local | listener) |
Remove a listener.
listener | The specified event listener which needs to be removed. |
|
protected |
Removes all listeners with the same event listener ID.
|
protected |
Removes all listeners with the same event listener ID.
|
protected |
Removes all listeners with the same event listener ID.
void removeEventListenersForTarget | ( | Node * | target, |
bool | recursive = false |
||
) |
Removes all listeners which are associated with the specified target.
var removeEventListenersForTarget | ( | var | target, |
var | recursive = false |
||
) |
Removes all listeners which are associated with the specified target.
local removeEventListenersForTarget | ( | local | target, |
local | recursive = false |
||
) |
Removes all listeners which are associated with the specified target.
void removeEventListenersForType | ( | EventListener::Type | listenerType) |
Removes all listeners with the same event listener type.
var removeEventListenersForType | ( | var | listenerType) |
Removes all listeners with the same event listener type.
local removeEventListenersForType | ( | local | listenerType) |
Removes all listeners with the same event listener type.
void resumeEventListenersForTarget | ( | Node * | target, |
bool | recursive = false |
||
) |
Resumes all listeners which are associated the specified target.
var resumeEventListenersForTarget | ( | var | target, |
var | recursive = false |
||
) |
Resumes all listeners which are associated the specified target.
local resumeEventListenersForTarget | ( | local | target, |
local | recursive = false |
||
) |
Resumes all listeners which are associated the specified target.
|
protected |
Sets the dirty flag for a specified listener ID.
|
protected |
Sets the dirty flag for a specified listener ID.
|
protected |
Sets the dirty flag for a specified listener ID.
|
protected |
Sets the dirty flag for a node.
|
protected |
Sets the dirty flag for a node.
|
protected |
Sets the dirty flag for a node.
void setEnabled | ( | bool | isEnabled) |
Whether to enable dispatching events.
var setEnabled | ( | var | isEnabled) |
Whether to enable dispatching events.
local setEnabled | ( | local | isEnabled) |
Whether to enable dispatching events.
void setPriority | ( | EventListener * | listener, |
int | fixedPriority | ||
) |
Sets listener's priority with fixed value.
var setPriority | ( | var | listener, |
var | fixedPriority | ||
) |
Sets listener's priority with fixed value.
local setPriority | ( | local | listener, |
local | fixedPriority | ||
) |
Sets listener's priority with fixed value.
|
protected |
Sort event listener.
|
protected |
Sort event listener.
|
protected |
Sort event listener.
|
protected |
Sorts the listeners of specified type by fixed priority.
|
protected |
Sorts the listeners of specified type by fixed priority.
|
protected |
Sorts the listeners of specified type by fixed priority.
|
protected |
Sorts the listeners of specified type by scene graph priority.
|
protected |
Sorts the listeners of specified type by scene graph priority.
|
protected |
Sorts the listeners of specified type by scene graph priority.
|
protected |
Update dirty flag.
|
protected |
Update dirty flag.
|
protected |
Update dirty flag.
|
protected |
Updates all listeners 1) Removes all listener items that have been marked as 'removed' when dispatching event.
2) Adds all listener items that have been marked as 'added' when dispatching event.
|
protected |
Updates all listeners 1) Removes all listener items that have been marked as 'removed' when dispatching event.
2) Adds all listener items that have been marked as 'added' when dispatching event.
|
protected |
Updates all listeners 1) Removes all listener items that have been marked as 'removed' when dispatching event.
2) Adds all listener items that have been marked as 'added' when dispatching event.
|
protected |
Walks though scene graph to get the draw order for each node, it's called before sorting event listener with scene graph priority.
|
protected |
Walks though scene graph to get the draw order for each node, it's called before sorting event listener with scene graph priority.
|
protected |
Walks though scene graph to get the draw order for each node, it's called before sorting event listener with scene graph priority.
|
friend |
|
protected |
The nodes were associated with scene graph based priority listeners.
|
protected |
The nodes were associated with scene graph based priority listeners.
|
protected |
The nodes were associated with scene graph based priority listeners.
|
protected |
key: Global Z Order, value: Sorted Nodes
|
protected |
key: Global Z Order, value: Sorted Nodes
|
protected |
key: Global Z Order, value: Sorted Nodes
|
protected |
Whether the dispatcher is dispatching event.
|
protected |
Whether the dispatcher is dispatching event.
|
protected |
Whether the dispatcher is dispatching event.
|
protected |
|
protected |
|
protected |
|
protected |
Whether to enable dispatching event.
|
protected |
Whether to enable dispatching event.
|
protected |
Whether to enable dispatching event.
|
protected |
Listeners map.
|
protected |
Listeners map.
|
protected |
Listeners map.
|
protected |
The map of node and event listeners.
|
protected |
The map of node and event listeners.
|
protected |
The map of node and event listeners.
|
protected |
|
protected |
|
protected |
|
protected |
The map of node and its event priority.
|
protected |
The map of node and its event priority.
|
protected |
The map of node and its event priority.
|
protected |
The map of dirty flag.
|
protected |
The map of dirty flag.
|
protected |
The map of dirty flag.
|
protected |
The listeners to be added after dispatching event.
|
protected |
The listeners to be added after dispatching event.
|
protected |
The listeners to be added after dispatching event.