fixed #467 CCLayer:m_eTouchDelegateType = ccTouchDeletateAllBit all the time, which makes an error logic if adding standard touch delegate when CCTouchDispatcher::m_tLock = ture

This commit is contained in:
Walzer 2011-04-24 15:38:03 +08:00
parent 3e643d73a3
commit f7b294fe24
2 changed files with 27 additions and 19 deletions

View File

@ -30,23 +30,27 @@ THE SOFTWARE.
namespace cocos2d {
typedef enum
{
ccTouchDelegateStandardBit = 1 << 0,
ccTouchDelegateTargetedBit = 1 << 1,
ccTouchDeletateAllBit = (ccTouchDelegateStandardBit | ccTouchDelegateTargetedBit),
typedef enum
{
ccTouchDelegateStandardBit = 1 << 0,
ccTouchDelegateTargetedBit = 1 << 1,
ccTouchDeletateAllBit = (ccTouchDelegateStandardBit | ccTouchDelegateTargetedBit),
} ccTouchDelegateFlag;
class CCTouch;
class CCEvent;
class CCSet;
class CCTouchDispatcher;
class CC_DLL CCTouchDelegate
{
protected:
ccTouchDelegateFlag m_eTouchDelegateType;
public:
friend class CCTouchDispatcher; // only CCTouchDispatcher & children can change m_eTouchDelegateType
inline ccTouchDelegateFlag getTouchDelegateType(void) { return m_eTouchDelegateType; }
//! call the release() in child(layer or menu)
virtual void destroy(void) {}
//! call the retain() in child (layer or menu)
@ -65,19 +69,19 @@ public:
virtual void ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent) {}
virtual void ccTouchesCancelled(CCSet *pTouches, CCEvent *pEvent) {}
};
/**
@brief
Using this type of delegate results in two benefits:
- 1. You don't need to deal with CCSets, the dispatcher does the job of splitting
them. You get exactly one UITouch per call.
- 2. You can *claim* a UITouch by returning YES in ccTouchBegan. Updates of claimed
touches are sent only to the delegate(s) that claimed them. So if you get a move/
ended/cancelled update you're sure it's your touch. This frees you from doing a
lot of checks when doing multi-touch.
(The name TargetedTouchDelegate relates to updates "targeting" their specific
handler, without bothering the other handlers.)
@since v0.8
/**
@brief
Using this type of delegate results in two benefits:
- 1. You don't need to deal with CCSets, the dispatcher does the job of splitting
them. You get exactly one UITouch per call.
- 2. You can *claim* a UITouch by returning YES in ccTouchBegan. Updates of claimed
touches are sent only to the delegate(s) that claimed them. So if you get a move/
ended/cancelled update you're sure it's your touch. This frees you from doing a
lot of checks when doing multi-touch.
(The name TargetedTouchDelegate relates to updates "targeting" their specific
handler, without bothering the other handlers.)
@since v0.8
*/
class CC_DLL CCTargetedTouchDelegate : public CCTouchDelegate
{
@ -93,7 +97,7 @@ public:
virtual void ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent) {}
virtual void ccTouchCancelled(CCTouch *pTouch, CCEvent *pEvent) {}
};
/** @brief
This type of delegate is the same one used by CocoaTouch. You will receive all the events (Began,Moved,Ended,Cancelled).
@since v0.8

View File

@ -132,6 +132,8 @@ void CCTouchDispatcher::forceAddHandler(CCTouchHandler *pHandler, CCMutableArray
void CCTouchDispatcher::addStandardDelegate(CCTouchDelegate *pDelegate, int nPriority)
{
pDelegate->m_eTouchDelegateType = ccTouchDelegateStandardBit;
CCTouchHandler *pHandler = CCStandardTouchHandler::handlerWithDelegate(pDelegate, nPriority);
if (! m_bLocked)
{
@ -146,6 +148,8 @@ void CCTouchDispatcher::addStandardDelegate(CCTouchDelegate *pDelegate, int nPri
void CCTouchDispatcher::addTargetedDelegate(CCTouchDelegate *pDelegate, int nPriority, bool bSwallowsTouches)
{
pDelegate->m_eTouchDelegateType = ccTouchDelegateTargetedBit;
CCTouchHandler *pHandler = CCTargetedTouchHandler::handlerWithDelegate(pDelegate, nPriority, bSwallowsTouches);
if (! m_bLocked)
{