void CCEGLViewProtocol::handleTouchesBegin(int num, int ids[], float xs[], float ys[]) { CCSet set; 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); int nUnusedIndex = 0; // it is a new touch if (pIndex == NULL) { nUnusedIndex = getUnUsedIndex(); // The touches is more than MAX_TOUCHES ? if (nUnusedIndex == -1) { CCLOG("The touches is more than MAX_TOUCHES, nUnusedIndex = %d", nUnusedIndex); continue; } CCTouch* pTouch = s_pTouches[nUnusedIndex] = new CCTouch(); if (m_bIsRetinaEnabled) { // on iOS, though retina is enabled, the value got from os is also // relative to its original size pTouch->setTouchInfo(nUnusedIndex, (x - m_obViewPortRect.origin.x), (y - m_obViewPortRect.origin.y)); } else { pTouch->setTouchInfo(nUnusedIndex, (x - m_obViewPortRect.origin.x) / m_fScaleX, (y - m_obViewPortRect.origin.y) / m_fScaleY); } //CCLOG("x = %f y = %f", pTouch->getLocationInView().x, pTouch->getLocationInView().y); CCInteger* pInterObj = new CCInteger(nUnusedIndex); s_TouchesIntergerDict.setObject(pInterObj, id); set.addObject(pTouch); pInterObj->release(); } } if (set.count() == 0) { CCLOG("touchesBegan: count = 0"); return; } m_pDelegate->touchesBegan(&set, NULL); }
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::handleTouchesMove(int num, int ids[], float xs[], float ys[]) { CCSet set; 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; } CCLOGINFO("Moving touches with id: %d, x=%f, y=%f", id, x, y); CCTouch* pTouch = s_pTouches[pIndex->getValue()]; if (pTouch) { 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); } else { // It is error, should return. CCLOG("Moving touches with id: %d error", id); return; } } if (set.count() == 0) { CCLOG("touchesMoved: count = 0"); return; } m_pDelegate->touchesMoved(&set, NULL); }
void CCEGLViewProtocol::handleTouchesBegin(int num, int ids[], float xs[], float ys[]) { CCSet set; 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); int nUnusedIndex = 0; // it is a new touch if (pIndex == NULL) { nUnusedIndex = getUnUsedIndex(); // The touches is more than MAX_TOUCHES ? if (nUnusedIndex == -1) { CCLOG("The touches is more than MAX_TOUCHES, nUnusedIndex = %d", nUnusedIndex); continue; } CCTouch* pTouch = s_pTouches[nUnusedIndex] = new CCTouch(); pTouch->setTouchInfo(nUnusedIndex, (x - m_obViewPortRect.origin.x) / m_fScaleX, (y - m_obViewPortRect.origin.y) / m_fScaleY); //CCLOG("x = %f y = %f", pTouch->getLocationInView().x, pTouch->getLocationInView().y); CCInteger* pInterObj = new CCInteger(nUnusedIndex); s_TouchesIntergerDict.setObject(pInterObj, id); set.addObject(pTouch); pInterObj->release(); } } if (set.count() == 0) { CCLOG("touchesBegan: count = 0"); return; } CCEvent event; CCSet *allTouches= new CCSet; allTouches->autorelease(); getCurrentSetOfTouches(*allTouches); event.setAllTouches(allTouches); m_pDelegate->touchesBegan(&set, &event); }
void App::HandleTouchesEnd(int num, int ids[], float xs[], float ys[]) { int i; int id; float x; float y; CCSet set; CCTouch* pTouch; CCInteger* pIndex; for (i = 0; i < num; ++i) { id = ids[i]; x = xs[i]; y = ys[i]; pIndex = (CCInteger*)s_TouchesIntergerDict.objectForKey(id); if (pIndex == NULL) { CCLOG("if the index doesn't exist, it is an error"); continue; } pTouch = s_pTouches[pIndex->getValue()]; if (pTouch) { CCLOGINFO("Ending touches with id: %d, x=%f, y=%f", id, x, y); pTouch->setTouchInfo(pIndex->getValue(), x, y); 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; } } CCDirector::sharedDirector()->getTouchDispatcher()->touchesEnded(&set, NULL); }
void App::HandleTouchesBegin(int num, int ids[], float xs[], float ys[]) { int i; int id; int nUnusedIndex; float x; float y; CCSet set; CCTouch* pTouch; CCInteger* pIndex; CCInteger* pInterObj; for (i = 0; i < num; ++i) { id = ids[i]; x = xs[i]; y = ys[i]; pIndex = (CCInteger*)s_TouchesIntergerDict.objectForKey(id); nUnusedIndex = 0; // it is a new touch if (pIndex == NULL) { nUnusedIndex = getUnUsedIndex(); // The touches is more than MAX_TOUCHES ? if (nUnusedIndex == -1) { CCLOG("The touches is more than MAX_TOUCHES, nUnusedIndex = %d", nUnusedIndex); continue; } pTouch = s_pTouches[nUnusedIndex] = new CCTouch(); pTouch->setTouchInfo( nUnusedIndex, x, y ); pInterObj = new CCInteger(nUnusedIndex); s_TouchesIntergerDict.setObject(pInterObj, id); set.addObject(pTouch); pInterObj->release(); } } if (set.count() > 0) { CCDirector::sharedDirector()->getTouchDispatcher()->touchesBegan(&set, NULL); } }
void App::HandleTouchesMove(int num, int ids[], float xs[], float ys[]) { int i; int id; float x; float y; CCSet set; CCTouch* pTouch; CCInteger* pIndex; for (i = 0; i < num; ++i) { id = ids[i]; x = xs[i]; y = ys[i]; pIndex = (CCInteger*)s_TouchesIntergerDict.objectForKey(id); if (pIndex == NULL) { CCLOG("if the index doesn't exist, it is an error"); continue; } CCLOGINFO("Moving touches with id: %d, x=%f, y=%f", id, x, y); pTouch = s_pTouches[pIndex->getValue()]; if (pTouch) { pTouch->setTouchInfo(pIndex->getValue(), x, y); set.addObject(pTouch); } else { // It is error, should return. CCLOG("Moving touches with id: %d error", id); return; } } if (set.count() > 0) { CCDirector::sharedDirector()->getTouchDispatcher()->touchesMoved(&set, NULL); } }
void WHScrollView::responseMenu(CCTouch *pTouch, CCEvent *pEvent, bool bEnd) { if (!_touchMoved && !_dragging) { for (int i = 0; i < m_TouchLayer.size(); i++) { if (m_TouchLayerTouched[i]) { m_TouchLayerTouched[i] = false; if (canResponseMenu(pTouch)) { CCLayer* pTouchLayer = m_TouchLayer[i]; if (bEnd) pTouchLayer->onTouchEnded(pTouch, pEvent); else pTouchLayer->onTouchCancelled(pTouch, pEvent); } else { int offset = 10000; CCTouch touch; CCPoint screenPos = pTouch->getLocationInView(); screenPos.x += offset; screenPos.y += offset; touch.setTouchInfo(pTouch->getID(), screenPos.x, screenPos.y); CCLayer* pTouchLayer = m_TouchLayer[i]; pTouchLayer->onTouchMoved(&touch, pEvent); if (bEnd) pTouchLayer->onTouchEnded(&touch, pEvent); else pTouchLayer->onTouchCancelled(&touch, pEvent); } } } } }
CCTouch *CCTouch::copy() { CCTouch *copy = new CCTouch(); copy->setTouchInfo(getID(), m_point.x, m_point.y); return copy; }