From 87935ac436e3adc346f1493c4d5b24f8f3aa5b09 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 26 Feb 2013 19:59:14 +0800 Subject: [PATCH] tableview touch area fix. --- extensions/GUI/CCScrollView/CCTableView.cpp | 34 +++++++++++++++---- .../TableViewTest/TableViewTestScene.cpp | 2 +- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/extensions/GUI/CCScrollView/CCTableView.cpp b/extensions/GUI/CCScrollView/CCTableView.cpp index d7151a1ca9..a1015cac21 100644 --- a/extensions/GUI/CCScrollView/CCTableView.cpp +++ b/extensions/GUI/CCScrollView/CCTableView.cpp @@ -332,7 +332,10 @@ unsigned int CCTableView::_indexFromOffset(CCPoint offset) offset.y = this->getContainer()->getContentSize().height - offset.y - cellSize.height; } index = MAX(0, this->__indexFromOffset(offset)); - index = MIN(index, maxIdx); + if (index >maxIdx) + { + index = CC_INVALID_INDEX; + } return index; } @@ -401,7 +404,11 @@ void CCTableView::scrollViewDidScroll(CCScrollView* view) offset.y = offset.y + m_tViewSize.height/this->getContainer()->getScaleY() - cellSize.height; } startIdx = this->_indexFromOffset(offset); - + if (startIdx == CC_INVALID_INDEX) + { + startIdx = uCountOfItems - 1; + } + if (m_eVordering == kCCTableViewFillTopDown) { offset.y -= m_tViewSize.height/this->getContainer()->getScaleY(); @@ -413,7 +420,11 @@ void CCTableView::scrollViewDidScroll(CCScrollView* view) offset.x += m_tViewSize.width/this->getContainer()->getScaleX(); endIdx = this->_indexFromOffset(offset); - + if (endIdx == CC_INVALID_INDEX) + { + endIdx = uCountOfItems - 1; + } + #if 0 // For Testing. CCObject* pObj; int i = 0; @@ -492,7 +503,11 @@ void CCTableView::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent) } if (m_pTouchedCell){ - if(m_pTableViewDelegate != NULL) { + CCRect bb = this->boundingBox(); + bb.origin = m_pParent->convertToWorldSpace(bb.origin); + + if (bb.containsPoint(pTouch->getLocation()) && m_pTableViewDelegate != NULL) + { m_pTableViewDelegate->tableCellUnhighlight(this, m_pTouchedCell); m_pTableViewDelegate->tableCellTouched(this, m_pTouchedCell); } @@ -523,8 +538,15 @@ bool CCTableView::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent) } index = this->_indexFromOffset(point); - m_pTouchedCell = this->cellAtIndex(index); - + if (index == CC_INVALID_INDEX) + { + m_pTouchedCell = NULL; + } + else + { + m_pTouchedCell = this->cellAtIndex(index); + } + if (m_pTouchedCell && m_pTableViewDelegate != NULL) { m_pTableViewDelegate->tableCellHighlight(this, m_pTouchedCell); } diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/TableViewTest/TableViewTestScene.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/TableViewTest/TableViewTestScene.cpp index 7bbd2e691f..9360582d3c 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/TableViewTest/TableViewTestScene.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/TableViewTest/TableViewTestScene.cpp @@ -30,7 +30,7 @@ bool TableViewTestLayer::init() this->addChild(tableView); tableView->reloadData(); - tableView = CCTableView::create(this, CCSizeMake(60, 280)); + tableView = CCTableView::create(this, CCSizeMake(60, 250)); tableView->setDirection(kCCScrollViewDirectionVertical); tableView->setPosition(ccp(winSize.width-150,winSize.height/2-120)); tableView->setDelegate(this);