mirror of https://github.com/axmolengine/axmol.git
TableView updates to provide more touch input to CCTableViewDelegate
This commit is contained in:
parent
f424da2a7e
commit
4ec9793769
|
@ -72,6 +72,7 @@ CCTableView::CCTableView()
|
||||||
, m_pCellsFreed(NULL)
|
, m_pCellsFreed(NULL)
|
||||||
, m_pDataSource(NULL)
|
, m_pDataSource(NULL)
|
||||||
, m_pTableViewDelegate(NULL)
|
, m_pTableViewDelegate(NULL)
|
||||||
|
, m_pTouchedCell(NULL)
|
||||||
, m_eOldDirection(kCCScrollViewDirectionNone)
|
, m_eOldDirection(kCCScrollViewDirectionNone)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -486,24 +487,69 @@ void CCTableView::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent)
|
||||||
if (!this->isVisible()) {
|
if (!this->isVisible()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (m_pTouches->count() == 1 && !this->isTouchMoved()) {
|
|
||||||
|
if (m_pTouchedCell) {
|
||||||
|
m_pTableViewDelegate->tableCellUnhighlight(this, m_pTouchedCell);
|
||||||
|
m_pTableViewDelegate->tableCellTouched(this, m_pTouchedCell);
|
||||||
|
|
||||||
|
m_pTouchedCell = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
CCScrollView::ccTouchEnded(pTouch, pEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CCTableView::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
|
||||||
|
{
|
||||||
|
if (!this->isVisible()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool touchResult = CCScrollView::ccTouchBegan(pTouch, pEvent);
|
||||||
|
|
||||||
|
if(m_pTouches->count() == 1) {
|
||||||
unsigned int index;
|
unsigned int index;
|
||||||
CCTableViewCell *cell;
|
|
||||||
CCPoint point;
|
CCPoint point;
|
||||||
|
|
||||||
point = this->getContainer()->convertTouchToNodeSpace(pTouch);
|
point = this->getContainer()->convertTouchToNodeSpace(pTouch);
|
||||||
|
|
||||||
if (m_eVordering == kCCTableViewFillTopDown) {
|
if (m_eVordering == kCCTableViewFillTopDown) {
|
||||||
CCSize cellSize = m_pDataSource->cellSizeForTable(this);
|
CCSize cellSize = m_pDataSource->cellSizeForTable(this);
|
||||||
point.y -= cellSize.height;
|
point.y -= cellSize.height;
|
||||||
}
|
}
|
||||||
index = this->_indexFromOffset(point);
|
|
||||||
cell = this->_cellWithIndex(index);
|
|
||||||
|
|
||||||
if (cell) {
|
index = this->_indexFromOffset(point);
|
||||||
m_pTableViewDelegate->tableCellTouched(this, cell);
|
m_pTouchedCell = this->_cellWithIndex(index);
|
||||||
|
|
||||||
|
if (m_pTouchedCell) {
|
||||||
|
m_pTableViewDelegate->tableCellHighlight(this, m_pTouchedCell);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CCScrollView::ccTouchEnded(pTouch, pEvent);
|
else if(m_pTouchedCell) {
|
||||||
|
m_pTableViewDelegate->tableCellUnhighlight(this, m_pTouchedCell);
|
||||||
|
m_pTouchedCell = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return touchResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCTableView::ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent)
|
||||||
|
{
|
||||||
|
CCScrollView::ccTouchMoved(pTouch, pEvent);
|
||||||
|
|
||||||
|
if (m_pTouchedCell && isTouchMoved()) {
|
||||||
|
m_pTableViewDelegate->tableCellUnhighlight(this, m_pTouchedCell);
|
||||||
|
m_pTouchedCell = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCTableView::ccTouchCancelled(CCTouch *pTouch, CCEvent *pEvent)
|
||||||
|
{
|
||||||
|
CCScrollView::ccTouchCancelled(pTouch, pEvent);
|
||||||
|
|
||||||
|
if (m_pTouchedCell) {
|
||||||
|
m_pTableViewDelegate->tableCellUnhighlight(this, m_pTouchedCell);
|
||||||
|
m_pTouchedCell = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_CC_EXT_END
|
NS_CC_EXT_END
|
||||||
|
|
|
@ -54,6 +54,8 @@ public:
|
||||||
* @param cell cell that is touched
|
* @param cell cell that is touched
|
||||||
*/
|
*/
|
||||||
virtual void tableCellTouched(CCTableView* table, CCTableViewCell* cell) = 0;
|
virtual void tableCellTouched(CCTableView* table, CCTableViewCell* cell) = 0;
|
||||||
|
virtual void tableCellHighlight(CCTableView* table, CCTableViewCell* cell){};
|
||||||
|
virtual void tableCellUnhighlight(CCTableView* table, CCTableViewCell* cell){};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -176,10 +178,15 @@ public:
|
||||||
|
|
||||||
virtual void scrollViewDidScroll(CCScrollView* view);
|
virtual void scrollViewDidScroll(CCScrollView* view);
|
||||||
virtual void scrollViewDidZoom(CCScrollView* view) {}
|
virtual void scrollViewDidZoom(CCScrollView* view) {}
|
||||||
|
|
||||||
|
virtual bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent);
|
||||||
|
virtual void ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent);
|
||||||
virtual void ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent);
|
virtual void ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent);
|
||||||
|
virtual void ccTouchCancelled(CCTouch *pTouch, CCEvent *pEvent);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
CCTableViewCell *m_pTouchedCell;
|
||||||
/**
|
/**
|
||||||
* vertical direction of cell filling
|
* vertical direction of cell filling
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue