cocos2d-x  3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
EventListener Class Referenceabstract

The base class of event listener. More...

#include <CCEventListener.h>

Inheritance diagram for EventListener:
Ref EventListenerAcceleration EventListenerController EventListenerCustom EventListenerFocus EventListenerKeyboard EventListenerMouse EventListenerTouchAllAtOnce EventListenerTouchOneByOne

Public Types

enum  Type {
  UNKNOWN, TOUCH_ONE_BY_ONE, TOUCH_ALL_AT_ONCE, KEYBOARD,
  MOUSE, ACCELERATION, FOCUS, GAME_CONTROLLER,
  CUSTOM
}
 Type Event type. More...
 
typedef std::string ListenerID

Public Member Functions

bool init (Type t, const ListenerID &listenerID, const std::function< void(Event *)> &callback)
 Initializes event with type and callback function. More...
 
virtual ~EventListener ()
 Destructor. More...
 
virtual bool checkAvailable ()=0
 Checks whether the listener is available. More...
 
virtual EventListenerclone ()=0
 Clones the listener, its subclasses have to override this method. More...
 
void setEnabled (bool enabled)
 Enables or disables the listener. More...
 
local setEnabled ( local enabled)
 Enables or disables the listener. More...
 
bool isEnabled () const
 Checks whether the listener is enabled. More...
 
local isEnabled ()
 Checks whether the listener is enabled. More...
 
- Public Member Functions inherited from Ref
void retain ()
 Retains the ownership. More...
 
void release ()
 Releases the ownership immediately. More...
 
Refautorelease ()
 Releases the ownership sometime soon automatically. More...
 
unsigned int getReferenceCount () const
 Returns the Ref's current reference count. More...
 
virtual ~Ref ()
 Destructor. More...
 

Public Attributes

CC_CONSTRUCTOR_ACCESS __pad0__: EventListener()
var __pad0__: EventListener()
local __pad0__: EventListener()

Protected Member Functions

void setPaused (bool paused)
 Sets paused state for the listener The paused state is only used for scene graph priority listeners. More...
 
bool isPaused () const
 Checks whether the listener is paused. More...
 
void setRegistered (bool registered)
 Marks the listener was registered by EventDispatcher. More...
 
var setRegistered ( var registered)
 Marks the listener was registered by EventDispatcher. More...
 
local setRegistered ( local registered)
 Marks the listener was registered by EventDispatcher. More...
 
bool isRegistered () const
 Checks whether the listener was registered by EventDispatcher. More...
 
Type getType () const
 Gets the type of this listener. More...
 
const ListenerIDgetListenerID () const
 Gets the listener ID of this listener When event is being dispatched, listener ID is used as key for searching listeners according to event type. More...
 
local getListenerID ()
 Gets the listener ID of this listener When event is being dispatched, listener ID is used as key for searching listeners according to event type. More...
 
void setFixedPriority (int fixedPriority)
 Sets the fixed priority for this listener. More...
 
int getFixedPriority () const
 Gets the fixed priority of this listener. More...
 
void setAssociatedNode (Node *node)
 Sets the node associated with this listener. More...
 
NodegetAssociatedNode () const
 Gets the node associated with this listener. More...
 
- Protected Member Functions inherited from Ref
 Ref ()
 Constructor. More...
 
 Ref ()
 Constructor. More...
 

Protected Attributes

std::function< void(Event *)> _onEvent
Type _type
 Event callback function. More...
 
var _type
 Event callback function. More...
 
local _type
 Event callback function. More...
 
ListenerID _listenerID
 Event listener type. More...
 
var _listenerID
 Event listener type. More...
 
local _listenerID
 Event listener type. More...
 
bool _isRegistered
 Event listener ID. More...
 
var _isRegistered
 Event listener ID. More...
 
local _isRegistered
 Event listener ID. More...
 
int _fixedPriority
 Whether the listener has been added to dispatcher. More...
 
var _fixedPriority
 Whether the listener has been added to dispatcher. More...
 
local _fixedPriority
 Whether the listener has been added to dispatcher. More...
 
Node_node
var _node
local _node
bool _paused
var _paused
local _paused
bool _isEnabled
var _isEnabled
local _isEnabled
- Protected Attributes inherited from Ref
unsigned int _referenceCount
 count of references More...
 
local _referenceCount
 count of references More...
 

Friends

