void CCEGLViewProtocol::handleTouchesEndOrCancel(bool isEnd, int num, int ids[], float xs[], float ys[]) { for (int i = 0; i < num; ++i) { int id = ids[i]; float x = xs[i]; float y = ys[i]; std::map<int,int>::iterator pIndex = s_TouchesIntergerDict.find(id); if (pIndex == s_TouchesIntergerDict.end()) { CCLOG("if the index doesn't exist, it is an error"); continue; } /* Add to the set to send to the director */ { CCLOGINFO("Ending touches with id: %d, x=%f, y=%f", id, x, y); CCEvent touchEvent; touchEvent.Type = isEnd ? CCEvent::TouchEnded : CCEvent::TouchCancelled; touchEvent.Touch.TouchId = pIndex->second; touchEvent.Touch.X = (x - m_obViewPortRect.origin.x) / m_fScaleX;// * scaleFactor; touchEvent.Touch.Y = (y - m_obViewPortRect.origin.y) / m_fScaleY;// * scaleFactor; CCDirector::sharedDirector()->pushEvent(touchEvent); removeUsedIndexBit(pIndex->second); s_TouchesIntergerDict.erase(pIndex); } } }
void GLView::handleTouchesOfEndOrCancel(EventTouch::EventCode eventCode, int num, intptr_t ids[], float xs[], float ys[]) { intptr_t id = 0; float x = 0.0f; float y = 0.0f; EventTouch touchEvent; for (int i = 0; i < num; ++i) { id = ids[i]; x = xs[i]; y = ys[i]; auto iter = g_touchIdReorderMap.find(id); if (iter == g_touchIdReorderMap.end()) { CCLOG("if the index doesn't exist, it is an error"); continue; } /* Add to the set to send to the director */ Touch* touch = g_touches[iter->second]; if (touch) { CCLOGINFO("Ending touches with id: %d, x=%f, y=%f", id, x, y); touch->setTouchInfo(iter->second, (x - _viewPortRect.origin.x) / _scaleX, (y - _viewPortRect.origin.y) / _scaleY); touchEvent._touches.push_back(touch); g_touches[iter->second] = nullptr; removeUsedIndexBit(iter->second); g_touchIdReorderMap.erase(id); } else { CCLOG("Ending touches with id: %ld error", static_cast<long>(id)); return; } } if (touchEvent._touches.size() == 0) { CCLOG("touchesEnded or touchesCancel: size = 0"); return; } touchEvent._eventCode = eventCode; auto dispatcher = Director::getInstance()->getEventDispatcher(); dispatcher->dispatchEvent(&touchEvent); for (auto& touch : touchEvent._touches) { // release the touch object. touch->release(); } }
void CCEGLViewProtocol::getSetOfTouchesEndOrCancel(CCSet& set, int num, int ids[], float xs[], float ys[]) { for (int i = 0; i < num; ++i) { int id = ids[i]; float x = xs[i]; float y = ys[i]; CCInteger* pIndex = (CCInteger*) s_TouchesIntergerDict.objectForKey(id); if (pIndex == NULL) { CCLOG("if the index doesn't exist, it is an error"); continue; } /* Add to the set to send to the director */ CCTouch* pTouch = s_pTouches[pIndex->getValue()]; if (pTouch) { CCLOGINFO("Ending touches with id: %d, x=%f, y=%f", id, x, y); if (m_bIsRetinaEnabled) { pTouch->setTouchInfo(pIndex->getValue(), (x - m_obViewPortRect.origin.x), (y - m_obViewPortRect.origin.y)); } else { pTouch->setTouchInfo(pIndex->getValue(), (x - m_obViewPortRect.origin.x) / m_fScaleX, (y - m_obViewPortRect.origin.y) / m_fScaleY); } set.addObject(pTouch); // release the object pTouch->release(); s_pTouches[pIndex->getValue()] = NULL; removeUsedIndexBit(pIndex->getValue()); s_TouchesIntergerDict.removeObjectForKey(id); } else { CCLOG("Ending touches with id: %d error", id); return; } } if (set.count() == 0) { CCLOG("touchesEnded or touchesCancel: count = 0"); return; } }
void CCEGLViewProtocol::getSetOfTouchesEndOrCancel(CCSet& set, int num, int ids[], float xs[], float ys[]) { for (int i = 0; i < num; ++i) { int id = ids[i]; float x = xs[i]; float y = ys[i]; CC_CONTINUE_IF(s_TouchesIntergerDict.find(id) == s_TouchesIntergerDict.end()); int index = s_TouchesIntergerDict.at(id); /* Add to the set to send to the director */ CATouch* pTouch = s_pTouches[index]; if (pTouch) { CCLOGINFO("Ending touches with id: %d, x=%f, y=%f", id, x, y); pTouch->setTouchInfo(index, (x - m_obViewPortRect.origin.x) / m_fScaleX, (y - m_obViewPortRect.origin.y) / m_fScaleY); set.addObject(pTouch); // release the object pTouch->release(); s_pTouches[index] = NULL; removeUsedIndexBit(index); s_TouchesIntergerDict.erase(id); } else { CCLOG("Ending touches with id: %d error", id); return; } } if (set.count() == 0) { CCLOG("touchesEnded or touchesCancel: count = 0"); return; } }
bool TouchPool::handleTouch(TouchTrigger::TouchAction action,int num,intptr_t ids[],float xs[],float ys[]) { intptr_t id = 0; float x = 0.0f; float y = 0.0f; int unusedIndex = 0; TouchTrigger touchTrigger; for(int i=0;i<num;i++) { id = ids[i]; x = xs[i]; y = ys[i]; auto iter = _touchIdReorderMap.find(id); // it is a new touch if (iter == _touchIdReorderMap.end()) { if(action != TouchTrigger::TouchAction::DOWN) { FKLOG("if the index doesn't exist, it is an error"); continue; } FKLOG("id = %ld",(long int) id); unusedIndex = getUnUsedIndex(); // The touches is more than MAX_TOUCHES ? if (unusedIndex == -1) { FKLOG("The touches is more than MAX_TOUCHES, unusedIndex = %d", unusedIndex); continue; } Touch* touch = _touches[unusedIndex] = new (std::nothrow) Touch(); touch->setTouchInfo(unusedIndex, x, y); FKLOG("x = %f y = %f", touch->getLocationInView().x, touch->getLocationInView().y); _touchIdReorderMap.insert(std::make_pair(id, unusedIndex)); touchTrigger._touches.push_back(touch); } else { FKLOG("unusedindex = %d", iter->second); FKLOG("other x = %f y = %f", x, y); Touch* touch = _touches[iter->second]; if (touch) { touch->setTouchInfo(iter->second, x, y); touchTrigger._touches.push_back(touch); if(action == TouchTrigger::TouchAction::UP || action == TouchTrigger::TouchAction::CANCEL) { _touches[iter->second] = nullptr; removeUsedIndexBit(iter->second); _touchIdReorderMap.erase(id); } } else { // It is error, should return. FKLOG("Moving touches with id: %ld error", (long int)id); return false; } } } if (touchTrigger._touches.size() == 0) { FKLOG("touches: size = 0"); return false; } touchTrigger.setAction(action); bool result = dispatchTouch(&touchTrigger); if(action == TouchTrigger::TouchAction::UP || action == TouchTrigger::TouchAction::CANCEL) { for (auto& touch : touchTrigger._touches) { // release the touch object. touch->release(); } } return result; }