2013-09-03 18:22:03 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013 cocos2d-x.org
|
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-09-21 14:40:54 +08:00
|
|
|
#include "CCEventListenerTouch.h"
|
2013-09-03 18:22:03 +08:00
|
|
|
#include "CCEventDispatcher.h"
|
2013-09-21 14:40:54 +08:00
|
|
|
#include "CCEventTouch.h"
|
2013-09-03 18:22:03 +08:00
|
|
|
|
2013-09-12 17:31:37 +08:00
|
|
|
#include <algorithm>
|
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2013-10-12 11:25:28 +08:00
|
|
|
EventListenerTouchOneByOne::EventListenerTouchOneByOne()
|
2013-09-13 18:00:56 +08:00
|
|
|
: onTouchBegan(nullptr)
|
2013-09-03 18:22:03 +08:00
|
|
|
, onTouchMoved(nullptr)
|
|
|
|
, onTouchEnded(nullptr)
|
|
|
|
, onTouchCancelled(nullptr)
|
|
|
|
, _needSwallow(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-10-12 11:25:28 +08:00
|
|
|
EventListenerTouchOneByOne::~EventListenerTouchOneByOne()
|
2013-09-13 18:00:56 +08:00
|
|
|
{
|
2013-10-12 11:25:28 +08:00
|
|
|
CCLOGINFO("In the destructor of EventListenerTouchOneByOne, %p", this);
|
2013-09-13 18:00:56 +08:00
|
|
|
}
|
|
|
|
|
2013-10-12 11:25:28 +08:00
|
|
|
bool EventListenerTouchOneByOne::init()
|
2013-09-13 18:00:56 +08:00
|
|
|
{
|
2013-10-28 16:00:01 +08:00
|
|
|
if (EventListener::init(Type::TOUCH_ONE_BY_ONE, static_cast<ListenerID>(Type::TOUCH_ONE_BY_ONE), nullptr))
|
2013-09-13 18:00:56 +08:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-10-12 11:25:28 +08:00
|
|
|
void EventListenerTouchOneByOne::setSwallowTouches(bool needSwallow)
|
2013-09-03 18:22:03 +08:00
|
|
|
{
|
|
|
|
_needSwallow = needSwallow;
|
|
|
|
}
|
|
|
|
|
2013-10-12 11:25:28 +08:00
|
|
|
EventListenerTouchOneByOne* EventListenerTouchOneByOne::create()
|
2013-09-03 18:22:03 +08:00
|
|
|
{
|
2013-10-12 11:25:28 +08:00
|
|
|
auto ret = new EventListenerTouchOneByOne();
|
|
|
|
if (ret && ret->init())
|
2013-09-13 18:00:56 +08:00
|
|
|
{
|
|
|
|
ret->autorelease();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(ret);
|
|
|
|
}
|
2013-09-03 18:22:03 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-10-12 11:25:28 +08:00
|
|
|
bool EventListenerTouchOneByOne::checkAvailable()
|
2013-09-03 18:22:03 +08:00
|
|
|
{
|
2013-11-09 18:11:57 +08:00
|
|
|
if (onTouchBegan == nullptr)
|
2013-09-03 18:22:03 +08:00
|
|
|
{
|
2013-11-09 18:11:57 +08:00
|
|
|
CCASSERT(false, "Invalid EventListenerTouchOneByOne!");
|
2013-10-12 11:25:28 +08:00
|
|
|
return false;
|
2013-09-03 18:22:03 +08:00
|
|
|
}
|
2013-10-12 11:25:28 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
EventListenerTouchOneByOne* EventListenerTouchOneByOne::clone()
|
|
|
|
{
|
|
|
|
auto ret = new EventListenerTouchOneByOne();
|
|
|
|
if (ret && ret->init())
|
2013-09-03 18:22:03 +08:00
|
|
|
{
|
2013-10-12 11:25:28 +08:00
|
|
|
ret->autorelease();
|
|
|
|
|
|
|
|
ret->onTouchBegan = onTouchBegan;
|
|
|
|
ret->onTouchMoved = onTouchMoved;
|
|
|
|
ret->onTouchEnded = onTouchEnded;
|
|
|
|
ret->onTouchCancelled = onTouchCancelled;
|
|
|
|
|
|
|
|
ret->_claimedTouches = _claimedTouches;
|
|
|
|
ret->_needSwallow = _needSwallow;
|
2013-09-03 18:22:03 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-10-12 11:25:28 +08:00
|
|
|
CC_SAFE_DELETE(ret);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/////////
|
|
|
|
EventListenerTouchAllAtOnce::EventListenerTouchAllAtOnce()
|
|
|
|
: onTouchesBegan(nullptr)
|
|
|
|
, onTouchesMoved(nullptr)
|
|
|
|
, onTouchesEnded(nullptr)
|
|
|
|
, onTouchesCancelled(nullptr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
EventListenerTouchAllAtOnce::~EventListenerTouchAllAtOnce()
|
|
|
|
{
|
|
|
|
CCLOGINFO("In the destructor of EventListenerTouchAllAtOnce, %p", this);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EventListenerTouchAllAtOnce::init()
|
|
|
|
{
|
2013-10-28 16:00:01 +08:00
|
|
|
if (EventListener::init(Type::TOUCH_ALL_AT_ONCE, static_cast<ListenerID>(Type::TOUCH_ALL_AT_ONCE), nullptr))
|
2013-10-12 11:25:28 +08:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
EventListenerTouchAllAtOnce* EventListenerTouchAllAtOnce::create()
|
|
|
|
{
|
|
|
|
auto ret = new EventListenerTouchAllAtOnce();
|
|
|
|
if (ret && ret->init())
|
|
|
|
{
|
|
|
|
ret->autorelease();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(ret);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EventListenerTouchAllAtOnce::checkAvailable()
|
|
|
|
{
|
|
|
|
if (onTouchesBegan == nullptr && onTouchesMoved == nullptr
|
|
|
|
&& onTouchesEnded == nullptr && onTouchesCancelled == nullptr)
|
|
|
|
{
|
2013-11-09 18:11:57 +08:00
|
|
|
CCASSERT(false, "Invalid EventListenerTouchAllAtOnce!");
|
2013-10-12 11:25:28 +08:00
|
|
|
return false;
|
2013-09-03 18:22:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-10-12 11:25:28 +08:00
|
|
|
EventListenerTouchAllAtOnce* EventListenerTouchAllAtOnce::clone()
|
2013-09-13 16:36:25 +08:00
|
|
|
{
|
2013-10-12 11:25:28 +08:00
|
|
|
auto ret = new EventListenerTouchAllAtOnce();
|
|
|
|
if (ret && ret->init())
|
2013-09-13 18:00:56 +08:00
|
|
|
{
|
|
|
|
ret->autorelease();
|
|
|
|
|
|
|
|
ret->onTouchesBegan = onTouchesBegan;
|
|
|
|
ret->onTouchesMoved = onTouchesMoved;
|
|
|
|
ret->onTouchesEnded = onTouchesEnded;
|
|
|
|
ret->onTouchesCancelled = onTouchesCancelled;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(ret);
|
|
|
|
}
|
2013-09-13 16:36:25 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
NS_CC_END
|