mirror of https://github.com/axmolengine/axmol.git
issue #4557: Updates comments for EventListener::setEnabled/setPaused.
Also does whitespace cleanup and untabify codes. Thanks emacs. :)
This commit is contained in:
parent
7a5dba9eb9
commit
a3214b7505
|
@ -1,18 +1,18 @@
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||||
|
|
||||||
http://www.cocos2d-x.org
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
The above copyright notice and this permission notice shall be included in
|
||||||
all copies or substantial portions of the Software.
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
@ -22,8 +22,8 @@
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifndef cocos2d_libs_EventListener_h
|
#ifndef __CCEVENTLISTENER_H__
|
||||||
#define cocos2d_libs_EventListener_h
|
#define __CCEVENTLISTENER_H__
|
||||||
|
|
||||||
#include "CCPlatformMacros.h"
|
#include "CCPlatformMacros.h"
|
||||||
#include "CCRef.h"
|
#include "CCRef.h"
|
||||||
|
@ -56,30 +56,30 @@ public:
|
||||||
ACCELERATION,
|
ACCELERATION,
|
||||||
CUSTOM
|
CUSTOM
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::string ListenerID;
|
typedef std::string ListenerID;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/** Constructor */
|
/** Constructor */
|
||||||
EventListener();
|
EventListener();
|
||||||
|
|
||||||
/** Initializes event with type and callback function */
|
/** Initializes event with type and callback function */
|
||||||
bool init(Type t, const ListenerID& listenerID, const std::function<void(Event*)>& callback);
|
bool init(Type t, const ListenerID& listenerID, const std::function<void(Event*)>& callback);
|
||||||
public:
|
public:
|
||||||
/** Destructor */
|
/** Destructor */
|
||||||
virtual ~EventListener();
|
virtual ~EventListener();
|
||||||
|
|
||||||
/** Checks whether the listener is available. */
|
/** Checks whether the listener is available. */
|
||||||
virtual bool checkAvailable() = 0;
|
virtual bool checkAvailable() = 0;
|
||||||
|
|
||||||
/** Clones the listener, its subclasses have to override this method. */
|
/** Clones the listener, its subclasses have to override this method. */
|
||||||
virtual EventListener* clone() = 0;
|
virtual EventListener* clone() = 0;
|
||||||
|
|
||||||
/** Enables or disables the listener
|
/** Enables or disables the listener
|
||||||
* @note Only listeners with `enabled` state will be able to receive events.
|
* @note Only listeners with `enabled` state will be able to receive events.
|
||||||
* When an listener was initialized, it's enabled by default.
|
* When an listener was initialized, it's enabled by default.
|
||||||
* For a `scene graph priority` listener, to receive an event, excepting it was `enabled`,
|
* An event listener can receive events when it is enabled and is not paused.
|
||||||
* it also shouldn't be in `pause` state.
|
* paused state is always false when it is a fixed priority listener.
|
||||||
*/
|
*/
|
||||||
inline void setEnabled(bool enabled) { _isEnabled = enabled; };
|
inline void setEnabled(bool enabled) { _isEnabled = enabled; };
|
||||||
|
|
||||||
|
@ -88,12 +88,13 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
/** Sets pause state for the listener
|
/** Sets paused state for the listener
|
||||||
* The paused state is only used for scene graph priority listeners.
|
* The paused state is only used for scene graph priority listeners.
|
||||||
* `EventDispatcher::resumeAllEventListenersForTarget(node)` will set the paused state to `true`,
|
* `EventDispatcher::resumeAllEventListenersForTarget(node)` will set the paused state to `true`,
|
||||||
* while `EventDispatcher::pauseAllEventListenersForTarget(node)` will set it to `false`.
|
* while `EventDispatcher::pauseAllEventListenersForTarget(node)` will set it to `false`.
|
||||||
* @note Fixed priority listeners will never get paused. If a fixed priority doesn't want to receive events,
|
* @note 1) Fixed priority listeners will never get paused. If a fixed priority doesn't want to receive events,
|
||||||
* call `setEnabled(false)` instead.
|
* call `setEnabled(false)` instead.
|
||||||
|
* 2) In `Node`'s onEnter and onExit, listeners associated with that node will automatically update their `paused state`.
|
||||||
*/
|
*/
|
||||||
inline void setPaused(bool paused) { _paused = paused; };
|
inline void setPaused(bool paused) { _paused = paused; };
|
||||||
|
|
||||||
|
@ -139,11 +140,11 @@ protected:
|
||||||
// Properties
|
// Properties
|
||||||
//////////////
|
//////////////
|
||||||
std::function<void(Event*)> _onEvent; /// Event callback function
|
std::function<void(Event*)> _onEvent; /// Event callback function
|
||||||
|
|
||||||
Type _type; /// Event listener type
|
Type _type; /// Event listener type
|
||||||
ListenerID _listenerID; /// Event listener ID
|
ListenerID _listenerID; /// Event listener ID
|
||||||
bool _isRegistered; /// Whether the listener has been added to dispatcher.
|
bool _isRegistered; /// Whether the listener has been added to dispatcher.
|
||||||
|
|
||||||
int _fixedPriority; // The higher the number, the higher the priority, 0 is for scene graph base priority.
|
int _fixedPriority; // The higher the number, the higher the priority, 0 is for scene graph base priority.
|
||||||
Node* _node; // scene graph based priority
|
Node* _node; // scene graph based priority
|
||||||
bool _paused; // Whether the listener is paused
|
bool _paused; // Whether the listener is paused
|
||||||
|
@ -153,4 +154,4 @@ protected:
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
||||||
#endif
|
#endif // __CCEVENTLISTENER_H__
|
||||||
|
|
Loading…
Reference in New Issue