void EXZoomController::ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent){ bool multitouch = _touchesDic->count() > 1; if (multitouch) { CCArray* keys = _touchesDic->allKeys(); CCTouch *touch1 = (CCTouch*)_touchesDic->objectForKey(((CCString*)keys->objectAtIndex(0))->getCString()); CCTouch *touch2 = (CCTouch*)_touchesDic->objectForKey(((CCString*)keys->objectAtIndex(1))->getCString()); CCPoint pt1 = touch1->getLocationInView(); CCPoint pt2 = touch2->getLocationInView(); endZoom(pt1, pt2); //which touch remains? // if (touch == touch2) // beginScroll(_node->convertToNodeSpace(touch1->getLocation())); // else beginScroll(_node->convertToNodeSpace(touch2->getLocation())); } else { CCArray* keys = _touchesDic->allKeys(); CCTouch *touch = (CCTouch*)_touchesDic->objectForKey(((CCString*)keys->objectAtIndex(0))->getCString()); recordScrollPoint(touch); CCPoint pt = _node->convertToNodeSpace(touch->getLocation()); endScroll(pt); //handle double-tap zooming // if (zoomOnDoubleTap /**&& [touch tapCount] == 2*/) // handleDoubleTapAt(pt); } CCSetIterator iter = pTouches->begin(); for (; iter != pTouches->end(); iter++){ CCTouch* pTouch = (CCTouch*)(*iter); _touchesDic->removeObjectForKey(CCString::createWithFormat("%d",pTouch->getID())->getCString()); } }
void HFViewport::onTouchesEnded(const std::vector<Touch*>& pTouches, Event *pEvent) { CC_ASSERT(this->m_TargetNode); if( !m_TargetNode ) return; if(pTouches.empty()) { return; } m_doubleClicked = false; switch(mFingerMap.size()) { case 1: { if(isInAutoZoom) { endZoom(); isInAutoZoom = false; mTouchMode = TouchMode_Scroll; } CCTouch* ptouch =getAnyTouchObject(pTouches); CCLOG("touchMoved posX:%f, posY:%f", ptouch->getLocation().x, ptouch->getLocation().y); if (!moveableCheck(ptouch)) { CCLOG("skip in touched moved!"); // this is a single touch action if (mTouchDelegate) { auto singleTouch = this->m_TargetNode->convertToNodeSpace(ptouch->getLocation()); CCLOG("fire single touch! x:%f,y:%f",singleTouch.x,singleTouch.y); mTouchDelegate->onSingleTouchEnd(singleTouch); mTouchDelegate->onSingleTouchEnd(ptouch); mFingerMap.clear(); } return; } CC_BREAK_IF(this->mTouchMode != TouchMode_Scroll); CCTouch* objTouch = dynamic_cast<CCTouch*>(*pTouches.begin()); CC_ASSERT(objTouch); CCLOG(" x:%f, y:%f", objTouch->getLocation().x, objTouch->getLocation().y); if (!mForceStopScroll) { endScroll(objTouch); } mIsScrollBegan = false; long time = getNowTime(); if (time - m_tTouchTime >= 80) { m_tScrollDistance = CCPointZero; } mFingerMap.clear(); } break; case 2:{ CCLOG("end zoom------- end %d, finger(s)", pTouches.size()); for (auto touchItem: pTouches) { auto touchItemP = dynamic_cast<CCTouch*>(touchItem); mFingerMap.erase(touchItemP->getID()); } if (mFingerMap.size()) { isInAutoZoom = true; mTouchMode = TouchMode_Zoom; mIsScrollBegan = false; }else { endZoom(); } } break; default: if(isInAutoZoom) { endZoom(); isInAutoZoom = false; } mIsScrollBegan = false; break; } if (pTouches.size() == 0) { m_bTouchMoved = false; } }