2013-09-03 18:22:03 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013 cocos2d-x.org
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef __CCEVENT_H__
|
|
|
|
#define __CCEVENT_H__
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "platform/CCPlatformMacros.h"
|
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2013-09-13 16:34:34 +08:00
|
|
|
class Node;
|
|
|
|
|
2013-09-16 14:43:57 +08:00
|
|
|
/**
|
|
|
|
* Base class of all kinds of events.
|
|
|
|
*/
|
2013-09-03 18:22:03 +08:00
|
|
|
class Event
|
|
|
|
{
|
|
|
|
public:
|
2013-09-16 14:43:57 +08:00
|
|
|
/** Constructor */
|
2013-09-03 18:22:03 +08:00
|
|
|
Event(const std::string& type);
|
2013-09-16 14:43:57 +08:00
|
|
|
|
|
|
|
/** Destructor */
|
2013-09-03 18:22:03 +08:00
|
|
|
virtual ~Event();
|
|
|
|
|
2013-09-16 14:43:57 +08:00
|
|
|
/** Gets the event type */
|
2013-09-18 18:15:18 +08:00
|
|
|
inline const std::string& getType() const { return _type; };
|
2013-09-16 14:43:57 +08:00
|
|
|
|
|
|
|
/** Stops propagation for current event */
|
2013-09-18 18:15:18 +08:00
|
|
|
inline void stopPropagation() { _isStopped = true; };
|
2013-09-16 14:43:57 +08:00
|
|
|
|
|
|
|
/** Checks whether the event has been stopped */
|
2013-09-18 18:15:18 +08:00
|
|
|
inline bool isStopped() const { return _isStopped; };
|
2013-09-16 14:43:57 +08:00
|
|
|
|
|
|
|
/** @brief Gets current target of the event
|
|
|
|
* @return The target with which the event associates.
|
|
|
|
* @note It onlys be available when the event listener is associated with node.
|
|
|
|
* It returns 0 when the listener is associated with fixed priority.
|
|
|
|
*/
|
2013-09-18 18:15:18 +08:00
|
|
|
inline Node* getCurrentTarget() { return _currentTarget; };
|
|
|
|
|
|
|
|
/** Set user data */
|
|
|
|
inline void setUserData(void* data) { _userData = data; };
|
|
|
|
|
|
|
|
/** Get user data */
|
|
|
|
inline void* getUserData() const { return _userData; };
|
2013-09-13 16:34:34 +08:00
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
protected:
|
2013-09-16 14:43:57 +08:00
|
|
|
/** Sets current target */
|
2013-09-18 18:15:18 +08:00
|
|
|
inline void setCurrentTarget(Node* target) { _currentTarget = target; };
|
2013-09-16 14:43:57 +08:00
|
|
|
|
2013-09-18 18:15:18 +08:00
|
|
|
std::string _type; ///< Event type
|
|
|
|
bool _isStopped; ///< whether the event has been stopped.
|
|
|
|
Node* _currentTarget; ///< Current target
|
|
|
|
void* _userData; ///< User data
|
2013-09-12 17:31:37 +08:00
|
|
|
|
|
|
|
friend class EventDispatcher;
|
2013-09-03 18:22:03 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_CC_END
|
|
|
|
|
|
|
|
|
|
|
|
#endif // __CCEVENT_H__
|