2010-07-16 14:10:18 +08:00
|
|
|
/****************************************************************************
|
2011-03-19 14:45:51 +08:00
|
|
|
Copyright (c) 2010-2011 cocos2d-x.org
|
|
|
|
Copyright (c) 2009 Valentin Milea
|
2010-07-16 14:10:18 +08:00
|
|
|
|
|
|
|
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"
|
2011-03-07 17:11:57 +08:00
|
|
|
#include "CCMutableArray.h"
|
|
|
|
#include "CCSet.h"
|
2010-07-29 12:12:11 +08:00
|
|
|
#include "CCTouch.h"
|
2010-07-16 14:27:00 +08:00
|
|
|
#include "CCTexture2D.h"
|
2010-09-24 18:10:32 +08:00
|
|
|
#include "support/data_support/ccCArray.h"
|
2010-07-16 14:10:18 +08:00
|
|
|
|
|
|
|
#include <assert.h>
|
2011-07-08 15:01:51 +08:00
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used for sort
|
|
|
|
*/
|
|
|
|
static bool less(const cocos2d::CCTouchHandler *p1, const cocos2d::CCTouchHandler *p2)
|
|
|
|
{
|
|
|
|
return ((cocos2d::CCTouchHandler*)p1)->getPriority() < ((cocos2d::CCTouchHandler*)p2)->getPriority();
|
|
|
|
}
|
|
|
|
|
2010-08-04 15:46:12 +08:00
|
|
|
namespace cocos2d {
|
2010-07-16 14:10:18 +08:00
|
|
|
|
|
|
|
bool CCTouchDispatcher::isDispatchEvents(void)
|
|
|
|
{
|
|
|
|
return m_bDispatchEvents;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCTouchDispatcher::setDispatchEvents(bool bDispatchEvents)
|
|
|
|
{
|
|
|
|
m_bDispatchEvents = bDispatchEvents;
|
|
|
|
}
|
|
|
|
|
|
|
|
static CCTouchDispatcher *pSharedDispatcher = NULL;
|
|
|
|
|
2010-11-16 15:12:09 +08:00
|
|
|
CCTouchDispatcher* CCTouchDispatcher::sharedDispatcher(void)
|
2010-07-16 14:10:18 +08:00
|
|
|
{
|
|
|
|
// synchronized ??
|
|
|
|
if (pSharedDispatcher == NULL)
|
|
|
|
{
|
|
|
|
pSharedDispatcher = new CCTouchDispatcher();
|
|
|
|
pSharedDispatcher->init();
|
|
|
|
}
|
|
|
|
|
|
|
|
return pSharedDispatcher;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-03-07 17:11:57 +08:00
|
|
|
+(id) allocWithZone:(CCZone *)zone
|
2010-08-02 10:58:00 +08:00
|
|
|
{
|
|
|
|
@synchronized(self) {
|
2011-03-07 17:11:57 +08:00
|
|
|
CCAssert(sharedDispatcher == nil, @"Attempted to allocate a second instance of a singleton.");
|
2010-08-02 10:58:00 +08:00
|
|
|
return [super allocWithZone:zone];
|
|
|
|
}
|
|
|
|
return nil; // on subsequent allocation attempts return nil
|
2010-07-16 14:10:18 +08:00
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2010-09-04 12:02:52 +08:00
|
|
|
bool CCTouchDispatcher::init(void)
|
2010-07-16 14:10:18 +08:00
|
|
|
{
|
|
|
|
m_bDispatchEvents = true;
|
2011-03-07 17:11:57 +08:00
|
|
|
m_pTargetedHandlers = new CCMutableArray<CCTouchHandler*>(8);
|
|
|
|
m_pStandardHandlers = new CCMutableArray<CCTouchHandler*>(4);
|
2010-07-16 14:10:18 +08:00
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
m_pHandlersToAdd = new CCMutableArray<CCTouchHandler*>(8);
|
2010-08-27 14:13:32 +08:00
|
|
|
m_pHandlersToRemove = ccCArrayNew(8);
|
2010-07-16 14:10:18 +08:00
|
|
|
|
|
|
|
m_bToRemove = false;
|
|
|
|
m_bToAdd = false;
|
|
|
|
m_bToQuit = false;
|
|
|
|
m_bLocked = false;
|
|
|
|
|
2011-06-20 17:31:38 +08:00
|
|
|
m_sHandlerHelperData[CCTOUCHBEGAN].m_type = CCTOUCHBEGAN;
|
|
|
|
m_sHandlerHelperData[CCTOUCHMOVED].m_type = CCTOUCHMOVED;
|
|
|
|
m_sHandlerHelperData[CCTOUCHENDED].m_type = CCTOUCHENDED;
|
|
|
|
m_sHandlerHelperData[CCTOUCHCANCELLED].m_type = CCTOUCHCANCELLED;
|
2010-07-16 14:10:18 +08:00
|
|
|
|
2010-09-04 12:02:52 +08:00
|
|
|
return true;
|
2010-07-16 14:10:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CCTouchDispatcher::~CCTouchDispatcher(void)
|
|
|
|
{
|
2011-04-01 16:06:53 +08:00
|
|
|
CC_SAFE_RELEASE(m_pTargetedHandlers);
|
|
|
|
CC_SAFE_RELEASE(m_pStandardHandlers);
|
|
|
|
CC_SAFE_RELEASE(m_pHandlersToAdd);
|
2010-08-27 14:13:32 +08:00
|
|
|
|
2011-04-01 16:06:53 +08:00
|
|
|
ccCArrayFree(m_pHandlersToRemove);
|
|
|
|
m_pHandlersToRemove = NULL;
|
2010-07-16 14:10:18 +08:00
|
|
|
}
|
|
|
|
|
2010-08-02 10:58:00 +08:00
|
|
|
//
|
|
|
|
// handlers management
|
2010-07-16 14:10:18 +08:00
|
|
|
//
|
2011-03-07 17:11:57 +08:00
|
|
|
void CCTouchDispatcher::forceAddHandler(CCTouchHandler *pHandler, CCMutableArray<CCTouchHandler*> *pArray)
|
2010-07-16 14:10:18 +08:00
|
|
|
{
|
2010-08-02 10:58:00 +08:00
|
|
|
unsigned int u = 0;
|
2010-07-16 14:10:18 +08:00
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CCMutableArray<CCTouchHandler*>::CCMutableArrayIterator iter;
|
2010-08-27 14:13:32 +08:00
|
|
|
for (iter = pArray->begin(); iter != pArray->end(); ++iter)
|
|
|
|
{
|
|
|
|
CCTouchHandler *h = *iter;
|
|
|
|
if (h)
|
|
|
|
{
|
|
|
|
if (h->getPriority() < pHandler->getPriority())
|
|
|
|
{
|
|
|
|
++u;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (h->getDelegate() == pHandler->getDelegate())
|
|
|
|
{
|
|
|
|
assert(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-07-16 14:10:18 +08:00
|
|
|
|
|
|
|
pArray->insertObjectAtIndex(pHandler, u);
|
|
|
|
}
|
|
|
|
|
2010-09-03 09:32:13 +08:00
|
|
|
void CCTouchDispatcher::addStandardDelegate(CCTouchDelegate *pDelegate, int nPriority)
|
2010-07-16 14:10:18 +08:00
|
|
|
{
|
2011-04-24 15:38:03 +08:00
|
|
|
pDelegate->m_eTouchDelegateType = ccTouchDelegateStandardBit;
|
|
|
|
|
2010-07-16 14:10:18 +08:00
|
|
|
CCTouchHandler *pHandler = CCStandardTouchHandler::handlerWithDelegate(pDelegate, nPriority);
|
|
|
|
if (! m_bLocked)
|
|
|
|
{
|
|
|
|
forceAddHandler(pHandler, m_pStandardHandlers);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_pHandlersToAdd->addObject(pHandler);
|
|
|
|
m_bToAdd = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-03 09:32:13 +08:00
|
|
|
void CCTouchDispatcher::addTargetedDelegate(CCTouchDelegate *pDelegate, int nPriority, bool bSwallowsTouches)
|
2010-07-16 14:10:18 +08:00
|
|
|
{
|
2011-04-24 15:38:03 +08:00
|
|
|
pDelegate->m_eTouchDelegateType = ccTouchDelegateTargetedBit;
|
|
|
|
|
2010-07-16 14:10:18 +08:00
|
|
|
CCTouchHandler *pHandler = CCTargetedTouchHandler::handlerWithDelegate(pDelegate, nPriority, bSwallowsTouches);
|
|
|
|
if (! m_bLocked)
|
|
|
|
{
|
|
|
|
forceAddHandler(pHandler, m_pTargetedHandlers);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_pHandlersToAdd->addObject(pHandler);
|
|
|
|
m_bToAdd = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCTouchDispatcher::forceRemoveDelegate(CCTouchDelegate *pDelegate)
|
|
|
|
{
|
2010-10-09 09:57:24 +08:00
|
|
|
CCTouchHandler *pHandler;
|
2011-03-07 17:11:57 +08:00
|
|
|
CCMutableArray<CCTouchHandler*>::CCMutableArrayIterator iter;
|
2010-10-09 09:57:24 +08:00
|
|
|
|
2010-07-16 14:10:18 +08:00
|
|
|
// XXX: remove it from both handlers ???
|
2010-10-09 09:57:24 +08:00
|
|
|
|
|
|
|
// remove handler from m_pStandardHandlers
|
|
|
|
for (iter = m_pStandardHandlers->begin(); iter != m_pStandardHandlers->end(); ++iter)
|
2010-07-16 14:10:18 +08:00
|
|
|
{
|
2010-10-09 09:57:24 +08:00
|
|
|
pHandler = *iter;
|
|
|
|
if (pHandler && pHandler->getDelegate() == pDelegate)
|
|
|
|
{
|
|
|
|
m_pStandardHandlers->removeObject(pHandler);
|
|
|
|
break;
|
|
|
|
}
|
2010-07-16 14:10:18 +08:00
|
|
|
}
|
2010-10-09 09:57:24 +08:00
|
|
|
|
|
|
|
|
|
|
|
// remove handler from m_pTargetedHandlers
|
|
|
|
for (iter = m_pTargetedHandlers->begin(); iter != m_pTargetedHandlers->end(); ++iter)
|
2010-07-16 14:10:18 +08:00
|
|
|
{
|
2010-10-09 09:57:24 +08:00
|
|
|
pHandler = *iter;
|
|
|
|
if (pHandler && pHandler->getDelegate() == pDelegate)
|
|
|
|
{
|
|
|
|
m_pTargetedHandlers->removeObject(pHandler);
|
|
|
|
break;
|
|
|
|
}
|
2010-07-16 14:10:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCTouchDispatcher::removeDelegate(CCTouchDelegate *pDelegate)
|
|
|
|
{
|
|
|
|
if (pDelegate == NULL)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! m_bLocked)
|
|
|
|
{
|
|
|
|
forceRemoveDelegate(pDelegate);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-08-27 14:13:32 +08:00
|
|
|
ccCArrayAppendValue(m_pHandlersToRemove, pDelegate);
|
2010-07-16 14:10:18 +08:00
|
|
|
m_bToRemove = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCTouchDispatcher::forceRemoveAllDelegates(void)
|
|
|
|
{
|
2010-08-27 14:13:32 +08:00
|
|
|
m_pStandardHandlers->removeAllObjects();
|
|
|
|
m_pTargetedHandlers->removeAllObjects();
|
2010-07-16 14:10:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCTouchDispatcher::removeAllDelegates(void)
|
|
|
|
{
|
|
|
|
if (! m_bLocked)
|
|
|
|
{
|
|
|
|
forceRemoveAllDelegates();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_bToQuit = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-08 15:01:51 +08:00
|
|
|
CCTouchHandler* CCTouchDispatcher::findHandler(CCTouchDelegate *pDelegate)
|
|
|
|
{
|
|
|
|
CCMutableArray<CCTouchHandler*>::CCMutableArrayIterator iter;
|
|
|
|
|
|
|
|
for (iter = m_pTargetedHandlers->begin(); iter != m_pTargetedHandlers->end(); ++iter)
|
|
|
|
{
|
|
|
|
if ((*iter)->getDelegate() == pDelegate)
|
|
|
|
{
|
|
|
|
return *iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (iter = m_pStandardHandlers->begin(); iter != m_pStandardHandlers->end(); ++iter)
|
|
|
|
{
|
|
|
|
if ((*iter)->getDelegate() == pDelegate)
|
|
|
|
{
|
|
|
|
return *iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCTouchDispatcher::rearrangeHandlers(CCMutableArray<CCTouchHandler*> *pArray)
|
|
|
|
{
|
2011-08-20 05:21:16 +08:00
|
|
|
std::sort(pArray->begin(), pArray->end(), less);
|
2011-07-08 15:01:51 +08:00
|
|
|
}
|
|
|
|
|
2010-07-16 14:10:18 +08:00
|
|
|
void CCTouchDispatcher::setPriority(int nPriority, CCTouchDelegate *pDelegate)
|
|
|
|
{
|
2011-07-08 15:01:51 +08:00
|
|
|
assert(pDelegate != NULL);
|
|
|
|
|
|
|
|
CCTouchHandler *handler = NULL;
|
|
|
|
|
|
|
|
handler = this->findHandler(pDelegate);
|
|
|
|
|
|
|
|
assert(handler != NULL);
|
|
|
|
|
|
|
|
handler->setPriority(nPriority);
|
|
|
|
|
|
|
|
this->rearrangeHandlers(m_pTargetedHandlers);
|
|
|
|
this->rearrangeHandlers(m_pStandardHandlers);
|
2010-07-16 14:10:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2010-08-02 10:58:00 +08:00
|
|
|
// dispatch events
|
|
|
|
//
|
2011-03-18 09:39:34 +08:00
|
|
|
void CCTouchDispatcher::touches(CCSet *pTouches, CCEvent *pEvent, unsigned int uIndex)
|
2010-07-16 14:10:18 +08:00
|
|
|
{
|
2010-08-04 10:36:37 +08:00
|
|
|
assert(uIndex >= 0 && uIndex < 4);
|
2010-07-16 14:10:18 +08:00
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CCSet *pMutableTouches;
|
2010-07-16 14:10:18 +08:00
|
|
|
m_bLocked = true;
|
|
|
|
|
|
|
|
// optimization to prevent a mutable copy when it is not necessary
|
2010-08-27 14:13:32 +08:00
|
|
|
unsigned int uTargetedHandlersCount = m_pTargetedHandlers->count();
|
|
|
|
unsigned int uStandardHandlersCount = m_pStandardHandlers->count();
|
2010-07-16 14:10:18 +08:00
|
|
|
bool bNeedsMutableSet = (uTargetedHandlersCount && uStandardHandlersCount);
|
|
|
|
|
|
|
|
pMutableTouches = (bNeedsMutableSet ? pTouches->mutableCopy() : pTouches);
|
|
|
|
|
|
|
|
struct ccTouchHandlerHelperData sHelper = m_sHandlerHelperData[uIndex];
|
2010-08-02 10:58:00 +08:00
|
|
|
//
|
|
|
|
// process the target handlers 1st
|
2010-07-16 14:10:18 +08:00
|
|
|
//
|
|
|
|
if (uTargetedHandlersCount > 0)
|
|
|
|
{
|
2010-07-29 12:12:11 +08:00
|
|
|
CCTouch *pTouch;
|
2011-03-07 17:11:57 +08:00
|
|
|
CCSetIterator setIter;
|
2010-07-16 14:10:18 +08:00
|
|
|
for (setIter = pTouches->begin(); setIter != pTouches->end(); ++setIter)
|
|
|
|
{
|
2010-08-31 11:20:37 +08:00
|
|
|
pTouch = (CCTouch *)(*setIter);
|
2010-07-16 14:10:18 +08:00
|
|
|
CCTargetedTouchHandler *pHandler;
|
2011-03-07 17:11:57 +08:00
|
|
|
CCMutableArray<CCTouchHandler*>::CCMutableArrayIterator arrayIter;
|
2010-07-16 14:10:18 +08:00
|
|
|
for (arrayIter = m_pTargetedHandlers->begin(); arrayIter != m_pTargetedHandlers->end(); ++arrayIter)
|
2010-08-27 14:13:32 +08:00
|
|
|
/*for (unsigned int i = 0; i < m_pTargetedHandlers->num; ++i)*/
|
2010-07-16 14:10:18 +08:00
|
|
|
{
|
2010-08-31 11:20:37 +08:00
|
|
|
pHandler = (CCTargetedTouchHandler *)(*arrayIter);
|
2010-07-16 14:10:18 +08:00
|
|
|
|
2010-08-30 13:42:17 +08:00
|
|
|
if (! pHandler)
|
2010-08-04 18:17:07 +08:00
|
|
|
{
|
2010-08-30 13:42:17 +08:00
|
|
|
break;
|
2010-08-04 18:17:07 +08:00
|
|
|
}
|
2010-08-30 13:42:17 +08:00
|
|
|
|
|
|
|
bool bClaimed = false;
|
2011-06-20 17:31:38 +08:00
|
|
|
if (uIndex == CCTOUCHBEGAN)
|
2010-08-30 13:42:17 +08:00
|
|
|
{
|
2010-09-03 09:32:13 +08:00
|
|
|
bClaimed = pHandler->getDelegate()->ccTouchBegan(pTouch, pEvent);
|
2011-06-20 17:31:38 +08:00
|
|
|
|
2010-08-30 13:42:17 +08:00
|
|
|
if (bClaimed)
|
|
|
|
{
|
|
|
|
pHandler->getClaimedTouches()->addObject(pTouch);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
if (pHandler->getClaimedTouches()->containsObject(pTouch))
|
|
|
|
{
|
|
|
|
// moved ended cancelled
|
|
|
|
bClaimed = true;
|
|
|
|
|
2011-05-31 14:04:14 +08:00
|
|
|
switch (sHelper.m_type)
|
|
|
|
{
|
2011-06-20 17:31:38 +08:00
|
|
|
case CCTOUCHMOVED:
|
2010-09-03 09:32:13 +08:00
|
|
|
pHandler->getDelegate()->ccTouchMoved(pTouch, pEvent);
|
2010-08-30 13:42:17 +08:00
|
|
|
break;
|
2011-06-20 17:31:38 +08:00
|
|
|
case CCTOUCHENDED:
|
2010-09-03 09:32:13 +08:00
|
|
|
pHandler->getDelegate()->ccTouchEnded(pTouch, pEvent);
|
2010-08-30 13:42:17 +08:00
|
|
|
pHandler->getClaimedTouches()->removeObject(pTouch);
|
|
|
|
break;
|
2011-06-20 17:31:38 +08:00
|
|
|
case CCTOUCHCANCELLED:
|
2010-09-03 09:32:13 +08:00
|
|
|
pHandler->getDelegate()->ccTouchCancelled(pTouch, pEvent);
|
2010-08-30 13:42:17 +08:00
|
|
|
pHandler->getClaimedTouches()->removeObject(pTouch);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bClaimed && pHandler->isSwallowsTouches())
|
|
|
|
{
|
|
|
|
if (bNeedsMutableSet)
|
|
|
|
{
|
|
|
|
pMutableTouches->removeObject(pTouch);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2010-07-16 14:10:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-02 10:58:00 +08:00
|
|
|
//
|
|
|
|
// process standard handlers 2nd
|
2010-07-16 14:10:18 +08:00
|
|
|
//
|
|
|
|
if (uStandardHandlersCount > 0 && pMutableTouches->count() > 0)
|
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CCMutableArray<CCTouchHandler*>::CCMutableArrayIterator iter;
|
2010-07-16 14:10:18 +08:00
|
|
|
CCStandardTouchHandler *pHandler;
|
|
|
|
for (iter = m_pStandardHandlers->begin(); iter != m_pStandardHandlers->end(); ++iter)
|
|
|
|
{
|
2010-08-31 11:20:37 +08:00
|
|
|
pHandler = (CCStandardTouchHandler*)(*iter);
|
2010-07-16 14:10:18 +08:00
|
|
|
|
2010-08-30 13:42:17 +08:00
|
|
|
if (! pHandler)
|
2010-08-04 18:17:07 +08:00
|
|
|
{
|
2010-08-30 13:42:17 +08:00
|
|
|
break;
|
2010-08-04 18:17:07 +08:00
|
|
|
}
|
2010-08-30 13:42:17 +08:00
|
|
|
|
|
|
|
switch (sHelper.m_type)
|
|
|
|
{
|
2011-06-20 17:31:38 +08:00
|
|
|
case CCTOUCHBEGAN:
|
2010-09-03 09:32:13 +08:00
|
|
|
pHandler->getDelegate()->ccTouchesBegan(pMutableTouches, pEvent);
|
2010-08-30 13:42:17 +08:00
|
|
|
break;
|
2011-06-20 17:31:38 +08:00
|
|
|
case CCTOUCHMOVED:
|
2010-09-03 09:32:13 +08:00
|
|
|
pHandler->getDelegate()->ccTouchesMoved(pMutableTouches, pEvent);
|
2010-08-30 13:42:17 +08:00
|
|
|
break;
|
2011-06-20 17:31:38 +08:00
|
|
|
case CCTOUCHENDED:
|
2010-09-03 09:32:13 +08:00
|
|
|
pHandler->getDelegate()->ccTouchesEnded(pMutableTouches, pEvent);
|
2010-08-30 13:42:17 +08:00
|
|
|
break;
|
2011-06-20 17:31:38 +08:00
|
|
|
case CCTOUCHCANCELLED:
|
2010-09-03 09:32:13 +08:00
|
|
|
pHandler->getDelegate()->ccTouchesCancelled(pMutableTouches, pEvent);
|
2010-08-30 13:42:17 +08:00
|
|
|
break;
|
|
|
|
}
|
2010-07-16 14:10:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bNeedsMutableSet)
|
|
|
|
{
|
|
|
|
pMutableTouches->release();
|
|
|
|
}
|
|
|
|
|
2010-08-02 10:58:00 +08:00
|
|
|
//
|
|
|
|
// Optimization. To prevent a [handlers copy] which is expensive
|
|
|
|
// the add/removes/quit is done after the iterations
|
2010-07-16 14:10:18 +08:00
|
|
|
//
|
|
|
|
m_bLocked = false;
|
|
|
|
if (m_bToRemove)
|
|
|
|
{
|
|
|
|
m_bToRemove = false;
|
2010-08-27 14:13:32 +08:00
|
|
|
for (unsigned int i = 0; i < m_pHandlersToRemove->num; ++i)
|
2010-07-16 14:10:18 +08:00
|
|
|
{
|
2010-08-27 14:13:32 +08:00
|
|
|
forceRemoveDelegate((CCTouchDelegate*)m_pHandlersToRemove->arr[i]);
|
2010-07-16 14:10:18 +08:00
|
|
|
}
|
2010-08-27 14:13:32 +08:00
|
|
|
ccCArrayRemoveAllValues(m_pHandlersToRemove);
|
2010-07-16 14:10:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_bToAdd)
|
|
|
|
{
|
|
|
|
m_bToAdd = false;
|
2011-03-07 17:11:57 +08:00
|
|
|
CCMutableArray<CCTouchHandler*>::CCMutableArrayIterator iter;
|
2010-08-27 14:13:32 +08:00
|
|
|
CCTouchHandler *pHandler;
|
|
|
|
for (iter = m_pHandlersToAdd->begin(); iter != m_pHandlersToAdd->end(); ++iter)
|
|
|
|
{
|
|
|
|
pHandler = *iter;
|
2010-08-28 15:47:51 +08:00
|
|
|
if (! pHandler)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2010-08-30 13:42:17 +08:00
|
|
|
|
|
|
|
if (pHandler->getDelegate()->getTouchDelegateType() & ccTouchDelegateTargetedBit)
|
|
|
|
{
|
|
|
|
forceAddHandler(pHandler, m_pTargetedHandlers);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
forceAddHandler(pHandler, m_pStandardHandlers);
|
|
|
|
}
|
2010-08-27 14:13:32 +08:00
|
|
|
}
|
|
|
|
|
2010-08-30 13:48:27 +08:00
|
|
|
m_pHandlersToAdd->removeAllObjects();
|
2010-07-16 14:10:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_bToQuit)
|
|
|
|
{
|
|
|
|
m_bToQuit = false;
|
|
|
|
forceRemoveAllDelegates();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-18 09:39:34 +08:00
|
|
|
void CCTouchDispatcher::touchesBegan(CCSet *touches, CCEvent *pEvent)
|
2010-07-16 14:10:18 +08:00
|
|
|
{
|
|
|
|
if (m_bDispatchEvents)
|
|
|
|
{
|
2011-06-20 17:31:38 +08:00
|
|
|
this->touches(touches, pEvent, CCTOUCHBEGAN);
|
2010-07-16 14:10:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-18 09:39:34 +08:00
|
|
|
void CCTouchDispatcher::touchesMoved(CCSet *touches, CCEvent *pEvent)
|
2010-07-16 14:10:18 +08:00
|
|
|
{
|
|
|
|
if (m_bDispatchEvents)
|
|
|
|
{
|
2011-06-20 17:31:38 +08:00
|
|
|
this->touches(touches, pEvent, CCTOUCHMOVED);
|
2010-07-16 14:10:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-18 09:39:34 +08:00
|
|
|
void CCTouchDispatcher::touchesEnded(CCSet *touches, CCEvent *pEvent)
|
2010-07-16 14:10:18 +08:00
|
|
|
{
|
|
|
|
if (m_bDispatchEvents)
|
|
|
|
{
|
2011-06-20 17:31:38 +08:00
|
|
|
this->touches(touches, pEvent, CCTOUCHENDED);
|
2010-07-16 14:10:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-18 09:39:34 +08:00
|
|
|
void CCTouchDispatcher::touchesCancelled(CCSet *touches, CCEvent *pEvent)
|
2010-07-16 14:10:18 +08:00
|
|
|
{
|
|
|
|
if (m_bDispatchEvents)
|
|
|
|
{
|
2011-06-20 17:31:38 +08:00
|
|
|
this->touches(touches, pEvent, CCTOUCHCANCELLED);
|
2010-07-16 14:10:18 +08:00
|
|
|
}
|
|
|
|
}
|
2010-08-04 15:46:12 +08:00
|
|
|
}//namespace cocos2d
|