[EventDispatcher] Fixing compilation error after changing of Touch(It doesn't inherit from Object).

This commit is contained in:
James Chen 2013-09-12 14:42:56 +08:00
parent 6623879f6d
commit 5d95711865
3 changed files with 33 additions and 34 deletions

View File

@ -61,7 +61,7 @@ ScrollView::ScrollView()
ScrollView::~ScrollView() ScrollView::~ScrollView()
{ {
CC_SAFE_RELEASE(_touches);
} }
ScrollView* ScrollView::create(Size size, Node* container/* = NULL*/) ScrollView* ScrollView::create(Size size, Node* container/* = NULL*/)
@ -111,8 +111,7 @@ bool ScrollView::initWithViewSize(Size size, Node *container/* = NULL*/)
setTouchEnabled(true); setTouchEnabled(true);
setTouchMode(Touch::DispatchMode::ONE_BY_ONE); setTouchMode(Touch::DispatchMode::ONE_BY_ONE);
_touches = new Array(); _touches.reserve(TouchEvent::MAX_TOUCHES);
_touches->init();
_delegate = NULL; _delegate = NULL;
_bounceable = true; _bounceable = true;
@ -136,11 +135,6 @@ bool ScrollView::init()
return this->initWithViewSize(Size(200, 200), NULL); return this->initWithViewSize(Size(200, 200), NULL);
} }
//void ScrollView::registerWithTouchDispatcher()
//{
// Director::getInstance()->getTouchDispatcher()->addTargetedDelegate(this, Layer::getTouchPriority(), false);
//}
bool ScrollView::isNodeVisible(Node* node) bool ScrollView::isNodeVisible(Node* node)
{ {
const Point offset = this->getContentOffset(); const Point offset = this->getContentOffset();
@ -189,8 +183,7 @@ void ScrollView::setTouchEnabled(bool e)
{ {
_dragging = false; _dragging = false;
_touchMoved = false; _touchMoved = false;
if(_touches) _touches.clear();
_touches->removeAllObjects();
} }
} }
@ -611,19 +604,19 @@ bool ScrollView::onTouchBegan(Touch* touch, Event* event)
Rect frame = getViewRect(); Rect frame = getViewRect();
//dispatcher does not know about clipping. reject touches outside visible bounds. //dispatcher does not know about clipping. reject touches outside visible bounds.
if (_touches->count() > 2 || if (_touches.size() > 2 ||
_touchMoved || _touchMoved ||
!frame.containsPoint(_container->convertToWorldSpace(_container->convertTouchToNodeSpace(touch)))) !frame.containsPoint(_container->convertToWorldSpace(_container->convertTouchToNodeSpace(touch))))
{ {
return false; return false;
} }
if (!_touches->containsObject(touch)) if (std::find(_touches.begin(), _touches.end(), touch) != _touches.end())
{ {
_touches->addObject(touch); _touches.push_back(touch);
} }
if (_touches->count() == 1) if (_touches.size() == 1)
{ // scrolling { // scrolling
_touchPoint = this->convertTouchToNodeSpace(touch); _touchPoint = this->convertTouchToNodeSpace(touch);
_touchMoved = false; _touchMoved = false;
@ -631,13 +624,13 @@ bool ScrollView::onTouchBegan(Touch* touch, Event* event)
_scrollDistance = Point(0.0f, 0.0f); _scrollDistance = Point(0.0f, 0.0f);
_touchLength = 0.0f; _touchLength = 0.0f;
} }
else if (_touches->count() == 2) else if (_touches.size() == 2)
{ {
_touchPoint = (this->convertTouchToNodeSpace((Touch*)_touches->getObjectAtIndex(0)).getMidpoint( _touchPoint = (this->convertTouchToNodeSpace(_touches[0]).getMidpoint(
this->convertTouchToNodeSpace((Touch*)_touches->getObjectAtIndex(1)))); this->convertTouchToNodeSpace(_touches[1])));
_touchLength = _container->convertTouchToNodeSpace((Touch*)_touches->getObjectAtIndex(0)).getDistance( _touchLength = _container->convertTouchToNodeSpace(_touches[0]).getDistance(
_container->convertTouchToNodeSpace((Touch*)_touches->getObjectAtIndex(1))); _container->convertTouchToNodeSpace(_touches[1]));
_dragging = false; _dragging = false;
} }
@ -651,9 +644,9 @@ void ScrollView::onTouchMoved(Touch* touch, Event* event)
return; return;
} }
if (_touches->containsObject(touch)) if (std::find(_touches.begin(), _touches.end(), touch) != _touches.end())
{ {
if (_touches->count() == 1 && _dragging) if (_touches.size() == 1 && _dragging)
{ // scrolling { // scrolling
Point moveDistance, newPoint, maxInset, minInset; Point moveDistance, newPoint, maxInset, minInset;
Rect frame; Rect frame;
@ -661,7 +654,7 @@ void ScrollView::onTouchMoved(Touch* touch, Event* event)
frame = getViewRect(); frame = getViewRect();
newPoint = this->convertTouchToNodeSpace((Touch*)_touches->getObjectAtIndex(0)); newPoint = this->convertTouchToNodeSpace(_touches[0]);
moveDistance = newPoint - _touchPoint; moveDistance = newPoint - _touchPoint;
float dis = 0.0f; float dis = 0.0f;
@ -716,10 +709,10 @@ void ScrollView::onTouchMoved(Touch* touch, Event* event)
this->setContentOffset(Point(newX, newY)); this->setContentOffset(Point(newX, newY));
} }
} }
else if (_touches->count() == 2 && !_dragging) else if (_touches.size() == 2 && !_dragging)
{ {
const float len = _container->convertTouchToNodeSpace((Touch*)_touches->getObjectAtIndex(0)).getDistance( const float len = _container->convertTouchToNodeSpace(_touches[0]).getDistance(
_container->convertTouchToNodeSpace((Touch*)_touches->getObjectAtIndex(1))); _container->convertTouchToNodeSpace(_touches[1]));
this->setZoomScale(this->getZoomScale()*len/_touchLength); this->setZoomScale(this->getZoomScale()*len/_touchLength);
} }
} }
@ -731,16 +724,19 @@ void ScrollView::onTouchEnded(Touch* touch, Event* event)
{ {
return; return;
} }
if (_touches->containsObject(touch))
auto touchIter = std::find(_touches.begin(), _touches.end(), touch);
if (touchIter != _touches.end())
{ {
if (_touches->count() == 1 && _touchMoved) if (_touches.size() == 1 && _touchMoved)
{ {
this->schedule(schedule_selector(ScrollView::deaccelerateScrolling)); this->schedule(schedule_selector(ScrollView::deaccelerateScrolling));
} }
_touches->removeObject(touch); _touches.erase(touchIter);
} }
if (_touches->count() == 0) if (_touches.size() == 0)
{ {
_dragging = false; _dragging = false;
_touchMoved = false; _touchMoved = false;
@ -753,8 +749,11 @@ void ScrollView::onTouchCancelled(Touch* touch, Event* event)
{ {
return; return;
} }
_touches->removeObject(touch);
if (_touches->count() == 0) auto touchIter = std::find(_touches.begin(), _touches.end(), touch);
_touches.erase(touchIter);
if (_touches.size() == 0)
{ {
_dragging = false; _dragging = false;
_touchMoved = false; _touchMoved = false;

View File

@ -304,9 +304,9 @@ protected:
*/ */
float _touchLength; float _touchLength;
/** /**
* UITouch objects to detect multitouch * Touch objects to detect multitouch
*/ */
Array* _touches; std::vector<Touch*> _touches;
/** /**
* size to clip. Node boundingBox uses contentSize directly. * size to clip. Node boundingBox uses contentSize directly.
* It's semantically different what it actually means to common scroll views. * It's semantically different what it actually means to common scroll views.

View File

@ -592,7 +592,7 @@ bool TableView::onTouchBegan(Touch *pTouch, Event *pEvent)
bool touchResult = ScrollView::onTouchBegan(pTouch, pEvent); bool touchResult = ScrollView::onTouchBegan(pTouch, pEvent);
if(_touches->count() == 1) { if(_touches.size() == 1) {
unsigned int index; unsigned int index;
Point point; Point point;