bool CATableView::ccTouchBegan(CATouch *pTouch, CAEvent *pEvent) { if (!m_vTouches.empty()) { m_vTouches.replace(0, pTouch); return true; } bool isInertia = m_tInertia.getLength() < 1.0f; if (!CAScrollView::ccTouchBegan(pTouch, pEvent)) return false; if (m_bAllowsSelection && this->isScrollWindowNotOutSide() == false && isInertia) { CCPoint point = m_pContainer->convertTouchToNodeSpace(pTouch); std::map<CAIndexPath2E, CATableViewCell*>::iterator itr; for (itr=m_pUsedTableCells.begin(); itr!=m_pUsedTableCells.end(); itr++) { CATableViewCell* cell = itr->second; CC_CONTINUE_IF(cell == NULL); if (cell->getFrame().containsPoint(point) && cell->isVisible()) { CC_BREAK_IF(cell->getControlState() == CAControlStateDisabled); if (m_pHighlightedTableCells) { m_pHighlightedTableCells->setControlStateNormal(); } m_pHighlightedTableCells = cell; CC_BREAK_IF(cell->getControlState() == CAControlStateSelected); CCDelayTime* delayTime = CCDelayTime::create(0.05f); CCCallFunc* func = CCCallFunc::create(cell, callfunc_selector(CATableViewCell::setControlStateHighlighted)); CCSequence* actions = CCSequence::create(delayTime, func, NULL); m_pContainer->runAction(actions); break; } } } return true; }
bool CATableView::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent) { if (m_pTouches->count() > 0) return false; if (!CAScrollView::ccTouchBegan(pTouch, pEvent)) return false; if (m_bAllowsSelection && this->isScrollWindowNotOutSide() == false) { CCPoint point = m_pContainer->convertTouchToNodeSpace(pTouch); std::deque<CATableViewCell*>::iterator itr; for (itr=m_pTableCells.begin(); itr!=m_pTableCells.end(); itr++) { CATableViewCell* cell = *itr; if (cell->getFrame().containsPoint(point)) { CC_BREAK_IF(cell->getControlState() == CAControlStateDisabled); m_pHighlightedTableCells = cell; CC_BREAK_IF(cell->getControlState() == CAControlStateSelected); CCDelayTime* delayTime = CCDelayTime::create(0.1f); CCCallFunc* func = CCCallFunc::create(cell, callfunc_selector(CATableViewCell::setControlStateHighlighted)); CCSequence* actions = CCSequence::create(delayTime, func, NULL); actions->setTag(0xffff); this->runAction(actions); break; } } } m_tBeginPoint = pTouch->getLocation(); return true; }