mirror of https://github.com/axmolengine/axmol.git
fixed #118
This commit is contained in:
parent
082b90ea06
commit
9a12e848f5
|
@ -42,7 +42,7 @@ All features from CCNode are valid, plus the following new features:
|
|||
- It can receive Accelerometer input
|
||||
*/
|
||||
/// @todo public UIAccelerometerDelegate
|
||||
class CCX_DLL CCLayer : public CCNode, public CCStandardTouchDelegate, public CCTargetedTouchDelegate//, public UIAccelerometerDelegate
|
||||
class CCX_DLL CCLayer : public CCNode, public CCTouchDelegate//, public UIAccelerometerDelegate
|
||||
{
|
||||
public:
|
||||
CCLayer();
|
||||
|
|
|
@ -29,8 +29,6 @@ THE SOFTWARE.
|
|||
#include "ccxCommon.h"
|
||||
|
||||
namespace cocos2d {
|
||||
class CCTouch;
|
||||
class UIEvent;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
|
@ -39,12 +37,11 @@ typedef enum
|
|||
ccTouchDeletateAllBit = (ccTouchDelegateStandardBit | ccTouchDelegateTargetedBit),
|
||||
} ccTouchDelegateFlag;
|
||||
|
||||
//class CCX_DLL CCTouchDelegate : virtual public NSObject
|
||||
class CCTouch;
|
||||
class UIEvent;
|
||||
class NSSet;
|
||||
class CCX_DLL CCTouchDelegate
|
||||
{
|
||||
// public:
|
||||
// // for RTTI support
|
||||
// virtual void v() {};
|
||||
protected:
|
||||
ccTouchDelegateFlag m_eTouchDelegateType;
|
||||
|
||||
|
@ -54,41 +51,49 @@ public:
|
|||
virtual void destroy(void) {}
|
||||
// call the retain() in child (layer or menu)
|
||||
virtual void keep(void) {}
|
||||
};
|
||||
|
||||
class CCX_DLL CCTargetedTouchDelegate : public CCTouchDelegate
|
||||
{
|
||||
public:
|
||||
CCTargetedTouchDelegate() { m_eTouchDelegateType = ccTouchDelegateTargetedBit; }
|
||||
/** Return YES to claim the touch.
|
||||
@since v0.8
|
||||
*/
|
||||
virtual bool ccTouchBegan(CCTouch *pTouch, UIEvent *pEvent) { return false;};
|
||||
|
||||
// optional
|
||||
virtual void ccTouchMoved(CCTouch *pTouch, UIEvent *pEvent) {}
|
||||
virtual void ccTouchEnded(CCTouch *pTouch, UIEvent *pEvent) {}
|
||||
virtual void ccTouchCancelled(CCTouch *pTouch, UIEvent *pEvent) {}
|
||||
};
|
||||
|
||||
/**
|
||||
CCStandardTouchDelegate.
|
||||
|
||||
This type of delegate is the same one used by CocoaTouch. You will receive all the events (Began,Moved,Ended,Cancelled).
|
||||
@since v0.8
|
||||
*/
|
||||
|
||||
class NSSet;
|
||||
class CCX_DLL CCStandardTouchDelegate : public CCTouchDelegate
|
||||
{
|
||||
public:
|
||||
CCStandardTouchDelegate() { m_eTouchDelegateType = ccTouchDelegateTargetedBit; }
|
||||
// optional
|
||||
virtual void ccTouchesBegan(NSSet *pTouches, UIEvent *pEvent) {}
|
||||
virtual void ccTouchesMoved(NSSet *pTouches, UIEvent *pEvent) {}
|
||||
virtual void ccTouchesEnded(NSSet *pTouches, UIEvent *pEvent) {}
|
||||
virtual void ccTouchesCancelled(NSSet *pTouches, UIEvent *pEvent) {}
|
||||
virtual void ccTouchesBegan(NSSet *pTouches, UIEvent *pEvent) {}
|
||||
virtual void ccTouchesMoved(NSSet *pTouches, UIEvent *pEvent) {}
|
||||
virtual void ccTouchesEnded(NSSet *pTouches, UIEvent *pEvent) {}
|
||||
virtual void ccTouchesCancelled(NSSet *pTouches, UIEvent *pEvent) {}
|
||||
};
|
||||
|
||||
class CCX_DLL CCTargetedTouchDelegate : public CCTouchDelegate
|
||||
{
|
||||
public:
|
||||
CCTargetedTouchDelegate() { m_eTouchDelegateType = ccTouchDelegateTargetedBit; }
|
||||
// Return YES to claim the touch.
|
||||
// @since v0
|
||||
virtual bool ccTouchBegan(CCTouch *pTouch, UIEvent *pEvent) { return false;};
|
||||
|
||||
// optional
|
||||
virtual void ccTouchMoved(CCTouch *pTouch, UIEvent *pEvent) {}
|
||||
virtual void ccTouchEnded(CCTouch *pTouch, UIEvent *pEvent) {}
|
||||
virtual void ccTouchCancelled(CCTouch *pTouch, UIEvent *pEvent) {}
|
||||
};
|
||||
|
||||
// CCStandardTouchDelegate.
|
||||
// This type of delegate is the same one used by CocoaTouch. You will receive all the events (Began,Moved,Ended,Cancelled).
|
||||
// @since v0.8
|
||||
class CCX_DLL CCStandardTouchDelegate : public CCTouchDelegate
|
||||
{
|
||||
public:
|
||||
CCStandardTouchDelegate() { m_eTouchDelegateType = ccTouchDelegateTargetedBit; }
|
||||
// optional
|
||||
virtual void ccTouchesBegan(NSSet *pTouches, UIEvent *pEvent) {}
|
||||
virtual void ccTouchesMoved(NSSet *pTouches, UIEvent *pEvent) {}
|
||||
virtual void ccTouchesEnded(NSSet *pTouches, UIEvent *pEvent) {}
|
||||
virtual void ccTouchesCancelled(NSSet *pTouches, UIEvent *pEvent) {}
|
||||
};
|
||||
|
||||
}//namespace cocos2d
|
||||
|
||||
#endif // __TOUCH_DISPATHCHER_CCTOUCH_DELEGATE_PROTOCOL_H__
|
||||
|
|
|
@ -103,13 +103,13 @@ public:
|
|||
See StandardTouchDelegate description.
|
||||
IMPORTANT: The delegate will be retained.
|
||||
*/
|
||||
void addStandardDelegate(CCStandardTouchDelegate *pDelegate, int nPriority);
|
||||
void addStandardDelegate(CCTouchDelegate *pDelegate, int nPriority);
|
||||
|
||||
/** Adds a targeted touch delegate to the dispatcher's list.
|
||||
See TargetedTouchDelegate description.
|
||||
IMPORTANT: The delegate will be retained.
|
||||
*/
|
||||
void addTargetedDelegate(CCTargetedTouchDelegate *pDelegate, int nPriority, bool bSwallowsTouches);
|
||||
void addTargetedDelegate(CCTouchDelegate *pDelegate, int nPriority, bool bSwallowsTouches);
|
||||
|
||||
/** Removes a touch delegate.
|
||||
The delegate will be released
|
||||
|
|
|
@ -34,7 +34,7 @@ CCLayer::CCLayer()
|
|||
:m_bIsTouchEnabled(false)
|
||||
,m_bIsAccelerometerEnabled(false)
|
||||
{
|
||||
CCTouchDelegate::m_eTouchDelegateType = ccTouchDeletateAllBit;
|
||||
m_eTouchDelegateType = ccTouchDeletateAllBit;
|
||||
m_tAnchorPoint = ccp(0.5f, 0.5f);
|
||||
m_bIsRelativeAnchorPoint = false;
|
||||
}
|
||||
|
@ -107,8 +107,7 @@ void CCLayer::setIsTouchEnabled(bool enabled)
|
|||
else
|
||||
{
|
||||
// have problems?
|
||||
CCTouchDispatcher::getSharedDispatcher()->removeDelegate((CCTargetedTouchDelegate*)(this));
|
||||
CCTouchDispatcher::getSharedDispatcher()->removeDelegate((CCStandardTouchDelegate*)(this));
|
||||
CCTouchDispatcher::getSharedDispatcher()->removeDelegate(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -157,8 +156,7 @@ void CCLayer::onExit()
|
|||
{
|
||||
if( m_bIsTouchEnabled )
|
||||
{
|
||||
CCTouchDispatcher::getSharedDispatcher()->removeDelegate((CCTargetedTouchDelegate*)(this));
|
||||
CCTouchDispatcher::getSharedDispatcher()->removeDelegate((CCStandardTouchDelegate*)(this));
|
||||
CCTouchDispatcher::getSharedDispatcher()->removeDelegate(this);
|
||||
}
|
||||
/**
|
||||
if( isAccelerometerEnabled )
|
||||
|
|
|
@ -133,7 +133,7 @@ void CCTouchDispatcher::forceAddHandler(CCTouchHandler *pHandler, NSMutableArray
|
|||
pHandler->retain();
|
||||
}
|
||||
|
||||
void CCTouchDispatcher::addStandardDelegate(CCStandardTouchDelegate *pDelegate, int nPriority)
|
||||
void CCTouchDispatcher::addStandardDelegate(CCTouchDelegate *pDelegate, int nPriority)
|
||||
{
|
||||
CCTouchHandler *pHandler = CCStandardTouchHandler::handlerWithDelegate(pDelegate, nPriority);
|
||||
if (! m_bLocked)
|
||||
|
@ -147,7 +147,7 @@ void CCTouchDispatcher::addStandardDelegate(CCStandardTouchDelegate *pDelegate,
|
|||
}
|
||||
}
|
||||
|
||||
void CCTouchDispatcher::addTargetedDelegate(CCTargetedTouchDelegate *pDelegate, int nPriority, bool bSwallowsTouches)
|
||||
void CCTouchDispatcher::addTargetedDelegate(CCTouchDelegate *pDelegate, int nPriority, bool bSwallowsTouches)
|
||||
{
|
||||
CCTouchHandler *pHandler = CCTargetedTouchHandler::handlerWithDelegate(pDelegate, nPriority, bSwallowsTouches);
|
||||
if (! m_bLocked)
|
||||
|
@ -282,7 +282,7 @@ void CCTouchDispatcher::touches(NSSet *pTouches, UIEvent *pEvent, unsigned int u
|
|||
bool bClaimed = false;
|
||||
if (uIndex == ccTouchBegan)
|
||||
{
|
||||
bClaimed = ((CCTargetedTouchDelegate *)(pHandler->getDelegate()))->ccTouchBegan(pTouch, pEvent);
|
||||
bClaimed = pHandler->getDelegate()->ccTouchBegan(pTouch, pEvent);
|
||||
if (bClaimed)
|
||||
{
|
||||
pHandler->getClaimedTouches()->addObject(pTouch);
|
||||
|
@ -296,14 +296,14 @@ void CCTouchDispatcher::touches(NSSet *pTouches, UIEvent *pEvent, unsigned int u
|
|||
switch (sHelper.m_type)
|
||||
{
|
||||
case ccTouchMoved:
|
||||
((CCTargetedTouchDelegate*)(pHandler->getDelegate()))->ccTouchMoved(pTouch, pEvent);
|
||||
pHandler->getDelegate()->ccTouchMoved(pTouch, pEvent);
|
||||
break;
|
||||
case ccTouchEnded:
|
||||
((CCTargetedTouchDelegate*)(pHandler->getDelegate()))->ccTouchEnded(pTouch, pEvent);
|
||||
pHandler->getDelegate()->ccTouchEnded(pTouch, pEvent);
|
||||
pHandler->getClaimedTouches()->removeObject(pTouch);
|
||||
break;
|
||||
case ccTouchCancelled:
|
||||
((CCTargetedTouchDelegate*)(pHandler->getDelegate()))->ccTouchCancelled(pTouch, pEvent);
|
||||
pHandler->getDelegate()->ccTouchCancelled(pTouch, pEvent);
|
||||
pHandler->getClaimedTouches()->removeObject(pTouch);
|
||||
break;
|
||||
}
|
||||
|
@ -341,16 +341,16 @@ void CCTouchDispatcher::touches(NSSet *pTouches, UIEvent *pEvent, unsigned int u
|
|||
switch (sHelper.m_type)
|
||||
{
|
||||
case ccTouchBegan:
|
||||
((CCStandardTouchDelegate*)(pHandler->getDelegate()))->ccTouchesBegan(pMutableTouches, pEvent);
|
||||
pHandler->getDelegate()->ccTouchesBegan(pMutableTouches, pEvent);
|
||||
break;
|
||||
case ccTouchMoved:
|
||||
((CCStandardTouchDelegate*)(pHandler->getDelegate()))->ccTouchesMoved(pMutableTouches, pEvent);
|
||||
pHandler->getDelegate()->ccTouchesMoved(pMutableTouches, pEvent);
|
||||
break;
|
||||
case ccTouchEnded:
|
||||
((CCStandardTouchDelegate*)(pHandler->getDelegate()))->ccTouchesEnded(pMutableTouches, pEvent);
|
||||
pHandler->getDelegate()->ccTouchesEnded(pMutableTouches, pEvent);
|
||||
break;
|
||||
case ccTouchCancelled:
|
||||
((CCStandardTouchDelegate*)(pHandler->getDelegate()))->ccTouchesCancelled(pMutableTouches, pEvent);
|
||||
pHandler->getDelegate()->ccTouchesCancelled(pMutableTouches, pEvent);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,8 @@ THE SOFTWARE.
|
|||
|
||||
#include "CCTouchHandler.h"
|
||||
#include "ccMacros.h"
|
||||
#include "Cocos2dDefine.h"
|
||||
|
||||
#include <assert.h>
|
||||
namespace cocos2d {
|
||||
|
||||
|
@ -60,12 +62,23 @@ void CCTouchHandler::setEnalbedSelectors(int nValue)
|
|||
CCTouchHandler* CCTouchHandler::handlerWithDelegate(CCTouchDelegate *pDelegate, int nPriority)
|
||||
{
|
||||
CCTouchHandler *pHandler = new CCTouchHandler();
|
||||
pHandler->autorelease();
|
||||
|
||||
return pHandler->initWithDelegate(pDelegate, nPriority);
|
||||
if (pHandler)
|
||||
{
|
||||
if (pHandler->initWithDelegate(pDelegate, nPriority))
|
||||
{
|
||||
pHandler->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
CCX_SAFE_RELEASE_NULL(pHandler);
|
||||
}
|
||||
}
|
||||
|
||||
return pHandler;
|
||||
}
|
||||
|
||||
CCTouchHandler* CCTouchHandler::initWithDelegate(CCTouchDelegate *pDelegate, int nPriority)
|
||||
bool CCTouchHandler::initWithDelegate(CCTouchDelegate *pDelegate, int nPriority)
|
||||
{
|
||||
assert(pDelegate != NULL);
|
||||
|
||||
|
@ -73,7 +86,7 @@ CCTouchHandler* CCTouchHandler::initWithDelegate(CCTouchDelegate *pDelegate, int
|
|||
m_nPriority = nPriority;
|
||||
m_nEnabledSelectors = 0;
|
||||
|
||||
return this;
|
||||
return true;
|
||||
}
|
||||
|
||||
CCTouchHandler::~CCTouchHandler(void)
|
||||
|
@ -82,7 +95,7 @@ CCTouchHandler::~CCTouchHandler(void)
|
|||
}
|
||||
|
||||
// implementation of CCStandardTouchHandler
|
||||
CCTouchHandler* CCStandardTouchHandler::initWithDelegate(CCTouchDelegate *pDelegate, int nPriority)
|
||||
bool CCStandardTouchHandler::initWithDelegate(CCTouchDelegate *pDelegate, int nPriority)
|
||||
{
|
||||
if (CCTouchHandler::initWithDelegate(pDelegate, nPriority))
|
||||
{
|
||||
|
@ -97,19 +110,30 @@ CCTouchHandler* CCStandardTouchHandler::initWithDelegate(CCTouchDelegate *pDeleg
|
|||
if( [del respondsToSelector:@selector(ccTouchesCancelled:withEvent:)] )
|
||||
enabledSelectors_ |= ccTouchSelectorCancelledBit;
|
||||
*/
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return this;
|
||||
return false;
|
||||
}
|
||||
|
||||
CCStandardTouchHandler* CCStandardTouchHandler::handlerWithDelegate(CCStandardTouchDelegate *pDelegate, int nPriority)
|
||||
CCStandardTouchHandler* CCStandardTouchHandler::handlerWithDelegate(CCTouchDelegate *pDelegate, int nPriority)
|
||||
{
|
||||
CCStandardTouchHandler* pTouchHandler = new CCStandardTouchHandler();
|
||||
CCStandardTouchHandler* pHandler = new CCStandardTouchHandler();
|
||||
|
||||
pTouchHandler->initWithDelegate(pDelegate, nPriority);
|
||||
pTouchHandler->autorelease();
|
||||
if (pHandler)
|
||||
{
|
||||
if (pHandler->initWithDelegate(pDelegate, nPriority))
|
||||
{
|
||||
pHandler->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
CCX_SAFE_RELEASE_NULL(pHandler);
|
||||
}
|
||||
}
|
||||
|
||||
return pTouchHandler;
|
||||
return pHandler;
|
||||
}
|
||||
|
||||
// implementation of CCTargetedTouchHandler
|
||||
|
@ -131,14 +155,23 @@ NSMutableSet* CCTargetedTouchHandler::getClaimedTouches(void)
|
|||
|
||||
CCTargetedTouchHandler* CCTargetedTouchHandler::handlerWithDelegate(CCTouchDelegate *pDelegate, int nPriority, bool bSwallow)
|
||||
{
|
||||
CCTargetedTouchHandler *pTargetedHandler = new CCTargetedTouchHandler();
|
||||
pTargetedHandler->initWithDelegate(pDelegate, nPriority, bSwallow);
|
||||
pTargetedHandler->autorelease();
|
||||
CCTargetedTouchHandler *pHandler = new CCTargetedTouchHandler();
|
||||
if (pHandler)
|
||||
{
|
||||
if (pHandler->initWithDelegate(pDelegate, nPriority, bSwallow))
|
||||
{
|
||||
pHandler->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
CCX_SAFE_RELEASE_NULL(pHandler);
|
||||
}
|
||||
}
|
||||
|
||||
return pTargetedHandler;
|
||||
return pHandler;
|
||||
}
|
||||
|
||||
CCTouchHandler* CCTargetedTouchHandler::initWithDelegate(CCTouchDelegate *pDelegate, int nPriority, bool bSwallow)
|
||||
bool CCTargetedTouchHandler::initWithDelegate(CCTouchDelegate *pDelegate, int nPriority, bool bSwallow)
|
||||
{
|
||||
if (CCTouchHandler::initWithDelegate(pDelegate, nPriority))
|
||||
{
|
||||
|
@ -155,9 +188,10 @@ CCTouchHandler* CCTargetedTouchHandler::initWithDelegate(CCTouchDelegate *pDeleg
|
|||
if( [aDelegate respondsToSelector:@selector(ccTouchCancelled:withEvent:)] )
|
||||
enabledSelectors_ |= ccTouchSelectorCancelledBit;
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
|
||||
return this;
|
||||
return false;
|
||||
}
|
||||
|
||||
CCTargetedTouchHandler::~CCTargetedTouchHandler(void)
|
||||
|
|
|
@ -53,7 +53,7 @@ public:
|
|||
void setEnalbedSelectors(int nValue);
|
||||
|
||||
// initializes a TouchHandler with a delegate and a priority
|
||||
virtual CCTouchHandler* initWithDelegate(CCTouchDelegate *pDelegate, int nPriority);
|
||||
virtual bool initWithDelegate(CCTouchDelegate *pDelegate, int nPriority);
|
||||
|
||||
public:
|
||||
// allocates a TouchHandler with a delegate and a priority
|
||||
|
@ -71,10 +71,10 @@ protected:
|
|||
class CCStandardTouchHandler : public CCTouchHandler
|
||||
{
|
||||
public:
|
||||
virtual CCTouchHandler* initWithDelegate(CCTouchDelegate *pDelegate, int nPriority);
|
||||
virtual bool initWithDelegate(CCTouchDelegate *pDelegate, int nPriority);
|
||||
|
||||
public:
|
||||
static CCStandardTouchHandler* handlerWithDelegate(CCStandardTouchDelegate *pDelegate, int nPriority);
|
||||
static CCStandardTouchHandler* handlerWithDelegate(CCTouchDelegate *pDelegate, int nPriority);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -94,7 +94,7 @@ public:
|
|||
// MutableSet that contains the claimed touches
|
||||
NSMutableSet* getClaimedTouches(void);
|
||||
|
||||
CCTouchHandler* initWithDelegate(CCTouchDelegate *pDelegate, int nPriority, bool bSwallow);
|
||||
bool initWithDelegate(CCTouchDelegate *pDelegate, int nPriority, bool bSwallow);
|
||||
|
||||
public:
|
||||
static CCTargetedTouchHandler* handlerWithDelegate(CCTouchDelegate *pDelegate, int nPriority, bool bSwallow);
|
||||
|
|
Loading…
Reference in New Issue