2010-07-16 11:39:21 +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 11:39:21 +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 "CCTouchHandler.h"
|
|
|
|
#include "ccMacros.h"
|
2010-09-03 09:32:13 +08:00
|
|
|
|
2010-08-04 15:46:12 +08:00
|
|
|
namespace cocos2d {
|
2010-07-16 11:39:21 +08:00
|
|
|
|
|
|
|
CCTouchDelegate* CCTouchHandler::getDelegate(void)
|
|
|
|
{
|
|
|
|
return m_pDelegate;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCTouchHandler::setDelegate(CCTouchDelegate *pDelegate)
|
|
|
|
{
|
2010-11-05 17:29:24 +08:00
|
|
|
if (pDelegate)
|
2010-09-06 11:48:04 +08:00
|
|
|
{
|
2012-02-09 15:49:14 +08:00
|
|
|
dynamic_cast<CCObject*>(pDelegate)->retain();
|
2010-11-05 17:29:24 +08:00
|
|
|
}
|
|
|
|
|
2012-02-09 15:49:14 +08:00
|
|
|
dynamic_cast<CCObject*>(pDelegate)->retain();
|
|
|
|
|
2010-11-05 17:29:24 +08:00
|
|
|
if (m_pDelegate)
|
|
|
|
{
|
2012-02-09 15:49:14 +08:00
|
|
|
dynamic_cast<CCObject*>(m_pDelegate)->release();
|
2010-11-05 17:29:24 +08:00
|
|
|
}
|
2012-02-09 15:49:14 +08:00
|
|
|
|
2010-07-16 11:39:21 +08:00
|
|
|
m_pDelegate = pDelegate;
|
|
|
|
}
|
|
|
|
|
2010-08-02 10:58:00 +08:00
|
|
|
int CCTouchHandler::getPriority(void)
|
2010-07-16 11:39:21 +08:00
|
|
|
{
|
|
|
|
return m_nPriority;
|
|
|
|
}
|
|
|
|
|
2010-08-02 10:58:00 +08:00
|
|
|
void CCTouchHandler::setPriority(int nPriority)
|
2010-07-16 11:39:21 +08:00
|
|
|
{
|
|
|
|
m_nPriority = nPriority;
|
|
|
|
}
|
|
|
|
|
2010-08-02 10:58:00 +08:00
|
|
|
int CCTouchHandler::getEnabledSelectors(void)
|
2010-07-16 11:39:21 +08:00
|
|
|
{
|
|
|
|
return m_nEnabledSelectors;
|
|
|
|
}
|
|
|
|
|
2010-08-02 10:58:00 +08:00
|
|
|
void CCTouchHandler::setEnalbedSelectors(int nValue)
|
2010-07-16 11:39:21 +08:00
|
|
|
{
|
|
|
|
m_nEnabledSelectors = nValue;
|
|
|
|
}
|
|
|
|
|
2010-08-02 10:58:00 +08:00
|
|
|
CCTouchHandler* CCTouchHandler::handlerWithDelegate(CCTouchDelegate *pDelegate, int nPriority)
|
2010-07-16 11:39:21 +08:00
|
|
|
{
|
|
|
|
CCTouchHandler *pHandler = new CCTouchHandler();
|
|
|
|
|
2010-09-03 09:32:13 +08:00
|
|
|
if (pHandler)
|
|
|
|
{
|
|
|
|
if (pHandler->initWithDelegate(pDelegate, nPriority))
|
|
|
|
{
|
|
|
|
pHandler->autorelease();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_SAFE_RELEASE_NULL(pHandler);
|
2010-09-03 09:32:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pHandler;
|
2010-07-16 11:39:21 +08:00
|
|
|
}
|
|
|
|
|
2010-09-03 09:32:13 +08:00
|
|
|
bool CCTouchHandler::initWithDelegate(CCTouchDelegate *pDelegate, int nPriority)
|
2010-07-16 11:39:21 +08:00
|
|
|
{
|
2011-11-28 17:28:43 +08:00
|
|
|
CCAssert(pDelegate != NULL, "touch delegate should not be null");
|
2010-07-16 11:39:21 +08:00
|
|
|
|
2011-12-28 14:47:54 +08:00
|
|
|
m_pDelegate = pDelegate;
|
|
|
|
|
2012-02-09 15:49:14 +08:00
|
|
|
dynamic_cast<CCObject*>(pDelegate)->retain();
|
2011-12-28 14:47:54 +08:00
|
|
|
|
2010-07-16 11:39:21 +08:00
|
|
|
m_nPriority = nPriority;
|
|
|
|
m_nEnabledSelectors = 0;
|
|
|
|
|
2010-09-03 09:32:13 +08:00
|
|
|
return true;
|
2010-07-16 11:39:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CCTouchHandler::~CCTouchHandler(void)
|
|
|
|
{
|
2011-04-01 16:06:53 +08:00
|
|
|
if (m_pDelegate)
|
|
|
|
{
|
2012-02-09 15:49:14 +08:00
|
|
|
dynamic_cast<CCObject*>(m_pDelegate)->release();
|
2011-04-01 16:06:53 +08:00
|
|
|
}
|
2010-07-16 11:39:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// implementation of CCStandardTouchHandler
|
2010-09-03 09:32:13 +08:00
|
|
|
bool CCStandardTouchHandler::initWithDelegate(CCTouchDelegate *pDelegate, int nPriority)
|
2010-07-16 11:39:21 +08:00
|
|
|
{
|
2010-09-02 14:54:42 +08:00
|
|
|
if (CCTouchHandler::initWithDelegate(pDelegate, nPriority))
|
2010-07-16 11:39:21 +08:00
|
|
|
{
|
2010-09-03 09:32:13 +08:00
|
|
|
return true;
|
2010-07-16 11:39:21 +08:00
|
|
|
}
|
|
|
|
|
2010-09-03 09:32:13 +08:00
|
|
|
return false;
|
2010-07-16 11:39:21 +08:00
|
|
|
}
|
|
|
|
|
2010-09-03 09:32:13 +08:00
|
|
|
CCStandardTouchHandler* CCStandardTouchHandler::handlerWithDelegate(CCTouchDelegate *pDelegate, int nPriority)
|
2010-07-16 11:39:21 +08:00
|
|
|
{
|
2010-09-03 09:32:13 +08:00
|
|
|
CCStandardTouchHandler* pHandler = new CCStandardTouchHandler();
|
2010-07-16 11:39:21 +08:00
|
|
|
|
2010-09-03 09:32:13 +08:00
|
|
|
if (pHandler)
|
|
|
|
{
|
|
|
|
if (pHandler->initWithDelegate(pDelegate, nPriority))
|
|
|
|
{
|
|
|
|
pHandler->autorelease();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_SAFE_RELEASE_NULL(pHandler);
|
2010-09-03 09:32:13 +08:00
|
|
|
}
|
|
|
|
}
|
2010-07-16 11:39:21 +08:00
|
|
|
|
2010-09-03 09:32:13 +08:00
|
|
|
return pHandler;
|
2010-07-16 11:39:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// implementation of CCTargetedTouchHandler
|
|
|
|
|
|
|
|
bool CCTargetedTouchHandler::isSwallowsTouches(void)
|
|
|
|
{
|
|
|
|
return m_bSwallowsTouches;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCTargetedTouchHandler::setSwallowsTouches(bool bSwallowsTouches)
|
|
|
|
{
|
|
|
|
m_bSwallowsTouches = bSwallowsTouches;
|
|
|
|
}
|
|
|
|
|
2012-02-07 15:35:10 +08:00
|
|
|
CCSet* CCTargetedTouchHandler::getClaimedTouches(void)
|
2010-07-16 11:39:21 +08:00
|
|
|
{
|
|
|
|
return m_pClaimedTouches;
|
|
|
|
}
|
|
|
|
|
2010-08-02 10:58:00 +08:00
|
|
|
CCTargetedTouchHandler* CCTargetedTouchHandler::handlerWithDelegate(CCTouchDelegate *pDelegate, int nPriority, bool bSwallow)
|
2010-07-16 11:39:21 +08:00
|
|
|
{
|
2010-09-03 09:32:13 +08:00
|
|
|
CCTargetedTouchHandler *pHandler = new CCTargetedTouchHandler();
|
|
|
|
if (pHandler)
|
|
|
|
{
|
|
|
|
if (pHandler->initWithDelegate(pDelegate, nPriority, bSwallow))
|
|
|
|
{
|
|
|
|
pHandler->autorelease();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_SAFE_RELEASE_NULL(pHandler);
|
2010-09-03 09:32:13 +08:00
|
|
|
}
|
|
|
|
}
|
2010-07-16 11:39:21 +08:00
|
|
|
|
2010-09-03 09:32:13 +08:00
|
|
|
return pHandler;
|
2010-07-16 11:39:21 +08:00
|
|
|
}
|
|
|
|
|
2010-09-03 09:32:13 +08:00
|
|
|
bool CCTargetedTouchHandler::initWithDelegate(CCTouchDelegate *pDelegate, int nPriority, bool bSwallow)
|
2010-07-16 11:39:21 +08:00
|
|
|
{
|
2010-09-02 14:54:42 +08:00
|
|
|
if (CCTouchHandler::initWithDelegate(pDelegate, nPriority))
|
2010-07-16 11:39:21 +08:00
|
|
|
{
|
2012-02-07 15:35:10 +08:00
|
|
|
m_pClaimedTouches = new CCSet();
|
2010-07-16 11:39:21 +08:00
|
|
|
m_bSwallowsTouches = bSwallow;
|
|
|
|
|
2010-09-03 09:32:13 +08:00
|
|
|
return true;
|
2010-07-16 11:39:21 +08:00
|
|
|
}
|
|
|
|
|
2010-09-03 09:32:13 +08:00
|
|
|
return false;
|
2010-07-16 11:39:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CCTargetedTouchHandler::~CCTargetedTouchHandler(void)
|
|
|
|
{
|
2011-04-01 16:06:53 +08:00
|
|
|
CC_SAFE_RELEASE(m_pClaimedTouches);
|
2010-07-16 11:39:21 +08:00
|
|
|
}
|
2010-08-04 15:46:12 +08:00
|
|
|
}//namespace cocos2d
|