issue #1458: Updated project configuration for all platforms.

CCTableView::viewWithSource --> CCTableView::create, adding TableViewTest.
This commit is contained in:
James Chen 2012-09-10 13:39:12 +08:00
parent 554b1709c3
commit 1460f4e42f
12 changed files with 166 additions and 149 deletions

View File

@ -145,6 +145,9 @@ OBJECTS = ../actions/CCAction.o \
../../extensions/CCBReader/CCSpriteLoader.o \ ../../extensions/CCBReader/CCSpriteLoader.o \
../../extensions/CCBReader/CCLayerLoader.o \ ../../extensions/CCBReader/CCLayerLoader.o \
../../extensions/GUI/CCScrollView/CCScrollView.o \ ../../extensions/GUI/CCScrollView/CCScrollView.o \
../../extensions/GUI/CCScrollView/CCSorting.o \
../../extensions/GUI/CCScrollView/CCTableView.o \
../../extensions/GUI/CCScrollView/CCTableViewCell.o \
../../extensions/GUI/CCControlExtension/CCControlButton.o \ ../../extensions/GUI/CCControlExtension/CCControlButton.o \
../../extensions/GUI/CCControlExtension/CCControlColourPicker.o \ ../../extensions/GUI/CCControlExtension/CCControlColourPicker.o \
../../extensions/GUI/CCControlExtension/CCControl.o \ ../../extensions/GUI/CCControlExtension/CCControl.o \

View File

@ -1 +1 @@
e78f546d2199a6e37906db590c8a47033f3febd8 6dfcf25474cd85fc1f77e3578c3b54357cdc0446

View File

@ -35,6 +35,9 @@ GUI/CCControlExtension/CCMenuPassive.cpp \
GUI/CCControlExtension/CCScale9Sprite.cpp \ GUI/CCControlExtension/CCScale9Sprite.cpp \
GUI/CCControlExtension/CCSpacer.cpp \ GUI/CCControlExtension/CCSpacer.cpp \
GUI/CCScrollView/CCScrollView.cpp \ GUI/CCScrollView/CCScrollView.cpp \
GUI/CCScrollView/CCTableView.cpp \
GUI/CCScrollView/CCTableViewCell.cpp \
GUI/CCScrollView/CCSorting.cpp \
GUI/CCEditBox/CCEditBox.cpp \ GUI/CCEditBox/CCEditBox.cpp \
GUI/CCEditBox/CCEditBoxImplAndroid.cpp \ GUI/CCEditBox/CCEditBoxImplAndroid.cpp \
network/HttpClient.cpp network/HttpClient.cpp

View File