class EventDispatcher

Detailed Description

The base class of event listener.

If you need custom listener which with different callback, you need to inherit this class. For instance, you could refer to EventListenerAcceleration, EventListenerKeyboard, EventListenerTouchOneByOne, EventListenerCustom.

Member Typedef Documentation

typedef std::string ListenerID
local ListenerID

Constructor & Destructor Documentation

virtual ~EventListener ( )
virtual

Destructor.

local ~EventListener ( )
virtual

Destructor.

Member Function Documentation

virtual bool checkAvailable ( )
pure virtual
var checkAvailable ( )
pure virtual
local checkAvailable ( )
pure virtual
Node* getAssociatedNode ( ) const
inlineprotected

Gets the node associated with this listener.

Returns
nullptr if it's a fixed priority listener, otherwise return non-nullptr
var getAssociatedNode ( )
inlineprotected

Gets the node associated with this listener.

Returns
nullptr if it's a fixed priority listener, otherwise return non-nullptr
local getAssociatedNode ( )
inlineprotected

Gets the node associated with this listener.

Returns
nullptr if it's a fixed priority listener, otherwise return non-nullptr
int getFixedPriority ( ) const
inlineprotected

Gets the fixed priority of this listener.

Returns
0 if it's a scene graph priority listener, non-zero for fixed priority listener
var getFixedPriority ( )
inlineprotected

Gets the fixed priority of this listener.

Returns
0 if it's a scene graph priority listener, non-zero for fixed priority listener
local getFixedPriority ( )
inlineprotected

Gets the fixed priority of this listener.

Returns
0 if it's a scene graph priority listener, non-zero for fixed priority listener
const ListenerID& getListenerID ( ) const
inlineprotected

Gets the listener ID of this listener When event is being dispatched, listener ID is used as key for searching listeners according to event type.

var getListenerID ( )
inlineprotected

Gets the listener ID of this listener When event is being dispatched, listener ID is used as key for searching listeners according to event type.

local getListenerID ( )
inlineprotected

Gets the listener ID of this listener When event is being dispatched, listener ID is used as key for searching listeners according to event type.

Type getType ( ) const
inlineprotected

Gets the type of this listener.

Note
It's different from EventType, e.g. TouchEvent has two kinds of event listeners - EventListenerOneByOne, EventListenerAllAtOnce
var getType ( )
inlineprotected

Gets the type of this listener.

Note
It's different from EventType, e.g. TouchEvent has two kinds of event listeners - EventListenerOneByOne, EventListenerAllAtOnce
local getType ( )
inlineprotected

Gets the type of this listener.

Note
It's different from EventType, e.g. TouchEvent has two kinds of event listeners - EventListenerOneByOne, EventListenerAllAtOnce
bool init ( Type  t,
const ListenerID listenerID,
const std::function< void(Event *)> &  callback 
)

Initializes event with type and callback function.

local init ( local  t,
local  listenerID,
local  callback 
)

Initializes event with type and callback function.

bool isEnabled ( ) const
inline

Checks whether the listener is enabled.

Returns
True if the listenrt is enabled.
var isEnabled ( )
inline

Checks whether the listener is enabled.

Returns
True if the listenrt is enabled.
local isEnabled ( )
inline

Checks whether the listener is enabled.

Returns
True if the listenrt is enabled.
bool isPaused ( ) const
inlineprotected

Checks whether the listener is paused.

var isPaused ( )
inlineprotected

Checks whether the listener is paused.

local isPaused ( )
inlineprotected

Checks whether the listener is paused.

bool isRegistered ( ) const
inlineprotected

Checks whether the listener was registered by EventDispatcher.

var isRegistered ( )
inlineprotected

Checks whether the listener was registered by EventDispatcher.

local isRegistered ( )
inlineprotected

Checks whether the listener was registered by EventDispatcher.

void setAssociatedNode ( Node node)
inlineprotected

Sets the node associated with this listener.

var setAssociatedNode ( var  node)
inlineprotected

Sets the node associated with this listener.

local setAssociatedNode ( local  node)
inlineprotected

Sets the node associated with this listener.

void setEnabled ( bool  enabled)
inline

Enables or disables the listener.

Note
Only listeners with enabled state will be able to receive events. When an listener was initialized, it's enabled by default. An event listener can receive events when it is enabled and is not paused. paused state is always false when it is a fixed priority listener.
Parameters
enabledTrue if enables the listener.
var setEnabled ( var  enabled)
inline

