2012-04-19 14:35:52 +08:00
|
|
|
/****************************************************************************
|
2012-09-24 21:22:20 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2012-04-19 14:35:52 +08:00
|
|
|
Copyright (c) 2009 Valentin Milea
|
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "CCTouchDispatcher.h"
|
|
|
|
#include "CCTouchHandler.h"
|
2012-06-19 16:20:46 +08:00
|
|
|
#include "cocoa/CCArray.h"
|
|
|
|
#include "cocoa/CCSet.h"
|
2012-04-19 14:35:52 +08:00
|
|
|
#include "CCTouch.h"
|
2012-06-19 16:20:46 +08:00
|
|
|
#include "textures/CCTexture2D.h"
|
2012-04-19 14:35:52 +08:00
|
|
|
#include "support/data_support/ccCArray.h"
|
|
|
|
#include "ccMacros.h"
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used for sort
|
|
|
|
*/
|
2012-06-07 11:38:59 +08:00
|
|
|
static int less(const CCObject* p1, const CCObject* p2)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2012-06-07 11:38:59 +08:00
|
|
|
return ((CCTouchHandler*)p1)->getPriority() < ((CCTouchHandler*)p2)->getPriority();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CCTouchDispatcher::isDispatchEvents(void)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _dispatchEvents;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCTouchDispatcher::setDispatchEvents(bool bDispatchEvents)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_dispatchEvents = bDispatchEvents;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
+(id) allocWithZone:(CCZone *)zone
|
|
|
|
{
|
|
|
|
@synchronized(self) {
|
|
|
|
CCAssert(sharedDispatcher == nil, @"Attempted to allocate a second instance of a singleton.");
|
|
|
|
return [super allocWithZone:zone];
|
|
|
|
}
|
|
|
|
return nil; // on subsequent allocation attempts return nil
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool CCTouchDispatcher::init(void)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_dispatchEvents = true;
|
|
|
|
_targetedHandlers = CCArray::createWithCapacity(8);
|
|
|
|
_targetedHandlers->retain();
|
|
|
|
_standardHandlers = CCArray::createWithCapacity(4);
|
|
|
|
_standardHandlers->retain();
|
|
|
|
_handlersToAdd = CCArray::createWithCapacity(8);
|
|
|
|
_handlersToAdd->retain();
|
|
|
|
_handlersToRemove = ccCArrayNew(8);
|
|
|
|
|
|
|
|
_toRemove = false;
|
|
|
|
_toAdd = false;
|
|
|
|
_toQuit = false;
|
|
|
|
_locked = false;
|
|
|
|
|
|
|
|
_handlerHelperData[CCTOUCHBEGAN]._type = CCTOUCHBEGAN;
|
|
|
|
_handlerHelperData[CCTOUCHMOVED]._type = CCTOUCHMOVED;
|
|
|
|
_handlerHelperData[CCTOUCHENDED]._type = CCTOUCHENDED;
|
|
|
|
_handlerHelperData[CCTOUCHCANCELLED]._type = CCTOUCHCANCELLED;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCTouchDispatcher::~CCTouchDispatcher(void)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CC_SAFE_RELEASE(_targetedHandlers);
|
|
|
|
CC_SAFE_RELEASE(_standardHandlers);
|
|
|
|
CC_SAFE_RELEASE(_handlersToAdd);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
ccCArrayFree(_handlersToRemove);
|
|
|
|
_handlersToRemove = NULL;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// handlers management
|
|
|
|
//
|
|
|
|
void CCTouchDispatcher::forceAddHandler(CCTouchHandler *pHandler, CCArray *pArray)
|
|
|
|
{
|
|
|
|
unsigned int u = 0;
|
|
|
|
|
|
|
|
CCObject* pObj = NULL;
|
|
|
|
CCARRAY_FOREACH(pArray, pObj)
|
|
|
|
{
|
|
|
|
CCTouchHandler *h = (CCTouchHandler *)pObj;
|
|
|
|
if (h)
|
|
|
|
{
|
|
|
|
if (h->getPriority() < pHandler->getPriority())
|
|
|
|
{
|
|
|
|
++u;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (h->getDelegate() == pHandler->getDelegate())
|
|
|
|
{
|
|
|
|
CCAssert(0, "");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pArray->insertObject(pHandler, u);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCTouchDispatcher::addStandardDelegate(CCTouchDelegate *pDelegate, int nPriority)
|
|
|
|
{
|
|
|
|
CCTouchHandler *pHandler = CCStandardTouchHandler::handlerWithDelegate(pDelegate, nPriority);
|
2013-06-15 14:03:30 +08:00
|
|
|
if (! _locked)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
forceAddHandler(pHandler, _standardHandlers);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
/* If pHandler is contained in _handlersToRemove, if so remove it from _handlersToRemove and return.
|
2012-04-19 14:35:52 +08:00
|
|
|
* Refer issue #752(cocos2d-x)
|
|
|
|
*/
|
2013-06-15 14:03:30 +08:00
|
|
|
if (ccCArrayContainsValue(_handlersToRemove, pDelegate))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
ccCArrayRemoveValue(_handlersToRemove, pDelegate);
|
2012-04-19 14:35:52 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_handlersToAdd->addObject(pHandler);
|
|
|
|
_toAdd = true;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCTouchDispatcher::addTargetedDelegate(CCTouchDelegate *pDelegate, int nPriority, bool bSwallowsTouches)
|
|
|
|
{
|
|
|
|
CCTouchHandler *pHandler = CCTargetedTouchHandler::handlerWithDelegate(pDelegate, nPriority, bSwallowsTouches);
|
2013-06-15 14:03:30 +08:00
|
|
|
if (! _locked)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
forceAddHandler(pHandler, _targetedHandlers);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
/* If pHandler is contained in _handlersToRemove, if so remove it from _handlersToRemove and return.
|
2012-04-19 14:35:52 +08:00
|
|
|
* Refer issue #752(cocos2d-x)
|
|
|
|
*/
|
2013-06-15 14:03:30 +08:00
|
|
|
if (ccCArrayContainsValue(_handlersToRemove, pDelegate))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
ccCArrayRemoveValue(_handlersToRemove, pDelegate);
|
2012-04-19 14:35:52 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_handlersToAdd->addObject(pHandler);
|
|
|
|
_toAdd = true;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCTouchDispatcher::forceRemoveDelegate(CCTouchDelegate *pDelegate)
|
|
|
|
{
|
|
|
|
CCTouchHandler *pHandler;
|
|
|
|
|
|
|
|
// XXX: remove it from both handlers ???
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
// remove handler from _standardHandlers
|
2012-04-19 14:35:52 +08:00
|
|
|
CCObject* pObj = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
CCARRAY_FOREACH(_standardHandlers, pObj)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
pHandler = (CCTouchHandler*)pObj;
|
|
|
|
if (pHandler && pHandler->getDelegate() == pDelegate)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_standardHandlers->removeObject(pHandler);
|
2012-04-19 14:35:52 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
// remove handler from _targetedHandlers
|
|
|
|
CCARRAY_FOREACH(_targetedHandlers, pObj)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
pHandler = (CCTouchHandler*)pObj;
|
|
|
|
if (pHandler && pHandler->getDelegate() == pDelegate)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_targetedHandlers->removeObject(pHandler);
|
2012-04-19 14:35:52 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCTouchDispatcher::removeDelegate(CCTouchDelegate *pDelegate)
|
|
|
|
{
|
|
|
|
if (pDelegate == NULL)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (! _locked)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
forceRemoveDelegate(pDelegate);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
/* If pHandler is contained in _handlersToAdd, if so remove it from _handlersToAdd and return.
|
2012-04-19 14:35:52 +08:00
|
|
|
* Refer issue #752(cocos2d-x)
|
|
|
|
*/
|
2013-06-15 14:03:30 +08:00
|
|
|
CCTouchHandler *pHandler = findHandler(_handlersToAdd, pDelegate);
|
2012-04-19 14:35:52 +08:00
|
|
|
if (pHandler)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_handlersToAdd->removeObject(pHandler);
|
2012-04-19 14:35:52 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
ccCArrayAppendValue(_handlersToRemove, pDelegate);
|
|
|
|
_toRemove = true;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCTouchDispatcher::forceRemoveAllDelegates(void)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_standardHandlers->removeAllObjects();
|
|
|
|
_targetedHandlers->removeAllObjects();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCTouchDispatcher::removeAllDelegates(void)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (! _locked)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
forceRemoveAllDelegates();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_toQuit = true;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CCTouchHandler* CCTouchDispatcher::findHandler(CCTouchDelegate *pDelegate)
|
|
|
|
{
|
|
|
|
CCObject* pObj = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
CCARRAY_FOREACH(_targetedHandlers, pObj)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
CCTouchHandler* pHandler = (CCTouchHandler*)pObj;
|
|
|
|
if (pHandler->getDelegate() == pDelegate)
|
|
|
|
{
|
|
|
|
return pHandler;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
CCARRAY_FOREACH(_standardHandlers, pObj)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
CCTouchHandler* pHandler = (CCTouchHandler*)pObj;
|
|
|
|
if (pHandler->getDelegate() == pDelegate)
|
|
|
|
{
|
|
|
|
return pHandler;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCTouchHandler* CCTouchDispatcher::findHandler(CCArray* pArray, CCTouchDelegate *pDelegate)
|
|
|
|
{
|
|
|
|
CCAssert(pArray != NULL && pDelegate != NULL, "");
|
|
|
|
|
|
|
|
CCObject* pObj = NULL;
|
|
|
|
CCARRAY_FOREACH(pArray, pObj)
|
|
|
|
{
|
|
|
|
CCTouchHandler* pHandle = (CCTouchHandler*)pObj;
|
|
|
|
if (pHandle->getDelegate() == pDelegate)
|
|
|
|
{
|
|
|
|
return pHandle;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCTouchDispatcher::rearrangeHandlers(CCArray *pArray)
|
|
|
|
{
|
2012-06-07 11:38:59 +08:00
|
|
|
std::sort(pArray->data->arr, pArray->data->arr + pArray->data->num, less);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCTouchDispatcher::setPriority(int nPriority, CCTouchDelegate *pDelegate)
|
|
|
|
{
|
|
|
|
CCAssert(pDelegate != NULL, "");
|
|
|
|
|
|
|
|
CCTouchHandler *handler = NULL;
|
|
|
|
|
|
|
|
handler = this->findHandler(pDelegate);
|
|
|
|
|
|
|
|
CCAssert(handler != NULL, "");
|
2012-06-07 11:38:59 +08:00
|
|
|
|
|
|
|
if (handler->getPriority() != nPriority)
|
|
|
|
{
|
|
|
|
handler->setPriority(nPriority);
|
2013-06-15 14:03:30 +08:00
|
|
|
this->rearrangeHandlers(_targetedHandlers);
|
|
|
|
this->rearrangeHandlers(_standardHandlers);
|
2012-06-07 11:38:59 +08:00
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// dispatch events
|
|
|
|
//
|
|
|
|
void CCTouchDispatcher::touches(CCSet *pTouches, CCEvent *pEvent, unsigned int uIndex)
|
|
|
|
{
|
|
|
|
CCAssert(uIndex >= 0 && uIndex < 4, "");
|
|
|
|
|
|
|
|
CCSet *pMutableTouches;
|
2013-06-15 14:03:30 +08:00
|
|
|
_locked = true;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// optimization to prevent a mutable copy when it is not necessary
|
2013-06-15 14:03:30 +08:00
|
|
|
unsigned int uTargetedHandlersCount = _targetedHandlers->count();
|
|
|
|
unsigned int uStandardHandlersCount = _standardHandlers->count();
|
2012-04-19 14:35:52 +08:00
|
|
|
bool bNeedsMutableSet = (uTargetedHandlersCount && uStandardHandlersCount);
|
|
|
|
|
|
|
|
pMutableTouches = (bNeedsMutableSet ? pTouches->mutableCopy() : pTouches);
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
struct ccTouchHandlerHelperData sHelper = _handlerHelperData[uIndex];
|
2012-04-19 14:35:52 +08:00
|
|
|
//
|
|
|
|
// process the target handlers 1st
|
|
|
|
//
|
|
|
|
if (uTargetedHandlersCount > 0)
|
|
|
|
{
|
|
|
|
CCTouch *pTouch;
|
|
|
|
CCSetIterator setIter;
|
|
|
|
for (setIter = pTouches->begin(); setIter != pTouches->end(); ++setIter)
|
|
|
|
{
|
|
|
|
pTouch = (CCTouch *)(*setIter);
|
|
|
|
|
|
|
|
CCTargetedTouchHandler *pHandler = NULL;
|
|
|
|
CCObject* pObj = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
CCARRAY_FOREACH(_targetedHandlers, pObj)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
pHandler = (CCTargetedTouchHandler *)(pObj);
|
|
|
|
|
|
|
|
if (! pHandler)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool bClaimed = false;
|
|
|
|
if (uIndex == CCTOUCHBEGAN)
|
|
|
|
{
|
|
|
|
bClaimed = pHandler->getDelegate()->ccTouchBegan(pTouch, pEvent);
|
|
|
|
|
|
|
|
if (bClaimed)
|
|
|
|
{
|
|
|
|
pHandler->getClaimedTouches()->addObject(pTouch);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
if (pHandler->getClaimedTouches()->containsObject(pTouch))
|
|
|
|
{
|
2012-09-17 15:02:24 +08:00
|
|
|
// moved ended canceled
|
2012-04-19 14:35:52 +08:00
|
|
|
bClaimed = true;
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
switch (sHelper._type)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
case CCTOUCHMOVED:
|
|
|
|
pHandler->getDelegate()->ccTouchMoved(pTouch, pEvent);
|
|
|
|
break;
|
|
|
|
case CCTOUCHENDED:
|
|
|
|
pHandler->getDelegate()->ccTouchEnded(pTouch, pEvent);
|
|
|
|
pHandler->getClaimedTouches()->removeObject(pTouch);
|
|
|
|
break;
|
|
|
|
case CCTOUCHCANCELLED:
|
|
|
|
pHandler->getDelegate()->ccTouchCancelled(pTouch, pEvent);
|
|
|
|
pHandler->getClaimedTouches()->removeObject(pTouch);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bClaimed && pHandler->isSwallowsTouches())
|
|
|
|
{
|
|
|
|
if (bNeedsMutableSet)
|
|
|
|
{
|
|
|
|
pMutableTouches->removeObject(pTouch);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// process standard handlers 2nd
|
|
|
|
//
|
|
|
|
if (uStandardHandlersCount > 0 && pMutableTouches->count() > 0)
|
|
|
|
{
|
|
|
|
CCStandardTouchHandler *pHandler = NULL;
|
|
|
|
CCObject* pObj = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
CCARRAY_FOREACH(_standardHandlers, pObj)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
pHandler = (CCStandardTouchHandler*)(pObj);
|
|
|
|
|
|
|
|
if (! pHandler)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
switch (sHelper._type)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
case CCTOUCHBEGAN:
|
|
|
|
pHandler->getDelegate()->ccTouchesBegan(pMutableTouches, pEvent);
|
|
|
|
break;
|
|
|
|
case CCTOUCHMOVED:
|
|
|
|
pHandler->getDelegate()->ccTouchesMoved(pMutableTouches, pEvent);
|
|
|
|
break;
|
|
|
|
case CCTOUCHENDED:
|
|
|
|
pHandler->getDelegate()->ccTouchesEnded(pMutableTouches, pEvent);
|
|
|
|
break;
|
|
|
|
case CCTOUCHCANCELLED:
|
|
|
|
pHandler->getDelegate()->ccTouchesCancelled(pMutableTouches, pEvent);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bNeedsMutableSet)
|
|
|
|
{
|
|
|
|
pMutableTouches->release();
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Optimization. To prevent a [handlers copy] which is expensive
|
|
|
|
// the add/removes/quit is done after the iterations
|
|
|
|
//
|
2013-06-15 14:03:30 +08:00
|
|
|
_locked = false;
|
|
|
|
if (_toRemove)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_toRemove = false;
|
|
|
|
for (unsigned int i = 0; i < _handlersToRemove->num; ++i)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
forceRemoveDelegate((CCTouchDelegate*)_handlersToRemove->arr[i]);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2013-06-15 14:03:30 +08:00
|
|
|
ccCArrayRemoveAllValues(_handlersToRemove);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_toAdd)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_toAdd = false;
|
2012-04-19 14:35:52 +08:00
|
|
|
CCTouchHandler* pHandler = NULL;
|
|
|
|
CCObject* pObj = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
CCARRAY_FOREACH(_handlersToAdd, pObj)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
pHandler = (CCTouchHandler*)pObj;
|
|
|
|
if (! pHandler)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dynamic_cast<CCTargetedTouchHandler*>(pHandler) != NULL)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
forceAddHandler(pHandler, _targetedHandlers);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
forceAddHandler(pHandler, _standardHandlers);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_handlersToAdd->removeAllObjects();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_toQuit)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_toQuit = false;
|
2012-04-19 14:35:52 +08:00
|
|
|
forceRemoveAllDelegates();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCTouchDispatcher::touchesBegan(CCSet *touches, CCEvent *pEvent)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_dispatchEvents)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
this->touches(touches, pEvent, CCTOUCHBEGAN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCTouchDispatcher::touchesMoved(CCSet *touches, CCEvent *pEvent)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_dispatchEvents)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
this->touches(touches, pEvent, CCTOUCHMOVED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCTouchDispatcher::touchesEnded(CCSet *touches, CCEvent *pEvent)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_dispatchEvents)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
this->touches(touches, pEvent, CCTOUCHENDED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCTouchDispatcher::touchesCancelled(CCSet *touches, CCEvent *pEvent)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_dispatchEvents)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
this->touches(touches, pEvent, CCTOUCHCANCELLED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_CC_END
|