@ -37,6 +37,7 @@
#include "CCDirector.h" #include "CCDirector.h"
#include "kazmath/GL/matrix.h" #include "kazmath/GL/matrix.h"
#include "touch_dispatcher/CCTouch.h" #include "touch_dispatcher/CCTouch.h"
#include "CCEGLView.h"
NS_CC_EXT_BEGIN NS_CC_EXT_BEGIN
@ -53,7 +54,7 @@ CCScrollView::CCScrollView()
, m_pDelegate(NULL) , m_pDelegate(NULL)
, m_bDragging(false) , m_bDragging(false)
, m_bBounceable(false) , m_bBounceable(false)
, m_eDirection(CCScrollViewDirectionBoth) , m_eDirection(kCCScrollViewDirectionBoth)
, m_bClippingToBounds(false) , m_bClippingToBounds(false)
, m_pContainer(NULL) , m_pContainer(NULL)
, m_bTouchMoved(false) , m_bTouchMoved(false)
@ -130,7 +131,7 @@ bool CCScrollView::initWithViewSize(CCSize size, CCNode *container/* = NULL*/)
m_bBounceable = true; m_bBounceable = true;
m_bClippingToBounds = true; m_bClippingToBounds = true;
//m_pContainer->setContentSize(CCSizeZero); //m_pContainer->setContentSize(CCSizeZero);
m_eDirection = CCScrollViewDirectionBoth; m_eDirection = kCCScrollViewDirectionBoth;
m_pContainer->setPosition(ccp(0.0f, 0.0f)); m_pContainer->setPosition(ccp(0.0f, 0.0f));
m_fTouchLength = 0.0f; m_fTouchLength = 0.0f;
@ -347,13 +348,13 @@ void CCScrollView::relocateContainer(bool animated)
newX = oldPoint.x; newX = oldPoint.x;
newY = oldPoint.y; newY = oldPoint.y;
if (m_eDirection == CCScrollViewDirectionBoth || m_eDirection == CCScrollViewDirectionHorizontal) if (m_eDirection == kCCScrollViewDirectionBoth || m_eDirection == kCCScrollViewDirectionHorizontal)
{ {
newX = MIN(newX, max.x); newX = MIN(newX, max.x);
newX = MAX(newX, min.x); newX = MAX(newX, min.x);
} }
if (m_eDirection == CCScrollViewDirectionBoth || m_eDirection == CCScrollViewDirectionVertical) if (m_eDirection == kCCScrollViewDirectionBoth || m_eDirection == kCCScrollViewDirectionVertical)
{ {
newY = MIN(newY, max.y); newY = MIN(newY, max.y);
newY = MAX(newY, min.y); newY = MAX(newY, min.y);
@ -504,10 +505,10 @@ void CCScrollView::beforeDraw()
glEnable(GL_SCISSOR_TEST); glEnable(GL_SCISSOR_TEST);
float s = this->getScale(); float s = this->getScale();
CCDirector *director = CCDirector::sharedDirector(); // CCDirector *director = CCDirector::sharedDirector();
s *= director->getContentScaleFactor(); // s *= director->getContentScaleFactor();
CCEGLView::sharedOpenGLView()->setScissorInPoints(screenPos.x*s, screenPos.y*s, m_tViewSize.width*s, m_tViewSize.height*s);
glScissor((GLint)screenPos.x, (GLint)screenPos.y, (GLsizei)(m_tViewSize.width*s), (GLsizei)(m_tViewSize.height*s)); //glScissor((GLint)screenPos.x, (GLint)screenPos.y, (GLsizei)(m_tViewSize.width*s), (GLsizei)(m_tViewSize.height*s));
} }
} }
@ -657,10 +658,10 @@ void CCScrollView::ccTouchMoved(CCTouch* touch, CCEvent* event)
{ {
switch (m_eDirection) switch (m_eDirection)
{ {
case CCScrollViewDirectionVertical: case kCCScrollViewDirectionVertical:
moveDistance = ccp(0.0f, moveDistance.y); moveDistance = ccp(0.0f, moveDistance.y);
break; break;
case CCScrollViewDirectionHorizontal: case kCCScrollViewDirectionHorizontal:
moveDistance = ccp(moveDistance.x, 0.0f); moveDistance = ccp(moveDistance.x, 0.0f);
break; break;
default: default:

View File

@ -42,10 +42,10 @@ NS_CC_EXT_BEGIN
*/ */
typedef enum { typedef enum {
CCScrollViewDirectionNone = -1, kCCScrollViewDirectionNone = -1,
CCScrollViewDirectionHorizontal = 0, kCCScrollViewDirectionHorizontal = 0,
CCScrollViewDirectionVertical, kCCScrollViewDirectionVertical,
CCScrollViewDirectionBoth kCCScrollViewDirectionBoth
} CCScrollViewDirection; } CCScrollViewDirection;
class CCScrollView; class CCScrollView;

View File

@ -37,12 +37,12 @@
NS_CC_EXT_BEGIN NS_CC_EXT_BEGIN
CCTableView* CCTableView::viewWithDataSource(CCTableViewDataSource* dataSource, CCSize size) CCTableView* CCTableView::create(CCTableViewDataSource* dataSource, CCSize size)
{ {
return CCTableView::viewWithDataSource(dataSource, size, NULL); return CCTableView::create(dataSource, size, NULL);
} }
CCTableView* CCTableView::viewWithDataSource(CCTableViewDataSource* dataSource, CCSize size, CCNode *container) CCTableView* CCTableView::create(CCTableViewDataSource* dataSource, CCSize size, CCNode *container)
{ {
CCTableView *table = new CCTableView(); CCTableView *table = new CCTableView();
table->initWithViewSize(size, container); table->initWithViewSize(size, container);
@ -57,12 +57,12 @@ bool CCTableView::initWithViewSize(CCSize size, CCNode* container/* = NULL*/)
{ {
if (CCScrollView::initWithViewSize(size,container)) if (CCScrollView::initWithViewSize(size,container))
{ {
cellsUsed_ = new CCArrayForObjectSorting(); m_pCellsUsed = new CCArrayForObjectSorting();
cellsFreed_ = new CCArrayForObjectSorting(); m_pCellsFreed = new CCArrayForObjectSorting();
indices_ = new std::set<unsigned int>(); m_pIndices = new std::set<unsigned int>();
tDelegate_ = NULL; m_pTableViewDelegate = NULL;
vordering_ = CCTableViewFillBottomUp; m_eVordering = kCCTableViewFillBottomUp;
this->setDirection(CCScrollViewDirectionVertical); this->setDirection(kCCScrollViewDirectionVertical);
CCScrollView::setDelegate(this); CCScrollView::setDelegate(this);
return true; return true;
@ -71,28 +71,28 @@ bool CCTableView::initWithViewSize(CCSize size, CCNode* container/* = NULL*/)
} }
CCTableView::CCTableView() CCTableView::CCTableView()
: indices_(NULL) : m_pIndices(NULL)
, cellsUsed_(NULL) , m_pCellsUsed(NULL)
, cellsFreed_(NULL) , m_pCellsFreed(NULL)
, dataSource_(NULL) , m_pDataSource(NULL)
, tDelegate_(NULL) , m_pTableViewDelegate(NULL)
, m_eOldDirection(CCScrollViewDirectionNone) , m_eOldDirection(kCCScrollViewDirectionNone)
{ {
} }
CCTableView::~CCTableView() CCTableView::~CCTableView()
{ {
CC_SAFE_DELETE(indices_); CC_SAFE_DELETE(m_pIndices);
CC_SAFE_RELEASE(cellsUsed_); CC_SAFE_RELEASE(m_pCellsUsed);
CC_SAFE_RELEASE(cellsFreed_); CC_SAFE_RELEASE(m_pCellsFreed);
} }
void CCTableView::setVerticalFillOrder(CCTableViewVerticalFillOrder fillOrder) void CCTableView::setVerticalFillOrder(CCTableViewVerticalFillOrder fillOrder)
{ {
if (vordering_ != fillOrder) { if (m_eVordering != fillOrder) {
vordering_ = fillOrder; m_eVordering = fillOrder;
if (cellsUsed_->count() > 0) { if (m_pCellsUsed->count() > 0) {
this->reloadData(); this->reloadData();
} }
} }
@ -100,16 +100,16 @@ void CCTableView::setVerticalFillOrder(CCTableViewVerticalFillOrder fillOrder)
CCTableViewVerticalFillOrder CCTableView::getVerticalFillOrder() CCTableViewVerticalFillOrder CCTableView::getVerticalFillOrder()
{ {
return vordering_; return m_eVordering;
} }
void CCTableView::reloadData() void CCTableView::reloadData()
{ {
CCObject* pObj = NULL; CCObject* pObj = NULL;
CCARRAY_FOREACH(cellsUsed_, pObj) CCARRAY_FOREACH(m_pCellsUsed, pObj)
{ {
CCTableViewCell* cell = (CCTableViewCell*)pObj; CCTableViewCell* cell = (CCTableViewCell*)pObj;
cellsFreed_->addObject(cell); m_pCellsFreed->addObject(cell);
cell->reset(); cell->reset();
if (cell->getParent() == this->getContainer()) if (cell->getParent() == this->getContainer())
{ {
@ -117,12 +117,12 @@ void CCTableView::reloadData()
} }
} }
indices_->clear(); m_pIndices->clear();
cellsUsed_->release(); m_pCellsUsed->release();
cellsUsed_ = new CCArrayForObjectSorting(); m_pCellsUsed = new CCArrayForObjectSorting();
this->_updateContentSize(); this->_updateContentSize();
if (dataSource_->numberOfCellsInTableView(this) > 0) if (m_pDataSource->numberOfCellsInTableView(this) > 0)
{ {
this->scrollViewDidScroll(this); this->scrollViewDidScroll(this);
} }
@ -135,7 +135,7 @@ CCTableViewCell *CCTableView::cellAtIndex(unsigned int idx)
void CCTableView::updateCellAtIndex(unsigned int idx) void CCTableView::updateCellAtIndex(unsigned int idx)
{ {
if (idx == CC_INVALID_INDEX || idx > dataSource_->numberOfCellsInTableView(this)-1) if (idx == CC_INVALID_INDEX || idx > m_pDataSource->numberOfCellsInTableView(this)-1)
{ {
return; return;
} }
@ -146,34 +146,34 @@ void CCTableView::updateCellAtIndex(unsigned int idx)
if (cell) { if (cell) {
this->_moveCellOutOfSight(cell); this->_moveCellOutOfSight(cell);
} }
cell = dataSource_->tableCellAtIndex(this, idx); cell = m_pDataSource->tableCellAtIndex(this, idx);
this->_setIndexForCell(idx, cell); this->_setIndexForCell(idx, cell);
this->_addCellIfNecessary(cell); this->_addCellIfNecessary(cell);
} }
void CCTableView::insertCellAtIndex(unsigned int idx) void CCTableView::insertCellAtIndex(unsigned int idx)
{ {
if (idx == CC_INVALID_INDEX || idx > dataSource_->numberOfCellsInTableView(this)-1) { if (idx == CC_INVALID_INDEX || idx > m_pDataSource->numberOfCellsInTableView(this)-1) {
return; return;
} }
CCTableViewCell *cell; CCTableViewCell *cell;
int newIdx; int newIdx;
cell = (CCTableViewCell*)cellsUsed_->objectWithObjectID(idx); cell = (CCTableViewCell*)m_pCellsUsed->objectWithObjectID(idx);
if (cell) if (cell)
{ {
newIdx = cellsUsed_->indexOfSortedObject(cell); newIdx = m_pCellsUsed->indexOfSortedObject(cell);
for (unsigned int i=newIdx; i<cellsUsed_->count(); i++) for (unsigned int i=newIdx; i<m_pCellsUsed->count(); i++)
{ {
cell = (CCTableViewCell*)cellsUsed_->objectAtIndex(i); cell = (CCTableViewCell*)m_pCellsUsed->objectAtIndex(i);
this->_setIndexForCell(cell->getIdx()+1, cell); this->_setIndexForCell(cell->getIdx()+1, cell);
} }
} }
// [indices_ shiftIndexesStartingAtIndex:idx by:1]; // [m_pIndices shiftIndexesStartingAtIndex:idx by:1];
//insert a new cell //insert a new cell
cell = dataSource_->tableCellAtIndex(this, idx); cell = m_pDataSource->tableCellAtIndex(this, idx);
this->_setIndexForCell(idx, cell); this->_setIndexForCell(idx, cell);
this->_addCellIfNecessary(cell); this->_addCellIfNecessary(cell);
@ -182,7 +182,7 @@ void CCTableView::insertCellAtIndex(unsigned int idx)
void CCTableView::removeCellAtIndex(unsigned int idx) void CCTableView::removeCellAtIndex(unsigned int idx)
{ {
if (idx == CC_INVALID_INDEX || idx > dataSource_->numberOfCellsInTableView(this)-1) { if (idx == CC_INVALID_INDEX || idx > m_pDataSource->numberOfCellsInTableView(this)-1) {
return; return;
} }
@ -194,15 +194,15 @@ void CCTableView::removeCellAtIndex(unsigned int idx)
return; return;
} }
newIdx = cellsUsed_->indexOfSortedObject(cell); newIdx = m_pCellsUsed->indexOfSortedObject(cell);
//remove first //remove first
this->_moveCellOutOfSight(cell); this->_moveCellOutOfSight(cell);
indices_->erase(idx); m_pIndices->erase(idx);
// [indices_ shiftIndexesStartingAtIndex:idx+1 by:-1]; // [m_pIndices shiftIndexesStartingAtIndex:idx+1 by:-1];
for (unsigned int i=cellsUsed_->count()-1; i > newIdx; i--) { for (unsigned int i=m_pCellsUsed->count()-1; i > newIdx; i--) {
cell = (CCTableViewCell*)cellsUsed_->objectAtIndex(i); cell = (CCTableViewCell*)m_pCellsUsed->objectAtIndex(i);
this->_setIndexForCell(cell->getIdx()-1, cell); this->_setIndexForCell(cell->getIdx()-1, cell);
} }
} }
@ -211,12 +211,12 @@ CCTableViewCell *CCTableView::dequeueCell()
{ {
CCTableViewCell *cell; CCTableViewCell *cell;
if (cellsFreed_->count() == 0) { if (m_pCellsFreed->count() == 0) {
cell = NULL; cell = NULL;
} else { } else {
cell = (CCTableViewCell*)cellsFreed_->objectAtIndex(0); cell = (CCTableViewCell*)m_pCellsFreed->objectAtIndex(0);
cell->retain(); cell->retain();
cellsFreed_->removeObjectAtIndex(0); m_pCellsFreed->removeObjectAtIndex(0);
cell->autorelease(); cell->autorelease();
} }
return cell; return cell;
@ -228,9 +228,9 @@ void CCTableView::_addCellIfNecessary(CCTableViewCell * cell)
{ {
this->getContainer()->addChild(cell); this->getContainer()->addChild(cell);
} }
cellsUsed_->insertSortedObject(cell); m_pCellsUsed->insertSortedObject(cell);
indices_->insert(cell->getIdx()); m_pIndices->insert(cell->getIdx());
// [indices_ addIndex:cell.idx]; // [m_pIndices addIndex:cell.idx];
} }
void CCTableView::_updateContentSize() void CCTableView::_updateContentSize()
@ -238,12 +238,12 @@ void CCTableView::_updateContentSize()
CCSize size, cellSize; CCSize size, cellSize;
unsigned int cellCount; unsigned int cellCount;
cellSize = dataSource_->cellSizeForTable(this); cellSize = m_pDataSource->cellSizeForTable(this);
cellCount = dataSource_->numberOfCellsInTableView(this); cellCount = m_pDataSource->numberOfCellsInTableView(this);
switch (this->getDirection()) switch (this->getDirection())
{ {
case CCScrollViewDirectionHorizontal: case kCCScrollViewDirectionHorizontal:
size = CCSizeMake(cellCount * cellSize.width, cellSize.height); size = CCSizeMake(cellCount * cellSize.width, cellSize.height);
break; break;
default: default:
@ -254,7 +254,7 @@ void CCTableView::_updateContentSize()
if (m_eOldDirection != m_eDirection) if (m_eOldDirection != m_eDirection)
{ {
if (m_eDirection == CCScrollViewDirectionHorizontal) if (m_eDirection == kCCScrollViewDirectionHorizontal)
{ {
this->setContentOffset(ccp(0,0)); this->setContentOffset(ccp(0,0));
} }
@ -271,8 +271,8 @@ CCPoint CCTableView::_offsetFromIndex(unsigned int index)
{ {
CCPoint offset = this->__offsetFromIndex(index); CCPoint offset = this->__offsetFromIndex(index);
const CCSize cellSize = dataSource_->cellSizeForTable(this); const CCSize cellSize = m_pDataSource->cellSizeForTable(this);
if (vordering_ == CCTableViewFillTopDown) { if (m_eVordering == kCCTableViewFillTopDown) {
offset.y = this->getContainer()->getContentSize().height - offset.y - cellSize.height; offset.y = this->getContainer()->getContentSize().height - offset.y - cellSize.height;
} }
return offset; return offset;
@ -283,9 +283,9 @@ CCPoint CCTableView::__offsetFromIndex(unsigned int index)
CCPoint offset; CCPoint offset;
CCSize cellSize; CCSize cellSize;
cellSize = dataSource_->cellSizeForTable(this); cellSize = m_pDataSource->cellSizeForTable(this);
switch (this->getDirection()) { switch (this->getDirection()) {
case CCScrollViewDirectionHorizontal: case kCCScrollViewDirectionHorizontal:
offset = ccp(cellSize.width * index, 0.0f); offset = ccp(cellSize.width * index, 0.0f);
break; break;
default: default:
@ -299,10 +299,10 @@ CCPoint CCTableView::__offsetFromIndex(unsigned int index)
unsigned int CCTableView::_indexFromOffset(CCPoint offset) unsigned int CCTableView::_indexFromOffset(CCPoint offset)
{ {
int index = 0; int index = 0;
const int maxIdx = dataSource_->numberOfCellsInTableView(this)-1; const int maxIdx = m_pDataSource->numberOfCellsInTableView(this)-1;
const CCSize cellSize = dataSource_->cellSizeForTable(this); const CCSize cellSize = m_pDataSource->cellSizeForTable(this);
if (vordering_ == CCTableViewFillTopDown) { if (m_eVordering == kCCTableViewFillTopDown) {
offset.y = this->getContainer()->getContentSize().height - offset.y - cellSize.height; offset.y = this->getContainer()->getContentSize().height - offset.y - cellSize.height;
} }
index = MAX(0, this->__indexFromOffset(offset)); index = MAX(0, this->__indexFromOffset(offset));
@ -316,10 +316,10 @@ int CCTableView::__indexFromOffset(CCPoint offset)
int index = 0; int index = 0;
CCSize cellSize; CCSize cellSize;
cellSize = dataSource_->cellSizeForTable(this); cellSize = m_pDataSource->cellSizeForTable(this);
switch (this->getDirection()) { switch (this->getDirection()) {
case CCScrollViewDirectionHorizontal: case kCCScrollViewDirectionHorizontal:
index = offset.x/cellSize.width; index = offset.x/cellSize.width;
break; break;
default: default:
@ -336,10 +336,10 @@ CCTableViewCell* CCTableView::_cellWithIndex(unsigned int cellIndex)
found = NULL; found = NULL;
// if ([indices_ containsIndex:cellIndex]) // if ([m_pIndices containsIndex:cellIndex])
if (indices_->find(cellIndex) != indices_->end()) if (m_pIndices->find(cellIndex) != m_pIndices->end())
{ {
found = (CCTableViewCell *)cellsUsed_->objectWithObjectID(cellIndex); found = (CCTableViewCell *)m_pCellsUsed->objectWithObjectID(cellIndex);
} }
return found; return found;
@ -347,10 +347,10 @@ CCTableViewCell* CCTableView::_cellWithIndex(unsigned int cellIndex)
void CCTableView::_moveCellOutOfSight(CCTableViewCell *cell) void CCTableView::_moveCellOutOfSight(CCTableViewCell *cell)
{ {
cellsFreed_->addObject(cell); m_pCellsFreed->addObject(cell);
cellsUsed_->removeSortedObject(cell); m_pCellsUsed->removeSortedObject(cell);
indices_->erase(cell->getIdx()); m_pIndices->erase(cell->getIdx());
// [indices_ removeIndex:cell.idx]; // [m_pIndices removeIndex:cell.idx];
cell->reset(); cell->reset();
if (cell->getParent() == this->getContainer()) { if (cell->getParent() == this->getContainer()) {
this->getContainer()->removeChild(cell, true);; this->getContainer()->removeChild(cell, true);;
@ -366,21 +366,20 @@ void CCTableView::_setIndexForCell(unsigned int index, CCTableViewCell *cell)
void CCTableView::scrollViewDidScroll(CCScrollView* view) void CCTableView::scrollViewDidScroll(CCScrollView* view)
{ {
CCLOG("container pos x = %f, y = %f", getContainer()->getPosition().x, getContainer()->getPosition().y);
unsigned int startIdx = 0, endIdx = 0, idx = 0, maxIdx = 0; unsigned int startIdx = 0, endIdx = 0, idx = 0, maxIdx = 0;
CCPoint offset; CCPoint offset;
offset = ccpMult(this->getContentOffset(), -1); offset = ccpMult(this->getContentOffset(), -1);
maxIdx = MAX(dataSource_->numberOfCellsInTableView(this)-1, 0); maxIdx = MAX(m_pDataSource->numberOfCellsInTableView(this)-1, 0);
const CCSize cellSize = dataSource_->cellSizeForTable(this); const CCSize cellSize = m_pDataSource->cellSizeForTable(this);
if (vordering_ == CCTableViewFillTopDown) { if (m_eVordering == kCCTableViewFillTopDown) {
offset.y = offset.y + m_tViewSize.height/this->getContainer()->getScaleY() - cellSize.height; offset.y = offset.y + m_tViewSize.height/this->getContainer()->getScaleY() - cellSize.height;
} }
startIdx = this->_indexFromOffset(offset); startIdx = this->_indexFromOffset(offset);
if (vordering_ == CCTableViewFillTopDown) if (m_eVordering == kCCTableViewFillTopDown)
{ {
offset.y -= m_tViewSize.height/this->getContainer()->getScaleY(); offset.y -= m_tViewSize.height/this->getContainer()->getScaleY();
} }
@ -392,9 +391,10 @@ void CCTableView::scrollViewDidScroll(CCScrollView* view)
endIdx = this->_indexFromOffset(offset); endIdx = this->_indexFromOffset(offset);
#if 0 // For Testing.
CCObject* pObj; CCObject* pObj;
int i = 0; int i = 0;
CCARRAY_FOREACH(cellsUsed_, pObj) CCARRAY_FOREACH(m_pCellsUsed, pObj)
{ {
CCTableViewCell* pCell = (CCTableViewCell*)pObj; CCTableViewCell* pCell = (CCTableViewCell*)pObj;
CCLog("cells Used index %d, value = %d", i, pCell->getIdx()); CCLog("cells Used index %d, value = %d", i, pCell->getIdx());
@ -402,54 +402,59 @@ void CCTableView::scrollViewDidScroll(CCScrollView* view)
} }
CCLog("---------------------------------------"); CCLog("---------------------------------------");
i = 0; i = 0;
CCARRAY_FOREACH(cellsFreed_, pObj) CCARRAY_FOREACH(m_pCellsFreed, pObj)
{ {
CCTableViewCell* pCell = (CCTableViewCell*)pObj; CCTableViewCell* pCell = (CCTableViewCell*)pObj;
CCLog("cells freed index %d, value = %d", i, pCell->getIdx()); CCLog("cells freed index %d, value = %d", i, pCell->getIdx());
i++; i++;
} }
CCLog("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); CCLog("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
if (cellsUsed_->count() > 0) #endif
if (m_pCellsUsed->count() > 0)
{ {
CCTableViewCell* cell = (CCTableViewCell*)cellsUsed_->objectAtIndex(0); CCTableViewCell* cell = (CCTableViewCell*)m_pCellsUsed->objectAtIndex(0);
idx = cell->getIdx(); idx = cell->getIdx();
while(idx <startIdx) while(idx <startIdx)
{ {
this->_moveCellOutOfSight(cell); this->_moveCellOutOfSight(cell);
if (cellsUsed_->count() > 0) { if (m_pCellsUsed->count() > 0)
cell = (CCTableViewCell*)cellsUsed_->objectAtIndex(0); {
cell = (CCTableViewCell*)m_pCellsUsed->objectAtIndex(0);
idx = cell->getIdx(); idx = cell->getIdx();
} else { }
else
{
break; break;
} }
CCLog("idx 0 = %d", idx);
} }
} }
if (cellsUsed_->count() > 0) if (m_pCellsUsed->count() > 0)
{ {
CCTableViewCell *cell = (CCTableViewCell*)cellsUsed_->lastObject(); CCTableViewCell *cell = (CCTableViewCell*)m_pCellsUsed->lastObject();
idx = cell->getIdx(); idx = cell->getIdx();
while(idx <= maxIdx && idx > endIdx) while(idx <= maxIdx && idx > endIdx)
{ {
this->_moveCellOutOfSight(cell); this->_moveCellOutOfSight(cell);
if (cellsUsed_->count() > 0) if (m_pCellsUsed->count() > 0)
{ {
cell = (CCTableViewCell*)cellsUsed_->lastObject(); cell = (CCTableViewCell*)m_pCellsUsed->lastObject();
idx = cell->getIdx(); idx = cell->getIdx();
} else { }
else
{
break; break;
} }
CCLog("idx 1 = %d, maxIdx = %d, endIdx = %d", idx, maxIdx, endIdx);
} }
} }
for (unsigned int i=startIdx; i <= endIdx; i++) for (unsigned int i=startIdx; i <= endIdx; i++)
{ {
//if ([indices_ containsIndex:i]) //if ([m_pIndices containsIndex:i])
if (indices_->find(i) != indices_->end()) if (m_pIndices->find(i) != m_pIndices->end())
{ {
continue; continue;
} }
@ -468,15 +473,15 @@ void CCTableView::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent)
CCPoint point; CCPoint point;
point = this->getContainer()->convertTouchToNodeSpace(pTouch); point = this->getContainer()->convertTouchToNodeSpace(pTouch);
if (vordering_ == CCTableViewFillTopDown) { if (m_eVordering == kCCTableViewFillTopDown) {
CCSize cellSize = dataSource_->cellSizeForTable(this); CCSize cellSize = m_pDataSource->cellSizeForTable(this);
point.y -= cellSize.height; point.y -= cellSize.height;
} }
index = this->_indexFromOffset(point); index = this->_indexFromOffset(point);
cell = this->_cellWithIndex(index); cell = this->_cellWithIndex(index);
if (cell) { if (cell) {
tDelegate_->table_cellTouched(this, cell); m_pTableViewDelegate->tableCellTouched(this, cell);
} }
} }
CCScrollView::ccTouchEnded(pTouch, pEvent); CCScrollView::ccTouchEnded(pTouch, pEvent);

View File

@ -42,8 +42,8 @@ class CCTableView;
class CCArrayForObjectSorting; class CCArrayForObjectSorting;
typedef enum { typedef enum {
CCTableViewFillTopDown, kCCTableViewFillTopDown,
CCTableViewFillBottomUp kCCTableViewFillBottomUp
} CCTableViewVerticalFillOrder; } CCTableViewVerticalFillOrder;
/** /**
@ -58,7 +58,7 @@ public:
* @param table table contains the given cell * @param table table contains the given cell
* @param cell cell that is touched * @param cell cell that is touched
*/ */
virtual void table_cellTouched(CCTableView* table, CCTableViewCell* cell) = 0; virtual void tableCellTouched(CCTableView* table, CCTableViewCell* cell) = 0;
}; };
@ -103,27 +103,6 @@ class CCTableView : public CCScrollView, public CCScrollViewDelegate
public: public:
CCTableView(); CCTableView();
virtual ~CCTableView(); virtual ~CCTableView();
/**
* vertical direction of cell filling
*/
CCTableViewVerticalFillOrder vordering_;
/**
* data source
*/
CCTableViewDataSource* getDataSource() { return dataSource_; }
void setDataSource(CCTableViewDataSource* source) { dataSource_ = source; }
/**
* delegate
*/
CCTableViewDelegate* getDelegate() { return tDelegate_; }
void setDelegate(CCTableViewDelegate* pDelegate) { tDelegate_ = pDelegate; }
/**
* determines how cell is ordered and filled in the view.
*/
void setVerticalFillOrder(CCTableViewVerticalFillOrder order);
CCTableViewVerticalFillOrder getVerticalFillOrder();
/** /**
* An intialized table view object * An intialized table view object
@ -132,7 +111,7 @@ public:
* @param size view size * @param size view size
* @return table view * @return table view
*/ */
static CCTableView* viewWithDataSource(CCTableViewDataSource* dataSource, CCSize size); static CCTableView* create(CCTableViewDataSource* dataSource, CCSize size);
/** /**
* An initialized table view object * An initialized table view object
* *
@ -141,7 +120,25 @@ public:
* @param container parent object for cells * @param container parent object for cells
* @return table view * @return table view
*/ */
static CCTableView* viewWithDataSource(CCTableViewDataSource* dataSource, CCSize size, CCNode *container); static CCTableView* create(CCTableViewDataSource* dataSource, CCSize size, CCNode *container);
/**
* data source
*/
CCTableViewDataSource* getDataSource() { return m_pDataSource; }
void setDataSource(CCTableViewDataSource* source) { m_pDataSource = source; }
/**
* delegate
*/
CCTableViewDelegate* getDelegate() { return m_pTableViewDelegate; }
void setDelegate(CCTableViewDelegate* pDelegate) { m_pTableViewDelegate = pDelegate; }
/**
* determines how cell is ordered and filled in the view.
*/
void setVerticalFillOrder(CCTableViewVerticalFillOrder order);
CCTableViewVerticalFillOrder getVerticalFillOrder();
bool initWithViewSize(CCSize size, CCNode* container = NULL); bool initWithViewSize(CCSize size, CCNode* container = NULL);
/** /**
@ -187,27 +184,33 @@ public:
virtual void ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent); virtual void ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent);
protected: protected:
/**
* vertical direction of cell filling
*/
CCTableViewVerticalFillOrder m_eVordering;
/** /**
* index set to query the indexes of the cells used. * index set to query the indexes of the cells used.
*/ */
std::set<unsigned int>* indices_; std::set<unsigned int>* m_pIndices;
//NSMutableIndexSet *indices_; //NSMutableIndexSet *indices_;
/** /**
* cells that are currently in the table * cells that are currently in the table
*/ */
CCArrayForObjectSorting *cellsUsed_; CCArrayForObjectSorting* m_pCellsUsed;
/** /**
* free list of cells * free list of cells
*/ */
CCArrayForObjectSorting *cellsFreed_; CCArrayForObjectSorting* m_pCellsFreed;
/** /**
* weak link to the data source object * weak link to the data source object
*/ */
CCTableViewDataSource* dataSource_; CCTableViewDataSource* m_pDataSource;
/** /**
* weak link to the delegate object * weak link to the delegate object
*/ */
CCTableViewDelegate* tDelegate_; CCTableViewDelegate* m_pTableViewDelegate;
CCScrollViewDirection m_eOldDirection; CCScrollViewDirection m_eOldDirection;
@ -217,7 +220,7 @@ protected:
CCPoint _offsetFromIndex(unsigned int index); CCPoint _offsetFromIndex(unsigned int index);
void _updateContentSize(); void _updateContentSize();
CCTableViewCell *_cellWithIndex(unsigned int cellIndex); CCTableViewCell* _cellWithIndex(unsigned int cellIndex);
void _moveCellOutOfSight(CCTableViewCell *cell); void _moveCellOutOfSight(CCTableViewCell *cell);
void _setIndexForCell(unsigned int index, CCTableViewCell *cell); void _setIndexForCell(unsigned int index, CCTableViewCell *cell);
void _addCellIfNecessary(CCTableViewCell * cell); void _addCellIfNecessary(CCTableViewCell * cell);

View File

@ -51,6 +51,8 @@ Classes/ExtensionsTest/CocosBuilderTest/ButtonTest/ButtonTestLayer.cpp \
Classes/ExtensionsTest/CocosBuilderTest/MenuTest/MenuTestLayer.cpp \ Classes/ExtensionsTest/CocosBuilderTest/MenuTest/MenuTestLayer.cpp \
Classes/ExtensionsTest/NetworkTest/HttpClientTest.cpp \ Classes/ExtensionsTest/NetworkTest/HttpClientTest.cpp \
Classes/ExtensionsTest/EditBoxTest/EditBoxTest.cpp \ Classes/ExtensionsTest/EditBoxTest/EditBoxTest.cpp \
Classes/ExtensionsTest/TableViewTest/TableViewTestScene.cpp \
Classes/ExtensionsTest/TableViewTest/CustomTableViewCell.cpp \
Classes/FontTest/FontTest.cpp \ Classes/FontTest/FontTest.cpp \
Classes/IntervalTest/IntervalTest.cpp \ Classes/IntervalTest/IntervalTest.cpp \
Classes/KeypadTest/KeypadTest.cpp \ Classes/KeypadTest/KeypadTest.cpp \

View File

@ -23,18 +23,18 @@ bool TableViewTestLayer::init()
CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCSize winSize = CCDirector::sharedDirector()->getWinSize();
CCTableView* tableView = CCTableView::viewWithDataSource(this, CCSizeMake(250, 60)); CCTableView* tableView = CCTableView::create(this, CCSizeMake(250, 60));
tableView->setDirection(CCScrollViewDirectionHorizontal); tableView->setDirection(kCCScrollViewDirectionHorizontal);
tableView->setPosition(ccp(20,winSize.height/2-30)); tableView->setPosition(ccp(20,winSize.height/2-30));
tableView->setDelegate(this); tableView->setDelegate(this);
this->addChild(tableView); this->addChild(tableView);
tableView->reloadData(); tableView->reloadData();
tableView = CCTableView::viewWithDataSource(this, CCSizeMake(60, 280)); tableView = CCTableView::create(this, CCSizeMake(60, 280));
tableView->setDirection(CCScrollViewDirectionVertical); tableView->setDirection(kCCScrollViewDirectionVertical);
tableView->setPosition(ccp(winSize.width-150,winSize.height/2-120)); tableView->setPosition(ccp(winSize.width-150,winSize.height/2-120));
tableView->setDelegate(this); tableView->setDelegate(this);
tableView->setVerticalFillOrder(CCTableViewFillTopDown); tableView->setVerticalFillOrder(kCCTableViewFillTopDown);
this->addChild(tableView); this->addChild(tableView);
tableView->reloadData(); tableView->reloadData();
@ -55,7 +55,7 @@ void TableViewTestLayer::toExtensionsMainLayer(cocos2d::CCObject *sender)
pScene->release(); pScene->release();
} }
void TableViewTestLayer::table_cellTouched(CCTableView* table, CCTableViewCell* cell) void TableViewTestLayer::tableCellTouched(CCTableView* table, CCTableViewCell* cell)
{ {
CCLOG("cell touched at index: %i", cell->getIdx()); CCLOG("cell touched at index: %i", cell->getIdx());
} }

View File

@ -17,7 +17,7 @@ public:
virtual void scrollViewDidScroll(cocos2d::extension::CCScrollView* view) {}; virtual void scrollViewDidScroll(cocos2d::extension::CCScrollView* view) {};
virtual void scrollViewDidZoom(cocos2d::extension::CCScrollView* view) {} virtual void scrollViewDidZoom(cocos2d::extension::CCScrollView* view) {}
virtual void table_cellTouched(cocos2d::extension::CCTableView* table, cocos2d::extension::CCTableViewCell* cell); virtual void tableCellTouched(cocos2d::extension::CCTableView* table, cocos2d::extension::CCTableViewCell* cell);
virtual cocos2d::CCSize cellSizeForTable(cocos2d::extension::CCTableView *table); virtual cocos2d::CCSize cellSizeForTable(cocos2d::extension::CCTableView *table);
virtual cocos2d::extension::CCTableViewCell* tableCellAtIndex(cocos2d::extension::CCTableView *table, unsigned int idx); virtual cocos2d::extension::CCTableViewCell* tableCellAtIndex(cocos2d::extension::CCTableView *table, unsigned int idx);
virtual unsigned int numberOfCellsInTableView(cocos2d::extension::CCTableView *table); virtual unsigned int numberOfCellsInTableView(cocos2d::extension::CCTableView *table);

View File

@ -1 +1 @@
13fb5118be504c0cb162fe003715353d23316944 48422011360e4d8706df417f7061b830a3b9613a

View File

@ -1 +1 @@
f5750ec007bd00599c51249ab60343d337af43c9 05fb7e1549cf656c61a502a07712b042ff7eec9b