Enables or disables the listener.

Note
Only listeners with enabled state will be able to receive events. When an listener was initialized, it's enabled by default. An event listener can receive events when it is enabled and is not paused. paused state is always false when it is a fixed priority listener.
Parameters
enabledTrue if enables the listener.
local setEnabled ( local  enabled)
inline

Enables or disables the listener.

Note
Only listeners with enabled state will be able to receive events. When an listener was initialized, it's enabled by default. An event listener can receive events when it is enabled and is not paused. paused state is always false when it is a fixed priority listener.
Parameters
enabledTrue if enables the listener.
void setFixedPriority ( int  fixedPriority)
inlineprotected

Sets the fixed priority for this listener.

Note
This method is only used for fixed priority listeners, it needs to access a non-zero value. 0 is reserved for scene graph priority listeners
var setFixedPriority ( var  fixedPriority)
inlineprotected

Sets the fixed priority for this listener.

Note
This method is only used for fixed priority listeners, it needs to access a non-zero value. 0 is reserved for scene graph priority listeners
local setFixedPriority ( local  fixedPriority)
inlineprotected

Sets the fixed priority for this listener.

Note
This method is only used for fixed priority listeners, it needs to access a non-zero value. 0 is reserved for scene graph priority listeners
void setPaused ( bool  paused)
inlineprotected

Sets paused state for the listener The paused state is only used for scene graph priority listeners.

EventDispatcher::resumeAllEventListenersForTarget(node) will set the paused state to true, while EventDispatcher::pauseAllEventListenersForTarget(node) will set it to false.

Note
1) Fixed priority listeners will never get paused. If a fixed priority doesn't want to receive events, call setEnabled(false) instead. 2) In Node's onEnter and onExit, the paused state of the listeners which associated with that node will be automatically updated.
var setPaused ( var  paused)
inlineprotected

Sets paused state for the listener The paused state is only used for scene graph priority listeners.

EventDispatcher::resumeAllEventListenersForTarget(node) will set the paused state to true, while EventDispatcher::pauseAllEventListenersForTarget(node) will set it to false.

Note
1) Fixed priority listeners will never get paused. If a fixed priority doesn't want to receive events, call setEnabled(false) instead. 2) In Node's onEnter and onExit, the paused state of the listeners which associated with that node will be automatically updated.
local setPaused ( local  paused)
inlineprotected

Sets paused state for the listener The paused state is only used for scene graph priority listeners.

EventDispatcher::resumeAllEventListenersForTarget(node) will set the paused state to true, while EventDispatcher::pauseAllEventListenersForTarget(node) will set it to false.

Note
1) Fixed priority listeners will never get paused. If a fixed priority doesn't want to receive events, call setEnabled(false) instead. 2) In Node's onEnter and onExit, the paused state of the listeners which associated with that node will be automatically updated.
void setRegistered ( bool  registered)
inlineprotected

Marks the listener was registered by EventDispatcher.

var setRegistered ( var  registered)
inlineprotected

Marks the listener was registered by EventDispatcher.

local setRegistered ( local  registered)
inlineprotected

Marks the listener was registered by EventDispatcher.

Friends And Related Function Documentation

friend class EventDispatcher
friend
var EventDispatcher
friend
local EventDispatcher
friend

Member Data Documentation

var __pad0__
local __pad0__
int _fixedPriority
protected

Whether the listener has been added to dispatcher.

var _fixedPriority
protected

Whether the listener has been added to dispatcher.

local _fixedPriority
protected

Whether the listener has been added to dispatcher.

bool _isEnabled
protected
var _isEnabled
protected
local _isEnabled
protected
bool _isRegistered
protected

Event listener ID.

var _isRegistered
protected

Event listener ID.

local _isRegistered
protected

Event listener ID.

ListenerID _listenerID
protected

Event listener type.

var _listenerID
protected

Event listener type.

local _listenerID
protected

Event listener type.

Node* _node
protected
var _node
protected
local _node
protected
std::function<void(Event*)>
_onEvent
protected
bool _paused
protected
var _paused
protected
local _paused
protected
Type _type
protected

Event callback function.

var _type
protected

Event callback function.

local _type
protected

Event callback function.


The documentation for this class was generated from the following file: