From fd08f9852b2152a7fb7c0d83e9885b32223b55d4 Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 27 Apr 2012 12:00:54 +0800 Subject: [PATCH 01/14] issue #1194: Added some files refer to TextureWatcher. --- .../extensions/TextureWatcher/NdListView.cpp | 2146 +++++++++++++++++ .../extensions/TextureWatcher/NdListView.h | 154 ++ .../TextureWatcher/NdListViewCell.cpp | 96 + .../TextureWatcher/NdListViewCell.h | 60 + .../TextureWatcher/NdTextureWatcher.cpp | 396 +++ .../TextureWatcher/NdTextureWatcher.h | 46 + cocos2dx/proj.win32/cocos2d-win32.vcproj | 28 + 7 files changed, 2926 insertions(+) create mode 100644 cocos2dx/extensions/TextureWatcher/NdListView.cpp create mode 100644 cocos2dx/extensions/TextureWatcher/NdListView.h create mode 100644 cocos2dx/extensions/TextureWatcher/NdListViewCell.cpp create mode 100644 cocos2dx/extensions/TextureWatcher/NdListViewCell.h create mode 100644 cocos2dx/extensions/TextureWatcher/NdTextureWatcher.cpp create mode 100644 cocos2dx/extensions/TextureWatcher/NdTextureWatcher.h diff --git a/cocos2dx/extensions/TextureWatcher/NdListView.cpp b/cocos2dx/extensions/TextureWatcher/NdListView.cpp new file mode 100644 index 0000000000..ec202166a5 --- /dev/null +++ b/cocos2dx/extensions/TextureWatcher/NdListView.cpp @@ -0,0 +1,2146 @@ +#include "NdListView.h" +#include "../cocos2dx_support/LuaEngineImpl.h" + +namespace NdCxControl +{ +#define ND_LISTVIEW_ACTION_INTERVAL 0.6666 +/****************************************** +**************Public Functions************* +*******************************************/ +NdListView* NdListView::viewWithMode(NdListViewMode mode) +{ + NdListView *pRet = new NdListView(); + if (pRet && pRet->initWithMode(mode)) + { + pRet->autorelease(); + return pRet; + } + else + { + CC_SAFE_DELETE(pRet) + return NULL; + } +} + +bool NdListView::initWithMode(NdListViewMode mode) +{ + m_nMode = mode; + m_layerPanel = CCLayer::node(); + this->addChild(m_layerPanel); + + return CCLayerColor::initWithColorWidthHeight(ccc4(255, 255, 255, 0), 0, 0); +} + +NdListView::NdListView(void) + :m_nMode(NdListViewModeVertical) + ,m_nState(NdListViewStateWatting) + ,m_nSlideDir(NdListViewSlideDirNone) + ,m_layerPanel(NULL) + ,m_nSeparatorStyle(NdListViewCellSeparatorStyleSingleLine) + ,m_nSelectedRow(-1) + ,m_nCurrentRow(-1) + ,m_fActionDuration(ND_LISTVIEW_ACTION_INTERVAL) + ,m_pListViewParent(NULL) + ,m_bIsEnabled(true) + ,m_pDelegate(NULL) + ,m_nNumberOfRows(0) + ,m_bIsOnTouch(false) +{ + m_drawedRows = CCRangeMake(0, 0); + m_visibleRows = CCRangeMake(0, 0); + m_bIsTouchEnabled = true; +} + +NdListView::~NdListView(void) +{ +} + +void NdListView::setDelegateName(const char* pszName) +{ + if (pszName) + { + this->m_strDeletegate = string(pszName) + "."; + } + else + { + this->m_strDeletegate.clear(); + } +} + +void NdListView::selectCellAtRow(unsigned int nRow) +{ + NdListViewCell *cell = cellAtRow(nRow); + if (cell) + { + cell->selected(); + } +} + +void NdListView::unselectCellAtRow(unsigned int nRow) +{ + if (nRow == m_nSelectedRow) + { + m_nSelectedRow = -1; + } + NdListViewCell *cell = cellAtRow(nRow); + if (cell) + { + cell->unselected(); + } +} + +void NdListView::reload(void) +{ + m_layerPanel->removeAllChildrenWithCleanup(true); + m_layerPanel->setPosition(CCPointZero); + m_visibleRows = CCRangeMake(0, 0); + m_drawedRows = CCRangeMake(0, 0); + m_nNumberOfRows = triggerNumberOfCells(); + this->displayVisibleRows(); +} + +void NdListView::insertCellsAtRow(unsigned int nRow, unsigned int nCount) +{ + if (nRow >= m_nNumberOfRows) + { + if (m_nNumberOfRows > 0) + { + nRow = m_nNumberOfRows - 1; + } + else + { + nRow = 0; + } + } + + m_layerPanel->pauseSchedulerAndActions(); + if (m_nNumberOfRows == 0) + { + m_nNumberOfRows = this->triggerNumberOfCells(); + this->displayVisibleRows(); + } + else + { + m_nNumberOfRows = this->triggerNumberOfCells(); + + if (!this->isFullFill()) + { + this->displayVisibleRows(); + } + } + m_layerPanel->resumeSchedulerAndActions(); +} + +void NdListView::deleteCellsAtRow(unsigned int nRow, unsigned int nCount) +{ + if (m_nNumberOfRows == 0) + { + return; + } + if (nRow >= m_nNumberOfRows) + { + if (m_nNumberOfRows > 0) + { + nRow = m_nNumberOfRows - 1; + } + else + { + nRow = 0; + } + } + + m_layerPanel->pauseSchedulerAndActions(); + + + m_nNumberOfRows = this->triggerNumberOfCells(); + + for (unsigned int n = nRow;n < nRow + nCount; n++) + { + if (n >= m_drawedRows.location && n <= CCRange::CCMaxRange(m_drawedRows)) + { + NdListViewCell *cell = this->cellAtRow(n); + if (cell) + { + CCPoint pos = cell->getPosition(); + pos.y += cell->getContentSize().height; + m_layerPanel->removeChild(cell, true); + for (unsigned int i = n +1; i <= CCRange::CCMaxRange(m_drawedRows); i++) + { + cell = this->cellAtRow(i); + if (cell) + { + int tag = cell->getTag(); + cell->setTag(tag - 1); + if (NdListViewModeHorizontal == m_nMode) + { + cell->setPosition(pos); + pos.x += cell->getContentSize().width; + } + else if (NdListViewModeVertical == m_nMode) + { + pos.y -= cell->getContentSize().height; + cell->setPosition(pos); + } + } + } + if (m_drawedRows.length > 0) + { + m_drawedRows.length--; + unsigned int nLastRow = CCRange::CCMaxRange(m_drawedRows); + this->appendRowToBack(nLastRow + 1); + } + } + } + else + { + for (unsigned int i = m_drawedRows.location; i <= CCRange::CCMaxRange(m_drawedRows); i++) + { + NdListViewCell *cell = this->cellAtRow(i); + if (cell) + { + int tag = cell->getTag(); + cell->setTag(tag - 1); + } + } + if (m_drawedRows.location > 0) + { + m_drawedRows.location--; + } + } + } + + m_layerPanel->resumeSchedulerAndActions(); +} + +void NdListView::scrollCellToFront(unsigned int nRow, bool bAnimated) +{ + if (!isFullFill()) + { + return; + } + if (m_nNumberOfRows == 0) + { + return; + } + if (NdListViewStateWatting != m_nState) + { + this->stopActionImmediately(); + } + + if (nRow >= m_nNumberOfRows) + { + nRow = m_nNumberOfRows - 1; + } + + float disX = 0; + float disY = 0; + m_nSlideDir = NdListViewSlideDirNone; + if (NdListViewModeHorizontal == m_nMode) + { + float dis = 0; + unsigned int nCount = 0; + NdListViewCell *cell = NULL; + if (nRow > m_visibleRows.location) + { + m_nSlideDir = NdListViewSlideDirLeft; + } + else + { + m_nSlideDir = NdListViewSlideDirRight; + } + + while(1) + { + if (dis >= this->getContentSize().width || nRow + nCount >= m_nNumberOfRows) + { + break; + } + + if (NdListViewSlideDirRight == m_nSlideDir) + { + cell = appendRowToFront(nRow + nCount); + } + else if (NdListViewSlideDirLeft == m_nSlideDir) + { + cell = appendRowToBack(nRow + nCount); + } + + if (cell) + { + nCount++; + dis += cell->getContentSize().width; + } + else + { + CCLog("NdListView cell == NULL at line %d", __LINE__); + } + } + + if (NdListViewSlideDirLeft == m_nSlideDir && dis < this->getContentSize().width) + { + // at last + while(1) + { + if (dis >= this->getContentSize().width) + { + break; + } + cell = appendRowToBack(nRow - 1); + if (cell) + { + nRow--; + dis += cell->getContentSize().width; + nCount++; + } + else + { + CCLog("NdListView cell == NULL at line %d", __LINE__); + } + } + } + + if (NdListViewSlideDirRight == m_nSlideDir) + { + NdListViewCell* cell = NULL; + unsigned nLast = 0; + if (CCRange::CCLocationInRange(nRow + nCount - 1, m_visibleRows)) + { + cell = cellAtRow(nRow + nCount - 1); + nLast = nRow + nCount - 2; + } + else + { + cell = cellAtRow(m_visibleRows.location); + nLast = nRow + nCount - 1; + } + if (cell) + { + CCPoint pos = cell->getPosition(); + for (int i = nLast; i >= (int)nRow; i--) + { + cell = cellAtRow(i); + if (cell) + { + pos.x -= cell->getContentSize().width; + cell->setPosition(pos); + } + else + { + CCLog("NdListView cell == NULL at line %d", __LINE__); + } + } + } + else + { + CCLog("NdListView cell == NULL at line %d", __LINE__); + } + } + else if (NdListViewSlideDirLeft == m_nSlideDir) + { + NdListViewCell* cell = NULL; + unsigned nFirst = 0; + if (CCRange::CCLocationInRange(nRow, m_visibleRows)) + { + cell = cellAtRow(nRow); + nFirst = nRow + 1; + } + else + { + cell = cellAtRow(CCRange::CCMaxRange(m_visibleRows)); + nFirst = nRow; + } + if (cell) + { + CCPoint pos = cell->getPosition(); + pos.x += cell->getContentSize().width; + for (unsigned int i = nFirst; i < nRow + nCount; i++) + { + cell = cellAtRow(i); + if (cell) + { + cell->setPosition(pos); + pos.x += cell->getContentSize().width; + + } + else + { + CCLog("NdListView cell == NULL at line %d", __LINE__); + } + } + } + else + { + CCLog("NdListView cell == NULL at line %d", __LINE__); + } + } + + + cell = cellAtRow(nRow); + CCPoint ptCell = cell->convertToWorldSpace(CCPointZero); + CCPoint ptView = this->convertToWorldSpace(CCPointZero); + disX = ptView.x - ptCell.x; + } + else if (NdListViewModeVertical == m_nMode) + { + float dis = 0; + unsigned int nCount = 0; + NdListViewCell *cell = NULL; + if (nRow > m_visibleRows.location) + { + m_nSlideDir = NdListViewSlideDirUp; + } + else + { + m_nSlideDir = NdListViewSlideDirDown; + } + + while(1) + { + if (dis >= this->getContentSize().height || nRow + nCount >= m_nNumberOfRows) + { + break; + } + + if (NdListViewSlideDirDown == m_nSlideDir) + { + cell = appendRowToFront(nRow + nCount); + } + else if (NdListViewSlideDirUp == m_nSlideDir) + { + cell = appendRowToBack(nRow + nCount); + } + + if (cell) + { + nCount++; + dis += cell->getContentSize().height; + } + else + { + CCLog("NdListView cell == NULL at line %d", __LINE__); + } + } + + if (NdListViewSlideDirUp == m_nSlideDir && dis < this->getContentSize().height) + { + // at last + while(1) + { + if (dis >= this->getContentSize().height) + { + break; + } + cell = appendRowToBack(nRow - 1); + if (cell) + { + nRow--; + dis += cell->getContentSize().height; + nCount++; + } + else + { + CCLog("NdListView cell == NULL at line %d", __LINE__); + } + } + } + + if (NdListViewSlideDirDown == m_nSlideDir) + { + NdListViewCell* cell = NULL; + unsigned nLast = 0; + if (CCRange::CCLocationInRange(nRow + nCount - 1, m_visibleRows)) + { + cell = cellAtRow(nRow + nCount - 1); + nLast = nRow + nCount - 2; + } + else + { + cell = cellAtRow(m_visibleRows.location); + nLast = nRow + nCount - 1; + } + if (cell) + { + CCPoint pos = cell->getPosition(); + pos.y += cell->getContentSize().height; + for (int i = nLast; i >= (int)nRow; i--) + { + cell = cellAtRow(i); + if (cell) + { + cell->setPosition(pos); + pos.y += cell->getContentSize().height; + } + else + { + CCLog("NdListView cell == NULL at line %d", __LINE__); + } + } + } + else + { + CCLog("NdListView cell == NULL at line %d", __LINE__); + } + } + else if (NdListViewSlideDirUp == m_nSlideDir) + { + NdListViewCell* cell = NULL; + unsigned nFirst = 0; + if (CCRange::CCLocationInRange(nRow, m_visibleRows)) + { + cell = cellAtRow(nRow); + nFirst = nRow + 1; + } + else + { + cell = cellAtRow(CCRange::CCMaxRange(m_visibleRows)); + nFirst = nRow; + } + if (cell) + { + CCPoint pos = cell->getPosition(); + for (unsigned int i = nFirst; i < nRow + nCount; i++) + { + cell = cellAtRow(i); + if (cell) + { + pos.y -= cell->getContentSize().height; + cell->setPosition(pos); + } + else + { + CCLog("NdListView cell == NULL at line %d", __LINE__); + } + } + } + else + { + CCLog("NdListView cell == NULL at line %d", __LINE__); + } + } + + + cell = cellAtRow(nRow); + CCPoint ptCell = cell->convertToWorldSpace(CCPointZero); + CCPoint ptView = this->convertToWorldSpace(CCPointZero); + disY = ptView.y + this->getContentSize().height - (ptCell.y + cell->getContentSize().height); + } + + m_ptDestination = m_layerPanel->getPosition(); + m_ptDestination.x += disX; + m_ptDestination.y += disY; + m_nState = NdListViewStateScroll; + + if (bAnimated) + { + CCMoveBy *moveBy = CCMoveBy::actionWithDuration(m_fActionDuration, CCPointMake(disX, disY)); + CCEaseOut *ease = CCEaseOut::actionWithAction(moveBy, 3); + CCFiniteTimeAction *actions = CCSequence::actions(ease, CCCallFunc::actionWithTarget(this, callfunc_selector(NdListView::finishScroll)), NULL); + m_layerPanel->runAction(actions); + } + else + { + stopActionImmediately(); + } +} + +void NdListView::scrollCellToBack(unsigned int nRow, bool bAnimated) +{ + if (!isFullFill()) + { + return; + } + if (m_nNumberOfRows == 0) + { + return; + } + if (NdListViewStateWatting != m_nState) + { + this->stopActionImmediately(); + } + + if (nRow >= m_nNumberOfRows) + { + nRow = m_nNumberOfRows - 1; + } + + float disX = 0; + float disY = 0; + m_nSlideDir = NdListViewSlideDirNone; + if (NdListViewModeHorizontal == m_nMode) + { + float dis = 0; + int nCount = 0; + NdListViewCell *cell = NULL; + if (nRow > CCRange::CCMaxRange(m_visibleRows)) + { + m_nSlideDir = NdListViewSlideDirLeft; + } + else + { + m_nSlideDir = NdListViewSlideDirRight; + } + + while(1) + { + if (dis >= this->getContentSize().width || (int)nRow - nCount < 0) + { + break; + } + + if (NdListViewSlideDirRight == m_nSlideDir) + { + cell = appendRowToFront(nRow - nCount); + } + else if (NdListViewSlideDirLeft == m_nSlideDir) + { + cell = appendRowToBack(nRow - nCount); + } + + if (cell) + { + nCount++; + dis += cell->getContentSize().width; + } + else + { + CCLog("NdListView cell == NULL at line %d", __LINE__); + } + } + + if (NdListViewSlideDirRight == m_nSlideDir && dis < this->getContentSize().width) + { + // at first + while(1) + { + if (dis >= this->getContentSize().width) + { + break; + } + cell = appendRowToBack(nRow + 1); + if (cell) + { + nRow++; + dis += cell->getContentSize().width; + nCount++; + } + else + { + CCLog("NdListView cell == NULL at line %d", __LINE__); + } + } + } + + if (NdListViewSlideDirRight == m_nSlideDir) + { + NdListViewCell* cell = NULL; + unsigned nLast = 0; + if (CCRange::CCLocationInRange(nRow, m_visibleRows)) + { + cell = cellAtRow(nRow); + nLast = nRow - 1; + } + else + { + cell = cellAtRow(m_visibleRows.location); + nLast = nRow; + } + if (cell) + { + CCPoint pos = cell->getPosition(); + for (int i = nLast; i >= (int)(nRow - nCount + 1); i--) + { + cell = cellAtRow(i); + if (cell) + { + pos.x -= cell->getContentSize().width; + cell->setPosition(pos); + } + else + { + CCLog("NdListView cell == NULL at line %d", __LINE__); + } + } + } + else + { + CCLog("NdListView cell == NULL at line %d", __LINE__); + } + } + else if (NdListViewSlideDirLeft == m_nSlideDir) + { + NdListViewCell* cell = NULL; + unsigned nFirst = 0; + if (CCRange::CCLocationInRange(nRow - nCount + 1, m_visibleRows)) + { + cell = cellAtRow(nRow - nCount + 1); + nFirst = nRow - nCount + 2; + nCount--; + } + else + { + cell = cellAtRow(CCRange::CCMaxRange(m_visibleRows)); + nFirst = nRow - nCount + 1; + } + if (cell) + { + CCPoint pos = cell->getPosition(); + pos.x += cell->getContentSize().width; + for (unsigned int i = nFirst; i < nFirst + nCount; i++) + { + cell = cellAtRow(i); + if (cell) + { + cell->setPosition(pos); + pos.x += cell->getContentSize().width; + + } + else + { + CCLog("NdListView cell == NULL at line %d", __LINE__); + } + } + } + else + { + CCLog("NdListView cell == NULL at line %d", __LINE__); + } + } + + + cell = cellAtRow(nRow); + CCPoint ptCell = cell->convertToWorldSpace(CCPointZero); + CCPoint ptView = this->convertToWorldSpace(CCPointZero); + disX = ptView.x + this->getContentSize().width - (ptCell.x + cell->getContentSize().width); + } + else if (NdListViewModeVertical == m_nMode) + { + float dis = 0; + int nCount = 0; + NdListViewCell *cell = NULL; + if (nRow > CCRange::CCMaxRange(m_visibleRows)) + { + m_nSlideDir = NdListViewSlideDirUp; + } + else + { + m_nSlideDir = NdListViewSlideDirDown; + } + + while(1) + { + if (dis >= this->getContentSize().height || (int)nRow - nCount < 0) + { + break; + } + + if (NdListViewSlideDirDown == m_nSlideDir) + { + cell = appendRowToFront(nRow - nCount); + } + else if (NdListViewSlideDirUp == m_nSlideDir) + { + cell = appendRowToBack(nRow - nCount); + } + + if (cell) + { + nCount++; + dis += cell->getContentSize().height; + } + else + { + CCLog("NdListView cell == NULL at line %d", __LINE__); + } + } + + if (NdListViewSlideDirDown == m_nSlideDir && dis < this->getContentSize().height) + { + // at first + while(1) + { + if (dis >= this->getContentSize().height) + { + break; + } + cell = appendRowToBack(nRow + 1); + if (cell) + { + nRow++; + dis += cell->getContentSize().height; + nCount++; + } + else + { + CCLog("NdListView cell == NULL at line %d", __LINE__); + } + } + } + + if (NdListViewSlideDirDown == m_nSlideDir) + { + NdListViewCell* cell = NULL; + unsigned nLast = 0; + if (CCRange::CCLocationInRange(nRow, m_visibleRows)) + { + cell = cellAtRow(nRow); + nLast = nRow - 1; + } + else + { + cell = cellAtRow(m_visibleRows.location); + nLast = nRow; + } + if (cell) + { + CCPoint pos = cell->getPosition(); + pos.y += cell->getContentSize().height; + for (int i = nLast; i >= (int)(nRow - nCount + 1); i--) + { + cell = cellAtRow(i); + if (cell) + { + cell->setPosition(pos); + pos.y += cell->getContentSize().height; + } + else + { + CCLog("NdListView cell == NULL at line %d", __LINE__); + } + } + } + else + { + CCLog("NdListView cell == NULL at line %d", __LINE__); + } + } + else if (NdListViewSlideDirUp == m_nSlideDir) + { + NdListViewCell* cell = NULL; + unsigned nFirst = 0; + if (CCRange::CCLocationInRange(nRow - nCount + 1, m_visibleRows)) + { + cell = cellAtRow(nRow - nCount + 1); + nFirst = nRow - nCount + 2; + nCount--; + } + else + { + cell = cellAtRow(CCRange::CCMaxRange(m_visibleRows)); + nFirst = nRow - nCount + 1; + } + if (cell) + { + CCPoint pos = cell->getPosition(); + for (unsigned int i = nFirst; i < nFirst + nCount; i++) + { + cell = cellAtRow(i); + if (cell) + { + pos.y -= cell->getContentSize().height; + cell->setPosition(pos); + } + else + { + CCLog("NdListView cell == NULL at line %d", __LINE__); + } + } + } + else + { + CCLog("NdListView cell == NULL at line %d", __LINE__); + } + } + + + cell = cellAtRow(nRow); + CCPoint ptCell = cell->convertToWorldSpace(CCPointZero); + CCPoint ptView = this->convertToWorldSpace(CCPointZero); + disY = ptView.y - ptCell.y; + } + + m_ptDestination = m_layerPanel->getPosition(); + m_ptDestination.x += disX; + m_ptDestination.y += disY; + m_nState = NdListViewStateScroll; + + if (bAnimated) + { + CCMoveBy *moveBy = CCMoveBy::actionWithDuration(m_fActionDuration, CCPointMake(disX, disY)); + CCEaseOut *ease = CCEaseOut::actionWithAction(moveBy, 3); + CCFiniteTimeAction *actions = CCSequence::actions(ease, CCCallFunc::actionWithTarget(this, callfunc_selector(NdListView::finishScroll)), NULL); + m_layerPanel->runAction(actions); + } + else + { + stopActionImmediately(); + } +} + +NdListViewSlideDir NdListView::getSlideDir(CCPoint ptTouchBegan, CCPoint ptTouchEnd) +{ + NdListViewSlideDir nSlideDir = NdListViewSlideDirNone; + + int nOffsetX = ptTouchEnd.x - ptTouchBegan.x; + int nOffsetY = ptTouchEnd.y - ptTouchBegan.y; + + int disMin = CCDirector::sharedDirector()->getWinSize().height / 100; + + if(NdListViewModeHorizontal == m_nMode) + { + if(nOffsetX >= disMin) + { + nSlideDir = NdListViewSlideDirRight; + } + else if (nOffsetX <= -disMin) + { + nSlideDir = NdListViewSlideDirLeft; + } + } + else if (NdListViewModeVertical == m_nMode) + { + if(nOffsetY >= disMin) + { + nSlideDir = NdListViewSlideDirUp; + } + else if (nOffsetY <= -disMin) + { + nSlideDir = NdListViewSlideDirDown; + } + } + return nSlideDir; +} + +/****************************************** +**************Private Functions************ +*******************************************/ +int NdListView::rowForTouch(cocos2d::CCTouch *touch) +{ + CCPoint touchLocation = touch->locationInView(touch->view()); + touchLocation = CCDirector::sharedDirector()->convertToGL(touchLocation); + + CCArray *pChildren = m_layerPanel->getChildren(); + if (pChildren && pChildren->count() > 0) + { + CCObject* pObject = NULL; + CCARRAY_FOREACH(pChildren, pObject) + { + CCNode* pChild = (CCNode*) pObject; + if (pChild && pChild->getIsVisible()) + { + CCPoint local = pChild->convertToNodeSpace(touchLocation); + CCRect r = CCRectZero; + r.size = pChild->getContentSize(); + + if (CCRect::CCRectContainsPoint(r, local)) + { + return pChild->getTag(); + } + } + } + + } + + return -1; +} + +void NdListView::finishFix(void) +{ + if(m_pListViewParent) + { + m_pListViewParent->setIsEnabled(true); + } + m_nState = NdListViewStateWatting; + m_nSlideDir = NdListViewSlideDirNone; + clearUnvisibleRows(); + triggerDidScrollToRow(m_visibleRows.location); + + CCArray *children = m_layerPanel->getChildren(); + int nCount = 0; + if (children) + { + nCount = children->count(); + } + //CCLog("row num left:%d [%d, %d]", nCount, m_drawedRows.location, CCRange::CCMaxRange(m_drawedRows)); +} + +void NdListView::finishScroll(void) +{ + finishFix(); +} + +void NdListView::finishEaseOut(void) +{ + bool bNeedFix = false; + + if (NdListViewModeHorizontal == m_nMode) + { + bool bFullFill = isFullFill(); + if (NdListViewSlideDirLeft == m_nSlideDir && bFullFill) + { + NdListViewCell *cell = cellAtRow(m_nNumberOfRows - 1); + if (cell) + { + CCPoint ptCell = cell->convertToWorldSpace(CCPointZero); + CCPoint ptView = this->convertToWorldSpace(CCPointZero); + if (ptCell.x + cell->getContentSize().width < ptView.x + this->getContentSize().width) + { + bNeedFix = true; + fixLastRow(); + } + } + } + else + { + NdListViewCell *cell = cellAtRow(0); + if (cell) + { + CCPoint ptCell = cell->convertToWorldSpace(CCPointZero); + CCPoint ptView = this->convertToWorldSpace(CCPointZero); + if (ptCell.x > ptView.x || !bFullFill) + { + bNeedFix = true; + fixFirstRow(); + } + } + } + } + else if (NdListViewModeVertical == m_nMode) + { + bool bFullFill = this->isFullFill(); + if (NdListViewSlideDirUp == m_nSlideDir && bFullFill) + { + NdListViewCell *cell = cellAtRow(m_nNumberOfRows - 1); + if (cell) + { + CCPoint ptCell = cell->convertToWorldSpace(CCPointZero); + CCPoint ptView = this->convertToWorldSpace(CCPointZero); + if (ptCell.y > ptView.y) + { + bNeedFix = true; + fixLastRow(); + } + } + } + else + { + NdListViewCell *cell = cellAtRow(0); + if (cell) + { + CCPoint ptCell = cell->convertToWorldSpace(CCPointZero); + CCPoint ptView = this->convertToWorldSpace(CCPointZero); + if (ptCell.y + cell->getContentSize().height < ptView.y + this->getContentSize().height || !bFullFill) + { + bNeedFix = true; + fixFirstRow(); + } + } + } + } + + if (!bNeedFix) + { + finishFix(); + } +} + +bool NdListView::isTouchInside(CCTouch *touch) +{ + CCPoint point; + if (m_pListViewParent) + { + point = m_pListViewParent->convertTouchToNodeSpace(touch); + } + else + { + point = this->convertTouchToNodeSpace(touch); + } + CCRect bounds = CCRectMake(0, 0, this->getContentSize().width, this->getContentSize().height); + bool bIn = CCRect::CCRectContainsPoint(bounds, point); + return bIn; +} + +bool NdListView::isFullFill(void) +{ + bool bRet = false; + float length = 0; + for (unsigned int i = m_drawedRows.location; i <= CCRange::CCMaxRange(m_drawedRows); i++) + { + NdListViewCell *cell = cellAtRow(i); + if (cell) + { + if (NdListViewModeHorizontal == m_nMode) + { + length += cell->getContentSize().width; + if (length >= this->getContentSize().width) + { + bRet = true; + break; + } + } + else if (NdListViewModeVertical == m_nMode) + { + length += cell->getContentSize().height; + if (length >= this->getContentSize().height) + { + bRet = true; + break; + } + } + } + } + return bRet; +} + +NdListViewCell *NdListView::cellAtRow(unsigned int nRow) +{ + NdListViewCell *cell = (NdListViewCell*)m_layerPanel->getChildByTag(nRow); + return cell; +} + +void NdListView::stopActionImmediately(void) +{ + m_layerPanel->stopAllActions(); + if (NdListViewStateScroll == m_nState) + { + m_layerPanel->setPosition(m_ptDestination); + finishScroll(); + } +} + +unsigned int NdListView::triggerNumberOfCells(void) +{ + unsigned int nRow = 0; + NdListViewProtrolData data; + + if (m_strDeletegate.size() > 0) + { + CCScriptEngineProtocol* scriptEngine = CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine(); + if (scriptEngine) + { + std::string script; + script = m_strDeletegate + "NdListView_numberOfCells"; + scriptEngine->executeCallFuncNTDT(script.c_str(), this, "NdCxControl::NdListView", &data, "NdCxControl::NdListViewProtrolData"); + nRow = data.nNumberOfRows; + } + } + + if (m_pDelegate) + { + m_pDelegate->NdListView_numberOfCells(this, &data); + nRow = data.nNumberOfRows; + } + return nRow; +} + +NdListViewCell *NdListView::triggerCellForRow(unsigned int nRow) +{ + NdListViewCell *cell = NULL; + NdListViewProtrolData data; + data.nRow = nRow; + data.cell = NULL; + if (m_strDeletegate.size() > 0) + { + CCScriptEngineProtocol* scriptEngine = CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine(); + if (scriptEngine) + { + std::string script; + script = m_strDeletegate + "NdListView_cellForRow"; + scriptEngine->executeCallFuncNTDT(script.c_str(), this, "NdCxControl::NdListView", &data, "NdCxControl::NdListViewProtrolData"); + cell = data.cell; + } + } + if (m_pDelegate) + { + m_pDelegate->NdListView_cellForRow(this, &data); + cell = data.cell; + } + return cell; +} + +void NdListView::triggerDidClickCellAtRow(unsigned int nRow) +{ + NdListViewProtrolData data; + data.nRow = nRow; + if (m_strDeletegate.size() > 0) + { + CCScriptEngineProtocol* scriptEngine = CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine(); + if (scriptEngine) + { + std::string script; + script = m_strDeletegate + "NdListView_didClickCellAtRow"; + scriptEngine->executeCallFuncNTDT(script.c_str(), this, "NdCxControl::NdListView", &data, "NdCxControl::NdListViewProtrolData"); + } + } + + if (m_pDelegate) + { + m_pDelegate->NdListView_didClickCellAtRow(this, &data); + } +} + +void NdListView::triggerDidScrollToRow(unsigned int nRow) +{ + NdListViewProtrolData data; + data.nRow = nRow; + if (m_strDeletegate.size() > 0) + { + CCScriptEngineProtocol* scriptEngine = CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine(); + if (scriptEngine) + { + std::string script; + script = m_strDeletegate + "NdListView_didScrollToRow"; + scriptEngine->executeCallFuncNTDT(script.c_str(), this, "NdCxControl::NdListView", &data, "NdCxControl::NdListViewProtrolData"); + } + } + if (m_pDelegate) + { + m_pDelegate->NdListView_didScrollToRow(this, &data); + } +} + +void NdListView::displayVisibleRows(void) +{ + CCSize size = getContentSize(); + float posPannel, boundPannel; + unsigned int rowCount = m_drawedRows.location; + + NdListViewCell *cell = cellAtRow(rowCount); + + if (m_nMode == NdListViewModeHorizontal) + { + if (cell) + { + posPannel = cell->getPosition().x; + } + else + { + posPannel = m_layerPanel->getPosition().x; + } + boundPannel = posPannel + size.width; + } + else if (m_nMode == NdListViewModeVertical) + { + if (cell) + { + posPannel = cell->getPosition().y + cell->getContentSize().height; + } + else + { + posPannel = size.height - m_layerPanel->getPosition().y; + } + boundPannel = posPannel - size.height; + } + + NdListViewCell *lastCell = NULL; + while(1) + { + // row condition + if (rowCount >= m_nNumberOfRows) + break; + + // size condition + if (m_nMode == NdListViewModeHorizontal) + { + if (posPannel >= boundPannel) + break; + } + else if (m_nMode == NdListViewModeVertical) + { + if (posPannel <= boundPannel) + break; + } + + // get cell + NdListViewCell *cell = cellAtRow(rowCount); + + if (NULL == cell) + { + cell = triggerCellForRow(rowCount); + if (cell) + { + CCSize cellSize = cell->getContentSize(); + if (m_nMode == NdListViewModeHorizontal) + { + cell->setPosition(CCPointMake(posPannel, 0)); + cell->setContentSize(CCSizeMake(cellSize.width, size.height)); + } + else if (m_nMode == NdListViewModeVertical) + { + cell->setPosition(CCPointMake(0, posPannel - cellSize.height)); + cell->setContentSize(CCSizeMake(size.width, cellSize.height)); + } + m_layerPanel->addChild(cell, rowCount, rowCount); + } + } + + if (cell) + { + if (m_nMode == NdListViewModeHorizontal) + { + posPannel += cell->getContentSize().width; + } + else if (m_nMode == NdListViewModeVertical) + { + posPannel -= cell->getContentSize().height; + } + cell->setSeparatorStyle(m_nSeparatorStyle); + lastCell = cell; + } + + ++rowCount; + } + m_drawedRows.length = rowCount - m_drawedRows.location; + // 设置可视范围 + m_visibleRows = m_drawedRows; + + if (lastCell) + { + lastCell->setSeparatorStyle(NdListViewCellSeparatorStyleNone); + } +} + +NdListViewCell* NdListView::appendRowToBack(unsigned int nRow) +{ + if (nRow >= m_nNumberOfRows) + { + return NULL; + } + NdListViewCell *cell = cellAtRow(nRow); + if (cell == NULL) + { + cell = triggerCellForRow(nRow); + if (cell) + { + CCSize size = this->getContentSize(); + CCSize cellSize = cell->getContentSize(); + float pos; + unsigned int nLastRow = CCRange::CCMaxRange(m_drawedRows); + NdListViewCell *lastCell = cellAtRow(nLastRow); + if (lastCell) + { + if (m_nMode == NdListViewModeHorizontal) + { + pos = lastCell->getPosition().x + lastCell->getContentSize().width; + cell->setPosition(CCPointMake(pos, 0)); + cell->setContentSize(CCSizeMake(cellSize.width, size.height)); + } + else if (m_nMode == NdListViewModeVertical) + { + pos = lastCell->getPosition().y - cell->getContentSize().height; + cell->setPosition(CCPointMake(0, pos)); + cell->setContentSize(CCSizeMake(size.width, cellSize.height)); + } + + if (nRow == m_nSelectedRow) + { + cell->selected(); + } + m_layerPanel->addChild(cell, nRow, nRow); + if (nRow > CCRange::CCMaxRange(m_drawedRows)) + { + cell->setSeparatorStyle(NdListViewCellSeparatorStyleNone); + lastCell->setSeparatorStyle(m_nSeparatorStyle); + m_drawedRows.length += nRow - CCRange::CCMaxRange(m_drawedRows); + } + else + { + cell->setSeparatorStyle(m_nSeparatorStyle); + } + } + else + { + CCLog("NdListView cell == NULL at line %d", __LINE__); + } + } + else + { + CCLog("NdListView cell == NULL at line %d", __LINE__); + } + } + return cell; +} + +NdListViewCell* NdListView::appendRowToFront(unsigned int nRow) +{ + NdListViewCell *cell = cellAtRow(nRow); + if (cell == NULL) + { + cell = triggerCellForRow(nRow); + if (cell) + { + CCSize size = this->getContentSize(); + CCSize cellSize = cell->getContentSize(); + float pos; + unsigned int nFirstRow = m_drawedRows.location; + NdListViewCell *firstCell = cellAtRow(nFirstRow); + if (firstCell) + { + if (m_nMode == NdListViewModeHorizontal) + { + pos = firstCell->getPosition().x - cell->getContentSize().width; + cell->setPosition(CCPointMake(pos, 0)); + cell->setContentSize(CCSizeMake(cellSize.width, size.height)); + } + else if (m_nMode == NdListViewModeVertical) + { + pos = firstCell->getPosition().y + firstCell->getContentSize().height; + cell->setPosition(CCPointMake(0, pos)); + cell->setContentSize(CCSizeMake(size.width, cellSize.height)); + } + cell->setSeparatorStyle(m_nSeparatorStyle); + if (nRow == m_nSelectedRow) + { + cell->selected(); + } + m_layerPanel->addChild(cell, nRow, nRow); + if (nRow < m_drawedRows.location) + { + m_drawedRows.length += m_drawedRows.location - nRow; + m_drawedRows.location = nRow; + } + } + else + { + CCLog("NdListView cell == NULL at line %d", __LINE__); + } + } + else + { + CCLog("NdListView cell == NULL at line %d", __LINE__); + } + } + return cell; +} +// 对齐末行 +void NdListView::fixFirstRow(void) +{ + unsigned int location = m_drawedRows.location; + + NdListViewCell *cell = cellAtRow(location); + if (cell) + { + float disX = 0; + float disY = 0; + CCPoint posCell = cell->convertToWorldSpace(CCPointZero); + CCPoint posView = this->convertToWorldSpace(CCPointZero); + if (NdListViewModeHorizontal == m_nMode) + { + float dis = posCell.x - posView.x; + dis = -dis; + + disX = dis; + disY = 0; + } + else if (NdListViewModeVertical == m_nMode) + { + float dis = posCell.y + cell->getContentSize().height - (posView.y + this->getContentSize().height); + dis = -dis; + + disX = 0; + disY = dis; + } + + m_nState = NdListViewStateFix; + CCMoveBy *moveBy = CCMoveBy::actionWithDuration(m_fActionDuration, CCPointMake(disX, disY)); + CCEaseInOut *ease = CCEaseInOut::actionWithAction(moveBy, 2); + CCFiniteTimeAction *actions = CCSequence::actions(ease, CCCallFunc::actionWithTarget(this, callfunc_selector(NdListView::finishFix)), NULL); + m_layerPanel->runAction(actions); + } + else + { + this->finishFix(); + } +} +// 对齐首行 +void NdListView::fixLastRow(void) +{ + unsigned int nLastRow = CCRange::CCMaxRange(m_drawedRows); + NdListViewCell *cell = cellAtRow(nLastRow); + if (cell) + { + float disX = 0; + float disY = 0; + CCPoint posCell = cell->convertToWorldSpace(CCPointZero); + CCPoint posView = this->convertToWorldSpace(CCPointZero); + if (NdListViewModeHorizontal == m_nMode) + { + float dis = posCell.x + cell->getContentSize().width - (posView.x + this->getContentSize().width); + dis = -dis; + + disX = dis; + disY = 0; + } + else if (NdListViewModeVertical == m_nMode) + { + float dis = posCell.y - posView.y; + dis = -dis; + + disX = 0; + disY = dis; + } + + m_nState = NdListViewStateFix; + CCMoveBy *moveBy = CCMoveBy::actionWithDuration(m_fActionDuration, CCPointMake(disX, disY)); + CCEaseInOut *ease = CCEaseInOut::actionWithAction(moveBy, 2); + CCFiniteTimeAction *actions = CCSequence::actions(ease, CCCallFunc::actionWithTarget(this, callfunc_selector(NdListView::finishFix)), NULL); + m_layerPanel->runAction(actions); + } + else + { + finishFix(); + } +} +// 手势滑动界面,减速效果 +void NdListView::easeOutWithDistance(float dis) +{ + float disX = 0; + float disY = 0; + + if (NdListViewModeHorizontal == m_nMode) + { + if (NdListViewSlideDirLeft == m_nSlideDir) + { + // drag Left + while(1) + { + unsigned int nLastRow = CCRange::CCMaxRange(m_drawedRows); + NdListViewCell *cell = cellAtRow(nLastRow); + if (cell) + { + CCPoint ptCell = cell->convertToWorldSpace(CCPointZero); + CCPoint ptView = this->convertToWorldSpace(CCPointZero); + if (nLastRow < m_nNumberOfRows - 1) + { + float offset = ptView.x + this->getContentSize().width - (ptCell.x + cell->getContentSize().width); + if (offset > dis) + { + appendRowToBack(nLastRow + 1); + } + else + { + dis = offset; + break; + } + } + else + { + // already is the last row + float leftMin = cell->getContentSize().width / 5; + float offset = ptCell.x + cell->getContentSize().width + dis - ptView.x; + if (offset < -leftMin) + { + dis = ptView.x + leftMin - (ptCell.x + cell->getContentSize().width); + } + offset = ptCell.x + cell->getContentSize().width + dis - (ptView.x + this->getContentSize().width) ; + if (offset > 0) + { + dis = ptView.x + this->getContentSize().width - (ptCell.x + cell->getContentSize().width); + } + break; + } + } + else + { + break; + } + } + } + else + { + // drag right + while(1) + { + unsigned int nFirstRow = m_drawedRows.location; + NdListViewCell *cell = cellAtRow(nFirstRow); + if (cell) + { + CCPoint ptCell = cell->convertToWorldSpace(CCPointZero); + CCPoint ptView = this->convertToWorldSpace(CCPointZero); + if (nFirstRow > 0) + { + float offset = ptView.x - ptCell.x; + if (offset < dis) + { + appendRowToFront(nFirstRow - 1); + } + else + { + dis = offset; + break; + } + } + else + { + // already is the first row + float leftMin = cell->getContentSize().width / 5; + float offset = ptCell.x + dis - (ptView.x + this->getContentSize().width); + if (offset > leftMin) + { + dis = ptView.x + this->getContentSize().width - leftMin - ptCell.x; + } + offset = ptView.x - ptCell.x; + if (offset > 0) + { + dis = offset; + } + break; + } + } + else + { + + } + } + } + disX = dis; + disY = 0; + } + else if (NdListViewModeVertical == m_nMode) + { + if (NdListViewSlideDirUp == m_nSlideDir) + { + // drag up + while(1) + { + unsigned int nLastRow = CCRange::CCMaxRange(m_drawedRows); + NdListViewCell *cell = cellAtRow(nLastRow); + if (cell) + { + CCPoint ptCell = cell->convertToWorldSpace(CCPointZero); + CCPoint ptView = this->convertToWorldSpace(CCPointZero); + if (nLastRow < m_nNumberOfRows - 1) + { + float offset = ptView.y - ptCell.y; + if (offset < dis) + { + appendRowToBack(nLastRow + 1); + } + else + { + dis = offset; + break; + } + } + else + { + // already is the last row + m_fActionDuration *= 0.5; + float leftMin = cell->getContentSize().height / 5; + float offset = ptCell.y + dis - (ptView.y + this->getContentSize().height); + if (offset > -leftMin) + { + dis = ptView.y + this->getContentSize().height - leftMin - ptCell.y; + } + break; + } + } + else + { + break; + } + } + } + else + { + // drag down + while(1) + { + unsigned int nFirstRow = m_drawedRows.location; + NdListViewCell *cell = cellAtRow(nFirstRow); + if (cell) + { + CCPoint ptCell = cell->convertToWorldSpace(CCPointZero); + CCPoint ptView = this->convertToWorldSpace(CCPointZero); + if (nFirstRow > 0) + { + float offset = ptView.y + this->getContentSize().height - (ptCell.y + cell->getContentSize().height); + if (offset > dis) + { + appendRowToFront(nFirstRow - 1); + } + else + { + dis = offset; + break; + } + } + else + { + // already is the first row + m_fActionDuration *= 0.5; + float leftMin = cell->getContentSize().height / 5; + float offset = ptCell.y + cell->getContentSize().height + dis - ptView.y; + if (offset < leftMin) + { + dis = ptView.y + leftMin - (ptCell.y + cell->getContentSize().height); + } + break; + } + } + else + { + + } + } + } + disX = 0; + disY = dis; + } + + m_nState = NdListViewStateEaseOut; + CCMoveBy *moveBy = CCMoveBy::actionWithDuration(m_fActionDuration, CCPointMake(disX, disY)); + CCEaseOut *ease = CCEaseOut::actionWithAction(moveBy, 3); + CCFiniteTimeAction *actions = CCSequence::actions(ease, CCCallFunc::actionWithTarget(this, callfunc_selector(NdListView::finishEaseOut)), NULL); + m_layerPanel->runAction(actions); +} + +void NdListView::clearUnvisibleRows(void) +{ + CCRange oldRange = m_drawedRows; + for (unsigned int i = oldRange.location; i < oldRange.location + oldRange.length; i++) + { + NdListViewCell *cell = cellAtRow(i); + if (cell) + { + CCPoint posCell = cell->convertToWorldSpace(CCPointZero); + CCPoint posView = this->convertToWorldSpace(CCPointZero); + if (NdListViewModeHorizontal == m_nMode) + { + if (posCell.x + cell->getContentSize().width <= posView.x) + { + m_layerPanel->removeChild(cell, true); + } + else + { + break; + } + } + else if (NdListViewModeVertical == m_nMode) + { + if (posCell.y >= posView.y + this->getContentSize().height) + { + m_layerPanel->removeChild(cell, true); + } + else + { + break; + } + } + } + m_drawedRows.location++; + m_drawedRows.length--; + } + + oldRange = m_drawedRows; + for (int i = oldRange.location + oldRange.length - 1; i >= (int)oldRange.location; i--) + { + NdListViewCell *cell = cellAtRow(i); + if (cell) + { + CCPoint posCell = cell->convertToWorldSpace(CCPointZero); + CCPoint posView = this->convertToWorldSpace(CCPointZero); + if (NdListViewModeHorizontal == m_nMode) + { + if (posCell.x >= posView.x + this->getContentSize().width) + { + m_layerPanel->removeChild(cell, true); + } + else + { + break; + } + } + else if (NdListViewModeVertical == m_nMode) + { + if (posCell.y + cell->getContentSize().height <= posView.y) + { + m_layerPanel->removeChild(cell, true); + } + else + { + break; + } + } + } + m_drawedRows.length--; + } + + m_visibleRows = m_drawedRows; +} +/****************************************** +**************Virturl Functions************ +*******************************************/ +void NdListView::registerWithTouchDispatcher() +{ + if (m_pListViewParent) + { + CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, kCCMenuTouchPriority - 1, false); + } + else + { + CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, kCCMenuTouchPriority - 2, false); + } +} + +void NdListView::onEnter(void) +{ + if (0 == m_nNumberOfRows) + { + m_layerPanel->setPosition(CCPointZero); + m_layerPanel->setContentSize(this->getContentSize()); + // get number of rows + m_nNumberOfRows = triggerNumberOfCells(); + displayVisibleRows(); + } + + CCLayerColor::onEnter(); +} + +void NdListView::onExit(void) +{ + CCLayerColor::onExit(); +} + +void NdListView::visit(void) +{ + if (!m_pListViewParent) + { + CCRect rectSelf; + float factor = CC_CONTENT_SCALE_FACTOR(); + rectSelf.origin = convertToWorldSpace(CCPoint(0,0)); + rectSelf.origin.x *= factor; + rectSelf.origin.y *= factor; + rectSelf.size = this->getContentSize(); + rectSelf.size.width *= factor; + rectSelf.size.height *= factor; + glScissor((GLsizei)rectSelf.origin.x, (GLsizei)rectSelf.origin.y, (GLsizei)rectSelf.size.width , (GLsizei)rectSelf.size.height); + glEnable(GL_SCISSOR_TEST); + } + CCLayerColor::visit(); + if (!m_pListViewParent) + { + glDisable(GL_SCISSOR_TEST); + } +} + +bool NdListView::ccTouchBegan(CCTouch* touch, CCEvent* event) +{ + CC_UNUSED_PARAM(event); + + if (!isTouchInside(touch) || !getIsVisible() || !m_bIsEnabled) + { + return false; + } + + if (m_pListViewParent && NdListViewSlideDirNone != m_pListViewParent->getSlideDir()) + { + return false; + } + + CCArray *children = this->getChildren(); + if (!m_bIsVisible || !children || children->count() == 0) + { + return false; + } + + if (m_bIsOnTouch) + { + return false; + } + + CCPoint touchPoint = touch->locationInView(touch->view()); + + m_ptTouchBegan = m_ptTouchEnd = CCDirector::sharedDirector()->convertToGL(touchPoint); + m_ptPanelOffset = m_layerPanel->getPosition(); + + m_timeTouchBegan = clock(); + + m_nCurrentRow = this->rowForTouch(touch); + if (m_nCurrentRow != -1) + { + if (NdListViewStateWatting != m_nState) + { + stopActionImmediately(); + } + + m_nState = NdListViewStateTrackingTouch; + if (NdListViewSlideDirNone == m_nSlideDir) + { + this->selectCellAtRow(m_nCurrentRow); + } + else + { + m_nCurrentRow = -1; + } + m_bIsOnTouch = true; + return true; + } + + + return false; +} + +void NdListView::ccTouchMoved(CCTouch* touch, CCEvent* event) +{ + CC_UNUSED_PARAM(event); + if (NdListViewStateTrackingTouch != m_nState || !isTouchInside(touch) || !m_bIsEnabled) + { + return; + } + + CCPoint touchPoint = touch->locationInView(touch->view()); + m_ptTouchEnd = CCDirector::sharedDirector()->convertToGL(touchPoint); + + + NdListViewSlideDir nsliderDir = NdListViewSlideDirNone; + if (m_pListViewParent && NdListViewSlideDirNone != m_pListViewParent->getSlideDir(m_ptTouchBegan, m_ptTouchEnd)) + { + return; + } + else + { + nsliderDir = getSlideDir(m_ptTouchBegan, m_ptTouchEnd); + } + + + if(NdListViewModeHorizontal == m_nMode && NdListViewSlideDirNone != nsliderDir) + { + m_nSlideDir = nsliderDir; + m_layerPanel->setPosition(CCPointMake(m_ptPanelOffset.x + (m_ptTouchEnd.x - m_ptTouchBegan.x),m_ptPanelOffset.y)); + if (NdListViewSlideDirLeft == m_nSlideDir) + { + // drag left + unsigned int nLastRow = CCRange::CCMaxRange(m_drawedRows); + if (nLastRow < m_nNumberOfRows - 1) + { + NdListViewCell *cell = cellAtRow(nLastRow); + CCPoint posCell = cell->convertToWorldSpace(CCPointZero); + CCPoint posView = this->convertToWorldSpace(CCPointZero); + if (posCell.x + cell->getContentSize().width <= posView.x + this->getContentSize().width) + { + appendRowToBack(nLastRow + 1); + } + } + } + else + { + // drag right + unsigned int nFirstRow = m_drawedRows.location; + if (nFirstRow > 0) + { + NdListViewCell *cell = cellAtRow(nFirstRow); + CCPoint posCell = cell->convertToWorldSpace(CCPointZero); + CCPoint posView = this->convertToWorldSpace(CCPointZero); + if (posCell.x >= posView.x) + { + appendRowToFront(nFirstRow - 1); + } + } + } + } + else if (NdListViewModeVertical == m_nMode && NdListViewSlideDirNone != nsliderDir) + { + m_nSlideDir = nsliderDir; + m_layerPanel->setPosition(CCPointMake(m_ptPanelOffset.x, m_ptPanelOffset.y + (m_ptTouchEnd.y - m_ptTouchBegan.y))); + if (NdListViewSlideDirUp == m_nSlideDir) + { + // drag up + unsigned int nLastRow = CCRange::CCMaxRange(m_drawedRows); + if (nLastRow < m_nNumberOfRows - 1) + { + NdListViewCell *cell = cellAtRow(nLastRow); + CCPoint posCell = cell->convertToWorldSpace(CCPointZero); + CCPoint posView = this->convertToWorldSpace(CCPointZero); + if (posCell.y >= posView.y) + { + appendRowToBack(nLastRow + 1); + } + } + } + else + { + // drag down + unsigned int nFirstRow = m_drawedRows.location; + if (nFirstRow > 0) + { + NdListViewCell *cell = cellAtRow(nFirstRow); + CCPoint posCell = cell->convertToWorldSpace(CCPointZero); + CCPoint posView = this->convertToWorldSpace(CCPointZero); + if (posCell.y + cell->getContentSize().height <= posView.y + this->getContentSize().height) + { + appendRowToFront(nFirstRow - 1); + } + } + } + } + + if (NdListViewSlideDirNone != m_nSlideDir && m_nCurrentRow != -1 && m_nCurrentRow != m_nSelectedRow) + { + this->unselectCellAtRow(m_nCurrentRow); + } + + if (NdListViewSlideDirNone != m_nSlideDir && m_pListViewParent) + { + m_pListViewParent->setIsEnabled(false); + } +} + +void NdListView::ccTouchEnded(CCTouch* touch, CCEvent* event) +{ + CC_UNUSED_PARAM(touch); + CC_UNUSED_PARAM(event); + + if(m_nState != NdListViewStateTrackingTouch || !m_bIsEnabled) + { + m_bIsOnTouch = false; + return; + } + + m_fActionDuration = ND_LISTVIEW_ACTION_INTERVAL; + clock_t timeElapse = clock() - m_timeTouchBegan; +#if CC_TARGET_PLATFORM != CC_PLATFORM_WIN32 && CC_TARGET_PLATFORM != CC_PLATFORM_MAC + // 手机平台用时较长,此系数可能需要根据不同平台做相应调整 + timeElapse /= 200; +#endif + if(NdListViewSlideDirLeft == m_nSlideDir || NdListViewSlideDirRight == m_nSlideDir) + { + float dis = m_ptTouchEnd.x - m_ptTouchBegan.x; + float speed = dis / timeElapse; + if (fabs(speed) > 0.1 && timeElapse < 300) + { + easeOutWithDistance(dis * 3); + } + else + { + if (NdListViewSlideDirLeft == m_nSlideDir && isFullFill()) + { + // drag up + fixLastRow(); + } + else + { + // drag down + fixFirstRow(); + } + } + } + else if (NdListViewSlideDirUp == m_nSlideDir || NdListViewSlideDirDown == m_nSlideDir) + { + float dis = m_ptTouchEnd.y - m_ptTouchBegan.y; + float speed = dis / timeElapse; + if (fabs(speed) > 0.1 && timeElapse < 300) + { + easeOutWithDistance(dis * 3); + } + else + { + if (NdListViewSlideDirUp == m_nSlideDir && isFullFill()) + { + // drag up + fixLastRow(); + } + else + { + // drag down + fixFirstRow(); + } + } + } + else + { + finishFix(); + } + + int currentRow = this->rowForTouch(touch); + if (currentRow != -1 && isTouchInside(touch)) + { + if (currentRow == m_nCurrentRow) + { + if (NdListViewSlideDirNone == m_nSlideDir) + { + if (m_pListViewParent == NULL || (m_pListViewParent && NdListViewSlideDirNone == m_pListViewParent->getSlideDir())) + { + if (m_nSelectedRow != -1 && m_nSelectedRow != m_nCurrentRow) + { + this->unselectCellAtRow(m_nSelectedRow); + } + m_nSelectedRow = m_nCurrentRow; + + if (!this->isMenuTouch(touch, this->cellAtRow(m_nSelectedRow))) + { + triggerDidClickCellAtRow(m_nSelectedRow); + } + } + } + else + { + if (m_nSelectedRow != m_nCurrentRow) + { + this->unselectCellAtRow(m_nCurrentRow); + } + } + } + else + { + if (-1 != m_nCurrentRow) + { + this->unselectCellAtRow(m_nCurrentRow); + } + } + } + else + { + if (-1 != m_nCurrentRow) + { + this->unselectCellAtRow(m_nCurrentRow); + m_nCurrentRow = -1; + } + } + m_bIsOnTouch = false; +} + +bool NdListView::isMenuTouch(CCTouch *touch, CCNode *parent) +{ + if (parent->getClassType() == CCMenuItem_classID) + { + CCPoint touchPoint = touch->locationInView(touch->view()); + touchPoint.y = cocos2d::CCDirector::sharedDirector()->getWinSize().height - touchPoint.y; + touchPoint = parent->convertToNodeSpace(touchPoint); + CCRect rect = CCRectZero; + rect.size = parent->getContentSize(); + return CCRect::CCRectContainsPoint(rect, touchPoint); + } + else + { + CCArray *pChildrens = parent->getChildren(); + if (pChildrens && pChildrens->count() > 0) + { + for (int i = 0; i < pChildrens->count(); i++) + { + CCNode *pChildren = (CCNode*)pChildrens->objectAtIndex(i); + if (this->isMenuTouch(touch, pChildren)) + { + return true; + } + } + } + } + return false; +} + +void NdListView::ccTouchCancelled(CCTouch *touch, CCEvent *event) +{ + CC_UNUSED_PARAM(touch); + CC_UNUSED_PARAM(event); + + CCAssert(m_nState == NdListViewStateTrackingTouch, "[NdListview ccTouchCancelled] -- invalid state"); + + finishFix(); + m_bIsOnTouch = false; +} + +} // end of namespace NdCxControl + + + + diff --git a/cocos2dx/extensions/TextureWatcher/NdListView.h b/cocos2dx/extensions/TextureWatcher/NdListView.h new file mode 100644 index 0000000000..59a3cc07e9 --- /dev/null +++ b/cocos2dx/extensions/TextureWatcher/NdListView.h @@ -0,0 +1,154 @@ +#ifndef __ND_LIST_VIEW_H__ +#define __ND_LIST_VIEW_H__ + +#include +#include "platform.h" +#include +#include "../cocos2dx_support/LuaEngine.h" +#include "NdListViewCell.h" + +using namespace cocos2d; +namespace NdCxControl +{ + typedef enum + { + NdListViewSlideDirNone, + NdListViewSlideDirUp, + NdListViewSlideDirDown, + NdListViewSlideDirLeft, + NdListViewSlideDirRight, + } NdListViewSlideDir; + + typedef enum + { + NdListViewStateWatting, + NdListViewStateTrackingTouch, + NdListViewStateEaseOut, + NdListViewStateFix, + NdListViewStateScroll, + } NdListViewState; + + typedef enum + { + NdListViewModeHorizontal, + NdListViewModeVertical, + } NdListViewMode; + + typedef struct _NdListViewProtrolData + { + unsigned int nNumberOfRows; + unsigned int nRow; + NdListViewCell *cell; + } NdListViewProtrolData; + + class NdListViewDelegate + { + public : + NdListViewDelegate(){}; + virtual ~NdListViewDelegate(){}; + + virtual void NdListView_numberOfCells(NdListView *listView, NdListViewProtrolData *data)=0; + virtual void NdListView_cellForRow(NdListView *listView, NdListViewProtrolData *data)=0; + virtual void NdListView_didClickCellAtRow(NdListView *listView, NdListViewProtrolData *data)=0; + virtual void NdListView_didScrollToRow(NdListView *listView, NdListViewProtrolData *data)=0; + }; + + + class LUA_DLL NdListView : public CCLayerColor + { + public: + virtual ~NdListView(void); + NdListView(void); + + static NdListView* viewWithMode(NdListViewMode mode); + bool initWithMode(NdListViewMode mode); + + void setDelegateName(const char* pszName); + void selectCellAtRow(unsigned int nRow); + void unselectCellAtRow(unsigned int nRow); + void scrollCellToFront(unsigned int nRow, bool bAnimated); + void scrollCellToBack(unsigned int nRow, bool bAnimated); + void reload(void); + void insertCellsAtRow(unsigned int nRow, unsigned int nCount); + void deleteCellsAtRow(unsigned int nRow, unsigned int nCount); + NdListViewCell *cellAtRow(unsigned int nRow); + + NdListViewSlideDir getSlideDir(CCPoint ptTouchBegan, CCPoint ptTouchEnd); + inline NdListViewSlideDir getSlideDir(void) { return m_nSlideDir; } + + inline NdListViewCellSeparatorStyle getSeparatorStyle(void) { return m_nSeparatorStyle; } + inline void setSeparatorStyle(NdListViewCellSeparatorStyle style) { m_nSeparatorStyle = style; } + inline NdListViewMode getMode(void) { return m_nMode; } + + inline void setListViewParent(NdListView *pParent) { m_pListViewParent = pParent; } + inline NdListView *getListViewParent(void) { return m_pListViewParent; } + + inline void setIsEnabled(bool bEnabled) { m_bIsEnabled = bEnabled; } + inline bool getIsEnabled(void) { return m_bIsEnabled; } + + // un + void setDelegate(const NdListViewDelegate *pDelegate); + void finishFix(void); + void finishScroll(void); + void finishEaseOut(void); + + public: + virtual bool ccTouchBegan(CCTouch* touch, CCEvent* event); + virtual void ccTouchEnded(CCTouch* touch, CCEvent* event); + virtual void ccTouchCancelled(CCTouch *touch, CCEvent* event); + virtual void ccTouchMoved(CCTouch* touch, CCEvent* event); + + virtual void onEnter(void); + virtual void onExit(void); + + virtual void registerWithTouchDispatcher(void); + virtual void visit(void); + + protected: + void displayVisibleRows(void); + NdListViewCell* appendRowToBack(unsigned int nRow); + NdListViewCell* appendRowToFront(unsigned int nRow); + void fixFirstRow(void); + void fixLastRow(void); + void easeOutWithDistance(float dis); + void clearUnvisibleRows(void); + + int rowForTouch(cocos2d::CCTouch *touch); + bool isTouchInside(CCTouch *touch); + bool isFullFill(void); + + void stopActionImmediately(void); + + unsigned int triggerNumberOfCells(void); + NdListViewCell *triggerCellForRow(unsigned int nRow); + void triggerDidClickCellAtRow(unsigned int nRow); + void triggerDidScrollToRow(unsigned int nRow); + bool isMenuTouch(CCTouch *touch, CCNode *parent); + + private: + NdListViewState m_nState; + NdListViewMode m_nMode; + NdListViewSlideDir m_nSlideDir; + NdListViewCellSeparatorStyle m_nSeparatorStyle; + unsigned int m_nNumberOfRows; + float m_fActionDuration; + clock_t m_timeTouchBegan; + CCRange m_drawedRows; //所有已绘制的cell + CCRange m_visibleRows; //所有可见的cell + CCPoint m_ptTouchBegan; + CCPoint m_ptTouchEnd; + CCPoint m_ptPanelOffset; + CCPoint m_ptDestination; + std::string m_strDeletegate; + NdListViewDelegate* m_pDelegate; + CCLayer* m_layerPanel; + NdListView* m_pListViewParent; + int m_nSelectedRow; + int m_nCurrentRow; + bool m_bIsEnabled; + bool m_bIsOnTouch; + }; +} // end of namespace NdCxControl + + +#endif // __ND_LIST_VIEW_H__ \ No newline at end of file diff --git a/cocos2dx/extensions/TextureWatcher/NdListViewCell.cpp b/cocos2dx/extensions/TextureWatcher/NdListViewCell.cpp new file mode 100644 index 0000000000..11b6f216ef --- /dev/null +++ b/cocos2dx/extensions/TextureWatcher/NdListViewCell.cpp @@ -0,0 +1,96 @@ + +#include "NdListView.h" +#include "NdListViewCell.h" + + +const int TOUCHBEGIN = 1; +const int TOUCHEND = 2; +const int TOUCHMOVING = 3; +const int TOUCHCANCELLED= 4; + +namespace NdCxControl +{ +/****************************************** +**************Public Functions************* +*******************************************/ +NdListViewCell::NdListViewCell(void) + :m_nSeparatorStyle(NdListViewCellSeparatorStyleNone) + ,m_bIsSelected(false) +{ + setIsTouchEnabled(true); + m_selectionColor = ccc4(0, 0, 255, 255); + m_separatorLineColor = ccc3(128, 128, 128); +} + +NdListViewCell::~NdListViewCell(void) +{ + +} + +NdListViewCell *NdListViewCell::node(void) +{ + NdListViewCell *pRet = new NdListViewCell(); + pRet->initWithColorWidthHeight(ccc4(255, 255, 255, 255), 0, 0); + pRet->autorelease(); + return pRet; +} + +void NdListViewCell::selected(void) +{ + m_bIsSelected = true; + CCLayerColor::setColor(ccc3(m_selectionColor.r, m_selectionColor.g, m_selectionColor.b)); + CCLayerColor::setOpacity(m_selectionColor.a); +} + +void NdListViewCell::unselected(void) +{ + m_bIsSelected = false; + CCLayerColor::setColor(ccc3(m_normalColor.r, m_normalColor.g, m_normalColor.b)); + CCLayerColor::setOpacity(m_normalColor.a); +} + +/****************************************** +**************Virturl Functions************ +*******************************************/ +bool NdListViewCell::initWithColorWidthHeight(ccColor4B color, GLfloat width, GLfloat height) +{ + this->m_normalColor = color; + return CCLayerColor::initWithColorWidthHeight(color, width, height); +} + +void NdListViewCell::draw(void) +{ + CCLayerColor::draw(); + CCSize size = this->getContentSize(); + NdListView *owner = this->getOwner(); + if (NdListViewCellSeparatorStyleSingleLine == m_nSeparatorStyle) + { + glLineWidth(1.0f); + glColor4ub(m_separatorLineColor.r, m_separatorLineColor.g, m_separatorLineColor.b, 255); + + if (NdListViewModeHorizontal == owner->getMode()) + { + ccDrawLine(CCPointMake(size.width, 0), CCPointMake(size.width, size.height)); + } + else if (NdListViewModeVertical == owner->getMode()) + { + ccDrawLine(CCPointMake(0, 0), CCPointMake(size.width, 0)); + } + } +} + +void NdListViewCell::setColor(ccColor3B var) +{ + m_normalColor.r = var.r; + m_normalColor.g = var.g; + m_normalColor.b = var.b; + CCLayerColor::setColor(var); +} + +void NdListViewCell::setOpacity(GLubyte var) +{ + m_normalColor.a = var; + CCLayerColor::setOpacity(var); +} + +} // end of namespace NdCxControl \ No newline at end of file diff --git a/cocos2dx/extensions/TextureWatcher/NdListViewCell.h b/cocos2dx/extensions/TextureWatcher/NdListViewCell.h new file mode 100644 index 0000000000..74fa59c569 --- /dev/null +++ b/cocos2dx/extensions/TextureWatcher/NdListViewCell.h @@ -0,0 +1,60 @@ +#ifndef __ND_LIST_VIEW_CELL_H_ +#define __ND_LIST_VIEW_CELL_H_ + +#include "ControlDefine.h" +#include "cocos2d.h" +#include +#include +using namespace cocos2d; + +namespace NdCxControl { + +#define LUA_DLL CC_DLL + +class NdListView; +typedef enum +{ + NdListViewCellSeparatorStyleNone, + NdListViewCellSeparatorStyleSingleLine, +}NdListViewCellSeparatorStyle; + +class LUA_DLL NdListViewCell : public CCLayerColor +{ + public: + NdListViewCell(void); + virtual ~NdListViewCell(void); + + static NdListViewCell *node(void); + + void selected(void); + void unselected(void); + + inline NdListViewCellSeparatorStyle getSeparatorStyle(void) { return m_nSeparatorStyle; } + inline void setSeparatorStyle(NdListViewCellSeparatorStyle style) { m_nSeparatorStyle = style; } + + inline ccColor4B getSelectionColor(void) { return m_selectionColor; } + inline void setSelectionColor(ccColor4B color) { m_selectionColor = color; } + + inline ccColor3B getSeparatorLineColor(void) { return m_separatorLineColor; } + inline void setSeparatorLineColor(ccColor3B color) { m_separatorLineColor = color; } + + public: + virtual bool initWithColorWidthHeight(ccColor4B color, GLfloat width, GLfloat height); + virtual void draw(void); + virtual void setColor(ccColor3B color); + virtual void setOpacity(GLubyte var); + + private: + inline NdListView *getOwner(void) { return (NdListView*)(this->getParent()->getParent()); } + + private: + NdListViewCellSeparatorStyle m_nSeparatorStyle; + bool m_bIsSelected; + ccColor4B m_selectionColor; + ccColor4B m_normalColor; + ccColor3B m_separatorLineColor; +}; + +} // end of NdCxControl + +#endif // __ND_LIST_VIEW_CELL_H_ \ No newline at end of file diff --git a/cocos2dx/extensions/TextureWatcher/NdTextureWatcher.cpp b/cocos2dx/extensions/TextureWatcher/NdTextureWatcher.cpp new file mode 100644 index 0000000000..4f4367008e --- /dev/null +++ b/cocos2dx/extensions/TextureWatcher/NdTextureWatcher.cpp @@ -0,0 +1,396 @@ +#include "NdTextureWatcher.h" +#include "CCTextureCache.h" +#include "CCLayer.h" +#include "CCSprite.h" +#include "NdCxList.h" +namespace NdCxControl { +#define NUM_PER_PAGE 4 +NdTextureWatcher::NdTextureWatcher() +{ + m_bHide = false; + m_nCurrnetPage = 1; + m_nTotalPage = 0; + m_bFresh = true; + m_pTextures = NULL; + m_pszString = NULL; + m_pLayer = CCLayerColor::layerWithColor(ccc4(128, 128, 128, 128)); + m_pLayer->retain(); + + // layer + CCSize size = CCDirector::sharedDirector()->getWinSize(); + size.height *= 0.6; + m_pLayer->setContentSize(size); + + // 屏蔽点击事件的menu + //* + CCLabelTTF *label = CCLabelTTF::labelWithString(" ", size, CCTextAlignmentLeft, "Arial", 12); + CCMenuItemLabel *menuItem = CCMenuItemLabel::itemWithLabel(label); + menuItem->setAnchorPoint(ccp(0, 0)); + menuItem->setPosition(ccp(0, 0)); + + CCMenu *menu = CCMenu::menuWithItem(menuItem); + menu->setAnchorPoint(ccp(0, 0)); + menu->setPosition(ccp(0, 0)); + m_pLayer->addChild(menu); + //*/ + + // list + NdCxList *list = NdCxList::node(size.width, ccc4(0, 0, 0, 0), size); + list->setHorizontal(true); + list->setRecodeNumPerPage(1); + list->setPageTurnEffect(true); + list->registerLoaderListern((CNdListLoaderListener*)this); + m_pLayer->addChild(list, 0, 0); + m_pList = list; + + // 隐藏按钮 + CCLabelTTF *labelHide = CCLabelTTF::labelWithString("Hide ", "Arial", 24); + labelHide->setColor(ccc3(255, 0, 0)); + CCMenuItemLabel *menuItem2 = CCMenuItemLabel::itemWithLabel(labelHide, this, menu_selector(NdTextureWatcher::actionHide)); + menuItem2->setAnchorPoint(ccp(0, 0)); + menuItem2->setPosition(ccp(0, 0)); + + CCMenu *menu2 = CCMenu::menuWithItem(menuItem2); + menu2->setAnchorPoint(ccp(0, 0)); + menu2->setPosition(ccp(size.width - menuItem2->getContentSize().width, 0)); + + m_labelHide = labelHide; + m_menuHide = menu2; + m_menuHide->retain(); + + // 更新按钮 + CCLabelTTF *labelFresh = CCLabelTTF::labelWithString("Fresh", "Arial", 24); + labelFresh->setColor(ccc3(255, 0, 0)); + CCMenuItemLabel *menuItem1 = CCMenuItemLabel::itemWithLabel(labelFresh, this, menu_selector(NdTextureWatcher::actionFresh)); + menuItem1->setAnchorPoint(ccp(0, 0)); + menuItem1->setPosition(ccp(0, 0)); + + CCMenu *menu1 = CCMenu::menuWithItem(menuItem1); + menu1->setAnchorPoint(ccp(0, 0)); + menu1->setPosition(ccp(size.width - menuItem1->getContentSize().width - menuItem2->getContentSize().width * 1.5, 0)); + m_pLayer->addChild(menu1); + + // label page + m_labelPage = CCLabelTTF::labelWithString(" ", CCSizeMake(size.width * 0.1, labelFresh->getContentSize().height), CCTextAlignmentCenter, "Arial", 16); + m_labelPage->setAnchorPoint(ccp(0.5, 0)); + m_labelPage->setPosition(ccp(size.width/2.0, 0)); + m_pLayer->addChild(m_labelPage, 0); +} +NdTextureWatcher::~NdTextureWatcher() +{ + if (m_menuHide) m_menuHide->release(); + if (m_pTextures) m_pTextures->release(); + if (m_pszString) delete []m_pszString; +} +void NdTextureWatcher::actionFresh(CCObject* object) +{ + NdTextureWatcher::sharedTextureWatcher()->fresh(); +} +void NdTextureWatcher::actionHide(CCObject *object) +{ + NdTextureWatcher::sharedTextureWatcher()->hide(); +} +void NdTextureWatcher::fresh() +{ + m_nCurrnetPage = 1; + m_bFresh = true; +} +void NdTextureWatcher::hide() +{ + m_bHide = !m_bHide; + if (m_bHide) + { + m_labelHide->setString("Show"); + m_pLayer->setPosition(ccp(0, -m_pLayer->getContentSize().height)); + } + else + { + m_labelHide->setString("Hide"); + m_pLayer->setPosition(ccp(0, 0)); + } + +} +void NdTextureWatcher::showTexture() +{ + m_pList->clear(); + if (m_nTotalPage == 0) return; + CCTexture2D* textrue; + std::vector keys = m_pTextures->allKeys(); + std::vector::iterator it; + + CCSize listItemSize = CCSize(m_pList->getContentSize().width / NUM_PER_PAGE, m_pList->getContentSize().height); + + CCSize size = CCSize(listItemSize.width * 0.9, listItemSize.height * 0.6); + + LayoutParam layout = CxLayout(); + layout.val_x.t = ABS_WITH_PIXEL; + layout.val_y.t = ABS_WITH_PIXEL; + layout.wrap = false; + + int num, index; + if (m_nTotalPage <= 1) + { + num = 1; + index = 1; + } + else + { + if (m_nCurrnetPage == 1) + { + num = 2; + index = 1; + } + else if (m_nCurrnetPage == m_nTotalPage) + { + num = 2; + index = 2; + } + else + { + num = 3; + index = 2; + } + } + + sprintf(m_pszString, "%d/%d", m_nCurrnetPage, m_nTotalPage); + m_labelPage->setString(m_pszString); + + CCLayer *layer; + for (int i = 1; i <= num; i++) + { + NdCxListItem *listItem = NdCxListItem::itemWithColor(ccc3(124, 124, 124)); + listItem->setOpacity(0); + listItem->setDrawTopLine(false); + listItem->setDrawBottomLine(false); + + CCLayer *layer1 = CCLayer::node(); + layer1->setContentSize(m_pList->getContentSize()); + layout.val_x.val.pixel_val = 0; + layout.val_y.val.pixel_val = 0; + listItem->addChildItem(layer1, layout); + + if (i == index) + { + layer = layer1; + m_pList->addListItem(listItem, true); + } + else + { + m_pList->addListItem(listItem, false); + } + } + + m_pList->disableAllCtrlEvent(); + m_pList->turnToPage(index - 1); + + + float offX = 0, offY = 0, offsetX = 0, offsetY = 0; + CC_UNUSED_PARAM(offsetY); + int nCount = 0; + int nStart = (m_nCurrnetPage - 1) * NUM_PER_PAGE; + int nEnd = nStart + NUM_PER_PAGE; + + for (it = keys.begin(); it != keys.end(); ++it) + { + if (nCount >= nStart && nCount < nEnd) + { + string key = *it; + textrue = CCTextureCache::sharedTextureCache()->textureForKey(key.c_str()); + //textrue = m_pTextures->objectForKey(*it); + if (textrue) + { + // 引用数 + sprintf(m_pszString, "[%d]", textrue->retainCount() - 2); + CCLabelTTF *labelCount = CCLabelTTF::labelWithString(m_pszString, "Arial", 16); + if (textrue->retainCount() - 2 > 0) + { + labelCount->setColor(ccc3(0, 255, 0)); + } + else + { + labelCount->setColor(ccc3(255, 0, 0)); + } + offX = offsetX + listItemSize.width * 0.5 - labelCount->getContentSize().width * 0.5; + offY = (listItemSize.height - size.height) * 0.5 - labelCount->getContentSize().height; + labelCount->setPosition(ccp(offX, offY)); + labelCount->setAnchorPoint(ccp(0, 0)); + layer->addChild(labelCount); + + // 大小 + sprintf(m_pszString, "%.0f*%.0f", textrue->getContentSize().width, textrue->getContentSize().height); + CCLabelTTF *labelSize = CCLabelTTF::labelWithString(m_pszString, "Arial", 16); + offX = offsetX + listItemSize.width * 0.5; + offY = (listItemSize.height - size.height) * 0.5 + size.height; + labelSize->setPosition(ccp(offX, offY)); + labelSize->setAnchorPoint(ccp(0.5, 0)); + layer->addChild(labelSize); + + // 名称 + int len = key.length(); + int pos = 0; +#if defined(ND_MAC) || defined(ND_IPHONE) + pos = key.rfind('/') + 1; +#else + pos = key.rfind('\\') + 1; + int pos2 = key.rfind('/') + 1; + pos = pos > pos2 ? pos : pos2; +#endif + string name = key.substr(pos, len - pos); + sprintf(m_pszString, "%s", name.c_str()); + CCSize dimensions = CCSizeMake(listItemSize.width * 0.9, labelSize->getContentSize().height); + CCLabelTTF *labelName = CCLabelTTF::labelWithString(m_pszString, dimensions, CCTextAlignmentCenter, "Arial", 16); + offX = offsetX + listItemSize.width * 0.5; + offY = offY + labelName->getContentSize().height; + labelName->setPosition(ccp(offX, offY)); + labelName->setAnchorPoint(ccp(0.5, 0)); + layer->addChild(labelName); + + CCSprite *sprite = CCSprite::spriteWithTexture(textrue); + sprite->setAnchorPoint(ccp(0, 0)); + + CCSize spriteSize = sprite->getContentSize(); + float scale; + if (spriteSize.width < size.width && spriteSize.height < size.height) + { + scale = 1; + } + else if (spriteSize.width * size.height >= spriteSize.height * size.width) + { + scale = size.width / spriteSize.width; + } + else + { + scale = size.height / spriteSize.height; + } + sprite->setScale(scale); + spriteSize.width *= scale; + spriteSize.height *= scale; + offX = offsetX + (listItemSize.width - spriteSize.width) * 0.5; + offY = (listItemSize.height - spriteSize.height) * 0.5; + sprite->setPosition(ccp(offX, offY)); + layer->addChild(sprite); + offsetX += listItemSize.width; + } + } + ++nCount; + } +} +void NdTextureWatcher::dovisit() +{ + if (m_bFresh) + { + if (m_pTextures) + { + m_pTextures->removeAllObjects(); + m_pTextures->release(); + } + if (m_pList) + { + m_pList->clear(); + } + CCTextureCache::sharedTextureCache()->removeUnusedTextures(); + m_pTextures = CCTextureCache::sharedTextureCache()->snapshotTextures(); + m_nTotalPage = (m_pTextures->count() + NUM_PER_PAGE - 1) / NUM_PER_PAGE; + if (m_pTextures->count() > 0) + { + m_bFresh = false; + showTexture(); + } + } + CCNode *pParent = m_pLayer->getParent(); + if (pParent) + { + if (pParent != CCDirector::sharedDirector()->getRunningScene()) + { + pParent->removeChild(m_pLayer, true); + CCDirector::sharedDirector()->getRunningScene()->addChild(m_pLayer, 9998); + m_bFresh = true; + } + } + else + { + CCDirector::sharedDirector()->getRunningScene()->addChild(m_pLayer, 9998); + } + + pParent = m_menuHide->getParent(); + if (pParent) + { + if (pParent != CCDirector::sharedDirector()->getRunningScene()) + { + pParent->removeChild(m_menuHide, true); + CCDirector::sharedDirector()->getRunningScene()->addChild(m_menuHide, 9999); + } + } + else + { + CCDirector::sharedDirector()->getRunningScene()->addChild(m_menuHide, 9999); + } +} +void NdTextureWatcher::visit(void* pSender) +{ + NdTextureWatcher *wartcher = (NdTextureWatcher*)pSender; + wartcher->dovisit(); +} + +static NdTextureWatcher *g_sharedTextureWatcher; +NdTextureWatcher * NdTextureWatcher::sharedTextureWatcher() +{ + if (!g_sharedTextureWatcher) + g_sharedTextureWatcher = new NdTextureWatcher(); + + return g_sharedTextureWatcher; +} + +void NdTextureWatcher::setDisplayWatcher(bool bDisplayWatcher) +{ + m_bDisplayWatcher = bDisplayWatcher; + if (m_bDisplayWatcher) + { + if (m_pszString == NULL) + { + m_pszString = new char[64]; + } + CCDirector::sharedDirector()->setWatcherCallbackFun(this, &NdTextureWatcher::visit); + } + else + { + CCDirector::sharedDirector()->setWatcherCallbackFun(NULL, NULL); + } +} + +void NdTextureWatcher::OnLoadItem(int nCurPage) +{ + //CCLog("page:%d", nCurPage); + int nextPage, prePage; + if (m_nCurrnetPage == 1) + { + nextPage = 1; + prePage = -1; + } + else if (m_nCurrnetPage == m_nTotalPage) + { + nextPage = -1; + prePage = 0; + } + else + { + nextPage = 2; + prePage = 0; + } + if (nCurPage == prePage) + { + m_nCurrnetPage--; + showTexture(); + } + else if (nCurPage == nextPage) + { + m_nCurrnetPage++; + showTexture(); + } + +} +void NdTextureWatcher::OnUnLoadItem(int nCurPage) +{ + +} +}// namespace \ No newline at end of file diff --git a/cocos2dx/extensions/TextureWatcher/NdTextureWatcher.h b/cocos2dx/extensions/TextureWatcher/NdTextureWatcher.h new file mode 100644 index 0000000000..29903145ed --- /dev/null +++ b/cocos2dx/extensions/TextureWatcher/NdTextureWatcher.h @@ -0,0 +1,46 @@ +#ifndef __CCMEMLAYER_H__ +#define __CCMEMLAYER_H__ +#include "ControlDefine.h" +#include "cocos2d.h" +#include "NdListLoaderListener.h" + +using namespace cocos2d; +namespace NdCxControl { + class NdCxList; +class CC_DLL NdTextureWatcher :public CCObject, public CNdListLoaderListener +{ +private: + NdTextureWatcher(); +public: + virtual ~NdTextureWatcher(); + + static NdTextureWatcher *sharedTextureWatcher(); + + void setDisplayWatcher(bool bDisplayWatcher); + void fresh(void); +protected: + void actionFresh(CCObject* object); + void actionHide(CCObject* object); + void hide(void); + void dovisit(void); + static void visit(void* pSender); + void showTexture(); +protected: + virtual void OnLoadItem(int nCurPage); + virtual void OnUnLoadItem(int nCurPage); +private: + bool m_bDisplayWatcher; + bool m_bFresh; + bool m_bHide; + CCDictionary *m_pTextures; + char *m_pszString; + int m_nCurrnetPage; + int m_nTotalPage; + CCLabelTTF *m_labelHide; + CCLabelTTF *m_labelPage; + CCMenu *m_menuHide; + CCLayerColor *m_pLayer; + NdCxList *m_pList; +}; +}// namespace +#endif \ No newline at end of file diff --git a/cocos2dx/proj.win32/cocos2d-win32.vcproj b/cocos2dx/proj.win32/cocos2d-win32.vcproj index 99463be24c..c9bbdbb7b2 100644 --- a/cocos2dx/proj.win32/cocos2d-win32.vcproj +++ b/cocos2dx/proj.win32/cocos2d-win32.vcproj @@ -1195,6 +1195,34 @@ > + + + + + + + + + + + + + + Date: Fri, 27 Apr 2012 18:47:49 +0800 Subject: [PATCH 02/14] issue #1194: Added extension namespace, all extension classes are in cocos2d::extension namespace, added CCTextureWatcher and CCListView. --- HelloWorld/proj.win32/HelloWorld.win32.vcproj | 2 +- cocos2dx/CCDirector.cpp | 27 +- cocos2dx/CCDirector.h | 7 + .../CCControlExtension/CCControl.cpp | 4 +- .../extensions/CCControlExtension/CCControl.h | 4 +- .../CCControlExtension/CCControlButton.cpp | 4 +- .../CCControlExtension/CCControlButton.h | 4 +- .../CCControlColourPicker.cpp | 4 +- .../CCControlColourPicker.h | 4 +- .../CCControlExtension/CCControlHuePicker.cpp | 4 +- .../CCControlExtension/CCControlHuePicker.h | 4 +- .../CCControlSaturationBrightnessPicker.cpp | 4 +- .../CCControlSaturationBrightnessPicker.h | 4 +- .../CCControlExtension/CCControlSlider.cpp | 4 +- .../CCControlExtension/CCControlSlider.h | 4 +- .../CCControlExtension/CCControlSwitch.cpp | 13 +- .../CCControlExtension/CCControlSwitch.h | 10 +- .../CCControlExtension/CCControlUtils.cpp | 4 +- .../CCControlExtension/CCControlUtils.h | 6 +- .../CCControlExtension/CCInvocation.cpp | 4 +- .../CCControlExtension/CCInvocation.h | 4 +- .../CCControlExtension/CCMenuPassive.cpp | 4 +- .../CCControlExtension/CCMenuPassive.h | 4 +- .../CCControlExtension/CCScale9Sprite.cpp | 4 +- .../CCControlExtension/CCScale9Sprite.h | 10 +- .../CCControlExtension/CCSpacer.cpp | 4 +- .../extensions/CCControlExtension/CCSpacer.h | 4 +- .../extensions/CCListView/CCControlDefine.h | 42 ++ .../CCListView.cpp} | 544 +++++++++--------- cocos2dx/extensions/CCListView/CCListView.h | 188 ++++++ .../CCListViewCell.cpp} | 46 +- .../CCListViewCell.h} | 43 +- .../CCNotificationCenter.cpp | 4 +- .../CCNotificationCenter.h | 9 +- .../CCTextureWatcher.cpp} | 444 +++++++------- .../CCTextureWatcher/CCTextureWatcher.h | 53 ++ .../extensions/TextureWatcher/NdListView.h | 154 ----- .../TextureWatcher/NdTextureWatcher.h | 46 -- cocos2dx/include/cocos2dExt.h | 2 + .../particle_nodes/CCParticleSystemQuad.cpp | 4 +- cocos2dx/platform/CCPlatformMacros.h | 6 + cocos2dx/proj.win32/cocos2d-win32.vcproj | 22 +- cocos2dx/textures/CCTextureAtlas.cpp | 4 +- cocos2dx/textures/CCTextureCache.cpp | 11 + cocos2dx/textures/CCTextureCache.h | 2 + .../ControlExtensionTest/CCControlScene.h | 2 +- tests/tests/ExtensionsTest/ExtensionsTest.cpp | 12 +- tests/tests/SchedulerTest/SchedulerTest.h | 1 - tests/tests/controller.cpp | 1 + tests/tests/testBasic.h | 3 +- 50 files changed, 944 insertions(+), 854 deletions(-) create mode 100644 cocos2dx/extensions/CCListView/CCControlDefine.h rename cocos2dx/extensions/{TextureWatcher/NdListView.cpp => CCListView/CCListView.cpp} (69%) create mode 100644 cocos2dx/extensions/CCListView/CCListView.h rename cocos2dx/extensions/{TextureWatcher/NdListViewCell.cpp => CCListView/CCListViewCell.cpp} (57%) rename cocos2dx/extensions/{TextureWatcher/NdListViewCell.h => CCListView/CCListViewCell.h} (50%) rename cocos2dx/extensions/{TextureWatcher/NdTextureWatcher.cpp => CCTextureWatcher/CCTextureWatcher.cpp} (56%) create mode 100644 cocos2dx/extensions/CCTextureWatcher/CCTextureWatcher.h delete mode 100644 cocos2dx/extensions/TextureWatcher/NdListView.h delete mode 100644 cocos2dx/extensions/TextureWatcher/NdTextureWatcher.h diff --git a/HelloWorld/proj.win32/HelloWorld.win32.vcproj b/HelloWorld/proj.win32/HelloWorld.win32.vcproj index e2a248db7c..d9580a04f8 100644 --- a/HelloWorld/proj.win32/HelloWorld.win32.vcproj +++ b/HelloWorld/proj.win32/HelloWorld.win32.vcproj @@ -41,7 +41,7 @@ using namespace std; -using namespace cocos2d; unsigned int g_uNumberOfDraws = 0; @@ -90,7 +90,7 @@ CCDirector::CCDirector(void) bool CCDirector::init(void) { CCLOG("cocos2d: %s", cocos2dVersion()); - + // scenes m_pRunningScene = NULL; m_pNextScene = NULL; @@ -131,6 +131,9 @@ bool CCDirector::init(void) m_fContentScaleFactor = 1; m_bIsContentScaleSupported = false; + m_pWatcherFun = NULL; + m_pWatcherSender = NULL; + // scheduler m_pScheduler = new CCScheduler(); // action manager @@ -232,6 +235,10 @@ void CCDirector::drawScene(void) showStats(); } + if (m_pWatcherFun && m_pWatcherSender) + { + (*m_pWatcherFun)(m_pWatcherSender); + } kmGLPopMatrix(); @@ -584,8 +591,9 @@ void CCDirector::purgeDirector() // cocos2d-x specific data structures CCUserDefault::purgeSharedUserDefault(); - CCNotificationCenter::purgeNotificationCenter(); - + extension::CCNotificationCenter::purgeNotificationCenter(); + extension::CCTextureWatcher::purgeTextureWatcher(); + ccGLInvalidateStateCache(); CHECK_GL_ERROR_DEBUG(); @@ -933,5 +941,12 @@ void CCDisplayLinkDirector::setAnimationInterval(double dValue) } } +void CCDirector::setWatcherCallbackFun(void *pSender, WatcherCallbackFun fun) +{ + m_pWatcherFun = fun; + m_pWatcherSender = pSender; +} + + NS_CC_END diff --git a/cocos2dx/CCDirector.h b/cocos2dx/CCDirector.h index a611b7db97..be8ea21778 100644 --- a/cocos2dx/CCDirector.h +++ b/cocos2dx/CCDirector.h @@ -273,6 +273,9 @@ public: void setContentScaleFactor(CCFloat scaleFactor); CCFloat getContentScaleFactor(void); + typedef void(*WatcherCallbackFun)(void *pSender); + void setWatcherCallbackFun(void *pSender, WatcherCallbackFun fun); + public: /** CCScheduler associated with this director @since v2.0 @@ -388,6 +391,10 @@ protected: /* contentScaleFactor could be simulated */ bool m_bIsContentScaleSupported; + + WatcherCallbackFun m_pWatcherFun; + void *m_pWatcherSender; + }; /** diff --git a/cocos2dx/extensions/CCControlExtension/CCControl.cpp b/cocos2dx/extensions/CCControlExtension/CCControl.cpp index 08c3a66800..130fd4f071 100644 --- a/cocos2dx/extensions/CCControlExtension/CCControl.cpp +++ b/cocos2dx/extensions/CCControlExtension/CCControl.cpp @@ -32,7 +32,7 @@ #include "CCMenu.h" #include "CCTouch.h" -NS_CC_BEGIN +NS_CC_EXT_BEGIN CCControl::CCControl() { @@ -299,4 +299,4 @@ CCArray* CCControl::dispatchListforControlEvent(CCControlEvent controlEvent) return invocationList; } -NS_CC_END +NS_CC_EXT_END diff --git a/cocos2dx/extensions/CCControlExtension/CCControl.h b/cocos2dx/extensions/CCControlExtension/CCControl.h index 26c7918c42..a73f15d959 100644 --- a/cocos2dx/extensions/CCControlExtension/CCControl.h +++ b/cocos2dx/extensions/CCControlExtension/CCControl.h @@ -33,7 +33,7 @@ #include "CCControlUtils.h" #include "CCLayer.h" -NS_CC_BEGIN +NS_CC_EXT_BEGIN class CCInvocation; @@ -206,6 +206,6 @@ public: }; -NS_CC_END +NS_CC_EXT_END #endif \ No newline at end of file diff --git a/cocos2dx/extensions/CCControlExtension/CCControlButton.cpp b/cocos2dx/extensions/CCControlExtension/CCControlButton.cpp index 8bf710b203..d84cd089bf 100644 --- a/cocos2dx/extensions/CCControlExtension/CCControlButton.cpp +++ b/cocos2dx/extensions/CCControlExtension/CCControlButton.cpp @@ -33,7 +33,7 @@ using namespace std; -NS_CC_BEGIN +NS_CC_EXT_BEGIN enum { @@ -462,4 +462,4 @@ void CCControlButton::ccTouchCancelled(CCTouch *pTouch, CCEvent *pEvent) sendActionsForControlEvents(CCControlEventTouchCancel); } -NS_CC_END +NS_CC_EXT_END diff --git a/cocos2dx/extensions/CCControlExtension/CCControlButton.h b/cocos2dx/extensions/CCControlExtension/CCControlButton.h index 664aa0da84..056e9a89cc 100644 --- a/cocos2dx/extensions/CCControlExtension/CCControlButton.h +++ b/cocos2dx/extensions/CCControlExtension/CCControlButton.h @@ -33,7 +33,7 @@ #include "CCInvocation.h" #include "CCScale9Sprite.h" -NS_CC_BEGIN +NS_CC_EXT_BEGIN /** @class CCControlButton Button control for Cocos2D. */ class CC_DLL CCControlButton : public CCControl @@ -181,6 +181,6 @@ public: }; -NS_CC_END +NS_CC_EXT_END #endif \ No newline at end of file diff --git a/cocos2dx/extensions/CCControlExtension/CCControlColourPicker.cpp b/cocos2dx/extensions/CCControlExtension/CCControlColourPicker.cpp index f8e62cc07b..cb10c38759 100644 --- a/cocos2dx/extensions/CCControlExtension/CCControlColourPicker.cpp +++ b/cocos2dx/extensions/CCControlExtension/CCControlColourPicker.cpp @@ -33,7 +33,7 @@ #include "CCSpriteFrameCache.h" #include "CCSpriteBatchNode.h" -NS_CC_BEGIN +NS_CC_EXT_BEGIN bool CCControlColourPicker::init() { @@ -158,4 +158,4 @@ bool CCControlColourPicker::ccTouchBegan(CCTouch* touch, CCEvent* pEvent) return false; } -NS_CC_END +NS_CC_EXT_END diff --git a/cocos2dx/extensions/CCControlExtension/CCControlColourPicker.h b/cocos2dx/extensions/CCControlExtension/CCControlColourPicker.h index ee2c9bc793..fd48cabf82 100644 --- a/cocos2dx/extensions/CCControlExtension/CCControlColourPicker.h +++ b/cocos2dx/extensions/CCControlExtension/CCControlColourPicker.h @@ -37,7 +37,7 @@ #include "CCControlHuePicker.h" #include "CCControlSaturationBrightnessPicker.h" -NS_CC_BEGIN +NS_CC_EXT_BEGIN class CC_DLL CCControlColourPicker: public CCControl { @@ -65,6 +65,6 @@ protected: }; -NS_CC_END +NS_CC_EXT_END #endif \ No newline at end of file diff --git a/cocos2dx/extensions/CCControlExtension/CCControlHuePicker.cpp b/cocos2dx/extensions/CCControlExtension/CCControlHuePicker.cpp index 09af99a2b7..b0f1006a82 100644 --- a/cocos2dx/extensions/CCControlExtension/CCControlHuePicker.cpp +++ b/cocos2dx/extensions/CCControlExtension/CCControlHuePicker.cpp @@ -31,7 +31,7 @@ #include "CCControlHuePicker.h" #include "CCPointExtension.h" -NS_CC_BEGIN +NS_CC_EXT_BEGIN CCControlHuePicker::~CCControlHuePicker() { @@ -158,4 +158,4 @@ void CCControlHuePicker::ccTouchMoved(CCTouch* touch, CCEvent* event) //checkSliderPosition(touchLocation); } -NS_CC_END +NS_CC_EXT_END diff --git a/cocos2dx/extensions/CCControlExtension/CCControlHuePicker.h b/cocos2dx/extensions/CCControlExtension/CCControlHuePicker.h index bbbc33d40e..607b865c62 100644 --- a/cocos2dx/extensions/CCControlExtension/CCControlHuePicker.h +++ b/cocos2dx/extensions/CCControlExtension/CCControlHuePicker.h @@ -35,7 +35,7 @@ #include "CCControl.h" #include "CCInvocation.h" -NS_CC_BEGIN +NS_CC_EXT_BEGIN class CC_DLL CCControlHuePicker : public CCControl { @@ -64,6 +64,6 @@ protected: virtual void ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent); }; -NS_CC_END +NS_CC_EXT_END #endif \ No newline at end of file diff --git a/cocos2dx/extensions/CCControlExtension/CCControlSaturationBrightnessPicker.cpp b/cocos2dx/extensions/CCControlExtension/CCControlSaturationBrightnessPicker.cpp index 5e2598bad8..5686dd072d 100644 --- a/cocos2dx/extensions/CCControlExtension/CCControlSaturationBrightnessPicker.cpp +++ b/cocos2dx/extensions/CCControlExtension/CCControlSaturationBrightnessPicker.cpp @@ -31,7 +31,7 @@ #include "CCControlSaturationBrightnessPicker.h" #include "CCPointExtension.h" -NS_CC_BEGIN +NS_CC_EXT_BEGIN CCControlSaturationBrightnessPicker::~CCControlSaturationBrightnessPicker() { @@ -176,4 +176,4 @@ void CCControlSaturationBrightnessPicker::ccTouchMoved(CCTouch* touch, CCEvent* //checkSliderPosition(touchLocation); } -NS_CC_END +NS_CC_EXT_END diff --git a/cocos2dx/extensions/CCControlExtension/CCControlSaturationBrightnessPicker.h b/cocos2dx/extensions/CCControlExtension/CCControlSaturationBrightnessPicker.h index c7e90ca13a..ab2ad2c49a 100644 --- a/cocos2dx/extensions/CCControlExtension/CCControlSaturationBrightnessPicker.h +++ b/cocos2dx/extensions/CCControlExtension/CCControlSaturationBrightnessPicker.h @@ -35,7 +35,7 @@ #include "CCControl.h" #include "CCInvocation.h" -NS_CC_BEGIN +NS_CC_EXT_BEGIN class CC_DLL CCControlSaturationBrightnessPicker : public CCControl { @@ -68,6 +68,6 @@ protected: virtual void ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent); }; -NS_CC_END +NS_CC_EXT_END #endif \ No newline at end of file diff --git a/cocos2dx/extensions/CCControlExtension/CCControlSlider.cpp b/cocos2dx/extensions/CCControlExtension/CCControlSlider.cpp index 161f8bb551..771054cf4a 100644 --- a/cocos2dx/extensions/CCControlExtension/CCControlSlider.cpp +++ b/cocos2dx/extensions/CCControlExtension/CCControlSlider.cpp @@ -31,7 +31,7 @@ #include "CCTouch.h" #include "CCDirector.h" -NS_CC_BEGIN +NS_CC_EXT_BEGIN CCControlSlider::~CCControlSlider() { @@ -218,4 +218,4 @@ float CCControlSlider::valueForLocation(CCPoint location) return m_minimumValue + percent * (m_maximumValue - m_minimumValue); } -NS_CC_END +NS_CC_EXT_END diff --git a/cocos2dx/extensions/CCControlExtension/CCControlSlider.h b/cocos2dx/extensions/CCControlExtension/CCControlSlider.h index 03ce12cf64..0fd5f94690 100644 --- a/cocos2dx/extensions/CCControlExtension/CCControlSlider.h +++ b/cocos2dx/extensions/CCControlExtension/CCControlSlider.h @@ -37,7 +37,7 @@ #define SLIDER_MARGIN_H 24 #define SLIDER_MARGIN_V 8 -NS_CC_BEGIN +NS_CC_EXT_BEGIN class CC_DLL CCControlSlider: public CCControl { @@ -106,6 +106,6 @@ protected: float valueForLocation(CCPoint location); }; -NS_CC_END +NS_CC_EXT_END #endif \ No newline at end of file diff --git a/cocos2dx/extensions/CCControlExtension/CCControlSwitch.cpp b/cocos2dx/extensions/CCControlExtension/CCControlSwitch.cpp index 84676921d2..dff0484dc2 100644 --- a/cocos2dx/extensions/CCControlExtension/CCControlSwitch.cpp +++ b/cocos2dx/extensions/CCControlExtension/CCControlSwitch.cpp @@ -24,16 +24,9 @@ */ #include "CCControlSwitch.h" -#include "CCPointExtension.h" -#include "CCLabelTTF.h" -#include "CCRenderTexture.h" -#include "CCTouch.h" -#include "CCDirector.h" -#include "ccShaders.h" -#include "CCActionTween.h" - -NS_CC_BEGIN +#include "cocos2d.h" +NS_CC_EXT_BEGIN // CCControlSwitchSprite class CCControlSwitchSprite : public CCSprite, public CCActionTweenDelegate @@ -438,4 +431,4 @@ void CCControlSwitch::ccTouchCancelled(CCTouch *pTouch, CCEvent *pEvent) } } -NS_CC_END +NS_CC_EXT_END diff --git a/cocos2dx/extensions/CCControlExtension/CCControlSwitch.h b/cocos2dx/extensions/CCControlExtension/CCControlSwitch.h index 37492fda80..13304a693f 100644 --- a/cocos2dx/extensions/CCControlExtension/CCControlSwitch.h +++ b/cocos2dx/extensions/CCControlExtension/CCControlSwitch.h @@ -29,11 +29,13 @@ #include "CCControl.h" -NS_CC_BEGIN + +namespace cocos2d { class CCSprite; } +namespace cocos2d { class CCLabelTTF; } + +NS_CC_EXT_BEGIN class CCControlSwitchSprite; -class CCSprite; -class CCLabelTTF; /** @class CCControlSwitch Switch control for Cocos2D. */ class CC_DLL CCControlSwitch : public CCControl @@ -85,7 +87,7 @@ protected: }; -NS_CC_END +NS_CC_EXT_END #endif /* __CCCONTROLSWITCH_H__ */ diff --git a/cocos2dx/extensions/CCControlExtension/CCControlUtils.cpp b/cocos2dx/extensions/CCControlExtension/CCControlUtils.cpp index abf29374f6..33d0ea7c35 100644 --- a/cocos2dx/extensions/CCControlExtension/CCControlUtils.cpp +++ b/cocos2dx/extensions/CCControlExtension/CCControlUtils.cpp @@ -1,7 +1,7 @@ #include "CCControlUtils.h" #include "CCPointExtension.h" -NS_CC_BEGIN +NS_CC_EXT_BEGIN CCSprite* CCControlUtils::addSpriteToTargetWithPosAndAnchor(const char* spriteName, CCNode * target, CCPoint pos, CCPoint anchor) { @@ -146,4 +146,4 @@ CCRect CCControlUtils::CCRectUnion(const CCRect& src1, const CCRect& src2) return result; } -NS_CC_END +NS_CC_EXT_END diff --git a/cocos2dx/extensions/CCControlExtension/CCControlUtils.h b/cocos2dx/extensions/CCControlExtension/CCControlUtils.h index 52052842a8..6bea70c9a8 100644 --- a/cocos2dx/extensions/CCControlExtension/CCControlUtils.h +++ b/cocos2dx/extensions/CCControlExtension/CCControlUtils.h @@ -34,7 +34,7 @@ #include "CCSprite.h" -NS_CC_BEGIN +NS_CC_EXT_BEGIN typedef struct { @@ -60,7 +60,7 @@ public: CCColor3bObject(ccColor3B s_value):value(s_value){} }; -class CCControlUtils +class CC_DLL CCControlUtils { public: static CCSprite* addSpriteToTargetWithPosAndAnchor(const char* spriteName, CCNode * target, CCPoint pos, CCPoint anchor); @@ -69,6 +69,6 @@ public: static CCRect CCRectUnion(const CCRect& src1, const CCRect& src2); }; -NS_CC_END +NS_CC_EXT_END #endif \ No newline at end of file diff --git a/cocos2dx/extensions/CCControlExtension/CCInvocation.cpp b/cocos2dx/extensions/CCControlExtension/CCInvocation.cpp index 0b23d2b6ff..1ac51fc575 100644 --- a/cocos2dx/extensions/CCControlExtension/CCInvocation.cpp +++ b/cocos2dx/extensions/CCControlExtension/CCInvocation.cpp @@ -1,6 +1,6 @@ #include "CCInvocation.h" -NS_CC_BEGIN +NS_CC_EXT_BEGIN CCInvocation::CCInvocation(CCObject* target, SEL_MenuHandler action, CCControlEvent controlEvent) { @@ -17,4 +17,4 @@ void CCInvocation::invoke(CCObject* sender) } } -NS_CC_END +NS_CC_EXT_END diff --git a/cocos2dx/extensions/CCControlExtension/CCInvocation.h b/cocos2dx/extensions/CCControlExtension/CCInvocation.h index 67ffd48494..b33b35f022 100644 --- a/cocos2dx/extensions/CCControlExtension/CCInvocation.h +++ b/cocos2dx/extensions/CCControlExtension/CCInvocation.h @@ -7,7 +7,7 @@ #include "CCObject.h" -NS_CC_BEGIN +NS_CC_EXT_BEGIN typedef unsigned int CCControlEvent; @@ -23,6 +23,6 @@ public: void invoke(CCObject* sender); }; -NS_CC_END +NS_CC_EXT_END #endif \ No newline at end of file diff --git a/cocos2dx/extensions/CCControlExtension/CCMenuPassive.cpp b/cocos2dx/extensions/CCControlExtension/CCMenuPassive.cpp index 9a36058f93..cb6536fcee 100644 --- a/cocos2dx/extensions/CCControlExtension/CCMenuPassive.cpp +++ b/cocos2dx/extensions/CCControlExtension/CCMenuPassive.cpp @@ -6,7 +6,7 @@ using namespace std; -NS_CC_BEGIN +NS_CC_EXT_BEGIN enum { @@ -437,4 +437,4 @@ const ccColor3B& CCMenuPassive::getColor(void) return m_tColor; } -NS_CC_END +NS_CC_EXT_END diff --git a/cocos2dx/extensions/CCControlExtension/CCMenuPassive.h b/cocos2dx/extensions/CCControlExtension/CCMenuPassive.h index 4b4d43acee..d3f72e7a8d 100644 --- a/cocos2dx/extensions/CCControlExtension/CCMenuPassive.h +++ b/cocos2dx/extensions/CCControlExtension/CCMenuPassive.h @@ -7,7 +7,7 @@ #include "CCControl.h" -NS_CC_BEGIN +NS_CC_EXT_BEGIN class CC_DLL CCMenuPassive : public CCLayer, public CCRGBAProtocol { @@ -59,6 +59,6 @@ public: virtual bool getIsOpacityModifyRGB(void) { return false;} }; -NS_CC_END +NS_CC_EXT_END #endif \ No newline at end of file diff --git a/cocos2dx/extensions/CCControlExtension/CCScale9Sprite.cpp b/cocos2dx/extensions/CCControlExtension/CCScale9Sprite.cpp index 3ec1935ca8..220a198119 100644 --- a/cocos2dx/extensions/CCControlExtension/CCScale9Sprite.cpp +++ b/cocos2dx/extensions/CCControlExtension/CCScale9Sprite.cpp @@ -13,7 +13,7 @@ #include "CCSprite.h" #include "CCPointExtension.h" -NS_CC_BEGIN +NS_CC_EXT_BEGIN CCScale9Sprite::CCScale9Sprite() { @@ -461,4 +461,4 @@ bool CCScale9Sprite::getIsOpacityModifyRGB() return m_bIsOpacityModifyRGB; } -NS_CC_END +NS_CC_EXT_END diff --git a/cocos2dx/extensions/CCControlExtension/CCScale9Sprite.h b/cocos2dx/extensions/CCControlExtension/CCScale9Sprite.h index 251ab73c7c..7b912463f1 100644 --- a/cocos2dx/extensions/CCControlExtension/CCScale9Sprite.h +++ b/cocos2dx/extensions/CCControlExtension/CCScale9Sprite.h @@ -13,11 +13,11 @@ #include "CCProtocols.h" -NS_CC_BEGIN +namespace cocos2d { class CCSprite; } +namespace cocos2d { class CCSpriteBatchNode; } +namespace cocos2d { class CCSpriteFrame; } -class CCSprite; -class CCSpriteBatchNode; -class CCSpriteFrame; +NS_CC_EXT_BEGIN enum positions { @@ -276,6 +276,6 @@ public: }; -NS_CC_END +NS_CC_EXT_END #endif // __CCScale9Sprite_H__ diff --git a/cocos2dx/extensions/CCControlExtension/CCSpacer.cpp b/cocos2dx/extensions/CCControlExtension/CCSpacer.cpp index e2ebc3e5c4..931866dc26 100644 --- a/cocos2dx/extensions/CCControlExtension/CCSpacer.cpp +++ b/cocos2dx/extensions/CCControlExtension/CCSpacer.cpp @@ -1,6 +1,6 @@ #include "CCSpacer.h" -NS_CC_BEGIN +NS_CC_EXT_BEGIN CCSpacer* CCSpacer::verticalSpacer(float space) { @@ -20,4 +20,4 @@ CCSpacer* CCSpacer::horizontalSpacer(float space) return pRet; } -NS_CC_END +NS_CC_EXT_END diff --git a/cocos2dx/extensions/CCControlExtension/CCSpacer.h b/cocos2dx/extensions/CCControlExtension/CCSpacer.h index 0c10b456df..7dbe4e6b16 100644 --- a/cocos2dx/extensions/CCControlExtension/CCSpacer.h +++ b/cocos2dx/extensions/CCControlExtension/CCSpacer.h @@ -3,7 +3,7 @@ #include "CCLayer.h" -NS_CC_BEGIN +NS_CC_EXT_BEGIN class CC_DLL CCSpacer: public CCLayer { @@ -12,6 +12,6 @@ public: static CCSpacer* horizontalSpacer(float space); }; -NS_CC_END +NS_CC_EXT_END #endif \ No newline at end of file diff --git a/cocos2dx/extensions/CCListView/CCControlDefine.h b/cocos2dx/extensions/CCListView/CCControlDefine.h new file mode 100644 index 0000000000..c6ff2de4a2 --- /dev/null +++ b/cocos2dx/extensions/CCListView/CCControlDefine.h @@ -0,0 +1,42 @@ +#ifndef __CCCONTROL_DEFINE_H__ +#define __CCCONTROL_DEFINE_H__ + +NS_CC_EXT_BEGIN + +typedef enum +{ + PARENT_CENTER, + VERTICAL_TOP, + VERTICAL_BOTTOM, + HORIZONTAL_LEFT, + HORIZONTAL_RIGHT, + ABS_WITH_PIXEL, + ABS_WITH_PERCENT, + REF_PREV_X_INC, + REF_PREV_X_DEC, + REF_PREV_Y_INC, + REF_PREV_Y_DEC, + REL_FLOW +} LAYOUT_TYPE; + +typedef struct +{ + LAYOUT_TYPE t; + union + { + float pixel_val; + float percent_val; + } val; +} LayoutParamVal; + +typedef struct +{ + LayoutParamVal val_x; + LayoutParamVal val_y; + float padding; + bool wrap; +} LayoutParam; + +NS_CC_EXT_END + +#endif /* __CCCONTROL_DEFINE_H__ */ diff --git a/cocos2dx/extensions/TextureWatcher/NdListView.cpp b/cocos2dx/extensions/CCListView/CCListView.cpp similarity index 69% rename from cocos2dx/extensions/TextureWatcher/NdListView.cpp rename to cocos2dx/extensions/CCListView/CCListView.cpp index ec202166a5..21f6b21ce7 100644 --- a/cocos2dx/extensions/TextureWatcher/NdListView.cpp +++ b/cocos2dx/extensions/CCListView/CCListView.cpp @@ -1,15 +1,18 @@ -#include "NdListView.h" -#include "../cocos2dx_support/LuaEngineImpl.h" +#include "CCListView.h" +//#include "../cocos2dx_support/LuaEngineImpl.h" +#include "cocos2d.h" + +using namespace std; + +NS_CC_EXT_BEGIN -namespace NdCxControl -{ #define ND_LISTVIEW_ACTION_INTERVAL 0.6666 /****************************************** **************Public Functions************* *******************************************/ -NdListView* NdListView::viewWithMode(NdListViewMode mode) +CCListView* CCListView::viewWithMode(CCListViewMode mode) { - NdListView *pRet = new NdListView(); + CCListView *pRet = new CCListView(); if (pRet && pRet->initWithMode(mode)) { pRet->autorelease(); @@ -17,26 +20,29 @@ NdListView* NdListView::viewWithMode(NdListViewMode mode) } else { - CC_SAFE_DELETE(pRet) + CC_SAFE_DELETE(pRet); return NULL; } } -bool NdListView::initWithMode(NdListViewMode mode) +bool CCListView::initWithMode(CCListViewMode mode) { + bool bRet = false; m_nMode = mode; m_layerPanel = CCLayer::node(); this->addChild(m_layerPanel); - return CCLayerColor::initWithColorWidthHeight(ccc4(255, 255, 255, 0), 0, 0); + bRet = CCLayerColor::initWithColor(ccc4(255, 255, 255, 0), 0, 0); + setIsTouchEnabled(true); + return bRet; } -NdListView::NdListView(void) - :m_nMode(NdListViewModeVertical) - ,m_nState(NdListViewStateWatting) - ,m_nSlideDir(NdListViewSlideDirNone) +CCListView::CCListView(void) + :m_nMode(CCListViewModeVertical) + ,m_nState(CCListViewStateWatting) + ,m_nSlideDir(CCListViewSlideDirNone) ,m_layerPanel(NULL) - ,m_nSeparatorStyle(NdListViewCellSeparatorStyleSingleLine) + ,m_nSeparatorStyle(CCListViewCellSeparatorStyleSingleLine) ,m_nSelectedRow(-1) ,m_nCurrentRow(-1) ,m_fActionDuration(ND_LISTVIEW_ACTION_INTERVAL) @@ -51,11 +57,11 @@ NdListView::NdListView(void) m_bIsTouchEnabled = true; } -NdListView::~NdListView(void) +CCListView::~CCListView(void) { } -void NdListView::setDelegateName(const char* pszName) +void CCListView::setDelegateName(const char* pszName) { if (pszName) { @@ -67,29 +73,29 @@ void NdListView::setDelegateName(const char* pszName) } } -void NdListView::selectCellAtRow(unsigned int nRow) +void CCListView::selectCellAtRow(unsigned int nRow) { - NdListViewCell *cell = cellAtRow(nRow); + CCListViewCell *cell = cellAtRow(nRow); if (cell) { cell->selected(); } } -void NdListView::unselectCellAtRow(unsigned int nRow) +void CCListView::unselectCellAtRow(unsigned int nRow) { if (nRow == m_nSelectedRow) { m_nSelectedRow = -1; } - NdListViewCell *cell = cellAtRow(nRow); + CCListViewCell *cell = cellAtRow(nRow); if (cell) { cell->unselected(); } } -void NdListView::reload(void) +void CCListView::reload(void) { m_layerPanel->removeAllChildrenWithCleanup(true); m_layerPanel->setPosition(CCPointZero); @@ -99,7 +105,7 @@ void NdListView::reload(void) this->displayVisibleRows(); } -void NdListView::insertCellsAtRow(unsigned int nRow, unsigned int nCount) +void CCListView::insertCellsAtRow(unsigned int nRow, unsigned int nCount) { if (nRow >= m_nNumberOfRows) { @@ -131,7 +137,7 @@ void NdListView::insertCellsAtRow(unsigned int nRow, unsigned int nCount) m_layerPanel->resumeSchedulerAndActions(); } -void NdListView::deleteCellsAtRow(unsigned int nRow, unsigned int nCount) +void CCListView::deleteCellsAtRow(unsigned int nRow, unsigned int nCount) { if (m_nNumberOfRows == 0) { @@ -158,7 +164,7 @@ void NdListView::deleteCellsAtRow(unsigned int nRow, unsigned int nCount) { if (n >= m_drawedRows.location && n <= CCRange::CCMaxRange(m_drawedRows)) { - NdListViewCell *cell = this->cellAtRow(n); + CCListViewCell *cell = this->cellAtRow(n); if (cell) { CCPoint pos = cell->getPosition(); @@ -171,12 +177,12 @@ void NdListView::deleteCellsAtRow(unsigned int nRow, unsigned int nCount) { int tag = cell->getTag(); cell->setTag(tag - 1); - if (NdListViewModeHorizontal == m_nMode) + if (CCListViewModeHorizontal == m_nMode) { cell->setPosition(pos); pos.x += cell->getContentSize().width; } - else if (NdListViewModeVertical == m_nMode) + else if (CCListViewModeVertical == m_nMode) { pos.y -= cell->getContentSize().height; cell->setPosition(pos); @@ -195,7 +201,7 @@ void NdListView::deleteCellsAtRow(unsigned int nRow, unsigned int nCount) { for (unsigned int i = m_drawedRows.location; i <= CCRange::CCMaxRange(m_drawedRows); i++) { - NdListViewCell *cell = this->cellAtRow(i); + CCListViewCell *cell = this->cellAtRow(i); if (cell) { int tag = cell->getTag(); @@ -212,7 +218,7 @@ void NdListView::deleteCellsAtRow(unsigned int nRow, unsigned int nCount) m_layerPanel->resumeSchedulerAndActions(); } -void NdListView::scrollCellToFront(unsigned int nRow, bool bAnimated) +void CCListView::scrollCellToFront(unsigned int nRow, bool bAnimated) { if (!isFullFill()) { @@ -222,7 +228,7 @@ void NdListView::scrollCellToFront(unsigned int nRow, bool bAnimated) { return; } - if (NdListViewStateWatting != m_nState) + if (CCListViewStateWatting != m_nState) { this->stopActionImmediately(); } @@ -234,19 +240,19 @@ void NdListView::scrollCellToFront(unsigned int nRow, bool bAnimated) float disX = 0; float disY = 0; - m_nSlideDir = NdListViewSlideDirNone; - if (NdListViewModeHorizontal == m_nMode) + m_nSlideDir = CCListViewSlideDirNone; + if (CCListViewModeHorizontal == m_nMode) { float dis = 0; unsigned int nCount = 0; - NdListViewCell *cell = NULL; + CCListViewCell *cell = NULL; if (nRow > m_visibleRows.location) { - m_nSlideDir = NdListViewSlideDirLeft; + m_nSlideDir = CCListViewSlideDirLeft; } else { - m_nSlideDir = NdListViewSlideDirRight; + m_nSlideDir = CCListViewSlideDirRight; } while(1) @@ -256,11 +262,11 @@ void NdListView::scrollCellToFront(unsigned int nRow, bool bAnimated) break; } - if (NdListViewSlideDirRight == m_nSlideDir) + if (CCListViewSlideDirRight == m_nSlideDir) { cell = appendRowToFront(nRow + nCount); } - else if (NdListViewSlideDirLeft == m_nSlideDir) + else if (CCListViewSlideDirLeft == m_nSlideDir) { cell = appendRowToBack(nRow + nCount); } @@ -272,11 +278,11 @@ void NdListView::scrollCellToFront(unsigned int nRow, bool bAnimated) } else { - CCLog("NdListView cell == NULL at line %d", __LINE__); + CCLog("CCListView cell == NULL at line %d", __LINE__); } } - if (NdListViewSlideDirLeft == m_nSlideDir && dis < this->getContentSize().width) + if (CCListViewSlideDirLeft == m_nSlideDir && dis < this->getContentSize().width) { // at last while(1) @@ -294,14 +300,14 @@ void NdListView::scrollCellToFront(unsigned int nRow, bool bAnimated) } else { - CCLog("NdListView cell == NULL at line %d", __LINE__); + CCLog("CCListView cell == NULL at line %d", __LINE__); } } } - if (NdListViewSlideDirRight == m_nSlideDir) + if (CCListViewSlideDirRight == m_nSlideDir) { - NdListViewCell* cell = NULL; + CCListViewCell* cell = NULL; unsigned nLast = 0; if (CCRange::CCLocationInRange(nRow + nCount - 1, m_visibleRows)) { @@ -326,18 +332,18 @@ void NdListView::scrollCellToFront(unsigned int nRow, bool bAnimated) } else { - CCLog("NdListView cell == NULL at line %d", __LINE__); + CCLog("CCListView cell == NULL at line %d", __LINE__); } } } else { - CCLog("NdListView cell == NULL at line %d", __LINE__); + CCLog("CCListView cell == NULL at line %d", __LINE__); } } - else if (NdListViewSlideDirLeft == m_nSlideDir) + else if (CCListViewSlideDirLeft == m_nSlideDir) { - NdListViewCell* cell = NULL; + CCListViewCell* cell = NULL; unsigned nFirst = 0; if (CCRange::CCLocationInRange(nRow, m_visibleRows)) { @@ -364,13 +370,13 @@ void NdListView::scrollCellToFront(unsigned int nRow, bool bAnimated) } else { - CCLog("NdListView cell == NULL at line %d", __LINE__); + CCLog("CCListView cell == NULL at line %d", __LINE__); } } } else { - CCLog("NdListView cell == NULL at line %d", __LINE__); + CCLog("CCListView cell == NULL at line %d", __LINE__); } } @@ -380,18 +386,18 @@ void NdListView::scrollCellToFront(unsigned int nRow, bool bAnimated) CCPoint ptView = this->convertToWorldSpace(CCPointZero); disX = ptView.x - ptCell.x; } - else if (NdListViewModeVertical == m_nMode) + else if (CCListViewModeVertical == m_nMode) { float dis = 0; unsigned int nCount = 0; - NdListViewCell *cell = NULL; + CCListViewCell *cell = NULL; if (nRow > m_visibleRows.location) { - m_nSlideDir = NdListViewSlideDirUp; + m_nSlideDir = CCListViewSlideDirUp; } else { - m_nSlideDir = NdListViewSlideDirDown; + m_nSlideDir = CCListViewSlideDirDown; } while(1) @@ -401,11 +407,11 @@ void NdListView::scrollCellToFront(unsigned int nRow, bool bAnimated) break; } - if (NdListViewSlideDirDown == m_nSlideDir) + if (CCListViewSlideDirDown == m_nSlideDir) { cell = appendRowToFront(nRow + nCount); } - else if (NdListViewSlideDirUp == m_nSlideDir) + else if (CCListViewSlideDirUp == m_nSlideDir) { cell = appendRowToBack(nRow + nCount); } @@ -417,11 +423,11 @@ void NdListView::scrollCellToFront(unsigned int nRow, bool bAnimated) } else { - CCLog("NdListView cell == NULL at line %d", __LINE__); + CCLog("CCListView cell == NULL at line %d", __LINE__); } } - if (NdListViewSlideDirUp == m_nSlideDir && dis < this->getContentSize().height) + if (CCListViewSlideDirUp == m_nSlideDir && dis < this->getContentSize().height) { // at last while(1) @@ -439,14 +445,14 @@ void NdListView::scrollCellToFront(unsigned int nRow, bool bAnimated) } else { - CCLog("NdListView cell == NULL at line %d", __LINE__); + CCLog("CCListView cell == NULL at line %d", __LINE__); } } } - if (NdListViewSlideDirDown == m_nSlideDir) + if (CCListViewSlideDirDown == m_nSlideDir) { - NdListViewCell* cell = NULL; + CCListViewCell* cell = NULL; unsigned nLast = 0; if (CCRange::CCLocationInRange(nRow + nCount - 1, m_visibleRows)) { @@ -472,18 +478,18 @@ void NdListView::scrollCellToFront(unsigned int nRow, bool bAnimated) } else { - CCLog("NdListView cell == NULL at line %d", __LINE__); + CCLog("CCListView cell == NULL at line %d", __LINE__); } } } else { - CCLog("NdListView cell == NULL at line %d", __LINE__); + CCLog("CCListView cell == NULL at line %d", __LINE__); } } - else if (NdListViewSlideDirUp == m_nSlideDir) + else if (CCListViewSlideDirUp == m_nSlideDir) { - NdListViewCell* cell = NULL; + CCListViewCell* cell = NULL; unsigned nFirst = 0; if (CCRange::CCLocationInRange(nRow, m_visibleRows)) { @@ -508,13 +514,13 @@ void NdListView::scrollCellToFront(unsigned int nRow, bool bAnimated) } else { - CCLog("NdListView cell == NULL at line %d", __LINE__); + CCLog("CCListView cell == NULL at line %d", __LINE__); } } } else { - CCLog("NdListView cell == NULL at line %d", __LINE__); + CCLog("CCListView cell == NULL at line %d", __LINE__); } } @@ -528,13 +534,13 @@ void NdListView::scrollCellToFront(unsigned int nRow, bool bAnimated) m_ptDestination = m_layerPanel->getPosition(); m_ptDestination.x += disX; m_ptDestination.y += disY; - m_nState = NdListViewStateScroll; + m_nState = CCListViewStateScroll; if (bAnimated) { CCMoveBy *moveBy = CCMoveBy::actionWithDuration(m_fActionDuration, CCPointMake(disX, disY)); CCEaseOut *ease = CCEaseOut::actionWithAction(moveBy, 3); - CCFiniteTimeAction *actions = CCSequence::actions(ease, CCCallFunc::actionWithTarget(this, callfunc_selector(NdListView::finishScroll)), NULL); + CCFiniteTimeAction *actions = CCSequence::actions(ease, CCCallFunc::actionWithTarget(this, callfunc_selector(CCListView::finishScroll)), NULL); m_layerPanel->runAction(actions); } else @@ -543,7 +549,7 @@ void NdListView::scrollCellToFront(unsigned int nRow, bool bAnimated) } } -void NdListView::scrollCellToBack(unsigned int nRow, bool bAnimated) +void CCListView::scrollCellToBack(unsigned int nRow, bool bAnimated) { if (!isFullFill()) { @@ -553,7 +559,7 @@ void NdListView::scrollCellToBack(unsigned int nRow, bool bAnimated) { return; } - if (NdListViewStateWatting != m_nState) + if (CCListViewStateWatting != m_nState) { this->stopActionImmediately(); } @@ -565,19 +571,19 @@ void NdListView::scrollCellToBack(unsigned int nRow, bool bAnimated) float disX = 0; float disY = 0; - m_nSlideDir = NdListViewSlideDirNone; - if (NdListViewModeHorizontal == m_nMode) + m_nSlideDir = CCListViewSlideDirNone; + if (CCListViewModeHorizontal == m_nMode) { float dis = 0; int nCount = 0; - NdListViewCell *cell = NULL; + CCListViewCell *cell = NULL; if (nRow > CCRange::CCMaxRange(m_visibleRows)) { - m_nSlideDir = NdListViewSlideDirLeft; + m_nSlideDir = CCListViewSlideDirLeft; } else { - m_nSlideDir = NdListViewSlideDirRight; + m_nSlideDir = CCListViewSlideDirRight; } while(1) @@ -587,11 +593,11 @@ void NdListView::scrollCellToBack(unsigned int nRow, bool bAnimated) break; } - if (NdListViewSlideDirRight == m_nSlideDir) + if (CCListViewSlideDirRight == m_nSlideDir) { cell = appendRowToFront(nRow - nCount); } - else if (NdListViewSlideDirLeft == m_nSlideDir) + else if (CCListViewSlideDirLeft == m_nSlideDir) { cell = appendRowToBack(nRow - nCount); } @@ -603,11 +609,11 @@ void NdListView::scrollCellToBack(unsigned int nRow, bool bAnimated) } else { - CCLog("NdListView cell == NULL at line %d", __LINE__); + CCLog("CCListView cell == NULL at line %d", __LINE__); } } - if (NdListViewSlideDirRight == m_nSlideDir && dis < this->getContentSize().width) + if (CCListViewSlideDirRight == m_nSlideDir && dis < this->getContentSize().width) { // at first while(1) @@ -625,14 +631,14 @@ void NdListView::scrollCellToBack(unsigned int nRow, bool bAnimated) } else { - CCLog("NdListView cell == NULL at line %d", __LINE__); + CCLog("CCListView cell == NULL at line %d", __LINE__); } } } - if (NdListViewSlideDirRight == m_nSlideDir) + if (CCListViewSlideDirRight == m_nSlideDir) { - NdListViewCell* cell = NULL; + CCListViewCell* cell = NULL; unsigned nLast = 0; if (CCRange::CCLocationInRange(nRow, m_visibleRows)) { @@ -657,18 +663,18 @@ void NdListView::scrollCellToBack(unsigned int nRow, bool bAnimated) } else { - CCLog("NdListView cell == NULL at line %d", __LINE__); + CCLog("CCListView cell == NULL at line %d", __LINE__); } } } else { - CCLog("NdListView cell == NULL at line %d", __LINE__); + CCLog("CCListView cell == NULL at line %d", __LINE__); } } - else if (NdListViewSlideDirLeft == m_nSlideDir) + else if (CCListViewSlideDirLeft == m_nSlideDir) { - NdListViewCell* cell = NULL; + CCListViewCell* cell = NULL; unsigned nFirst = 0; if (CCRange::CCLocationInRange(nRow - nCount + 1, m_visibleRows)) { @@ -696,13 +702,13 @@ void NdListView::scrollCellToBack(unsigned int nRow, bool bAnimated) } else { - CCLog("NdListView cell == NULL at line %d", __LINE__); + CCLog("CCListView cell == NULL at line %d", __LINE__); } } } else { - CCLog("NdListView cell == NULL at line %d", __LINE__); + CCLog("CCListView cell == NULL at line %d", __LINE__); } } @@ -712,18 +718,18 @@ void NdListView::scrollCellToBack(unsigned int nRow, bool bAnimated) CCPoint ptView = this->convertToWorldSpace(CCPointZero); disX = ptView.x + this->getContentSize().width - (ptCell.x + cell->getContentSize().width); } - else if (NdListViewModeVertical == m_nMode) + else if (CCListViewModeVertical == m_nMode) { float dis = 0; int nCount = 0; - NdListViewCell *cell = NULL; + CCListViewCell *cell = NULL; if (nRow > CCRange::CCMaxRange(m_visibleRows)) { - m_nSlideDir = NdListViewSlideDirUp; + m_nSlideDir = CCListViewSlideDirUp; } else { - m_nSlideDir = NdListViewSlideDirDown; + m_nSlideDir = CCListViewSlideDirDown; } while(1) @@ -733,11 +739,11 @@ void NdListView::scrollCellToBack(unsigned int nRow, bool bAnimated) break; } - if (NdListViewSlideDirDown == m_nSlideDir) + if (CCListViewSlideDirDown == m_nSlideDir) { cell = appendRowToFront(nRow - nCount); } - else if (NdListViewSlideDirUp == m_nSlideDir) + else if (CCListViewSlideDirUp == m_nSlideDir) { cell = appendRowToBack(nRow - nCount); } @@ -749,11 +755,11 @@ void NdListView::scrollCellToBack(unsigned int nRow, bool bAnimated) } else { - CCLog("NdListView cell == NULL at line %d", __LINE__); + CCLog("CCListView cell == NULL at line %d", __LINE__); } } - if (NdListViewSlideDirDown == m_nSlideDir && dis < this->getContentSize().height) + if (CCListViewSlideDirDown == m_nSlideDir && dis < this->getContentSize().height) { // at first while(1) @@ -771,14 +777,14 @@ void NdListView::scrollCellToBack(unsigned int nRow, bool bAnimated) } else { - CCLog("NdListView cell == NULL at line %d", __LINE__); + CCLog("CCListView cell == NULL at line %d", __LINE__); } } } - if (NdListViewSlideDirDown == m_nSlideDir) + if (CCListViewSlideDirDown == m_nSlideDir) { - NdListViewCell* cell = NULL; + CCListViewCell* cell = NULL; unsigned nLast = 0; if (CCRange::CCLocationInRange(nRow, m_visibleRows)) { @@ -804,18 +810,18 @@ void NdListView::scrollCellToBack(unsigned int nRow, bool bAnimated) } else { - CCLog("NdListView cell == NULL at line %d", __LINE__); + CCLog("CCListView cell == NULL at line %d", __LINE__); } } } else { - CCLog("NdListView cell == NULL at line %d", __LINE__); + CCLog("CCListView cell == NULL at line %d", __LINE__); } } - else if (NdListViewSlideDirUp == m_nSlideDir) + else if (CCListViewSlideDirUp == m_nSlideDir) { - NdListViewCell* cell = NULL; + CCListViewCell* cell = NULL; unsigned nFirst = 0; if (CCRange::CCLocationInRange(nRow - nCount + 1, m_visibleRows)) { @@ -841,13 +847,13 @@ void NdListView::scrollCellToBack(unsigned int nRow, bool bAnimated) } else { - CCLog("NdListView cell == NULL at line %d", __LINE__); + CCLog("CCListView cell == NULL at line %d", __LINE__); } } } else { - CCLog("NdListView cell == NULL at line %d", __LINE__); + CCLog("CCListView cell == NULL at line %d", __LINE__); } } @@ -861,13 +867,13 @@ void NdListView::scrollCellToBack(unsigned int nRow, bool bAnimated) m_ptDestination = m_layerPanel->getPosition(); m_ptDestination.x += disX; m_ptDestination.y += disY; - m_nState = NdListViewStateScroll; + m_nState = CCListViewStateScroll; if (bAnimated) { CCMoveBy *moveBy = CCMoveBy::actionWithDuration(m_fActionDuration, CCPointMake(disX, disY)); CCEaseOut *ease = CCEaseOut::actionWithAction(moveBy, 3); - CCFiniteTimeAction *actions = CCSequence::actions(ease, CCCallFunc::actionWithTarget(this, callfunc_selector(NdListView::finishScroll)), NULL); + CCFiniteTimeAction *actions = CCSequence::actions(ease, CCCallFunc::actionWithTarget(this, callfunc_selector(CCListView::finishScroll)), NULL); m_layerPanel->runAction(actions); } else @@ -876,35 +882,35 @@ void NdListView::scrollCellToBack(unsigned int nRow, bool bAnimated) } } -NdListViewSlideDir NdListView::getSlideDir(CCPoint ptTouchBegan, CCPoint ptTouchEnd) +CCListViewSlideDir CCListView::getSlideDir(CCPoint ptTouchBegan, CCPoint ptTouchEnd) { - NdListViewSlideDir nSlideDir = NdListViewSlideDirNone; + CCListViewSlideDir nSlideDir = CCListViewSlideDirNone; int nOffsetX = ptTouchEnd.x - ptTouchBegan.x; int nOffsetY = ptTouchEnd.y - ptTouchBegan.y; int disMin = CCDirector::sharedDirector()->getWinSize().height / 100; - if(NdListViewModeHorizontal == m_nMode) + if(CCListViewModeHorizontal == m_nMode) { if(nOffsetX >= disMin) { - nSlideDir = NdListViewSlideDirRight; + nSlideDir = CCListViewSlideDirRight; } else if (nOffsetX <= -disMin) { - nSlideDir = NdListViewSlideDirLeft; + nSlideDir = CCListViewSlideDirLeft; } } - else if (NdListViewModeVertical == m_nMode) + else if (CCListViewModeVertical == m_nMode) { if(nOffsetY >= disMin) { - nSlideDir = NdListViewSlideDirUp; + nSlideDir = CCListViewSlideDirUp; } else if (nOffsetY <= -disMin) { - nSlideDir = NdListViewSlideDirDown; + nSlideDir = CCListViewSlideDirDown; } } return nSlideDir; @@ -913,9 +919,9 @@ NdListViewSlideDir NdListView::getSlideDir(CCPoint ptTouchBegan, CCPoint ptTouch /****************************************** **************Private Functions************ *******************************************/ -int NdListView::rowForTouch(cocos2d::CCTouch *touch) +int CCListView::rowForTouch(cocos2d::CCTouch *touch) { - CCPoint touchLocation = touch->locationInView(touch->view()); + CCPoint touchLocation = touch->locationInView(); touchLocation = CCDirector::sharedDirector()->convertToGL(touchLocation); CCArray *pChildren = m_layerPanel->getChildren(); @@ -943,14 +949,14 @@ int NdListView::rowForTouch(cocos2d::CCTouch *touch) return -1; } -void NdListView::finishFix(void) +void CCListView::finishFix(void) { if(m_pListViewParent) { m_pListViewParent->setIsEnabled(true); } - m_nState = NdListViewStateWatting; - m_nSlideDir = NdListViewSlideDirNone; + m_nState = CCListViewStateWatting; + m_nSlideDir = CCListViewSlideDirNone; clearUnvisibleRows(); triggerDidScrollToRow(m_visibleRows.location); @@ -963,21 +969,21 @@ void NdListView::finishFix(void) //CCLog("row num left:%d [%d, %d]", nCount, m_drawedRows.location, CCRange::CCMaxRange(m_drawedRows)); } -void NdListView::finishScroll(void) +void CCListView::finishScroll(void) { finishFix(); } -void NdListView::finishEaseOut(void) +void CCListView::finishEaseOut(void) { bool bNeedFix = false; - if (NdListViewModeHorizontal == m_nMode) + if (CCListViewModeHorizontal == m_nMode) { bool bFullFill = isFullFill(); - if (NdListViewSlideDirLeft == m_nSlideDir && bFullFill) + if (CCListViewSlideDirLeft == m_nSlideDir && bFullFill) { - NdListViewCell *cell = cellAtRow(m_nNumberOfRows - 1); + CCListViewCell *cell = cellAtRow(m_nNumberOfRows - 1); if (cell) { CCPoint ptCell = cell->convertToWorldSpace(CCPointZero); @@ -991,7 +997,7 @@ void NdListView::finishEaseOut(void) } else { - NdListViewCell *cell = cellAtRow(0); + CCListViewCell *cell = cellAtRow(0); if (cell) { CCPoint ptCell = cell->convertToWorldSpace(CCPointZero); @@ -1004,12 +1010,12 @@ void NdListView::finishEaseOut(void) } } } - else if (NdListViewModeVertical == m_nMode) + else if (CCListViewModeVertical == m_nMode) { bool bFullFill = this->isFullFill(); - if (NdListViewSlideDirUp == m_nSlideDir && bFullFill) + if (CCListViewSlideDirUp == m_nSlideDir && bFullFill) { - NdListViewCell *cell = cellAtRow(m_nNumberOfRows - 1); + CCListViewCell *cell = cellAtRow(m_nNumberOfRows - 1); if (cell) { CCPoint ptCell = cell->convertToWorldSpace(CCPointZero); @@ -1023,7 +1029,7 @@ void NdListView::finishEaseOut(void) } else { - NdListViewCell *cell = cellAtRow(0); + CCListViewCell *cell = cellAtRow(0); if (cell) { CCPoint ptCell = cell->convertToWorldSpace(CCPointZero); @@ -1043,7 +1049,7 @@ void NdListView::finishEaseOut(void) } } -bool NdListView::isTouchInside(CCTouch *touch) +bool CCListView::isTouchInside(CCTouch *touch) { CCPoint point; if (m_pListViewParent) @@ -1059,16 +1065,16 @@ bool NdListView::isTouchInside(CCTouch *touch) return bIn; } -bool NdListView::isFullFill(void) +bool CCListView::isFullFill(void) { bool bRet = false; float length = 0; for (unsigned int i = m_drawedRows.location; i <= CCRange::CCMaxRange(m_drawedRows); i++) { - NdListViewCell *cell = cellAtRow(i); + CCListViewCell *cell = cellAtRow(i); if (cell) { - if (NdListViewModeHorizontal == m_nMode) + if (CCListViewModeHorizontal == m_nMode) { length += cell->getContentSize().width; if (length >= this->getContentSize().width) @@ -1077,7 +1083,7 @@ bool NdListView::isFullFill(void) break; } } - else if (NdListViewModeVertical == m_nMode) + else if (CCListViewModeVertical == m_nMode) { length += cell->getContentSize().height; if (length >= this->getContentSize().height) @@ -1091,122 +1097,122 @@ bool NdListView::isFullFill(void) return bRet; } -NdListViewCell *NdListView::cellAtRow(unsigned int nRow) +CCListViewCell *CCListView::cellAtRow(unsigned int nRow) { - NdListViewCell *cell = (NdListViewCell*)m_layerPanel->getChildByTag(nRow); + CCListViewCell *cell = (CCListViewCell*)m_layerPanel->getChildByTag(nRow); return cell; } -void NdListView::stopActionImmediately(void) +void CCListView::stopActionImmediately(void) { m_layerPanel->stopAllActions(); - if (NdListViewStateScroll == m_nState) + if (CCListViewStateScroll == m_nState) { m_layerPanel->setPosition(m_ptDestination); finishScroll(); } } -unsigned int NdListView::triggerNumberOfCells(void) +unsigned int CCListView::triggerNumberOfCells(void) { unsigned int nRow = 0; - NdListViewProtrolData data; + CCListViewProtrolData data; if (m_strDeletegate.size() > 0) { - CCScriptEngineProtocol* scriptEngine = CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine(); + CCScriptEngineProtocol* scriptEngine = CCScriptEngineManager::sharedManager()->getScriptEngine(); if (scriptEngine) { std::string script; - script = m_strDeletegate + "NdListView_numberOfCells"; - scriptEngine->executeCallFuncNTDT(script.c_str(), this, "NdCxControl::NdListView", &data, "NdCxControl::NdListViewProtrolData"); + script = m_strDeletegate + "CCListView_numberOfCells"; +//TODO: scriptEngine->executeCallFuncNTDT(script.c_str(), this, "NdCxControl::CCListView", &data, "NdCxControl::CCListViewProtrolData"); nRow = data.nNumberOfRows; } } if (m_pDelegate) { - m_pDelegate->NdListView_numberOfCells(this, &data); + m_pDelegate->CCListView_numberOfCells(this, &data); nRow = data.nNumberOfRows; } return nRow; } -NdListViewCell *NdListView::triggerCellForRow(unsigned int nRow) +CCListViewCell *CCListView::triggerCellForRow(unsigned int nRow) { - NdListViewCell *cell = NULL; - NdListViewProtrolData data; + CCListViewCell *cell = NULL; + CCListViewProtrolData data; data.nRow = nRow; data.cell = NULL; if (m_strDeletegate.size() > 0) { - CCScriptEngineProtocol* scriptEngine = CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine(); + CCScriptEngineProtocol* scriptEngine = CCScriptEngineManager::sharedManager()->getScriptEngine(); if (scriptEngine) { std::string script; - script = m_strDeletegate + "NdListView_cellForRow"; - scriptEngine->executeCallFuncNTDT(script.c_str(), this, "NdCxControl::NdListView", &data, "NdCxControl::NdListViewProtrolData"); + script = m_strDeletegate + "CCListView_cellForRow"; +//TODO: scriptEngine->executeCallFuncNTDT(script.c_str(), this, "NdCxControl::CCListView", &data, "NdCxControl::CCListViewProtrolData"); cell = data.cell; } } if (m_pDelegate) { - m_pDelegate->NdListView_cellForRow(this, &data); + m_pDelegate->CCListView_cellForRow(this, &data); cell = data.cell; } return cell; } -void NdListView::triggerDidClickCellAtRow(unsigned int nRow) +void CCListView::triggerDidClickCellAtRow(unsigned int nRow) { - NdListViewProtrolData data; + CCListViewProtrolData data; data.nRow = nRow; if (m_strDeletegate.size() > 0) { - CCScriptEngineProtocol* scriptEngine = CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine(); + CCScriptEngineProtocol* scriptEngine = CCScriptEngineManager::sharedManager()->getScriptEngine(); if (scriptEngine) { std::string script; - script = m_strDeletegate + "NdListView_didClickCellAtRow"; - scriptEngine->executeCallFuncNTDT(script.c_str(), this, "NdCxControl::NdListView", &data, "NdCxControl::NdListViewProtrolData"); + script = m_strDeletegate + "CCListView_didClickCellAtRow"; +//TODO: scriptEngine->executeCallFuncNTDT(script.c_str(), this, "NdCxControl::CCListView", &data, "NdCxControl::CCListViewProtrolData"); } } if (m_pDelegate) { - m_pDelegate->NdListView_didClickCellAtRow(this, &data); + m_pDelegate->CCListView_didClickCellAtRow(this, &data); } } -void NdListView::triggerDidScrollToRow(unsigned int nRow) +void CCListView::triggerDidScrollToRow(unsigned int nRow) { - NdListViewProtrolData data; + CCListViewProtrolData data; data.nRow = nRow; if (m_strDeletegate.size() > 0) { - CCScriptEngineProtocol* scriptEngine = CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine(); + CCScriptEngineProtocol* scriptEngine = CCScriptEngineManager::sharedManager()->getScriptEngine(); if (scriptEngine) { std::string script; - script = m_strDeletegate + "NdListView_didScrollToRow"; - scriptEngine->executeCallFuncNTDT(script.c_str(), this, "NdCxControl::NdListView", &data, "NdCxControl::NdListViewProtrolData"); + script = m_strDeletegate + "CCListView_didScrollToRow"; +//TODO: scriptEngine->executeCallFuncNTDT(script.c_str(), this, "NdCxControl::CCListView", &data, "NdCxControl::CCListViewProtrolData"); } } if (m_pDelegate) { - m_pDelegate->NdListView_didScrollToRow(this, &data); + m_pDelegate->CCListView_didScrollToRow(this, &data); } } -void NdListView::displayVisibleRows(void) +void CCListView::displayVisibleRows(void) { CCSize size = getContentSize(); float posPannel, boundPannel; unsigned int rowCount = m_drawedRows.location; - NdListViewCell *cell = cellAtRow(rowCount); + CCListViewCell *cell = cellAtRow(rowCount); - if (m_nMode == NdListViewModeHorizontal) + if (m_nMode == CCListViewModeHorizontal) { if (cell) { @@ -1218,7 +1224,7 @@ void NdListView::displayVisibleRows(void) } boundPannel = posPannel + size.width; } - else if (m_nMode == NdListViewModeVertical) + else if (m_nMode == CCListViewModeVertical) { if (cell) { @@ -1231,7 +1237,7 @@ void NdListView::displayVisibleRows(void) boundPannel = posPannel - size.height; } - NdListViewCell *lastCell = NULL; + CCListViewCell *lastCell = NULL; while(1) { // row condition @@ -1239,19 +1245,19 @@ void NdListView::displayVisibleRows(void) break; // size condition - if (m_nMode == NdListViewModeHorizontal) + if (m_nMode == CCListViewModeHorizontal) { if (posPannel >= boundPannel) break; } - else if (m_nMode == NdListViewModeVertical) + else if (m_nMode == CCListViewModeVertical) { if (posPannel <= boundPannel) break; } // get cell - NdListViewCell *cell = cellAtRow(rowCount); + CCListViewCell *cell = cellAtRow(rowCount); if (NULL == cell) { @@ -1259,12 +1265,12 @@ void NdListView::displayVisibleRows(void) if (cell) { CCSize cellSize = cell->getContentSize(); - if (m_nMode == NdListViewModeHorizontal) + if (m_nMode == CCListViewModeHorizontal) { cell->setPosition(CCPointMake(posPannel, 0)); cell->setContentSize(CCSizeMake(cellSize.width, size.height)); } - else if (m_nMode == NdListViewModeVertical) + else if (m_nMode == CCListViewModeVertical) { cell->setPosition(CCPointMake(0, posPannel - cellSize.height)); cell->setContentSize(CCSizeMake(size.width, cellSize.height)); @@ -1275,11 +1281,11 @@ void NdListView::displayVisibleRows(void) if (cell) { - if (m_nMode == NdListViewModeHorizontal) + if (m_nMode == CCListViewModeHorizontal) { posPannel += cell->getContentSize().width; } - else if (m_nMode == NdListViewModeVertical) + else if (m_nMode == CCListViewModeVertical) { posPannel -= cell->getContentSize().height; } @@ -1295,17 +1301,17 @@ void NdListView::displayVisibleRows(void) if (lastCell) { - lastCell->setSeparatorStyle(NdListViewCellSeparatorStyleNone); + lastCell->setSeparatorStyle(CCListViewCellSeparatorStyleNone); } } -NdListViewCell* NdListView::appendRowToBack(unsigned int nRow) +CCListViewCell* CCListView::appendRowToBack(unsigned int nRow) { if (nRow >= m_nNumberOfRows) { return NULL; } - NdListViewCell *cell = cellAtRow(nRow); + CCListViewCell *cell = cellAtRow(nRow); if (cell == NULL) { cell = triggerCellForRow(nRow); @@ -1315,16 +1321,16 @@ NdListViewCell* NdListView::appendRowToBack(unsigned int nRow) CCSize cellSize = cell->getContentSize(); float pos; unsigned int nLastRow = CCRange::CCMaxRange(m_drawedRows); - NdListViewCell *lastCell = cellAtRow(nLastRow); + CCListViewCell *lastCell = cellAtRow(nLastRow); if (lastCell) { - if (m_nMode == NdListViewModeHorizontal) + if (m_nMode == CCListViewModeHorizontal) { pos = lastCell->getPosition().x + lastCell->getContentSize().width; cell->setPosition(CCPointMake(pos, 0)); cell->setContentSize(CCSizeMake(cellSize.width, size.height)); } - else if (m_nMode == NdListViewModeVertical) + else if (m_nMode == CCListViewModeVertical) { pos = lastCell->getPosition().y - cell->getContentSize().height; cell->setPosition(CCPointMake(0, pos)); @@ -1338,7 +1344,7 @@ NdListViewCell* NdListView::appendRowToBack(unsigned int nRow) m_layerPanel->addChild(cell, nRow, nRow); if (nRow > CCRange::CCMaxRange(m_drawedRows)) { - cell->setSeparatorStyle(NdListViewCellSeparatorStyleNone); + cell->setSeparatorStyle(CCListViewCellSeparatorStyleNone); lastCell->setSeparatorStyle(m_nSeparatorStyle); m_drawedRows.length += nRow - CCRange::CCMaxRange(m_drawedRows); } @@ -1349,20 +1355,20 @@ NdListViewCell* NdListView::appendRowToBack(unsigned int nRow) } else { - CCLog("NdListView cell == NULL at line %d", __LINE__); + CCLog("CCListView cell == NULL at line %d", __LINE__); } } else { - CCLog("NdListView cell == NULL at line %d", __LINE__); + CCLog("CCListView cell == NULL at line %d", __LINE__); } } return cell; } -NdListViewCell* NdListView::appendRowToFront(unsigned int nRow) +CCListViewCell* CCListView::appendRowToFront(unsigned int nRow) { - NdListViewCell *cell = cellAtRow(nRow); + CCListViewCell *cell = cellAtRow(nRow); if (cell == NULL) { cell = triggerCellForRow(nRow); @@ -1372,16 +1378,16 @@ NdListViewCell* NdListView::appendRowToFront(unsigned int nRow) CCSize cellSize = cell->getContentSize(); float pos; unsigned int nFirstRow = m_drawedRows.location; - NdListViewCell *firstCell = cellAtRow(nFirstRow); + CCListViewCell *firstCell = cellAtRow(nFirstRow); if (firstCell) { - if (m_nMode == NdListViewModeHorizontal) + if (m_nMode == CCListViewModeHorizontal) { pos = firstCell->getPosition().x - cell->getContentSize().width; cell->setPosition(CCPointMake(pos, 0)); cell->setContentSize(CCSizeMake(cellSize.width, size.height)); } - else if (m_nMode == NdListViewModeVertical) + else if (m_nMode == CCListViewModeVertical) { pos = firstCell->getPosition().y + firstCell->getContentSize().height; cell->setPosition(CCPointMake(0, pos)); @@ -1401,29 +1407,29 @@ NdListViewCell* NdListView::appendRowToFront(unsigned int nRow) } else { - CCLog("NdListView cell == NULL at line %d", __LINE__); + CCLog("CCListView cell == NULL at line %d", __LINE__); } } else { - CCLog("NdListView cell == NULL at line %d", __LINE__); + CCLog("CCListView cell == NULL at line %d", __LINE__); } } return cell; } // 对齐末行 -void NdListView::fixFirstRow(void) +void CCListView::fixFirstRow(void) { unsigned int location = m_drawedRows.location; - NdListViewCell *cell = cellAtRow(location); + CCListViewCell *cell = cellAtRow(location); if (cell) { float disX = 0; float disY = 0; CCPoint posCell = cell->convertToWorldSpace(CCPointZero); CCPoint posView = this->convertToWorldSpace(CCPointZero); - if (NdListViewModeHorizontal == m_nMode) + if (CCListViewModeHorizontal == m_nMode) { float dis = posCell.x - posView.x; dis = -dis; @@ -1431,7 +1437,7 @@ void NdListView::fixFirstRow(void) disX = dis; disY = 0; } - else if (NdListViewModeVertical == m_nMode) + else if (CCListViewModeVertical == m_nMode) { float dis = posCell.y + cell->getContentSize().height - (posView.y + this->getContentSize().height); dis = -dis; @@ -1440,10 +1446,10 @@ void NdListView::fixFirstRow(void) disY = dis; } - m_nState = NdListViewStateFix; + m_nState = CCListViewStateFix; CCMoveBy *moveBy = CCMoveBy::actionWithDuration(m_fActionDuration, CCPointMake(disX, disY)); CCEaseInOut *ease = CCEaseInOut::actionWithAction(moveBy, 2); - CCFiniteTimeAction *actions = CCSequence::actions(ease, CCCallFunc::actionWithTarget(this, callfunc_selector(NdListView::finishFix)), NULL); + CCFiniteTimeAction *actions = CCSequence::actions(ease, CCCallFunc::actionWithTarget(this, callfunc_selector(CCListView::finishFix)), NULL); m_layerPanel->runAction(actions); } else @@ -1452,17 +1458,17 @@ void NdListView::fixFirstRow(void) } } // 对齐首行 -void NdListView::fixLastRow(void) +void CCListView::fixLastRow(void) { unsigned int nLastRow = CCRange::CCMaxRange(m_drawedRows); - NdListViewCell *cell = cellAtRow(nLastRow); + CCListViewCell *cell = cellAtRow(nLastRow); if (cell) { float disX = 0; float disY = 0; CCPoint posCell = cell->convertToWorldSpace(CCPointZero); CCPoint posView = this->convertToWorldSpace(CCPointZero); - if (NdListViewModeHorizontal == m_nMode) + if (CCListViewModeHorizontal == m_nMode) { float dis = posCell.x + cell->getContentSize().width - (posView.x + this->getContentSize().width); dis = -dis; @@ -1470,7 +1476,7 @@ void NdListView::fixLastRow(void) disX = dis; disY = 0; } - else if (NdListViewModeVertical == m_nMode) + else if (CCListViewModeVertical == m_nMode) { float dis = posCell.y - posView.y; dis = -dis; @@ -1479,10 +1485,10 @@ void NdListView::fixLastRow(void) disY = dis; } - m_nState = NdListViewStateFix; + m_nState = CCListViewStateFix; CCMoveBy *moveBy = CCMoveBy::actionWithDuration(m_fActionDuration, CCPointMake(disX, disY)); CCEaseInOut *ease = CCEaseInOut::actionWithAction(moveBy, 2); - CCFiniteTimeAction *actions = CCSequence::actions(ease, CCCallFunc::actionWithTarget(this, callfunc_selector(NdListView::finishFix)), NULL); + CCFiniteTimeAction *actions = CCSequence::actions(ease, CCCallFunc::actionWithTarget(this, callfunc_selector(CCListView::finishFix)), NULL); m_layerPanel->runAction(actions); } else @@ -1491,20 +1497,20 @@ void NdListView::fixLastRow(void) } } // 手势滑动界面,减速效果 -void NdListView::easeOutWithDistance(float dis) +void CCListView::easeOutWithDistance(float dis) { float disX = 0; float disY = 0; - if (NdListViewModeHorizontal == m_nMode) + if (CCListViewModeHorizontal == m_nMode) { - if (NdListViewSlideDirLeft == m_nSlideDir) + if (CCListViewSlideDirLeft == m_nSlideDir) { // drag Left while(1) { unsigned int nLastRow = CCRange::CCMaxRange(m_drawedRows); - NdListViewCell *cell = cellAtRow(nLastRow); + CCListViewCell *cell = cellAtRow(nLastRow); if (cell) { CCPoint ptCell = cell->convertToWorldSpace(CCPointZero); @@ -1551,7 +1557,7 @@ void NdListView::easeOutWithDistance(float dis) while(1) { unsigned int nFirstRow = m_drawedRows.location; - NdListViewCell *cell = cellAtRow(nFirstRow); + CCListViewCell *cell = cellAtRow(nFirstRow); if (cell) { CCPoint ptCell = cell->convertToWorldSpace(CCPointZero); @@ -1595,15 +1601,15 @@ void NdListView::easeOutWithDistance(float dis) disX = dis; disY = 0; } - else if (NdListViewModeVertical == m_nMode) + else if (CCListViewModeVertical == m_nMode) { - if (NdListViewSlideDirUp == m_nSlideDir) + if (CCListViewSlideDirUp == m_nSlideDir) { // drag up while(1) { unsigned int nLastRow = CCRange::CCMaxRange(m_drawedRows); - NdListViewCell *cell = cellAtRow(nLastRow); + CCListViewCell *cell = cellAtRow(nLastRow); if (cell) { CCPoint ptCell = cell->convertToWorldSpace(CCPointZero); @@ -1646,7 +1652,7 @@ void NdListView::easeOutWithDistance(float dis) while(1) { unsigned int nFirstRow = m_drawedRows.location; - NdListViewCell *cell = cellAtRow(nFirstRow); + CCListViewCell *cell = cellAtRow(nFirstRow); if (cell) { CCPoint ptCell = cell->convertToWorldSpace(CCPointZero); @@ -1687,24 +1693,24 @@ void NdListView::easeOutWithDistance(float dis) disY = dis; } - m_nState = NdListViewStateEaseOut; + m_nState = CCListViewStateEaseOut; CCMoveBy *moveBy = CCMoveBy::actionWithDuration(m_fActionDuration, CCPointMake(disX, disY)); CCEaseOut *ease = CCEaseOut::actionWithAction(moveBy, 3); - CCFiniteTimeAction *actions = CCSequence::actions(ease, CCCallFunc::actionWithTarget(this, callfunc_selector(NdListView::finishEaseOut)), NULL); + CCFiniteTimeAction *actions = CCSequence::actions(ease, CCCallFunc::actionWithTarget(this, callfunc_selector(CCListView::finishEaseOut)), NULL); m_layerPanel->runAction(actions); } -void NdListView::clearUnvisibleRows(void) +void CCListView::clearUnvisibleRows(void) { CCRange oldRange = m_drawedRows; for (unsigned int i = oldRange.location; i < oldRange.location + oldRange.length; i++) { - NdListViewCell *cell = cellAtRow(i); + CCListViewCell *cell = cellAtRow(i); if (cell) { CCPoint posCell = cell->convertToWorldSpace(CCPointZero); CCPoint posView = this->convertToWorldSpace(CCPointZero); - if (NdListViewModeHorizontal == m_nMode) + if (CCListViewModeHorizontal == m_nMode) { if (posCell.x + cell->getContentSize().width <= posView.x) { @@ -1715,7 +1721,7 @@ void NdListView::clearUnvisibleRows(void) break; } } - else if (NdListViewModeVertical == m_nMode) + else if (CCListViewModeVertical == m_nMode) { if (posCell.y >= posView.y + this->getContentSize().height) { @@ -1734,12 +1740,12 @@ void NdListView::clearUnvisibleRows(void) oldRange = m_drawedRows; for (int i = oldRange.location + oldRange.length - 1; i >= (int)oldRange.location; i--) { - NdListViewCell *cell = cellAtRow(i); + CCListViewCell *cell = cellAtRow(i); if (cell) { CCPoint posCell = cell->convertToWorldSpace(CCPointZero); CCPoint posView = this->convertToWorldSpace(CCPointZero); - if (NdListViewModeHorizontal == m_nMode) + if (CCListViewModeHorizontal == m_nMode) { if (posCell.x >= posView.x + this->getContentSize().width) { @@ -1750,7 +1756,7 @@ void NdListView::clearUnvisibleRows(void) break; } } - else if (NdListViewModeVertical == m_nMode) + else if (CCListViewModeVertical == m_nMode) { if (posCell.y + cell->getContentSize().height <= posView.y) { @@ -1770,19 +1776,20 @@ void NdListView::clearUnvisibleRows(void) /****************************************** **************Virturl Functions************ *******************************************/ -void NdListView::registerWithTouchDispatcher() +void CCListView::registerWithTouchDispatcher() { + CCDirector* pDirector = CCDirector::sharedDirector(); if (m_pListViewParent) { - CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, kCCMenuTouchPriority - 1, false); + pDirector->getTouchDispatcher()->addTargetedDelegate(this, kCCMenuHandlerPriority - 1, false); } else { - CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, kCCMenuTouchPriority - 2, false); + pDirector->getTouchDispatcher()->addTargetedDelegate(this, kCCMenuHandlerPriority - 2, false); } } -void NdListView::onEnter(void) +void CCListView::onEnter(void) { if (0 == m_nNumberOfRows) { @@ -1796,12 +1803,12 @@ void NdListView::onEnter(void) CCLayerColor::onEnter(); } -void NdListView::onExit(void) +void CCListView::onExit(void) { CCLayerColor::onExit(); } -void NdListView::visit(void) +void CCListView::visit(void) { if (!m_pListViewParent) { @@ -1823,7 +1830,7 @@ void NdListView::visit(void) } } -bool NdListView::ccTouchBegan(CCTouch* touch, CCEvent* event) +bool CCListView::ccTouchBegan(CCTouch* touch, CCEvent* event) { CC_UNUSED_PARAM(event); @@ -1832,7 +1839,7 @@ bool NdListView::ccTouchBegan(CCTouch* touch, CCEvent* event) return false; } - if (m_pListViewParent && NdListViewSlideDirNone != m_pListViewParent->getSlideDir()) + if (m_pListViewParent && CCListViewSlideDirNone != m_pListViewParent->getSlideDir()) { return false; } @@ -1848,7 +1855,7 @@ bool NdListView::ccTouchBegan(CCTouch* touch, CCEvent* event) return false; } - CCPoint touchPoint = touch->locationInView(touch->view()); + CCPoint touchPoint = touch->locationInView(); m_ptTouchBegan = m_ptTouchEnd = CCDirector::sharedDirector()->convertToGL(touchPoint); m_ptPanelOffset = m_layerPanel->getPosition(); @@ -1858,13 +1865,13 @@ bool NdListView::ccTouchBegan(CCTouch* touch, CCEvent* event) m_nCurrentRow = this->rowForTouch(touch); if (m_nCurrentRow != -1) { - if (NdListViewStateWatting != m_nState) + if (CCListViewStateWatting != m_nState) { stopActionImmediately(); } - m_nState = NdListViewStateTrackingTouch; - if (NdListViewSlideDirNone == m_nSlideDir) + m_nState = CCListViewStateTrackingTouch; + if (CCListViewSlideDirNone == m_nSlideDir) { this->selectCellAtRow(m_nCurrentRow); } @@ -1880,20 +1887,20 @@ bool NdListView::ccTouchBegan(CCTouch* touch, CCEvent* event) return false; } -void NdListView::ccTouchMoved(CCTouch* touch, CCEvent* event) +void CCListView::ccTouchMoved(CCTouch* touch, CCEvent* event) { CC_UNUSED_PARAM(event); - if (NdListViewStateTrackingTouch != m_nState || !isTouchInside(touch) || !m_bIsEnabled) + if (CCListViewStateTrackingTouch != m_nState || !isTouchInside(touch) || !m_bIsEnabled) { return; } - CCPoint touchPoint = touch->locationInView(touch->view()); + CCPoint touchPoint = touch->locationInView(); m_ptTouchEnd = CCDirector::sharedDirector()->convertToGL(touchPoint); - NdListViewSlideDir nsliderDir = NdListViewSlideDirNone; - if (m_pListViewParent && NdListViewSlideDirNone != m_pListViewParent->getSlideDir(m_ptTouchBegan, m_ptTouchEnd)) + CCListViewSlideDir nsliderDir = CCListViewSlideDirNone; + if (m_pListViewParent && CCListViewSlideDirNone != m_pListViewParent->getSlideDir(m_ptTouchBegan, m_ptTouchEnd)) { return; } @@ -1903,23 +1910,26 @@ void NdListView::ccTouchMoved(CCTouch* touch, CCEvent* event) } - if(NdListViewModeHorizontal == m_nMode && NdListViewSlideDirNone != nsliderDir) + if(CCListViewModeHorizontal == m_nMode && CCListViewSlideDirNone != nsliderDir) { m_nSlideDir = nsliderDir; m_layerPanel->setPosition(CCPointMake(m_ptPanelOffset.x + (m_ptTouchEnd.x - m_ptTouchBegan.x),m_ptPanelOffset.y)); - if (NdListViewSlideDirLeft == m_nSlideDir) + if (CCListViewSlideDirLeft == m_nSlideDir) { // drag left unsigned int nLastRow = CCRange::CCMaxRange(m_drawedRows); if (nLastRow < m_nNumberOfRows - 1) { - NdListViewCell *cell = cellAtRow(nLastRow); - CCPoint posCell = cell->convertToWorldSpace(CCPointZero); - CCPoint posView = this->convertToWorldSpace(CCPointZero); - if (posCell.x + cell->getContentSize().width <= posView.x + this->getContentSize().width) - { - appendRowToBack(nLastRow + 1); - } + CCListViewCell *cell = cellAtRow(nLastRow); + if (cell) + { + CCPoint posCell = cell->convertToWorldSpace(CCPointZero); + CCPoint posView = this->convertToWorldSpace(CCPointZero); + if (posCell.x + cell->getContentSize().width <= posView.x + this->getContentSize().width) + { + appendRowToBack(nLastRow + 1); + } + } } } else @@ -1928,7 +1938,7 @@ void NdListView::ccTouchMoved(CCTouch* touch, CCEvent* event) unsigned int nFirstRow = m_drawedRows.location; if (nFirstRow > 0) { - NdListViewCell *cell = cellAtRow(nFirstRow); + CCListViewCell *cell = cellAtRow(nFirstRow); CCPoint posCell = cell->convertToWorldSpace(CCPointZero); CCPoint posView = this->convertToWorldSpace(CCPointZero); if (posCell.x >= posView.x) @@ -1938,17 +1948,17 @@ void NdListView::ccTouchMoved(CCTouch* touch, CCEvent* event) } } } - else if (NdListViewModeVertical == m_nMode && NdListViewSlideDirNone != nsliderDir) + else if (CCListViewModeVertical == m_nMode && CCListViewSlideDirNone != nsliderDir) { m_nSlideDir = nsliderDir; m_layerPanel->setPosition(CCPointMake(m_ptPanelOffset.x, m_ptPanelOffset.y + (m_ptTouchEnd.y - m_ptTouchBegan.y))); - if (NdListViewSlideDirUp == m_nSlideDir) + if (CCListViewSlideDirUp == m_nSlideDir) { // drag up unsigned int nLastRow = CCRange::CCMaxRange(m_drawedRows); if (nLastRow < m_nNumberOfRows - 1) { - NdListViewCell *cell = cellAtRow(nLastRow); + CCListViewCell *cell = cellAtRow(nLastRow); CCPoint posCell = cell->convertToWorldSpace(CCPointZero); CCPoint posView = this->convertToWorldSpace(CCPointZero); if (posCell.y >= posView.y) @@ -1963,7 +1973,7 @@ void NdListView::ccTouchMoved(CCTouch* touch, CCEvent* event) unsigned int nFirstRow = m_drawedRows.location; if (nFirstRow > 0) { - NdListViewCell *cell = cellAtRow(nFirstRow); + CCListViewCell *cell = cellAtRow(nFirstRow); CCPoint posCell = cell->convertToWorldSpace(CCPointZero); CCPoint posView = this->convertToWorldSpace(CCPointZero); if (posCell.y + cell->getContentSize().height <= posView.y + this->getContentSize().height) @@ -1974,23 +1984,23 @@ void NdListView::ccTouchMoved(CCTouch* touch, CCEvent* event) } } - if (NdListViewSlideDirNone != m_nSlideDir && m_nCurrentRow != -1 && m_nCurrentRow != m_nSelectedRow) + if (CCListViewSlideDirNone != m_nSlideDir && m_nCurrentRow != -1 && m_nCurrentRow != m_nSelectedRow) { this->unselectCellAtRow(m_nCurrentRow); } - if (NdListViewSlideDirNone != m_nSlideDir && m_pListViewParent) + if (CCListViewSlideDirNone != m_nSlideDir && m_pListViewParent) { m_pListViewParent->setIsEnabled(false); } } -void NdListView::ccTouchEnded(CCTouch* touch, CCEvent* event) +void CCListView::ccTouchEnded(CCTouch* touch, CCEvent* event) { CC_UNUSED_PARAM(touch); CC_UNUSED_PARAM(event); - if(m_nState != NdListViewStateTrackingTouch || !m_bIsEnabled) + if(m_nState != CCListViewStateTrackingTouch || !m_bIsEnabled) { m_bIsOnTouch = false; return; @@ -2002,7 +2012,7 @@ void NdListView::ccTouchEnded(CCTouch* touch, CCEvent* event) // 手机平台用时较长,此系数可能需要根据不同平台做相应调整 timeElapse /= 200; #endif - if(NdListViewSlideDirLeft == m_nSlideDir || NdListViewSlideDirRight == m_nSlideDir) + if(CCListViewSlideDirLeft == m_nSlideDir || CCListViewSlideDirRight == m_nSlideDir) { float dis = m_ptTouchEnd.x - m_ptTouchBegan.x; float speed = dis / timeElapse; @@ -2012,7 +2022,7 @@ void NdListView::ccTouchEnded(CCTouch* touch, CCEvent* event) } else { - if (NdListViewSlideDirLeft == m_nSlideDir && isFullFill()) + if (CCListViewSlideDirLeft == m_nSlideDir && isFullFill()) { // drag up fixLastRow(); @@ -2024,7 +2034,7 @@ void NdListView::ccTouchEnded(CCTouch* touch, CCEvent* event) } } } - else if (NdListViewSlideDirUp == m_nSlideDir || NdListViewSlideDirDown == m_nSlideDir) + else if (CCListViewSlideDirUp == m_nSlideDir || CCListViewSlideDirDown == m_nSlideDir) { float dis = m_ptTouchEnd.y - m_ptTouchBegan.y; float speed = dis / timeElapse; @@ -2034,7 +2044,7 @@ void NdListView::ccTouchEnded(CCTouch* touch, CCEvent* event) } else { - if (NdListViewSlideDirUp == m_nSlideDir && isFullFill()) + if (CCListViewSlideDirUp == m_nSlideDir && isFullFill()) { // drag up fixLastRow(); @@ -2056,9 +2066,9 @@ void NdListView::ccTouchEnded(CCTouch* touch, CCEvent* event) { if (currentRow == m_nCurrentRow) { - if (NdListViewSlideDirNone == m_nSlideDir) + if (CCListViewSlideDirNone == m_nSlideDir) { - if (m_pListViewParent == NULL || (m_pListViewParent && NdListViewSlideDirNone == m_pListViewParent->getSlideDir())) + if (m_pListViewParent == NULL || (m_pListViewParent && CCListViewSlideDirNone == m_pListViewParent->getSlideDir())) { if (m_nSelectedRow != -1 && m_nSelectedRow != m_nCurrentRow) { @@ -2099,11 +2109,11 @@ void NdListView::ccTouchEnded(CCTouch* touch, CCEvent* event) m_bIsOnTouch = false; } -bool NdListView::isMenuTouch(CCTouch *touch, CCNode *parent) +bool CCListView::isMenuTouch(CCTouch *touch, CCNode *parent) { - if (parent->getClassType() == CCMenuItem_classID) + if (dynamic_cast(parent)) { - CCPoint touchPoint = touch->locationInView(touch->view()); + CCPoint touchPoint = touch->locationInView(); touchPoint.y = cocos2d::CCDirector::sharedDirector()->getWinSize().height - touchPoint.y; touchPoint = parent->convertToNodeSpace(touchPoint); CCRect rect = CCRectZero; @@ -2128,18 +2138,18 @@ bool NdListView::isMenuTouch(CCTouch *touch, CCNode *parent) return false; } -void NdListView::ccTouchCancelled(CCTouch *touch, CCEvent *event) +void CCListView::ccTouchCancelled(CCTouch *touch, CCEvent *event) { CC_UNUSED_PARAM(touch); CC_UNUSED_PARAM(event); - CCAssert(m_nState == NdListViewStateTrackingTouch, "[NdListview ccTouchCancelled] -- invalid state"); + CCAssert(m_nState == CCListViewStateTrackingTouch, "[NdListview ccTouchCancelled] -- invalid state"); finishFix(); m_bIsOnTouch = false; } -} // end of namespace NdCxControl +NS_CC_EXT_END diff --git a/cocos2dx/extensions/CCListView/CCListView.h b/cocos2dx/extensions/CCListView/CCListView.h new file mode 100644 index 0000000000..0ed5b885dd --- /dev/null +++ b/cocos2dx/extensions/CCListView/CCListView.h @@ -0,0 +1,188 @@ +#ifndef __CC_LIST_VIEW_H__ +#define __CC_LIST_VIEW_H__ + +#include +#include "platform.h" +#include +#include +//#include "../lua/cocos2dx_support/CCLuaEngine.h" +#include "CCListViewCell.h" + +NS_CC_EXT_BEGIN + +class CC_DLL CCRange +{ +public: + CCRange() + { + this->location = 0; + this->length = 0; + } + + CCRange(unsigned int loc, unsigned int len) + { + this->location = loc; + this->length = len; + } + + static unsigned int CCMaxRange(CCRange range) + { + return (range.location + range.length-1); + } + + static bool CCLocationInRange(unsigned int loc, CCRange range) + { + return (loc - range.location <= range.length); + } + + static bool CCEqualRanges(CCRange range1, CCRange range2) { return (range1.location == range2.location && range1.length == range2.length); } + + unsigned int length; + unsigned int location; +}; + +#define CCRangeMake(__min__, __max__) CCRange((__min__), (__max__)) + +typedef enum +{ + CCListViewSlideDirNone, + CCListViewSlideDirUp, + CCListViewSlideDirDown, + CCListViewSlideDirLeft, + CCListViewSlideDirRight, +} CCListViewSlideDir; + +typedef enum +{ + CCListViewStateWatting, + CCListViewStateTrackingTouch, + CCListViewStateEaseOut, + CCListViewStateFix, + CCListViewStateScroll, +} CCListViewState; + +typedef enum +{ + CCListViewModeHorizontal, + CCListViewModeVertical, +} CCListViewMode; + +typedef struct _CCListViewProtrolData +{ + unsigned int nNumberOfRows; + unsigned int nRow; + CCListViewCell *cell; +} CCListViewProtrolData; + +class CC_DLL CCListViewDelegate +{ +public : + CCListViewDelegate(){}; + virtual ~CCListViewDelegate(){}; + + virtual void CCListView_numberOfCells(CCListView *listView, CCListViewProtrolData *data)=0; + virtual void CCListView_cellForRow(CCListView *listView, CCListViewProtrolData *data)=0; + virtual void CCListView_didClickCellAtRow(CCListView *listView, CCListViewProtrolData *data)=0; + virtual void CCListView_didScrollToRow(CCListView *listView, CCListViewProtrolData *data)=0; +}; + + +class CC_DLL CCListView : public CCLayerColor +{ +public: + virtual ~CCListView(void); + CCListView(void); + + static CCListView* viewWithMode(CCListViewMode mode); + bool initWithMode(CCListViewMode mode); + + void setDelegateName(const char* pszName); + void selectCellAtRow(unsigned int nRow); + void unselectCellAtRow(unsigned int nRow); + void scrollCellToFront(unsigned int nRow, bool bAnimated); + void scrollCellToBack(unsigned int nRow, bool bAnimated); + void reload(void); + void insertCellsAtRow(unsigned int nRow, unsigned int nCount); + void deleteCellsAtRow(unsigned int nRow, unsigned int nCount); + CCListViewCell *cellAtRow(unsigned int nRow); + + CCListViewSlideDir getSlideDir(CCPoint ptTouchBegan, CCPoint ptTouchEnd); + inline CCListViewSlideDir getSlideDir(void) { return m_nSlideDir; } + + inline CCListViewCellSeparatorStyle getSeparatorStyle(void) { return m_nSeparatorStyle; } + inline void setSeparatorStyle(CCListViewCellSeparatorStyle style) { m_nSeparatorStyle = style; } + inline CCListViewMode getMode(void) { return m_nMode; } + + inline void setListViewParent(CCListView *pParent) { m_pListViewParent = pParent; } + inline CCListView *getListViewParent(void) { return m_pListViewParent; } + + inline void setIsEnabled(bool bEnabled) { m_bIsEnabled = bEnabled; } + inline bool getIsEnabled(void) { return m_bIsEnabled; } + + // un + void setDelegate(const CCListViewDelegate *pDelegate) { m_pDelegate = const_cast(pDelegate);} + void finishFix(void); + void finishScroll(void); + void finishEaseOut(void); + +public: + virtual bool ccTouchBegan(CCTouch* touch, CCEvent* event); + virtual void ccTouchEnded(CCTouch* touch, CCEvent* event); + virtual void ccTouchCancelled(CCTouch *touch, CCEvent* event); + virtual void ccTouchMoved(CCTouch* touch, CCEvent* event); + + virtual void onEnter(void); + virtual void onExit(void); + + virtual void registerWithTouchDispatcher(void); + virtual void visit(void); + +protected: + void displayVisibleRows(void); + CCListViewCell* appendRowToBack(unsigned int nRow); + CCListViewCell* appendRowToFront(unsigned int nRow); + void fixFirstRow(void); + void fixLastRow(void); + void easeOutWithDistance(float dis); + void clearUnvisibleRows(void); + + int rowForTouch(cocos2d::CCTouch *touch); + bool isTouchInside(CCTouch *touch); + bool isFullFill(void); + + void stopActionImmediately(void); + + unsigned int triggerNumberOfCells(void); + CCListViewCell *triggerCellForRow(unsigned int nRow); + void triggerDidClickCellAtRow(unsigned int nRow); + void triggerDidScrollToRow(unsigned int nRow); + bool isMenuTouch(CCTouch *touch, CCNode *parent); + +private: + CCListViewState m_nState; + CCListViewMode m_nMode; + CCListViewSlideDir m_nSlideDir; + CCListViewCellSeparatorStyle m_nSeparatorStyle; + unsigned int m_nNumberOfRows; + float m_fActionDuration; + clock_t m_timeTouchBegan; + CCRange m_drawedRows; //所有已绘制的cell + CCRange m_visibleRows; //所有可见的cell + CCPoint m_ptTouchBegan; + CCPoint m_ptTouchEnd; + CCPoint m_ptPanelOffset; + CCPoint m_ptDestination; + std::string m_strDeletegate; + CCListViewDelegate* m_pDelegate; + CCLayer* m_layerPanel; + CCListView* m_pListViewParent; + int m_nSelectedRow; + int m_nCurrentRow; + bool m_bIsEnabled; + bool m_bIsOnTouch; +}; + +NS_CC_EXT_END + + +#endif // __CC_LIST_VIEW_H__ \ No newline at end of file diff --git a/cocos2dx/extensions/TextureWatcher/NdListViewCell.cpp b/cocos2dx/extensions/CCListView/CCListViewCell.cpp similarity index 57% rename from cocos2dx/extensions/TextureWatcher/NdListViewCell.cpp rename to cocos2dx/extensions/CCListView/CCListViewCell.cpp index 11b6f216ef..bda9aafa5c 100644 --- a/cocos2dx/extensions/TextureWatcher/NdListViewCell.cpp +++ b/cocos2dx/extensions/CCListView/CCListViewCell.cpp @@ -1,20 +1,20 @@ +#include "CCListView.h" +#include "CCListViewCell.h" +#include "cocos2d.h" -#include "NdListView.h" -#include "NdListViewCell.h" - +NS_CC_EXT_BEGIN const int TOUCHBEGIN = 1; const int TOUCHEND = 2; const int TOUCHMOVING = 3; const int TOUCHCANCELLED= 4; -namespace NdCxControl -{ + /****************************************** **************Public Functions************* *******************************************/ -NdListViewCell::NdListViewCell(void) - :m_nSeparatorStyle(NdListViewCellSeparatorStyleNone) +CCListViewCell::CCListViewCell(void) + :m_nSeparatorStyle(CCListViewCellSeparatorStyleNone) ,m_bIsSelected(false) { setIsTouchEnabled(true); @@ -22,27 +22,27 @@ NdListViewCell::NdListViewCell(void) m_separatorLineColor = ccc3(128, 128, 128); } -NdListViewCell::~NdListViewCell(void) +CCListViewCell::~CCListViewCell(void) { } -NdListViewCell *NdListViewCell::node(void) +CCListViewCell *CCListViewCell::node(void) { - NdListViewCell *pRet = new NdListViewCell(); + CCListViewCell *pRet = new CCListViewCell(); pRet->initWithColorWidthHeight(ccc4(255, 255, 255, 255), 0, 0); pRet->autorelease(); return pRet; } -void NdListViewCell::selected(void) +void CCListViewCell::selected(void) { m_bIsSelected = true; CCLayerColor::setColor(ccc3(m_selectionColor.r, m_selectionColor.g, m_selectionColor.b)); CCLayerColor::setOpacity(m_selectionColor.a); } -void NdListViewCell::unselected(void) +void CCListViewCell::unselected(void) { m_bIsSelected = false; CCLayerColor::setColor(ccc3(m_normalColor.r, m_normalColor.g, m_normalColor.b)); @@ -52,34 +52,34 @@ void NdListViewCell::unselected(void) /****************************************** **************Virturl Functions************ *******************************************/ -bool NdListViewCell::initWithColorWidthHeight(ccColor4B color, GLfloat width, GLfloat height) +bool CCListViewCell::initWithColorWidthHeight(ccColor4B color, GLfloat width, GLfloat height) { this->m_normalColor = color; - return CCLayerColor::initWithColorWidthHeight(color, width, height); + return CCLayerColor::initWithColor(color, width, height); } -void NdListViewCell::draw(void) +void CCListViewCell::draw(void) { CCLayerColor::draw(); CCSize size = this->getContentSize(); - NdListView *owner = this->getOwner(); - if (NdListViewCellSeparatorStyleSingleLine == m_nSeparatorStyle) + CCListView *owner = this->getOwner(); + if (CCListViewCellSeparatorStyleSingleLine == m_nSeparatorStyle) { glLineWidth(1.0f); - glColor4ub(m_separatorLineColor.r, m_separatorLineColor.g, m_separatorLineColor.b, 255); + ccDrawColor4B(m_separatorLineColor.r, m_separatorLineColor.g, m_separatorLineColor.b, 255); - if (NdListViewModeHorizontal == owner->getMode()) + if (CCListViewModeHorizontal == owner->getMode()) { ccDrawLine(CCPointMake(size.width, 0), CCPointMake(size.width, size.height)); } - else if (NdListViewModeVertical == owner->getMode()) + else if (CCListViewModeVertical == owner->getMode()) { ccDrawLine(CCPointMake(0, 0), CCPointMake(size.width, 0)); } } } -void NdListViewCell::setColor(ccColor3B var) +void CCListViewCell::setColor(ccColor3B var) { m_normalColor.r = var.r; m_normalColor.g = var.g; @@ -87,10 +87,10 @@ void NdListViewCell::setColor(ccColor3B var) CCLayerColor::setColor(var); } -void NdListViewCell::setOpacity(GLubyte var) +void CCListViewCell::setOpacity(GLubyte var) { m_normalColor.a = var; CCLayerColor::setOpacity(var); } -} // end of namespace NdCxControl \ No newline at end of file +NS_CC_EXT_END \ No newline at end of file diff --git a/cocos2dx/extensions/TextureWatcher/NdListViewCell.h b/cocos2dx/extensions/CCListView/CCListViewCell.h similarity index 50% rename from cocos2dx/extensions/TextureWatcher/NdListViewCell.h rename to cocos2dx/extensions/CCListView/CCListViewCell.h index 74fa59c569..713cf91f83 100644 --- a/cocos2dx/extensions/TextureWatcher/NdListViewCell.h +++ b/cocos2dx/extensions/CCListView/CCListViewCell.h @@ -1,36 +1,31 @@ -#ifndef __ND_LIST_VIEW_CELL_H_ -#define __ND_LIST_VIEW_CELL_H_ +#ifndef __CC_LIST_VIEW_CELL_H_ +#define __CC_LIST_VIEW_CELL_H_ -#include "ControlDefine.h" -#include "cocos2d.h" -#include -#include -using namespace cocos2d; +#include "CCControlDefine.h" +#include "CCLayer.h" -namespace NdCxControl { +NS_CC_EXT_BEGIN -#define LUA_DLL CC_DLL - -class NdListView; +class CCListView; typedef enum { - NdListViewCellSeparatorStyleNone, - NdListViewCellSeparatorStyleSingleLine, -}NdListViewCellSeparatorStyle; + CCListViewCellSeparatorStyleNone, + CCListViewCellSeparatorStyleSingleLine, +}CCListViewCellSeparatorStyle; -class LUA_DLL NdListViewCell : public CCLayerColor +class CC_DLL CCListViewCell : public CCLayerColor { public: - NdListViewCell(void); - virtual ~NdListViewCell(void); + CCListViewCell(void); + virtual ~CCListViewCell(void); - static NdListViewCell *node(void); + static CCListViewCell *node(void); void selected(void); void unselected(void); - inline NdListViewCellSeparatorStyle getSeparatorStyle(void) { return m_nSeparatorStyle; } - inline void setSeparatorStyle(NdListViewCellSeparatorStyle style) { m_nSeparatorStyle = style; } + inline CCListViewCellSeparatorStyle getSeparatorStyle(void) { return m_nSeparatorStyle; } + inline void setSeparatorStyle(CCListViewCellSeparatorStyle style) { m_nSeparatorStyle = style; } inline ccColor4B getSelectionColor(void) { return m_selectionColor; } inline void setSelectionColor(ccColor4B color) { m_selectionColor = color; } @@ -45,16 +40,16 @@ class LUA_DLL NdListViewCell : public CCLayerColor virtual void setOpacity(GLubyte var); private: - inline NdListView *getOwner(void) { return (NdListView*)(this->getParent()->getParent()); } + inline CCListView *getOwner(void) { return (CCListView*)(this->getParent()->getParent()); } private: - NdListViewCellSeparatorStyle m_nSeparatorStyle; + CCListViewCellSeparatorStyle m_nSeparatorStyle; bool m_bIsSelected; ccColor4B m_selectionColor; ccColor4B m_normalColor; ccColor3B m_separatorLineColor; }; -} // end of NdCxControl +NS_CC_EXT_END -#endif // __ND_LIST_VIEW_CELL_H_ \ No newline at end of file +#endif // __CC_LIST_VIEW_CELL_H_ \ No newline at end of file diff --git a/cocos2dx/extensions/CCNotificationCenter/CCNotificationCenter.cpp b/cocos2dx/extensions/CCNotificationCenter/CCNotificationCenter.cpp index 3595343eca..9521a03943 100644 --- a/cocos2dx/extensions/CCNotificationCenter/CCNotificationCenter.cpp +++ b/cocos2dx/extensions/CCNotificationCenter/CCNotificationCenter.cpp @@ -28,7 +28,7 @@ THE SOFTWARE. using namespace std; -NS_CC_BEGIN +NS_CC_EXT_BEGIN static CCNotificationCenter *s_sharedNotifCenter = NULL; @@ -185,4 +185,4 @@ CCObject *CCNotificationObserver::getObject() return m_object; } -NS_CC_END +NS_CC_EXT_END diff --git a/cocos2dx/extensions/CCNotificationCenter/CCNotificationCenter.h b/cocos2dx/extensions/CCNotificationCenter/CCNotificationCenter.h index 5c9820dc64..24965cab6f 100644 --- a/cocos2dx/extensions/CCNotificationCenter/CCNotificationCenter.h +++ b/cocos2dx/extensions/CCNotificationCenter/CCNotificationCenter.h @@ -27,9 +27,10 @@ THE SOFTWARE. #include "CCObject.h" -NS_CC_BEGIN -class CCArray; +namespace cocos2d { class CCArray; } + +NS_CC_EXT_BEGIN class CC_DLL CCNotificationCenter : public CCObject { @@ -59,7 +60,7 @@ private: // // variables // - CCArray *m_observers; + cocos2d::CCArray *m_observers; }; class CC_DLL CCNotificationObserver : public CCObject @@ -79,6 +80,6 @@ private: CC_PROPERTY_READONLY(CCObject *, m_object, Object); }; -NS_CC_END +NS_CC_EXT_END #endif//__CCNOTIFICATIONCENTER_H__ \ No newline at end of file diff --git a/cocos2dx/extensions/TextureWatcher/NdTextureWatcher.cpp b/cocos2dx/extensions/CCTextureWatcher/CCTextureWatcher.cpp similarity index 56% rename from cocos2dx/extensions/TextureWatcher/NdTextureWatcher.cpp rename to cocos2dx/extensions/CCTextureWatcher/CCTextureWatcher.cpp index 4f4367008e..7c88ef71a3 100644 --- a/cocos2dx/extensions/TextureWatcher/NdTextureWatcher.cpp +++ b/cocos2dx/extensions/CCTextureWatcher/CCTextureWatcher.cpp @@ -1,11 +1,13 @@ -#include "NdTextureWatcher.h" -#include "CCTextureCache.h" -#include "CCLayer.h" -#include "CCSprite.h" -#include "NdCxList.h" -namespace NdCxControl { +#include "CCTextureWatcher.h" +#include "cocos2d.h" + +using namespace std; + +NS_CC_EXT_BEGIN + #define NUM_PER_PAGE 4 -NdTextureWatcher::NdTextureWatcher() + +CCTextureWatcher::CCTextureWatcher() { m_bHide = false; m_nCurrnetPage = 1; @@ -25,34 +27,34 @@ NdTextureWatcher::NdTextureWatcher() //* CCLabelTTF *label = CCLabelTTF::labelWithString(" ", size, CCTextAlignmentLeft, "Arial", 12); CCMenuItemLabel *menuItem = CCMenuItemLabel::itemWithLabel(label); - menuItem->setAnchorPoint(ccp(0, 0)); - menuItem->setPosition(ccp(0, 0)); + menuItem->setAnchorPoint(CCPoint(0, 0)); + menuItem->setPosition(CCPoint(0, 0)); CCMenu *menu = CCMenu::menuWithItem(menuItem); - menu->setAnchorPoint(ccp(0, 0)); - menu->setPosition(ccp(0, 0)); + menu->setAnchorPoint(CCPoint(0, 0)); + menu->setPosition(CCPoint(0, 0)); m_pLayer->addChild(menu); //*/ // list - NdCxList *list = NdCxList::node(size.width, ccc4(0, 0, 0, 0), size); - list->setHorizontal(true); - list->setRecodeNumPerPage(1); - list->setPageTurnEffect(true); - list->registerLoaderListern((CNdListLoaderListener*)this); - m_pLayer->addChild(list, 0, 0); + CCListView *list = CCListView::viewWithMode(CCListViewModeHorizontal); + list->setContentSize(size); + list->setDelegate(this); + list->setSeparatorStyle(CCListViewCellSeparatorStyleNone); + m_pLayer->addChild(list); m_pList = list; + // 隐藏按钮 CCLabelTTF *labelHide = CCLabelTTF::labelWithString("Hide ", "Arial", 24); labelHide->setColor(ccc3(255, 0, 0)); - CCMenuItemLabel *menuItem2 = CCMenuItemLabel::itemWithLabel(labelHide, this, menu_selector(NdTextureWatcher::actionHide)); - menuItem2->setAnchorPoint(ccp(0, 0)); - menuItem2->setPosition(ccp(0, 0)); + CCMenuItemLabel *menuItem2 = CCMenuItemLabel::itemWithLabel(labelHide, this, menu_selector(CCTextureWatcher::actionHide)); + menuItem2->setAnchorPoint(CCPoint(0, 0)); + menuItem2->setPosition(CCPoint(0, 0)); CCMenu *menu2 = CCMenu::menuWithItem(menuItem2); - menu2->setAnchorPoint(ccp(0, 0)); - menu2->setPosition(ccp(size.width - menuItem2->getContentSize().width, 0)); + menu2->setAnchorPoint(CCPoint(0, 0)); + menu2->setPosition(CCPoint(size.width - menuItem2->getContentSize().width, 0)); m_labelHide = labelHide; m_menuHide = menu2; @@ -61,221 +63,67 @@ NdTextureWatcher::NdTextureWatcher() // 更新按钮 CCLabelTTF *labelFresh = CCLabelTTF::labelWithString("Fresh", "Arial", 24); labelFresh->setColor(ccc3(255, 0, 0)); - CCMenuItemLabel *menuItem1 = CCMenuItemLabel::itemWithLabel(labelFresh, this, menu_selector(NdTextureWatcher::actionFresh)); - menuItem1->setAnchorPoint(ccp(0, 0)); - menuItem1->setPosition(ccp(0, 0)); + CCMenuItemLabel *menuItem1 = CCMenuItemLabel::itemWithLabel(labelFresh, this, menu_selector(CCTextureWatcher::actionFresh)); + menuItem1->setAnchorPoint(CCPoint(0, 0)); + menuItem1->setPosition(CCPoint(0, 0)); CCMenu *menu1 = CCMenu::menuWithItem(menuItem1); - menu1->setAnchorPoint(ccp(0, 0)); - menu1->setPosition(ccp(size.width - menuItem1->getContentSize().width - menuItem2->getContentSize().width * 1.5, 0)); + menu1->setAnchorPoint(CCPoint(0, 0)); + menu1->setPosition(CCPoint(size.width - menuItem1->getContentSize().width - menuItem2->getContentSize().width * 1.5, 0)); m_pLayer->addChild(menu1); // label page m_labelPage = CCLabelTTF::labelWithString(" ", CCSizeMake(size.width * 0.1, labelFresh->getContentSize().height), CCTextAlignmentCenter, "Arial", 16); - m_labelPage->setAnchorPoint(ccp(0.5, 0)); - m_labelPage->setPosition(ccp(size.width/2.0, 0)); + m_labelPage->setAnchorPoint(CCPoint(0.5, 0)); + m_labelPage->setPosition(CCPoint(size.width/2.0, 0)); m_pLayer->addChild(m_labelPage, 0); } -NdTextureWatcher::~NdTextureWatcher() +CCTextureWatcher::~CCTextureWatcher() { - if (m_menuHide) m_menuHide->release(); - if (m_pTextures) m_pTextures->release(); + if (m_menuHide) + { + m_menuHide->removeFromParentAndCleanup(true); + m_menuHide->release(); + } + + if (m_pLayer) + { + m_pLayer->removeFromParentAndCleanup(true); + } + + if (m_pTextures) m_pTextures->release(); if (m_pszString) delete []m_pszString; } -void NdTextureWatcher::actionFresh(CCObject* object) +void CCTextureWatcher::actionFresh(CCObject* object) { - NdTextureWatcher::sharedTextureWatcher()->fresh(); + CCTextureWatcher::sharedTextureWatcher()->fresh(); } -void NdTextureWatcher::actionHide(CCObject *object) +void CCTextureWatcher::actionHide(CCObject *object) { - NdTextureWatcher::sharedTextureWatcher()->hide(); + CCTextureWatcher::sharedTextureWatcher()->hide(); } -void NdTextureWatcher::fresh() +void CCTextureWatcher::fresh() { m_nCurrnetPage = 1; m_bFresh = true; } -void NdTextureWatcher::hide() +void CCTextureWatcher::hide() { m_bHide = !m_bHide; if (m_bHide) { m_labelHide->setString("Show"); - m_pLayer->setPosition(ccp(0, -m_pLayer->getContentSize().height)); + m_pLayer->setPosition(CCPoint(0, -m_pLayer->getContentSize().height)); } else { m_labelHide->setString("Hide"); - m_pLayer->setPosition(ccp(0, 0)); + m_pLayer->setPosition(CCPoint(0, 0)); } } -void NdTextureWatcher::showTexture() -{ - m_pList->clear(); - if (m_nTotalPage == 0) return; - CCTexture2D* textrue; - std::vector keys = m_pTextures->allKeys(); - std::vector::iterator it; - CCSize listItemSize = CCSize(m_pList->getContentSize().width / NUM_PER_PAGE, m_pList->getContentSize().height); - - CCSize size = CCSize(listItemSize.width * 0.9, listItemSize.height * 0.6); - - LayoutParam layout = CxLayout(); - layout.val_x.t = ABS_WITH_PIXEL; - layout.val_y.t = ABS_WITH_PIXEL; - layout.wrap = false; - - int num, index; - if (m_nTotalPage <= 1) - { - num = 1; - index = 1; - } - else - { - if (m_nCurrnetPage == 1) - { - num = 2; - index = 1; - } - else if (m_nCurrnetPage == m_nTotalPage) - { - num = 2; - index = 2; - } - else - { - num = 3; - index = 2; - } - } - - sprintf(m_pszString, "%d/%d", m_nCurrnetPage, m_nTotalPage); - m_labelPage->setString(m_pszString); - - CCLayer *layer; - for (int i = 1; i <= num; i++) - { - NdCxListItem *listItem = NdCxListItem::itemWithColor(ccc3(124, 124, 124)); - listItem->setOpacity(0); - listItem->setDrawTopLine(false); - listItem->setDrawBottomLine(false); - - CCLayer *layer1 = CCLayer::node(); - layer1->setContentSize(m_pList->getContentSize()); - layout.val_x.val.pixel_val = 0; - layout.val_y.val.pixel_val = 0; - listItem->addChildItem(layer1, layout); - - if (i == index) - { - layer = layer1; - m_pList->addListItem(listItem, true); - } - else - { - m_pList->addListItem(listItem, false); - } - } - - m_pList->disableAllCtrlEvent(); - m_pList->turnToPage(index - 1); - - - float offX = 0, offY = 0, offsetX = 0, offsetY = 0; - CC_UNUSED_PARAM(offsetY); - int nCount = 0; - int nStart = (m_nCurrnetPage - 1) * NUM_PER_PAGE; - int nEnd = nStart + NUM_PER_PAGE; - - for (it = keys.begin(); it != keys.end(); ++it) - { - if (nCount >= nStart && nCount < nEnd) - { - string key = *it; - textrue = CCTextureCache::sharedTextureCache()->textureForKey(key.c_str()); - //textrue = m_pTextures->objectForKey(*it); - if (textrue) - { - // 引用数 - sprintf(m_pszString, "[%d]", textrue->retainCount() - 2); - CCLabelTTF *labelCount = CCLabelTTF::labelWithString(m_pszString, "Arial", 16); - if (textrue->retainCount() - 2 > 0) - { - labelCount->setColor(ccc3(0, 255, 0)); - } - else - { - labelCount->setColor(ccc3(255, 0, 0)); - } - offX = offsetX + listItemSize.width * 0.5 - labelCount->getContentSize().width * 0.5; - offY = (listItemSize.height - size.height) * 0.5 - labelCount->getContentSize().height; - labelCount->setPosition(ccp(offX, offY)); - labelCount->setAnchorPoint(ccp(0, 0)); - layer->addChild(labelCount); - - // 大小 - sprintf(m_pszString, "%.0f*%.0f", textrue->getContentSize().width, textrue->getContentSize().height); - CCLabelTTF *labelSize = CCLabelTTF::labelWithString(m_pszString, "Arial", 16); - offX = offsetX + listItemSize.width * 0.5; - offY = (listItemSize.height - size.height) * 0.5 + size.height; - labelSize->setPosition(ccp(offX, offY)); - labelSize->setAnchorPoint(ccp(0.5, 0)); - layer->addChild(labelSize); - - // 名称 - int len = key.length(); - int pos = 0; -#if defined(ND_MAC) || defined(ND_IPHONE) - pos = key.rfind('/') + 1; -#else - pos = key.rfind('\\') + 1; - int pos2 = key.rfind('/') + 1; - pos = pos > pos2 ? pos : pos2; -#endif - string name = key.substr(pos, len - pos); - sprintf(m_pszString, "%s", name.c_str()); - CCSize dimensions = CCSizeMake(listItemSize.width * 0.9, labelSize->getContentSize().height); - CCLabelTTF *labelName = CCLabelTTF::labelWithString(m_pszString, dimensions, CCTextAlignmentCenter, "Arial", 16); - offX = offsetX + listItemSize.width * 0.5; - offY = offY + labelName->getContentSize().height; - labelName->setPosition(ccp(offX, offY)); - labelName->setAnchorPoint(ccp(0.5, 0)); - layer->addChild(labelName); - - CCSprite *sprite = CCSprite::spriteWithTexture(textrue); - sprite->setAnchorPoint(ccp(0, 0)); - - CCSize spriteSize = sprite->getContentSize(); - float scale; - if (spriteSize.width < size.width && spriteSize.height < size.height) - { - scale = 1; - } - else if (spriteSize.width * size.height >= spriteSize.height * size.width) - { - scale = size.width / spriteSize.width; - } - else - { - scale = size.height / spriteSize.height; - } - sprite->setScale(scale); - spriteSize.width *= scale; - spriteSize.height *= scale; - offX = offsetX + (listItemSize.width - spriteSize.width) * 0.5; - offY = (listItemSize.height - spriteSize.height) * 0.5; - sprite->setPosition(ccp(offX, offY)); - layer->addChild(sprite); - offsetX += listItemSize.width; - } - } - ++nCount; - } -} -void NdTextureWatcher::dovisit() +void CCTextureWatcher::dovisit() { if (m_bFresh) { @@ -284,17 +132,14 @@ void NdTextureWatcher::dovisit() m_pTextures->removeAllObjects(); m_pTextures->release(); } - if (m_pList) - { - m_pList->clear(); - } + CCTextureCache::sharedTextureCache()->removeUnusedTextures(); m_pTextures = CCTextureCache::sharedTextureCache()->snapshotTextures(); m_nTotalPage = (m_pTextures->count() + NUM_PER_PAGE - 1) / NUM_PER_PAGE; if (m_pTextures->count() > 0) { m_bFresh = false; - showTexture(); + m_pList->reload(); } } CCNode *pParent = m_pLayer->getParent(); @@ -326,22 +171,33 @@ void NdTextureWatcher::dovisit() CCDirector::sharedDirector()->getRunningScene()->addChild(m_menuHide, 9999); } } -void NdTextureWatcher::visit(void* pSender) +void CCTextureWatcher::visit(void* pSender) { - NdTextureWatcher *wartcher = (NdTextureWatcher*)pSender; + CCTextureWatcher *wartcher = (CCTextureWatcher*)pSender; wartcher->dovisit(); } -static NdTextureWatcher *g_sharedTextureWatcher; -NdTextureWatcher * NdTextureWatcher::sharedTextureWatcher() +static CCTextureWatcher *g_sharedTextureWatcher = NULL; + +CCTextureWatcher* CCTextureWatcher::sharedTextureWatcher() { if (!g_sharedTextureWatcher) - g_sharedTextureWatcher = new NdTextureWatcher(); + { + g_sharedTextureWatcher = new CCTextureWatcher(); + } return g_sharedTextureWatcher; } -void NdTextureWatcher::setDisplayWatcher(bool bDisplayWatcher) +void CCTextureWatcher::purgeTextureWatcher() +{ + if (g_sharedTextureWatcher != NULL) + { + CC_SAFE_RELEASE_NULL(g_sharedTextureWatcher); + } +} + +void CCTextureWatcher::setDisplayWatcher(bool bDisplayWatcher) { m_bDisplayWatcher = bDisplayWatcher; if (m_bDisplayWatcher) @@ -350,47 +206,137 @@ void NdTextureWatcher::setDisplayWatcher(bool bDisplayWatcher) { m_pszString = new char[64]; } - CCDirector::sharedDirector()->setWatcherCallbackFun(this, &NdTextureWatcher::visit); + CCDirector::sharedDirector()->setWatcherCallbackFun(this, &CCTextureWatcher::visit); } else { CCDirector::sharedDirector()->setWatcherCallbackFun(NULL, NULL); + purgeTextureWatcher(); } } -void NdTextureWatcher::OnLoadItem(int nCurPage) +void CCTextureWatcher::CCListView_numberOfCells(CCListView *listView, CCListViewProtrolData *data) +{ + data->nNumberOfRows = m_nTotalPage; +} + +void CCTextureWatcher::CCListView_cellForRow(CCListView *listView, CCListViewProtrolData *data) { - //CCLog("page:%d", nCurPage); - int nextPage, prePage; - if (m_nCurrnetPage == 1) - { - nextPage = 1; - prePage = -1; - } - else if (m_nCurrnetPage == m_nTotalPage) - { - nextPage = -1; - prePage = 0; - } - else - { - nextPage = 2; - prePage = 0; - } - if (nCurPage == prePage) - { - m_nCurrnetPage--; - showTexture(); - } - else if (nCurPage == nextPage) - { - m_nCurrnetPage++; - showTexture(); - } - -} -void NdTextureWatcher::OnUnLoadItem(int nCurPage) + m_nCurrnetPage = data->nRow + 1; + CCListViewCell *cell = CCListViewCell::node(); + cell->setOpacity(0); + cell->setContentSize(m_pList->getContentSize()); + cell->setSelectionColor(ccc4(0, 0, 0, 0)); + data->cell = cell; + + CCSize listItemSize = CCSize(m_pList->getContentSize().width / NUM_PER_PAGE, m_pList->getContentSize().height); + + CCSize size = CCSize(listItemSize.width * 0.9, listItemSize.height * 0.6); + + sprintf(m_pszString, "%d/%d", m_nCurrnetPage, m_nTotalPage); + m_labelPage->setString(m_pszString); + + float offX = 0, offY = 0, offsetX = 0, offsetY = 0; + CC_UNUSED_PARAM(offsetY); + int nCount = 0; + int nStart = (m_nCurrnetPage - 1) * NUM_PER_PAGE; + int nEnd = nStart + NUM_PER_PAGE; + + CCDictElement* pElement = NULL; + CCDICT_FOREACH(m_pTextures, pElement) + { + if (nCount >= nStart && nCount < nEnd) + { + string key = pElement->getStrKey(); + CCTexture2D* textrue = (CCTexture2D*)pElement->getObject(); + //textrue = m_pTextures->objectForKey(*it); + if (textrue) + { + // 引用数 + sprintf(m_pszString, "[%d]", textrue->retainCount() - 2); + CCLabelTTF *labelCount = CCLabelTTF::labelWithString(m_pszString, "Arial", 16); + if (textrue->retainCount() - 2 > 0) + { + labelCount->setColor(ccc3(0, 255, 0)); + } + else + { + labelCount->setColor(ccc3(255, 0, 0)); + } + offX = offsetX + listItemSize.width * 0.5 - labelCount->getContentSize().width * 0.5; + offY = (listItemSize.height - size.height) * 0.5 - labelCount->getContentSize().height; + labelCount->setPosition(CCPoint(offX, offY)); + labelCount->setAnchorPoint(CCPoint(0, 0)); + cell->addChild(labelCount); + + // 大小 + sprintf(m_pszString, "%.0f*%.0f", textrue->getContentSize().width, textrue->getContentSize().height); + CCLabelTTF *labelSize = CCLabelTTF::labelWithString(m_pszString, "Arial", 16); + offX = offsetX + listItemSize.width * 0.5; + offY = (listItemSize.height - size.height) * 0.5 + size.height; + labelSize->setPosition(CCPoint(offX, offY)); + labelSize->setAnchorPoint(CCPoint(0.5, 0)); + cell->addChild(labelSize); + + // 名称 + int len = key.length(); + int pos = 0; +#if defined(ND_MAC) || defined(ND_IPHONE) + pos = key.rfind('/') + 1; +#else + pos = key.rfind('\\') + 1; + int pos2 = key.rfind('/') + 1; + pos = pos > pos2 ? pos : pos2; +#endif + string name = key.substr(pos, len - pos); + sprintf(m_pszString, "%s", name.c_str()); + CCSize dimensions = CCSizeMake(listItemSize.width * 0.9, labelSize->getContentSize().height); + CCLabelTTF *labelName = CCLabelTTF::labelWithString(m_pszString, dimensions, CCTextAlignmentCenter, "Arial", 16); + offX = offsetX + listItemSize.width * 0.5; + offY = offY + labelName->getContentSize().height; + labelName->setPosition(CCPoint(offX, offY)); + labelName->setAnchorPoint(CCPoint(0.5, 0)); + cell->addChild(labelName); + + CCSprite *sprite = CCSprite::spriteWithTexture(textrue); + sprite->setAnchorPoint(CCPoint(0, 0)); + + CCSize spriteSize = sprite->getContentSize(); + float scale; + if (spriteSize.width < size.width && spriteSize.height < size.height) + { + scale = 1; + } + else if (spriteSize.width * size.height >= spriteSize.height * size.width) + { + scale = size.width / spriteSize.width; + } + else + { + scale = size.height / spriteSize.height; + } + sprite->setScale(scale); + spriteSize.width *= scale; + spriteSize.height *= scale; + offX = offsetX + (listItemSize.width - spriteSize.width) * 0.5; + offY = (listItemSize.height - spriteSize.height) * 0.5; + sprite->setPosition(CCPoint(offX, offY)); + cell->addChild(sprite); + offsetX += listItemSize.width; + } + } + ++nCount; + } +} + +void CCTextureWatcher::CCListView_didClickCellAtRow(CCListView *listView, CCListViewProtrolData *data) +{ + +} + +void CCTextureWatcher::CCListView_didScrollToRow(CCListView *listView, CCListViewProtrolData *data) { } -}// namespace \ No newline at end of file + +NS_CC_EXT_END diff --git a/cocos2dx/extensions/CCTextureWatcher/CCTextureWatcher.h b/cocos2dx/extensions/CCTextureWatcher/CCTextureWatcher.h new file mode 100644 index 0000000000..5fa7b5ecad --- /dev/null +++ b/cocos2dx/extensions/CCTextureWatcher/CCTextureWatcher.h @@ -0,0 +1,53 @@ +#ifndef __CCMEMLAYER_H__ +#define __CCMEMLAYER_H__ + +#include "extensions/CCListView/CCListView.h" + +namespace cocos2d { class CCDictionary; } +namespace cocos2d { class CCLabelTTF; } +namespace cocos2d { class CCMenu; } +namespace cocos2d { class CCLayerColor; } + + +NS_CC_EXT_BEGIN + +class CC_DLL CCTextureWatcher :public CCObject, public CCListViewDelegate +{ +private: + CCTextureWatcher(); +public: + virtual ~CCTextureWatcher(); + + static CCTextureWatcher* sharedTextureWatcher(); + static void purgeTextureWatcher(); + void setDisplayWatcher(bool bDisplayWatcher); + void fresh(void); +protected: + void actionFresh(CCObject* object); + void actionHide(CCObject* object); + void hide(void); + void dovisit(void); + static void visit(void* pSender); +protected: + virtual void CCListView_numberOfCells(CCListView *listView, CCListViewProtrolData *data); + virtual void CCListView_cellForRow(CCListView *listView, CCListViewProtrolData *data); + virtual void CCListView_didClickCellAtRow(CCListView *listView, CCListViewProtrolData *data); + virtual void CCListView_didScrollToRow(CCListView *listView, CCListViewProtrolData *data); +private: + bool m_bDisplayWatcher; + bool m_bFresh; + bool m_bHide; + CCDictionary *m_pTextures; + char *m_pszString; + int m_nCurrnetPage; + int m_nTotalPage; + CCLabelTTF *m_labelHide; + CCLabelTTF *m_labelPage; + CCMenu *m_menuHide; + CCLayerColor *m_pLayer; + CCListView *m_pList; +}; + +NS_CC_EXT_END + +#endif diff --git a/cocos2dx/extensions/TextureWatcher/NdListView.h b/cocos2dx/extensions/TextureWatcher/NdListView.h deleted file mode 100644 index 59a3cc07e9..0000000000 --- a/cocos2dx/extensions/TextureWatcher/NdListView.h +++ /dev/null @@ -1,154 +0,0 @@ -#ifndef __ND_LIST_VIEW_H__ -#define __ND_LIST_VIEW_H__ - -#include -#include "platform.h" -#include -#include "../cocos2dx_support/LuaEngine.h" -#include "NdListViewCell.h" - -using namespace cocos2d; -namespace NdCxControl -{ - typedef enum - { - NdListViewSlideDirNone, - NdListViewSlideDirUp, - NdListViewSlideDirDown, - NdListViewSlideDirLeft, - NdListViewSlideDirRight, - } NdListViewSlideDir; - - typedef enum - { - NdListViewStateWatting, - NdListViewStateTrackingTouch, - NdListViewStateEaseOut, - NdListViewStateFix, - NdListViewStateScroll, - } NdListViewState; - - typedef enum - { - NdListViewModeHorizontal, - NdListViewModeVertical, - } NdListViewMode; - - typedef struct _NdListViewProtrolData - { - unsigned int nNumberOfRows; - unsigned int nRow; - NdListViewCell *cell; - } NdListViewProtrolData; - - class NdListViewDelegate - { - public : - NdListViewDelegate(){}; - virtual ~NdListViewDelegate(){}; - - virtual void NdListView_numberOfCells(NdListView *listView, NdListViewProtrolData *data)=0; - virtual void NdListView_cellForRow(NdListView *listView, NdListViewProtrolData *data)=0; - virtual void NdListView_didClickCellAtRow(NdListView *listView, NdListViewProtrolData *data)=0; - virtual void NdListView_didScrollToRow(NdListView *listView, NdListViewProtrolData *data)=0; - }; - - - class LUA_DLL NdListView : public CCLayerColor - { - public: - virtual ~NdListView(void); - NdListView(void); - - static NdListView* viewWithMode(NdListViewMode mode); - bool initWithMode(NdListViewMode mode); - - void setDelegateName(const char* pszName); - void selectCellAtRow(unsigned int nRow); - void unselectCellAtRow(unsigned int nRow); - void scrollCellToFront(unsigned int nRow, bool bAnimated); - void scrollCellToBack(unsigned int nRow, bool bAnimated); - void reload(void); - void insertCellsAtRow(unsigned int nRow, unsigned int nCount); - void deleteCellsAtRow(unsigned int nRow, unsigned int nCount); - NdListViewCell *cellAtRow(unsigned int nRow); - - NdListViewSlideDir getSlideDir(CCPoint ptTouchBegan, CCPoint ptTouchEnd); - inline NdListViewSlideDir getSlideDir(void) { return m_nSlideDir; } - - inline NdListViewCellSeparatorStyle getSeparatorStyle(void) { return m_nSeparatorStyle; } - inline void setSeparatorStyle(NdListViewCellSeparatorStyle style) { m_nSeparatorStyle = style; } - inline NdListViewMode getMode(void) { return m_nMode; } - - inline void setListViewParent(NdListView *pParent) { m_pListViewParent = pParent; } - inline NdListView *getListViewParent(void) { return m_pListViewParent; } - - inline void setIsEnabled(bool bEnabled) { m_bIsEnabled = bEnabled; } - inline bool getIsEnabled(void) { return m_bIsEnabled; } - - // un - void setDelegate(const NdListViewDelegate *pDelegate); - void finishFix(void); - void finishScroll(void); - void finishEaseOut(void); - - public: - virtual bool ccTouchBegan(CCTouch* touch, CCEvent* event); - virtual void ccTouchEnded(CCTouch* touch, CCEvent* event); - virtual void ccTouchCancelled(CCTouch *touch, CCEvent* event); - virtual void ccTouchMoved(CCTouch* touch, CCEvent* event); - - virtual void onEnter(void); - virtual void onExit(void); - - virtual void registerWithTouchDispatcher(void); - virtual void visit(void); - - protected: - void displayVisibleRows(void); - NdListViewCell* appendRowToBack(unsigned int nRow); - NdListViewCell* appendRowToFront(unsigned int nRow); - void fixFirstRow(void); - void fixLastRow(void); - void easeOutWithDistance(float dis); - void clearUnvisibleRows(void); - - int rowForTouch(cocos2d::CCTouch *touch); - bool isTouchInside(CCTouch *touch); - bool isFullFill(void); - - void stopActionImmediately(void); - - unsigned int triggerNumberOfCells(void); - NdListViewCell *triggerCellForRow(unsigned int nRow); - void triggerDidClickCellAtRow(unsigned int nRow); - void triggerDidScrollToRow(unsigned int nRow); - bool isMenuTouch(CCTouch *touch, CCNode *parent); - - private: - NdListViewState m_nState; - NdListViewMode m_nMode; - NdListViewSlideDir m_nSlideDir; - NdListViewCellSeparatorStyle m_nSeparatorStyle; - unsigned int m_nNumberOfRows; - float m_fActionDuration; - clock_t m_timeTouchBegan; - CCRange m_drawedRows; //所有已绘制的cell - CCRange m_visibleRows; //所有可见的cell - CCPoint m_ptTouchBegan; - CCPoint m_ptTouchEnd; - CCPoint m_ptPanelOffset; - CCPoint m_ptDestination; - std::string m_strDeletegate; - NdListViewDelegate* m_pDelegate; - CCLayer* m_layerPanel; - NdListView* m_pListViewParent; - int m_nSelectedRow; - int m_nCurrentRow; - bool m_bIsEnabled; - bool m_bIsOnTouch; - }; -} // end of namespace NdCxControl - - -#endif // __ND_LIST_VIEW_H__ \ No newline at end of file diff --git a/cocos2dx/extensions/TextureWatcher/NdTextureWatcher.h b/cocos2dx/extensions/TextureWatcher/NdTextureWatcher.h deleted file mode 100644 index 29903145ed..0000000000 --- a/cocos2dx/extensions/TextureWatcher/NdTextureWatcher.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef __CCMEMLAYER_H__ -#define __CCMEMLAYER_H__ -#include "ControlDefine.h" -#include "cocos2d.h" -#include "NdListLoaderListener.h" - -using namespace cocos2d; -namespace NdCxControl { - class NdCxList; -class CC_DLL NdTextureWatcher :public CCObject, public CNdListLoaderListener -{ -private: - NdTextureWatcher(); -public: - virtual ~NdTextureWatcher(); - - static NdTextureWatcher *sharedTextureWatcher(); - - void setDisplayWatcher(bool bDisplayWatcher); - void fresh(void); -protected: - void actionFresh(CCObject* object); - void actionHide(CCObject* object); - void hide(void); - void dovisit(void); - static void visit(void* pSender); - void showTexture(); -protected: - virtual void OnLoadItem(int nCurPage); - virtual void OnUnLoadItem(int nCurPage); -private: - bool m_bDisplayWatcher; - bool m_bFresh; - bool m_bHide; - CCDictionary *m_pTextures; - char *m_pszString; - int m_nCurrnetPage; - int m_nTotalPage; - CCLabelTTF *m_labelHide; - CCLabelTTF *m_labelPage; - CCMenu *m_menuHide; - CCLayerColor *m_pLayer; - NdCxList *m_pList; -}; -}// namespace -#endif \ No newline at end of file diff --git a/cocos2dx/include/cocos2dExt.h b/cocos2dx/include/cocos2dExt.h index 7da39df66d..7b1b83725f 100644 --- a/cocos2dx/include/cocos2dExt.h +++ b/cocos2dx/include/cocos2dExt.h @@ -3,5 +3,7 @@ #include "extensions/CCNotificationCenter/CCNotificationCenter.h" #include "extensions/CCControlExtension/CCControlExtensions.h" +#include "extensions/CCListView/CCListView.h" +#include "extensions/CCTextureWatcher/CCTextureWatcher.h" #endif /* __COCOS2DEXT_H__ */ diff --git a/cocos2dx/particle_nodes/CCParticleSystemQuad.cpp b/cocos2dx/particle_nodes/CCParticleSystemQuad.cpp index cf6980a8b6..eaba6348f8 100644 --- a/cocos2dx/particle_nodes/CCParticleSystemQuad.cpp +++ b/cocos2dx/particle_nodes/CCParticleSystemQuad.cpp @@ -67,7 +67,7 @@ bool CCParticleSystemQuad::initWithTotalParticles(unsigned int numberOfParticles // Need to listen the event only when not use batchnode, because it will use VBO - CCNotificationCenter::sharedNotificationCenter()->addObserver(this, + extension::CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(CCParticleSystemQuad::listenBackToForeground), EVNET_COME_TO_FOREGROUND, NULL); @@ -99,7 +99,7 @@ CCParticleSystemQuad::~CCParticleSystemQuad() #endif } - CCNotificationCenter::sharedNotificationCenter()->removeObserver(this, EVNET_COME_TO_FOREGROUND); + extension::CCNotificationCenter::sharedNotificationCenter()->removeObserver(this, EVNET_COME_TO_FOREGROUND); } // implementation CCParticleSystemQuad diff --git a/cocos2dx/platform/CCPlatformMacros.h b/cocos2dx/platform/CCPlatformMacros.h index 2b8090d208..e3fda7014c 100644 --- a/cocos2dx/platform/CCPlatformMacros.h +++ b/cocos2dx/platform/CCPlatformMacros.h @@ -59,10 +59,16 @@ It's new in cocos2d-x since v0.99.5 #define NS_CC_BEGIN namespace cocos2d { #define NS_CC_END } #define USING_NS_CC using namespace cocos2d + #define NS_CC_EXT_BEGIN namespace cocos2d { namespace extension { + #define NS_CC_EXT_END }} + #define USING_NS_CC_EXT using namespace cocos2d::extension #else #define NS_CC_BEGIN #define NS_CC_END #define USING_NS_CC + #define NS_CC_EXT_BEGIN + #define NS_CC_EXT_END + #define USING_NS_CC_EXT #endif /** CC_PROPERTY_READONLY is used to declare a protected variable. diff --git a/cocos2dx/proj.win32/cocos2d-win32.vcproj b/cocos2dx/proj.win32/cocos2d-win32.vcproj index c9bbdbb7b2..f441c84c31 100644 --- a/cocos2dx/proj.win32/cocos2d-win32.vcproj +++ b/cocos2dx/proj.win32/cocos2d-win32.vcproj @@ -1196,30 +1196,38 @@ + + + + diff --git a/cocos2dx/textures/CCTextureAtlas.cpp b/cocos2dx/textures/CCTextureAtlas.cpp index 3fa61e1bdf..f4fa712e2c 100644 --- a/cocos2dx/textures/CCTextureAtlas.cpp +++ b/cocos2dx/textures/CCTextureAtlas.cpp @@ -64,7 +64,7 @@ CCTextureAtlas::~CCTextureAtlas() #endif CC_SAFE_RELEASE(m_pTexture); - CCNotificationCenter::sharedNotificationCenter()->removeObserver(this, EVNET_COME_TO_FOREGROUND); + extension::CCNotificationCenter::sharedNotificationCenter()->removeObserver(this, EVNET_COME_TO_FOREGROUND); } unsigned int CCTextureAtlas::getTotalQuads() @@ -177,7 +177,7 @@ bool CCTextureAtlas::initWithTexture(CCTexture2D *texture, unsigned int capacity memset( m_pIndices, 0, m_uCapacity * 6 * sizeof(GLushort) ); // listen the event when app go to background - CCNotificationCenter::sharedNotificationCenter()->addObserver(this, + extension::CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(CCTextureAtlas::listenBackToForeground), EVNET_COME_TO_FOREGROUND, NULL); diff --git a/cocos2dx/textures/CCTextureCache.cpp b/cocos2dx/textures/CCTextureCache.cpp index 6b8b34b287..7c809fa7dc 100644 --- a/cocos2dx/textures/CCTextureCache.cpp +++ b/cocos2dx/textures/CCTextureCache.cpp @@ -194,6 +194,17 @@ const char* CCTextureCache::description() return CCString::stringWithFormat("", m_pTextures->count())->getCString(); } +CCDictionary* CCTextureCache::snapshotTextures() +{ + CCDictionary* pRet = new CCDictionary(); + CCDictElement* pElement = NULL; + CCDICT_FOREACH(m_pTextures, pElement) + { + pRet->setObject(pElement->getObject(), pElement->getStrKey()); + } + return pRet; +} + void CCTextureCache::addImageAsync(const char *path, CCObject *target, SEL_CallFuncO selector) { CCAssert(path != NULL, "TextureCache: fileimage MUST not be NULL"); diff --git a/cocos2dx/textures/CCTextureCache.h b/cocos2dx/textures/CCTextureCache.h index 06659175b1..1ed542a5ed 100644 --- a/cocos2dx/textures/CCTextureCache.h +++ b/cocos2dx/textures/CCTextureCache.h @@ -65,6 +65,8 @@ public: const char* description(void); + CCDictionary* snapshotTextures(); + /** Retruns ths shared instance of the cache */ static CCTextureCache * sharedTextureCache(); diff --git a/tests/tests/ExtensionsTest/ControlExtensionTest/CCControlScene.h b/tests/tests/ExtensionsTest/ControlExtensionTest/CCControlScene.h index e58a543eaf..c2d99c5da1 100644 --- a/tests/tests/ExtensionsTest/ControlExtensionTest/CCControlScene.h +++ b/tests/tests/ExtensionsTest/ControlExtensionTest/CCControlScene.h @@ -30,7 +30,7 @@ #include "cocos2dExt.h" USING_NS_CC; - +USING_NS_CC_EXT; #define CONTROL_SCENE_NODE_FUNC(controlScene) \ public: \ diff --git a/tests/tests/ExtensionsTest/ExtensionsTest.cpp b/tests/tests/ExtensionsTest/ExtensionsTest.cpp index 0f29d63f65..cd3b34b7c2 100644 --- a/tests/tests/ExtensionsTest/ExtensionsTest.cpp +++ b/tests/tests/ExtensionsTest/ExtensionsTest.cpp @@ -5,7 +5,7 @@ enum { - MAX_COUNT = 2, + MAX_COUNT = 3, LINE_SPACE = 40, kItemTagBasic = 1000, }; @@ -13,7 +13,8 @@ enum static const std::string testsName[MAX_COUNT] = { "NotificationCenterTest", - "CCControlButtonTest" + "CCControlButtonTest", + "TextureWatcherTest" }; //////////////////////////////////////////////////////// @@ -59,6 +60,13 @@ void ExtensionsMainLayer::menuCallback(CCObject* pSender) CCDirector::sharedDirector()->replaceScene(pScene); } break; + case 2: + { + static bool s_bOpened = false; + s_bOpened = !s_bOpened; + CCTextureWatcher::sharedTextureWatcher()->setDisplayWatcher(s_bOpened); + } + break; default: break; } diff --git a/tests/tests/SchedulerTest/SchedulerTest.h b/tests/tests/SchedulerTest/SchedulerTest.h index fc9fd4d060..514105328f 100644 --- a/tests/tests/SchedulerTest/SchedulerTest.h +++ b/tests/tests/SchedulerTest/SchedulerTest.h @@ -3,7 +3,6 @@ #include "cocos2d.h" #include "../testBasic.h" -//#import "cocos2d.h" class SchedulerTestLayer : public CCLayer diff --git a/tests/tests/controller.cpp b/tests/tests/controller.cpp index 1c2515600a..84904394db 100644 --- a/tests/tests/controller.cpp +++ b/tests/tests/controller.cpp @@ -166,6 +166,7 @@ TestController::TestController() setIsTouchEnabled(true); addChild(pMenu, 1); + } TestController::~TestController() diff --git a/tests/tests/testBasic.h b/tests/tests/testBasic.h index 38c7712cc4..eedb63437d 100644 --- a/tests/tests/testBasic.h +++ b/tests/tests/testBasic.h @@ -3,7 +3,8 @@ #include "cocos2d.h" -using namespace cocos2d; +USING_NS_CC; +USING_NS_CC_EXT; using namespace std; class TestScene : public CCScene From 2addd06f212037dceccee8c5c7e504f30a36d4dc Mon Sep 17 00:00:00 2001 From: Walzer Date: Wed, 2 May 2012 10:39:17 +0800 Subject: [PATCH 03/14] fixed #1203, remove CCFileUtils::setResource & SimpleAudioEngine::setResource, these 2 methods were created for wophone. --- CocosDenshion/android/SimpleAudioEngine.cpp | 5 ----- CocosDenshion/bada/SimpleAudioEngine.cpp | 5 ----- CocosDenshion/include/SimpleAudioEngine.h | 6 ------ CocosDenshion/ios/SimpleAudioEngine.mm | 5 ----- CocosDenshion/linux/SimpleAudioEngine.cpp | 3 --- CocosDenshion/marmalade/SimpleAudioEngine.cpp | 5 ----- CocosDenshion/qnx/SimpleAudioEngine.cpp | 4 ---- CocosDenshion/win32/SimpleAudioEngine.cpp | 4 ---- cocos2dx/platform/CCFileUtils.h | 9 --------- cocos2dx/platform/android/CCFileUtils.cpp | 5 ----- cocos2dx/platform/ios/CCFileUtils.mm | 4 ---- cocos2dx/platform/win32/CCFileUtils.cpp | 6 ------ 12 files changed, 61 deletions(-) diff --git a/CocosDenshion/android/SimpleAudioEngine.cpp b/CocosDenshion/android/SimpleAudioEngine.cpp index 6208ed6668..ebcac6cf09 100644 --- a/CocosDenshion/android/SimpleAudioEngine.cpp +++ b/CocosDenshion/android/SimpleAudioEngine.cpp @@ -54,11 +54,6 @@ void SimpleAudioEngine::end() endJNI(); } -void SimpleAudioEngine::setResource(const char* pszZipFileName) -{ - -} - void SimpleAudioEngine::preloadBackgroundMusic(const char* pszFilePath) { preloadBackgroundMusicJNI(pszFilePath); diff --git a/CocosDenshion/bada/SimpleAudioEngine.cpp b/CocosDenshion/bada/SimpleAudioEngine.cpp index 217bbee8c3..df50b54746 100644 --- a/CocosDenshion/bada/SimpleAudioEngine.cpp +++ b/CocosDenshion/bada/SimpleAudioEngine.cpp @@ -295,11 +295,6 @@ void SimpleAudioEngine::end() } } -void SimpleAudioEngine::setResource(const char* pszZipFileName) -{ - -} - void SimpleAudioEngine::preloadBackgroundMusic(const char* pszFilePath) { openMediaPlayer(s_pBackPlayer, pszFilePath); diff --git a/CocosDenshion/include/SimpleAudioEngine.h b/CocosDenshion/include/SimpleAudioEngine.h index 3e87118e7b..5e510b7492 100644 --- a/CocosDenshion/include/SimpleAudioEngine.h +++ b/CocosDenshion/include/SimpleAudioEngine.h @@ -52,12 +52,6 @@ public: */ static void end(); - /** - @brief Set the zip file name - @param pszZipFileName The relative path of the .zip file - */ - static void setResource(const char* pszZipFileName); - /** @brief Preload background music @param pszFilePath The path of the background music file,or the FileName of T_SoundResInfo diff --git a/CocosDenshion/ios/SimpleAudioEngine.mm b/CocosDenshion/ios/SimpleAudioEngine.mm index 11e5ee0e49..175b97f122 100644 --- a/CocosDenshion/ios/SimpleAudioEngine.mm +++ b/CocosDenshion/ios/SimpleAudioEngine.mm @@ -172,11 +172,6 @@ void SimpleAudioEngine::end() static_end(); } -void SimpleAudioEngine::setResource(const char* pszZipFileName) -{ - -} - void SimpleAudioEngine::preloadBackgroundMusic(const char* pszFilePath) { static_preloadBackgroundMusic(pszFilePath); diff --git a/CocosDenshion/linux/SimpleAudioEngine.cpp b/CocosDenshion/linux/SimpleAudioEngine.cpp index f84f169a74..fd14c2a7ff 100644 --- a/CocosDenshion/linux/SimpleAudioEngine.cpp +++ b/CocosDenshion/linux/SimpleAudioEngine.cpp @@ -33,9 +33,6 @@ void SimpleAudioEngine::end() { // return; } -void SimpleAudioEngine::setResource(const char* pszZipFileName) { -} - ////////////////////////////////////////////////////////////////////////// // BackgroundMusic ////////////////////////////////////////////////////////////////////////// diff --git a/CocosDenshion/marmalade/SimpleAudioEngine.cpp b/CocosDenshion/marmalade/SimpleAudioEngine.cpp index 81d7eafa81..c51fdba554 100644 --- a/CocosDenshion/marmalade/SimpleAudioEngine.cpp +++ b/CocosDenshion/marmalade/SimpleAudioEngine.cpp @@ -95,11 +95,6 @@ namespace CocosDenshion } } - void SimpleAudioEngine::setResource(const char* pszZipFileName) - { - // todo - } - void SimpleAudioEngine::preloadBackgroundMusic(const char* pszFilePath) { s3eFile *fileHandle = s3eFileOpen(pszFilePath, "rb"); diff --git a/CocosDenshion/qnx/SimpleAudioEngine.cpp b/CocosDenshion/qnx/SimpleAudioEngine.cpp index dc5a9d210d..7ee64bfbfd 100644 --- a/CocosDenshion/qnx/SimpleAudioEngine.cpp +++ b/CocosDenshion/qnx/SimpleAudioEngine.cpp @@ -158,10 +158,6 @@ namespace CocosDenshion stopBackground(true); } - void SimpleAudioEngine::setResource(const char* pszZipFileName) - { - } - // // OGG support // diff --git a/CocosDenshion/win32/SimpleAudioEngine.cpp b/CocosDenshion/win32/SimpleAudioEngine.cpp index 120f16ffcc..cafe899d6a 100644 --- a/CocosDenshion/win32/SimpleAudioEngine.cpp +++ b/CocosDenshion/win32/SimpleAudioEngine.cpp @@ -62,10 +62,6 @@ void SimpleAudioEngine::end() return; } -void SimpleAudioEngine::setResource(const char* pszZipFileName) -{ -} - ////////////////////////////////////////////////////////////////////////// // BackgroundMusic ////////////////////////////////////////////////////////////////////////// diff --git a/cocos2dx/platform/CCFileUtils.h b/cocos2dx/platform/CCFileUtils.h index 3c3ef293b3..9d604088aa 100644 --- a/cocos2dx/platform/CCFileUtils.h +++ b/cocos2dx/platform/CCFileUtils.h @@ -157,15 +157,6 @@ public: static void setIsPopupNotify(bool bNotify); static bool getIsPopupNotify(); - /////////////////////////////////////////////////// - // interfaces on wophone - /////////////////////////////////////////////////// - /** - @brief Set the resource zip file name - @param pszZipFileName The relative path of the .zip file - */ - static void setResource(const char* pszZipFileName); - /////////////////////////////////////////////////// // interfaces on ios /////////////////////////////////////////////////// diff --git a/cocos2dx/platform/android/CCFileUtils.cpp b/cocos2dx/platform/android/CCFileUtils.cpp index 5c8f9747c2..4d2d437e9b 100644 --- a/cocos2dx/platform/android/CCFileUtils.cpp +++ b/cocos2dx/platform/android/CCFileUtils.cpp @@ -118,11 +118,6 @@ unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* psz return pData; } -void CCFileUtils::setResource(const char* pszZipFileName) -{ - CCAssert(0, "Have not implement!"); -} - int CCFileUtils::ccLoadFileIntoMemory(const char *filename, unsigned char **out) { CCAssert(0, "Have not implement!"); diff --git a/cocos2dx/platform/ios/CCFileUtils.mm b/cocos2dx/platform/ios/CCFileUtils.mm index 163c451816..a8d3a33962 100644 --- a/cocos2dx/platform/ios/CCFileUtils.mm +++ b/cocos2dx/platform/ios/CCFileUtils.mm @@ -475,10 +475,6 @@ unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* psz } return pBuffer; } -void CCFileUtils::setResource(const char* pszZipFileName) -{ - CCAssert(0, "Have not implement!"); -} // notification support when getFileData from a invalid file static bool s_bPopupNotify = true; diff --git a/cocos2dx/platform/win32/CCFileUtils.cpp b/cocos2dx/platform/win32/CCFileUtils.cpp index 7d582a701a..33a140424c 100644 --- a/cocos2dx/platform/win32/CCFileUtils.cpp +++ b/cocos2dx/platform/win32/CCFileUtils.cpp @@ -193,12 +193,6 @@ unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* psz return pBuffer; } -void CCFileUtils::setResource(const char* pszZipFileName) -{ - CC_UNUSED_PARAM(pszZipFileName); - CCAssert(0, "Have not implement!"); -} - string CCFileUtils::getWriteablePath() { // return the path that the exe file saved in From 63a8bbf0d953c020fa395b95d8429e26356836be Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 2 May 2012 10:39:39 +0800 Subject: [PATCH 04/14] issue #1194: Updated ios project configurations after adding CCTextureWatcher. --- .../proj.ios/HelloLua.xcodeproj/project.pbxproj.REMOVED.git-id | 2 +- .../HelloWorld.xcodeproj/project.pbxproj.REMOVED.git-id | 2 +- tests/proj.ios/test.xcodeproj/project.pbxproj.REMOVED.git-id | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/HelloLua/proj.ios/HelloLua.xcodeproj/project.pbxproj.REMOVED.git-id b/HelloLua/proj.ios/HelloLua.xcodeproj/project.pbxproj.REMOVED.git-id index 20a602eb43..1174ac380c 100644 --- a/HelloLua/proj.ios/HelloLua.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/HelloLua/proj.ios/HelloLua.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -9b310a8b553efc1db798797273bd0bfb1b11c857 \ No newline at end of file +3ffb5ef04b897f971e1e9c941002d06e5a91da50 \ No newline at end of file diff --git a/HelloWorld/proj.ios/HelloWorld.xcodeproj/project.pbxproj.REMOVED.git-id b/HelloWorld/proj.ios/HelloWorld.xcodeproj/project.pbxproj.REMOVED.git-id index de02f8069a..c5a97e0ad1 100644 --- a/HelloWorld/proj.ios/HelloWorld.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/HelloWorld/proj.ios/HelloWorld.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -918b8b44c7b180874afc0599a0e1b2b4e13f1e2a \ No newline at end of file +92dc1f3cb8db6691dae94a502b38db89e5293d2d \ No newline at end of file diff --git a/tests/proj.ios/test.xcodeproj/project.pbxproj.REMOVED.git-id b/tests/proj.ios/test.xcodeproj/project.pbxproj.REMOVED.git-id index 42e4bf174d..4c32f98122 100644 --- a/tests/proj.ios/test.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/tests/proj.ios/test.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -0ffd9a2963117b5a53222965ff2d95f8178971f2 \ No newline at end of file +d1a839f74c0ea5ee4cc2a177a02afb14a4897067 \ No newline at end of file From cb6a8e60dff20ecb4be5e42f60a017bcbe3aa3c0 Mon Sep 17 00:00:00 2001 From: Walzer Date: Wed, 2 May 2012 11:35:14 +0800 Subject: [PATCH 05/14] Add *.sdf into .gitignore, which would be generated by visual studio. Remove shell scripts for linux/bada/qnx at root folder. --- .gitignore | 1 + build-linux.sh | 76 ------------------------------ create-bada-project.vbs | 81 -------------------------------- create-linux-eclipse-project.sh | 9 ---- create-qnx-project.sh | 83 --------------------------------- create-qnx-project.vbs | 78 ------------------------------- 6 files changed, 1 insertion(+), 327 deletions(-) delete mode 100755 build-linux.sh delete mode 100644 create-bada-project.vbs delete mode 100755 create-linux-eclipse-project.sh delete mode 100755 create-qnx-project.sh delete mode 100644 create-qnx-project.vbs diff --git a/.gitignore b/.gitignore index 59978b5f0c..585d1ea6b7 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,7 @@ Thumbs.db [Bb]in [Dd]ebug*/ *.sbr +*.sdf obj/ [Rr]elease*/ _ReSharper*/ diff --git a/build-linux.sh b/build-linux.sh deleted file mode 100755 index b83d13341f..0000000000 --- a/build-linux.sh +++ /dev/null @@ -1,76 +0,0 @@ -#!/bin/sh -#p=$(dirname $_) -#echo "$p" - -#path=$(dirname $0) -#path=${path/\./$(pwd)} -#echo $path -p=. - -if [ ! -d "lib" ]; then -mkdir "lib" -fi - -if [ ! -d "lib/linux" ]; then -mkdir "lib/linux" -fi - -if [ ! -d "lib/linux/Debug" ]; then -mkdir "lib/linux/Debug" -fi - -if [ ! -d "lib/linux/Release" ]; then -mkdir "lib/linux/Release" -fi - -# copy cocosdenshino depended libs into lib/linux/Debug/ -cp CocosDenshion/third_party/linux/fmod/api/lib/*.so lib/linux/Debug - -if [ $# -ne 0 ]; then - if [ $1 = "clean" ]; then - cd $p/cocos2dx/proj.linux - make clean - - cd ../../ - cd $p/CocosDenshion/proj.linux - make clean - - cd ../.. - cd $p/Box2D/proj.linux - make clean - - cd ../.. - cd $p/chipmunk/proj.linux - make clean - - cd ../../ - rm -r lib/linux/Debug/*.so - fi - -else - cd $p/cocos2dx/proj.linux - echo "**********************building cocos2dx**************************" - make - cp -f libcocos2d.so ../../lib/linux/Debug - - echo "**********************building cocosdenshion*********************" - cd ../../ - cd $p/CocosDenshion/proj.linux - make - cp -f libcocosdenshion.so ../../lib/linux/Debug - - echo "**********************building Box2D******************************" - cd ../.. - cd $p/Box2D/proj.linux - make - cp -f libbox2d.a ../../lib/linux/Debug - - echo "**********************building chipmunk***************************" - cd ../.. - cd $p/chipmunk/proj.linux - make - cp -f libchipmunk.a ../../lib/linux/Debug - - cd ../../ -fi - diff --git a/create-bada-project.vbs b/create-bada-project.vbs deleted file mode 100644 index 96c8a4ffa6..0000000000 --- a/create-bada-project.vbs +++ /dev/null @@ -1,81 +0,0 @@ -set fso = Wscript.CreateObject("Scripting.FileSystemObject") - -dim szPrompt, msgRet -szPrompt = "Prompt" - -function ReplaceFileContent(fileName, oldStr, newStr) - set f = fso.opentextfile(fileName) - s = replace(f.readall, oldStr, newStr) - f.close - set r = fso.opentextfile(fileName, 2, true) - r.write s -end function - -function CopyFolder(srcFolder, desFolder) - if (fso.FolderExists(desFolder)) then - 'msgbox("none:"+srcFolder+":"+desFolder) - 'If the desFolder exist, do nothing. - else - CopyFolder = fso.CopyFolder(srcFolder, desFolder) - end if -end function - -function ConfigureProject() - dim szProjectName - szProjectName = Inputbox("Please Input Project Name:", szPrompt) - - if szProjectName = "" then - Wscript.quit - end if - - if (0 = strcomp(szProjectName, "HelloWorld", 1) or 0 = strcomp(szProjectName, "tests", 1)) then - msgRet = msgbox("Can not create a project named with "+szProjectName+", Please input again!", 1, szPrompt) - if (msgRet = 1) then - call ConfigureProject - end if - Wscript.quit - end if - - if (fso.FolderExists(szProjectName)) then - else - fso.CreateFolder(szProjectName) - end if - - dim badaFolder - badaFolder = szProjectName + "\bada" - if (fso.FolderExists(badaFolder)) then - msgRet = msgbox("The '"+szProjectName+"' project exists, can't override! Please input again!", 1, szPrompt) - if (msgRet = 1) then - call ConfigureProject - end if - Wcript.quit - end if - - dim szSrcClass, szSrcBada, szSrcResource - dim szDesClass, szDesBada, szDesResource - - szSrcClass = "HelloWorld\Classes" - szSrcBada = "HelloWorld\bada" - szSrcResource = "HelloWorld\Resources" - - szDesClass = szProjectName+"\Classes" - szDesBada = szProjectName+"\bada" - szDesResource = szProjectName+"\Resources" - - call CopyFolder(szSrcClass, szDesClass) - call CopyFolder(szSrcBada, szDesBada) - call CopyFolder(szSrcResource, szDesResource) - - dim i - for i=1 to 2 - call ReplaceFileContent(szProjectName+"\bada\sdk"+cstr(i)+".0\application.xml", "HelloWorld", szProjectName) - call ReplaceFileContent(szProjectName+"\bada\sdk"+cstr(i)+".0\.project", "HelloWorld", szProjectName) - call ReplaceFileContent(szProjectName+"\bada\sdk"+cstr(i)+".0\.cproject", "HelloWorld", szProjectName) - next - - call msgbox("Congratulations, the '"+szProjectName+"' project have been created successfully, please use Bada IDE to import the project!", 0, szPrompt) - -end function - -call ConfigureProject -Wscript.quit \ No newline at end of file diff --git a/create-linux-eclipse-project.sh b/create-linux-eclipse-project.sh deleted file mode 100755 index 876f3ba975..0000000000 --- a/create-linux-eclipse-project.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -# This script should be called by create-android-project.bat -# or should be runned in linux shell. It can not be runned under -# cygwin. -# Don't modify the script until you know what you do. - -# set environment paramters - -bash `pwd`/create-android-project.sh -linux $@ diff --git a/create-qnx-project.sh b/create-qnx-project.sh deleted file mode 100755 index c1117493f0..0000000000 --- a/create-qnx-project.sh +++ /dev/null @@ -1,83 +0,0 @@ -#!/bin/sh - -HELLOWORLD_ROOT=`pwd`/HelloWorld - -# make directory qnx and copy all files and directories into it -copy_qnx_folder(){ - if [ -d $PROJECT_DIR/qnx ]; then - echo "The '$PROJECT_NAME' project exists, can't override! Please input again!" - create_qnx_project - exit - fi - mkdir $PROJECT_DIR/qnx - echo $HELLOWORLD_ROOT - for file in `ls -a $HELLOWORLD_ROOT/qnx | grep -E '\.(project|cproject|xml|png|cpp)' ` - do - file=$HELLOWORLD_ROOT/qnx/$file - if [ -f $file ];then - #echo $file - cp $file $PROJECT_DIR/qnx - fi - done -} - -copy_cpp_h_from_helloworld(){ - if [ -d $PROJECT_DIR/Classes ]; then - echo "Classes folder exists, skip copying Classes folder!" - else - mkdir $PROJECT_DIR/Classes - for file in `ls $HELLOWORLD_ROOT/Classes/* | grep -E '.(cpp|h|mk)' ` - do - if [ -f $file ];then - #echo $file - cp $file $PROJECT_DIR/Classes - fi - done - fi -} - -# copy resources -copy_resouces(){ - if [ -d $PROJECT_DIR/Resources ]; then - echo "Resources folder exists, skip copying Resources folder!" - else - mkdir $PROJECT_DIR/Resources - - for file in $HELLOWORLD_ROOT/Resources/* - do - #echo $file - cp $file $PROJECT_DIR/Resources - done - fi -} - -# replace string -modify_file_content(){ - # here should use # instead of /, why?? - sed "s#HelloWorld#$PROJECT_NAME#" $PROJECT_DIR/qnx/$1 > $PROJECT_DIR/qnx/tmp.txt - rm $PROJECT_DIR/qnx/$1 - mv $PROJECT_DIR/qnx/tmp.txt $PROJECT_DIR/qnx/$1 -} - -create_qnx_project(){ - echo "Please input your project name:" - read PROJECT_NAME - PROJECT_DIR=`pwd`/$PROJECT_NAME - - # check if PROJECT_DIR is exist - if [ -d $PROJECT_DIR ]; then - echo "" - else - mkdir $PROJECT_DIR - fi - - copy_qnx_folder - modify_file_content .project - modify_file_content .cproject - modify_file_content bar-descriptor.xml - copy_cpp_h_from_helloworld - copy_resouces - echo "Congratulations, the '$PROJECT_NAME' project have been created successfully, please use QNX IDE to import the project!" -} - -create_qnx_project \ No newline at end of file diff --git a/create-qnx-project.vbs b/create-qnx-project.vbs deleted file mode 100644 index d9a8d69800..0000000000 --- a/create-qnx-project.vbs +++ /dev/null @@ -1,78 +0,0 @@ -set fso = Wscript.CreateObject("Scripting.FileSystemObject") - -dim szPrompt, msgRet -szPrompt = "Prompt" - -function ReplaceFileContent(fileName, oldStr, newStr) - set f = fso.opentextfile(fileName) - s = replace(f.readall, oldStr, newStr) - f.close - set r = fso.opentextfile(fileName, 2, true) - r.write s -end function - -function CopyFolder(srcFolder, desFolder) - if (fso.FolderExists(desFolder)) then - 'msgbox("none:"+srcFolder+":"+desFolder) - 'If the desFolder exist, do nothing. - else - CopyFolder = fso.CopyFolder(srcFolder, desFolder) - end if -end function - -function ConfigureProject() - dim szProjectName - szProjectName = Inputbox("Please Input Project Name:", szPrompt) - - if szProjectName = "" then - Wscript.quit - end if - - if (0 = strcomp(szProjectName, "HelloWorld", 1) or 0 = strcomp(szProjectName, "tests", 1)) then - msgRet = msgbox("Can not create a project named with "+szProjectName+", Please input again!", 1, szPrompt) - if (msgRet = 1) then - call ConfigureProject - end if - Wscript.quit - end if - - if (fso.FolderExists(szProjectName)) then - else - fso.CreateFolder(szProjectName) - end if - - dim qnxFolder - qnxFolder = szProjectName + "\qnx" - if (fso.FolderExists(qnxFolder)) then - msgRet = msgbox("The '"+szProjectName+"' project exists, can't override! Please input again!", 1, szPrompt) - if (msgRet = 1) then - call ConfigureProject - end if - Wcript.quit - end if - - dim szSrcClass, szSrcQnx, szSrcResource - dim szDesClass, szDesQnx, szDesResource - - szSrcClass = "HelloWorld\Classes" - szSrcQnx = "HelloWorld\qnx" - szSrcResource = "HelloWorld\Resources" - - szDesClass = szProjectName+"\Classes" - szDesQnx = szProjectName+"\qnx" - szDesResource = szProjectName+"\Resources" - - call CopyFolder(szSrcClass, szDesClass) - call CopyFolder(szSrcQnx, szDesQnx) - call CopyFolder(szSrcResource, szDesResource) - - call ReplaceFileContent(szProjectName+"\qnx\bar-descriptor.xml", "HelloWorld", szProjectName) - call ReplaceFileContent(szProjectName+"\qnx\.project", "HelloWorld", szProjectName) - call ReplaceFileContent(szProjectName+"\qnx\.cproject", "HelloWorld", szProjectName) - - call msgbox("Congratulations, the '"+szProjectName+"' project have been created successfully, please use QNX IDE to import the project!", 0, szPrompt) - -end function - -call ConfigureProject -Wscript.quit \ No newline at end of file From 5c7e7f6563d8a48d8fbdb2f4e96f262ca501b1c1 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 2 May 2012 12:01:53 +0800 Subject: [PATCH 06/14] issue #1194: Updated ios template. --- .../xcode4/cocos2dx.xctemplate/Classes/AppDelegate.cpp | 7 +------ .../cocos2dx.xctemplate/Classes/HelloWorldScene.cpp | 2 +- template/xcode4/cocos2dx.xctemplate/ios/AppController.mm | 2 +- .../cocos2dx_box2d.xctemplate/Classes/AppDelegate.cpp | 7 +------ .../Classes/HelloWorldScene.cpp | 4 ++-- .../cocos2dx_box2d.xctemplate/ios/AppController.mm | 2 +- .../cocos2dx_chipmunk.xctemplate/Classes/AppDelegate.cpp | 9 ++------- .../cocos2dx_chipmunk.xctemplate/ios/AppController.mm | 2 +- .../cocos2dx_lua.xctemplate/Classes/AppDelegate.cpp | 6 +----- .../xcode4/cocos2dx_lua.xctemplate/ios/AppController.mm | 2 +- .../TemplateInfo.plist.REMOVED.git-id | 1 + tools/xcode4_template_generator/run_generator.sh | 2 +- 12 files changed, 14 insertions(+), 32 deletions(-) create mode 100644 template/xcode4/lib_cocos2dx.xctemplate/TemplateInfo.plist.REMOVED.git-id diff --git a/template/xcode4/cocos2dx.xctemplate/Classes/AppDelegate.cpp b/template/xcode4/cocos2dx.xctemplate/Classes/AppDelegate.cpp index d2c74948af..9e688d9826 100644 --- a/template/xcode4/cocos2dx.xctemplate/Classes/AppDelegate.cpp +++ b/template/xcode4/cocos2dx.xctemplate/Classes/AppDelegate.cpp @@ -47,11 +47,6 @@ bool AppDelegate::initInstance() // if you want to use auto-scale, please enable view->create(320,480) in main.cpp #endif // CC_PLATFORM_ANDROID -#if (CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE) - // MaxAksenov said it's NOT a very elegant solution. I agree, haha - CCDirector::sharedDirector()->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft); -#endif - bRet = true; } while (0); return bRet; @@ -70,7 +65,7 @@ bool AppDelegate::applicationDidFinishLaunching() // pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft); // turn on display FPS - pDirector->setDisplayFPS(true); + pDirector->setDisplayStats(true); // set FPS. the default value is 1.0/60 if you don't call this pDirector->setAnimationInterval(1.0 / 60); diff --git a/template/xcode4/cocos2dx.xctemplate/Classes/HelloWorldScene.cpp b/template/xcode4/cocos2dx.xctemplate/Classes/HelloWorldScene.cpp index 69ff19630a..04d9a13b41 100644 --- a/template/xcode4/cocos2dx.xctemplate/Classes/HelloWorldScene.cpp +++ b/template/xcode4/cocos2dx.xctemplate/Classes/HelloWorldScene.cpp @@ -34,7 +34,7 @@ bool HelloWorld::init() // you may modify it. // add a "close" icon to exit the progress. it's an autorelease object - CCMenuItemImage *pCloseItem = CCMenuItemImage::itemFromNormalImage( + CCMenuItemImage *pCloseItem = CCMenuItemImage::itemWithNormalImage( "CloseNormal.png", "CloseSelected.png", this, diff --git a/template/xcode4/cocos2dx.xctemplate/ios/AppController.mm b/template/xcode4/cocos2dx.xctemplate/ios/AppController.mm index 13f4c43df5..a209ad42a5 100644 --- a/template/xcode4/cocos2dx.xctemplate/ios/AppController.mm +++ b/template/xcode4/cocos2dx.xctemplate/ios/AppController.mm @@ -29,7 +29,7 @@ static AppDelegate s_sharedApplication; window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; EAGLView *__glView = [EAGLView viewWithFrame: [window bounds] pixelFormat: kEAGLColorFormatRGBA8 - depthFormat: GL_DEPTH_COMPONENT16_OES + depthFormat: GL_DEPTH_COMPONENT16 preserveBackbuffer: NO sharegroup: nil multiSampling: NO diff --git a/template/xcode4/cocos2dx_box2d.xctemplate/Classes/AppDelegate.cpp b/template/xcode4/cocos2dx_box2d.xctemplate/Classes/AppDelegate.cpp index d2c74948af..9e688d9826 100644 --- a/template/xcode4/cocos2dx_box2d.xctemplate/Classes/AppDelegate.cpp +++ b/template/xcode4/cocos2dx_box2d.xctemplate/Classes/AppDelegate.cpp @@ -47,11 +47,6 @@ bool AppDelegate::initInstance() // if you want to use auto-scale, please enable view->create(320,480) in main.cpp #endif // CC_PLATFORM_ANDROID -#if (CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE) - // MaxAksenov said it's NOT a very elegant solution. I agree, haha - CCDirector::sharedDirector()->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft); -#endif - bRet = true; } while (0); return bRet; @@ -70,7 +65,7 @@ bool AppDelegate::applicationDidFinishLaunching() // pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft); // turn on display FPS - pDirector->setDisplayFPS(true); + pDirector->setDisplayStats(true); // set FPS. the default value is 1.0/60 if you don't call this pDirector->setAnimationInterval(1.0 / 60); diff --git a/template/xcode4/cocos2dx_box2d.xctemplate/Classes/HelloWorldScene.cpp b/template/xcode4/cocos2dx_box2d.xctemplate/Classes/HelloWorldScene.cpp index 7dee4cba9e..bc0855a4f7 100644 --- a/template/xcode4/cocos2dx_box2d.xctemplate/Classes/HelloWorldScene.cpp +++ b/template/xcode4/cocos2dx_box2d.xctemplate/Classes/HelloWorldScene.cpp @@ -130,7 +130,7 @@ void HelloWorld::addNewSpriteWithCoords(CCPoint p) int idx = (CCRANDOM_0_1() > .5 ? 0:1); int idy = (CCRANDOM_0_1() > .5 ? 0:1); - CCSprite *sprite = CCSprite::spriteWithBatchNode(sheet, CCRectMake(32 * idx,32 * idy,32,32)); + CCSprite *sprite = CCSprite::spriteWithTexture(sheet->getTexture(), CCRectMake(32 * idx,32 * idy,32,32)); sheet->addChild(sprite); sprite->setPosition( CCPointMake( p.x, p.y) ); @@ -195,7 +195,7 @@ void HelloWorld::ccTouchesEnded(CCSet* touches, CCEvent* event) if(!touch) break; - CCPoint location = touch->locationInView(touch->view()); + CCPoint location = touch->locationInView(); location = CCDirector::sharedDirector()->convertToGL(location); diff --git a/template/xcode4/cocos2dx_box2d.xctemplate/ios/AppController.mm b/template/xcode4/cocos2dx_box2d.xctemplate/ios/AppController.mm index 864117bd04..63aa8d6d04 100644 --- a/template/xcode4/cocos2dx_box2d.xctemplate/ios/AppController.mm +++ b/template/xcode4/cocos2dx_box2d.xctemplate/ios/AppController.mm @@ -29,7 +29,7 @@ static AppDelegate s_sharedApplication; window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; EAGLView *__glView = [EAGLView viewWithFrame: [window bounds] pixelFormat: kEAGLColorFormatRGBA8 - depthFormat: GL_DEPTH_COMPONENT16_OES + depthFormat: GL_DEPTH_COMPONENT16 preserveBackbuffer: NO sharegroup: nil multiSampling: NO diff --git a/template/xcode4/cocos2dx_chipmunk.xctemplate/Classes/AppDelegate.cpp b/template/xcode4/cocos2dx_chipmunk.xctemplate/Classes/AppDelegate.cpp index 81e29bffa7..39764a0e5d 100644 --- a/template/xcode4/cocos2dx_chipmunk.xctemplate/Classes/AppDelegate.cpp +++ b/template/xcode4/cocos2dx_chipmunk.xctemplate/Classes/AppDelegate.cpp @@ -46,12 +46,7 @@ bool AppDelegate::initInstance() // the default setting is to create a fullscreen view // if you want to use auto-scale, please enable view->create(320,480) in main.cpp #endif // CC_PLATFORM_ANDROID - -#if (CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE) - // MaxAksenov said it's NOT a very elegant solution. I agree, haha - CCDirector::sharedDirector()->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft); -#endif - + bRet = true; } while (0); return bRet; @@ -70,7 +65,7 @@ bool AppDelegate::applicationDidFinishLaunching() // pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft); // turn on display FPS - pDirector->setDisplayFPS(true); + pDirector->setDisplayStats(true); // set FPS. the default value is 1.0/60 if you don't call this pDirector->setAnimationInterval(1.0 / 60); diff --git a/template/xcode4/cocos2dx_chipmunk.xctemplate/ios/AppController.mm b/template/xcode4/cocos2dx_chipmunk.xctemplate/ios/AppController.mm index 09a52314ab..16882c7a1f 100644 --- a/template/xcode4/cocos2dx_chipmunk.xctemplate/ios/AppController.mm +++ b/template/xcode4/cocos2dx_chipmunk.xctemplate/ios/AppController.mm @@ -29,7 +29,7 @@ static AppDelegate s_sharedApplication; window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; EAGLView *__glView = [EAGLView viewWithFrame: [window bounds] pixelFormat: kEAGLColorFormatRGBA8 - depthFormat: GL_DEPTH_COMPONENT16_OES + depthFormat: GL_DEPTH_COMPONENT16 preserveBackbuffer: NO sharegroup: nil multiSampling: NO diff --git a/template/xcode4/cocos2dx_lua.xctemplate/Classes/AppDelegate.cpp b/template/xcode4/cocos2dx_lua.xctemplate/Classes/AppDelegate.cpp index b5096f6c4b..3eec69f5e6 100644 --- a/template/xcode4/cocos2dx_lua.xctemplate/Classes/AppDelegate.cpp +++ b/template/xcode4/cocos2dx_lua.xctemplate/Classes/AppDelegate.cpp @@ -63,10 +63,6 @@ bool AppDelegate::initInstance() #endif // CC_PLATFORM_ANDROID -#if (CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE) - // MaxAksenov said it's NOT a very elegant solution. I agree, haha - CCDirector::sharedDirector()->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft); -#endif bRet = true; } while (0); return bRet; @@ -82,7 +78,7 @@ bool AppDelegate::applicationDidFinishLaunching() // pDirector->enableRetinaDisplay(true); // turn on display FPS - pDirector->setDisplayFPS(true); + pDirector->setDisplayStats(true); // pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft); diff --git a/template/xcode4/cocos2dx_lua.xctemplate/ios/AppController.mm b/template/xcode4/cocos2dx_lua.xctemplate/ios/AppController.mm index 0c78fc60ac..f4ac87abf2 100644 --- a/template/xcode4/cocos2dx_lua.xctemplate/ios/AppController.mm +++ b/template/xcode4/cocos2dx_lua.xctemplate/ios/AppController.mm @@ -45,7 +45,7 @@ static AppDelegate s_sharedApplication; window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; EAGLView *__glView = [EAGLView viewWithFrame: [window bounds] pixelFormat: kEAGLColorFormatRGBA8 - depthFormat: GL_DEPTH_COMPONENT16_OES + depthFormat: GL_DEPTH_COMPONENT16 preserveBackbuffer: NO sharegroup: nil multiSampling: NO diff --git a/template/xcode4/lib_cocos2dx.xctemplate/TemplateInfo.plist.REMOVED.git-id b/template/xcode4/lib_cocos2dx.xctemplate/TemplateInfo.plist.REMOVED.git-id new file mode 100644 index 0000000000..7f4ba3bbc4 --- /dev/null +++ b/template/xcode4/lib_cocos2dx.xctemplate/TemplateInfo.plist.REMOVED.git-id @@ -0,0 +1 @@ +a0108c887c7176801731f3e9503263b79a9eeb62 \ No newline at end of file diff --git a/tools/xcode4_template_generator/run_generator.sh b/tools/xcode4_template_generator/run_generator.sh index 960763baea..9805277fcf 100755 --- a/tools/xcode4_template_generator/run_generator.sh +++ b/tools/xcode4_template_generator/run_generator.sh @@ -2,7 +2,7 @@ pushd ../../ echo "generating libcocos2dx" mkdir -p template/xcode4/lib_cocos2dx.xctemplate -python ./tools/xcode4_template_generator/template_generator.py --directory cocos2dx --identifier libcocos2dx --prefix libs --exclude "android win32 airplay wophone bada third_party CCImage.cpp CCThread.cpp CCFileUtils.cpp Android.mk Linux linux qnx marmalade" > ./template/xcode4/lib_cocos2dx.xctemplate/TemplateInfo.plist +python ./tools/xcode4_template_generator/template_generator.py --directory cocos2dx --identifier libcocos2dx --prefix libs --exclude "android win32 airplay wophone bada third_party CCImage.cpp CCThread.cpp proj.ios CCFileUtilsCommon_cpp.h CCImageCommon_cpp.h CCFileUtils.cpp Android.mk Linux linux qnx marmalade" > ./template/xcode4/lib_cocos2dx.xctemplate/TemplateInfo.plist echo "generating libcocosdenshion" mkdir -p template/xcode4/lib_cocosdenshion.xctemplate From a998062c57033c2e9ad2306c7115b2c8e4d461db Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 2 May 2012 12:04:27 +0800 Subject: [PATCH 07/14] issue #1194: Updated project configuration for android. Null pointer checking in CCNode::removeFromParentAndCleanup. --- HelloLua/proj.android/jni/helloworld/main.cpp | 15 +++++++++------ HelloWorld/proj.android/jni/helloworld/main.cpp | 15 ++++++++------- cocos2dx/Android.mk | 3 +++ cocos2dx/base_nodes/CCNode.cpp | 5 ++++- tests/proj.android/jni/tests/main.cpp | 15 ++++++++------- 5 files changed, 32 insertions(+), 21 deletions(-) diff --git a/HelloLua/proj.android/jni/helloworld/main.cpp b/HelloLua/proj.android/jni/helloworld/main.cpp index 2f5b1c64f3..a8d2945171 100644 --- a/HelloLua/proj.android/jni/helloworld/main.cpp +++ b/HelloLua/proj.android/jni/helloworld/main.cpp @@ -8,6 +8,7 @@ #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__) using namespace cocos2d; +using namespace cocos2d::extension; extern "C" { @@ -21,21 +22,23 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved) void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thiz, jint w, jint h) { - if (!cocos2d::CCDirector::sharedDirector()->getOpenGLView()) + if (!CCDirector::sharedDirector()->getOpenGLView()) { - cocos2d::CCEGLView *view = &cocos2d::CCEGLView::sharedOpenGLView(); + CCEGLView *view = &CCEGLView::sharedOpenGLView(); view->setFrameSize(w, h); // if you want to run in WVGA with HVGA resource, set it // view->create(480, 320); - cocos2d::CCDirector::sharedDirector()->setOpenGLView(view); + CCDirector::sharedDirector()->setOpenGLView(view); AppDelegate *pAppDelegate = new AppDelegate(); - cocos2d::CCApplication::sharedApplication().run(); + CCApplication::sharedApplication().run(); } else { - cocos2d::CCTextureCache::reloadAllTextures(); - cocos2d::CCDirector::sharedDirector()->setGLDefaultValues(); + CCShaderCache::sharedShaderCache()->reloadDefaultShaders(); + CCTextureCache::reloadAllTextures(); + CCNotificationCenter::sharedNotificationCenter()->postNotification(EVNET_COME_TO_FOREGROUND, NULL); + CCDirector::sharedDirector()->setGLDefaultValues(); } } diff --git a/HelloWorld/proj.android/jni/helloworld/main.cpp b/HelloWorld/proj.android/jni/helloworld/main.cpp index 12de1ac94c..f1bfd6cedd 100644 --- a/HelloWorld/proj.android/jni/helloworld/main.cpp +++ b/HelloWorld/proj.android/jni/helloworld/main.cpp @@ -11,6 +11,7 @@ #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__) using namespace cocos2d; +using namespace cocos2d::extension; extern "C" { @@ -24,16 +25,16 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved) void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thiz, jint w, jint h) { - if (!cocos2d::CCDirector::sharedDirector()->getOpenGLView()) + if (!CCDirector::sharedDirector()->getOpenGLView()) { - cocos2d::CCEGLView *view = &cocos2d::CCEGLView::sharedOpenGLView(); + CCEGLView *view = &CCEGLView::sharedOpenGLView(); view->setFrameSize(w, h); // if you want to run in WVGA with HVGA resource, set it // view->setDesignResolutionSize(480, 320); Please change it to (320, 480) if you're in portrait mode. - cocos2d::CCDirector::sharedDirector()->setOpenGLView(view); + CCDirector::sharedDirector()->setOpenGLView(view); AppDelegate *pAppDelegate = new AppDelegate(); - cocos2d::CCApplication::sharedApplication().run(); + CCApplication::sharedApplication().run(); } else { @@ -41,9 +42,9 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi ccGLInvalidateStateCache(); CCShaderCache::sharedShaderCache()->reloadDefaultShaders(); - cocos2d::CCTextureCache::reloadAllTextures(); - cocos2d::CCNotificationCenter::sharedNotificationCenter()->postNotification(EVNET_COME_TO_FOREGROUND, NULL); - cocos2d::CCDirector::sharedDirector()->setGLDefaultValues(); + CCTextureCache::reloadAllTextures(); + CCNotificationCenter::sharedNotificationCenter()->postNotification(EVNET_COME_TO_FOREGROUND, NULL); + CCDirector::sharedDirector()->setGLDefaultValues(); } } diff --git a/cocos2dx/Android.mk b/cocos2dx/Android.mk index a4bc32784a..ed05d5e0e2 100644 --- a/cocos2dx/Android.mk +++ b/cocos2dx/Android.mk @@ -53,6 +53,9 @@ extensions/CCControlExtension/CCInvocation.cpp \ extensions/CCControlExtension/CCMenuPassive.cpp \ extensions/CCControlExtension/CCScale9Sprite.cpp \ extensions/CCControlExtension/CCSpacer.cpp \ +extensions/CCListView/CCListView.cpp \ +extensions/CCListView/CCListViewCell.cpp \ +extensions/CCTextureWatcher/CCTextureWatcher.cpp \ kazmath/src/aabb.c \ kazmath/src/mat3.c \ kazmath/src/mat4.c \ diff --git a/cocos2dx/base_nodes/CCNode.cpp b/cocos2dx/base_nodes/CCNode.cpp index b5b8427ebb..870dd56578 100644 --- a/cocos2dx/base_nodes/CCNode.cpp +++ b/cocos2dx/base_nodes/CCNode.cpp @@ -524,7 +524,10 @@ void CCNode::addChild(CCNode *child) void CCNode::removeFromParentAndCleanup(bool cleanup) { - this->m_pParent->removeChild(this,cleanup); + if (m_pParent != NULL) + { + m_pParent->removeChild(this,cleanup); + } } /* "remove" logic MUST only be on this method diff --git a/tests/proj.android/jni/tests/main.cpp b/tests/proj.android/jni/tests/main.cpp index cf7becbae7..aeea16f4fe 100644 --- a/tests/proj.android/jni/tests/main.cpp +++ b/tests/proj.android/jni/tests/main.cpp @@ -9,6 +9,7 @@ #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__) using namespace cocos2d; +using namespace cocos2d::extension; extern "C" { @@ -22,16 +23,16 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved) void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thiz, jint w, jint h) { - if (!cocos2d::CCDirector::sharedDirector()->getOpenGLView()) + if (!CCDirector::sharedDirector()->getOpenGLView()) { - cocos2d::CCEGLView *view = &cocos2d::CCEGLView::sharedOpenGLView(); + CCEGLView *view = &CCEGLView::sharedOpenGLView(); view->setFrameSize(w, h); // if you want to run in WVGA with HVGA resource, set it // view->setDesignResolutionSize(480, 320); - cocos2d::CCDirector::sharedDirector()->setOpenGLView(view); + CCDirector::sharedDirector()->setOpenGLView(view); AppDelegate *pAppDelegate = new AppDelegate(); - cocos2d::CCApplication::sharedApplication().run(); + CCApplication::sharedApplication().run(); } else { @@ -39,9 +40,9 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi ccGLInvalidateStateCache(); CCShaderCache::sharedShaderCache()->reloadDefaultShaders(); - cocos2d::CCTextureCache::reloadAllTextures(); - cocos2d::CCNotificationCenter::sharedNotificationCenter()->postNotification(EVNET_COME_TO_FOREGROUND, NULL); - cocos2d::CCDirector::sharedDirector()->setGLDefaultValues(); + CCTextureCache::reloadAllTextures(); + CCNotificationCenter::sharedNotificationCenter()->postNotification(EVNET_COME_TO_FOREGROUND, NULL); + CCDirector::sharedDirector()->setGLDefaultValues(); } } From 4a002ea9cce4b28cf8e55b0723199a869ae78907 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 2 May 2012 12:51:48 +0800 Subject: [PATCH 08/14] issue #1194: Updated ios template of box2d. --- .../Classes/HelloWorldScene.cpp | 226 +++++++++++------- .../Classes/HelloWorldScene.h | 15 +- 2 files changed, 154 insertions(+), 87 deletions(-) diff --git a/template/xcode4/cocos2dx_box2d.xctemplate/Classes/HelloWorldScene.cpp b/template/xcode4/cocos2dx_box2d.xctemplate/Classes/HelloWorldScene.cpp index bc0855a4f7..89262ef590 100644 --- a/template/xcode4/cocos2dx_box2d.xctemplate/Classes/HelloWorldScene.cpp +++ b/template/xcode4/cocos2dx_box2d.xctemplate/Classes/HelloWorldScene.cpp @@ -12,87 +12,84 @@ using namespace cocos2d; using namespace CocosDenshion; #define PTM_RATIO 32 -enum + +enum { + kTagParentNode = 1, +}; + +PhysicsSprite::PhysicsSprite() +: m_pBody(NULL) { - kTagTileMap = 1, - kTagSpriteManager = 1, - kTagAnimation1 = 1, -}; + +} + +void PhysicsSprite::setPhysicsBody(b2Body * body) +{ + m_pBody = body; +} + +// this method will only get called if the sprite is batched. +// return YES if the physics values (angles, position ) changed +// If you return NO, then nodeToParentTransform won't be called. +bool PhysicsSprite::isDirty(void) +{ + return true; +} + +// returns the transform matrix according the Chipmunk Body values +CCAffineTransform PhysicsSprite::nodeToParentTransform(void) +{ + b2Vec2 pos = m_pBody->GetPosition(); + + float x = pos.x * PTM_RATIO; + float y = pos.y * PTM_RATIO; + + if ( !getIsRelativeAnchorPoint() ) { + x += m_tAnchorPointInPoints.x; + y += m_tAnchorPointInPoints.y; + } + + // Make matrix + float radians = m_pBody->GetAngle(); + float c = cosf(radians); + float s = sinf(radians); + + if( ! CCPoint::CCPointEqualToPoint(m_tAnchorPointInPoints, CCPointZero) ){ + x += c*-m_tAnchorPointInPoints.x + -s*-m_tAnchorPointInPoints.y; + y += s*-m_tAnchorPointInPoints.x + c*-m_tAnchorPointInPoints.y; + } + + // Rot, Translate Matrix + m_tTransform = CCAffineTransformMake( c, s, + -s, c, + x, y ); + + return m_tTransform; +} HelloWorld::HelloWorld() { setIsTouchEnabled( true ); setIsAccelerometerEnabled( true ); - - CCSize screenSize = CCDirector::sharedDirector()->getWinSize(); - //UXLOG(L"Screen width %0.2f screen height %0.2f",screenSize.width,screenSize.height); - - // Define the gravity vector. - b2Vec2 gravity; - gravity.Set(0.0f, -10.0f); - - // Do we want to let bodies sleep? - bool doSleep = true; - - // Construct a world object, which will hold and simulate the rigid bodies. - world = new b2World(gravity); - world->SetAllowSleeping(doSleep); - world->SetContinuousPhysics(true); - - /* - m_debugDraw = new GLESDebugDraw( PTM_RATIO ); - world->SetDebugDraw(m_debugDraw); - - uint flags = 0; - flags += b2DebugDraw::e_shapeBit; - flags += b2DebugDraw::e_jointBit; - flags += b2DebugDraw::e_aabbBit; - flags += b2DebugDraw::e_pairBit; - flags += b2DebugDraw::e_centerOfMassBit; - m_debugDraw->SetFlags(flags); - */ - - b2BodyDef groundBodyDef; - groundBodyDef.position.Set(screenSize.width/2/PTM_RATIO, - screenSize.height/2/PTM_RATIO); // bottom-left corner - - // Call the body factory which allocates memory for the ground body - // from a pool and creates the ground box shape (also from a pool). - // The body is also added to the world. - b2Body* groundBody = world->CreateBody(&groundBodyDef); - - // Define the ground box shape. - b2PolygonShape groundBox; - - // bottom - groundBox.SetAsBox(screenSize.width/2/PTM_RATIO, 0, b2Vec2(0, -screenSize.height/2/PTM_RATIO), 0); - groundBody->CreateFixture(&groundBox, 0); - - // top - groundBox.SetAsBox(screenSize.width/2/PTM_RATIO, 0, b2Vec2(0, screenSize.height/2/PTM_RATIO), 0); - groundBody->CreateFixture(&groundBox, 0); - - // left - groundBox.SetAsBox(0, screenSize.height/2/PTM_RATIO, b2Vec2(-screenSize.width/2/PTM_RATIO, 0), 0); - groundBody->CreateFixture(&groundBox, 0); - - // right - groundBox.SetAsBox(0, screenSize.height/2/PTM_RATIO, b2Vec2(screenSize.width/2/PTM_RATIO, 0), 0); - groundBody->CreateFixture(&groundBox, 0); - - - //Set up sprite - CCSpriteBatchNode *mgr = CCSpriteBatchNode::batchNodeWithFile("blocks.png", 150); - addChild(mgr, 0, kTagSpriteManager); - - addNewSpriteWithCoords( CCPointMake(screenSize.width/2, screenSize.height/2) ); - + + CCSize s = CCDirector::sharedDirector()->getWinSize(); + // init physics + this->initPhysics(); + + CCSpriteBatchNode *parent = CCSpriteBatchNode::batchNodeWithFile("blocks.png", 100); + m_pSpriteTexture = parent->getTexture(); + + addChild(parent, 0, kTagParentNode); + + + addNewSpriteAtPosition(ccp(s.width/2, s.height/2)); + CCLabelTTF *label = CCLabelTTF::labelWithString("Tap screen", "Marker Felt", 32); addChild(label, 0); - label->setColor( ccc3(0,0,255) ); - label->setPosition( CCPointMake( screenSize.width/2, screenSize.height-50) ); + label->setColor(ccc3(0,0,255)); + label->setPosition(ccp( s.width/2, s.height-50)); - schedule( schedule_selector(HelloWorld::tick) ); + scheduleUpdate(); } HelloWorld::~HelloWorld() @@ -103,21 +100,78 @@ HelloWorld::~HelloWorld() //delete m_debugDraw; } +void HelloWorld::initPhysics() +{ + + CCSize s = CCDirector::sharedDirector()->getWinSize(); + + b2Vec2 gravity; + gravity.Set(0.0f, -10.0f); + world = new b2World(gravity); + + // Do we want to let bodies sleep? + world->SetAllowSleeping(true); + + world->SetContinuousPhysics(true); + +// m_debugDraw = new GLESDebugDraw( PTM_RATIO ); +// world->SetDebugDraw(m_debugDraw); + + uint32 flags = 0; + flags += b2Draw::e_shapeBit; + // flags += b2Draw::e_jointBit; + // flags += b2Draw::e_aabbBit; + // flags += b2Draw::e_pairBit; + // flags += b2Draw::e_centerOfMassBit; + //m_debugDraw->SetFlags(flags); + + + // Define the ground body. + b2BodyDef groundBodyDef; + groundBodyDef.position.Set(0, 0); // bottom-left corner + + // Call the body factory which allocates memory for the ground body + // from a pool and creates the ground box shape (also from a pool). + // The body is also added to the world. + b2Body* groundBody = world->CreateBody(&groundBodyDef); + + // Define the ground box shape. + b2EdgeShape groundBox; + + // bottom + + groundBox.Set(b2Vec2(0,0), b2Vec2(s.width/PTM_RATIO,0)); + groundBody->CreateFixture(&groundBox,0); + + // top + groundBox.Set(b2Vec2(0,s.height/PTM_RATIO), b2Vec2(s.width/PTM_RATIO,s.height/PTM_RATIO)); + groundBody->CreateFixture(&groundBox,0); + + // left + groundBox.Set(b2Vec2(0,s.height/PTM_RATIO), b2Vec2(0,0)); + groundBody->CreateFixture(&groundBox,0); + + // right + groundBox.Set(b2Vec2(s.width/PTM_RATIO,s.height/PTM_RATIO), b2Vec2(s.width/PTM_RATIO,0)); + groundBody->CreateFixture(&groundBox,0); +} + void HelloWorld::draw() { - // Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY - // Needed states: GL_VERTEX_ARRAY, - // Unneeded states: GL_TEXTURE_2D, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY - glDisable(GL_TEXTURE_2D); - glDisableClientState(GL_COLOR_ARRAY); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - - //world->DrawDebugData(); - - // restore default GL states - glEnable(GL_TEXTURE_2D); - glEnableClientState(GL_COLOR_ARRAY); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); + // + // IMPORTANT: + // This is only for debug purposes + // It is recommend to disable it + // + CCLayer::draw(); + + ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position ); + + kmGLPushMatrix(); + + world->DrawDebugData(); + + kmGLPopMatrix(); } void HelloWorld::addNewSpriteWithCoords(CCPoint p) @@ -156,7 +210,7 @@ void HelloWorld::addNewSpriteWithCoords(CCPoint p) } -void HelloWorld::tick(ccTime dt) +void HelloWorld::update(ccTime dt) { //It is recommended that a fixed time step is used with Box2D for stability //of the simulation, however, we are using a variable time step here. diff --git a/template/xcode4/cocos2dx_box2d.xctemplate/Classes/HelloWorldScene.h b/template/xcode4/cocos2dx_box2d.xctemplate/Classes/HelloWorldScene.h index f37c94f836..4cf16516bc 100644 --- a/template/xcode4/cocos2dx_box2d.xctemplate/Classes/HelloWorldScene.h +++ b/template/xcode4/cocos2dx_box2d.xctemplate/Classes/HelloWorldScene.h @@ -12,6 +12,17 @@ #include "cocos2d.h" #include "Box2D.h" +class PhysicsSprite : public CCSprite +{ +public: + PhysicsSprite(); + void setPhysicsBody(b2Body * body); + virtual bool isDirty(void); + virtual CCAffineTransform nodeToParentTransform(void); +private: + b2Body* m_pBody; // strong ref +}; + class HelloWorld : public cocos2d::CCLayer { public: ~HelloWorld(); @@ -20,11 +31,13 @@ public: // returns a Scene that contains the HelloWorld as the only child static cocos2d::CCScene* scene(); + void initPhysics(); // adds a new sprite at a given coordinate void addNewSpriteWithCoords(cocos2d::CCPoint p); + virtual void draw(); virtual void ccTouchesEnded(cocos2d::CCSet* touches, cocos2d::CCEvent* event); - void tick(cocos2d::ccTime dt); + void update(cocos2d::ccTime dt); private: b2World* world; From 849a4ebc7ffecb7e1527cbbff43c279c4d7a3796 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 2 May 2012 13:03:47 +0800 Subject: [PATCH 09/14] issue #1194: Updated the box2d template for ios platform. --- .../Classes/HelloWorldScene.cpp | 18 +++++++++++------- .../Classes/HelloWorldScene.h | 7 ++++--- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/template/xcode4/cocos2dx_box2d.xctemplate/Classes/HelloWorldScene.cpp b/template/xcode4/cocos2dx_box2d.xctemplate/Classes/HelloWorldScene.cpp index 89262ef590..ab54b1cb3c 100644 --- a/template/xcode4/cocos2dx_box2d.xctemplate/Classes/HelloWorldScene.cpp +++ b/template/xcode4/cocos2dx_box2d.xctemplate/Classes/HelloWorldScene.cpp @@ -174,18 +174,20 @@ void HelloWorld::draw() kmGLPopMatrix(); } -void HelloWorld::addNewSpriteWithCoords(CCPoint p) +void HelloWorld::addNewSpriteAtPosition(CCPoint p) { - //UXLOG(L"Add sprite %0.2f x %02.f",p.x,p.y); - CCSpriteBatchNode* sheet = (CCSpriteBatchNode*)getChildByTag(kTagSpriteManager); + CCLOG("Add sprite %0.2f x %02.f",p.x,p.y); + CCNode* parent = getChildByTag(kTagParentNode); //We have a 64x64 sprite sheet with 4 different 32x32 images. The following code is //just randomly picking one of the images int idx = (CCRANDOM_0_1() > .5 ? 0:1); int idy = (CCRANDOM_0_1() > .5 ? 0:1); + PhysicsSprite *sprite = new PhysicsSprite(); + sprite->initWithTexture(m_pSpriteTexture, CCRectMake(32 * idx,32 * idy,32,32)); + sprite->autorelease(); - CCSprite *sprite = CCSprite::spriteWithTexture(sheet->getTexture(), CCRectMake(32 * idx,32 * idy,32,32)); - sheet->addChild(sprite); + parent->addChild(sprite); sprite->setPosition( CCPointMake( p.x, p.y) ); @@ -194,7 +196,7 @@ void HelloWorld::addNewSpriteWithCoords(CCPoint p) b2BodyDef bodyDef; bodyDef.type = b2_dynamicBody; bodyDef.position.Set(p.x/PTM_RATIO, p.y/PTM_RATIO); - bodyDef.userData = sprite; + b2Body *body = world->CreateBody(&bodyDef); // Define another box shape for our dynamic body. @@ -207,6 +209,8 @@ void HelloWorld::addNewSpriteWithCoords(CCPoint p) fixtureDef.density = 1.0f; fixtureDef.friction = 0.3f; body->CreateFixture(&fixtureDef); + + sprite->setPhysicsBody(body); } @@ -253,7 +257,7 @@ void HelloWorld::ccTouchesEnded(CCSet* touches, CCEvent* event) location = CCDirector::sharedDirector()->convertToGL(location); - addNewSpriteWithCoords( location ); + addNewSpriteAtPosition( location ); } } diff --git a/template/xcode4/cocos2dx_box2d.xctemplate/Classes/HelloWorldScene.h b/template/xcode4/cocos2dx_box2d.xctemplate/Classes/HelloWorldScene.h index 4cf16516bc..76c3b63e77 100644 --- a/template/xcode4/cocos2dx_box2d.xctemplate/Classes/HelloWorldScene.h +++ b/template/xcode4/cocos2dx_box2d.xctemplate/Classes/HelloWorldScene.h @@ -12,13 +12,13 @@ #include "cocos2d.h" #include "Box2D.h" -class PhysicsSprite : public CCSprite +class PhysicsSprite : public cocos2d::CCSprite { public: PhysicsSprite(); void setPhysicsBody(b2Body * body); virtual bool isDirty(void); - virtual CCAffineTransform nodeToParentTransform(void); + virtual cocos2d::CCAffineTransform nodeToParentTransform(void); private: b2Body* m_pBody; // strong ref }; @@ -33,7 +33,7 @@ public: void initPhysics(); // adds a new sprite at a given coordinate - void addNewSpriteWithCoords(cocos2d::CCPoint p); + void addNewSpriteAtPosition(cocos2d::CCPoint p); virtual void draw(); virtual void ccTouchesEnded(cocos2d::CCSet* touches, cocos2d::CCEvent* event); @@ -41,6 +41,7 @@ public: private: b2World* world; + cocos2d::CCTexture2D* m_pSpriteTexture; // weak ref }; #endif // __HELLO_WORLD_H__ From 41b1bca7401c68980e21b9fa5de51f6fa6f423ef Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 2 May 2012 14:06:12 +0800 Subject: [PATCH 10/14] issue #1194: Updated the chipmuck template for ios platform. --- .../Classes/HelloWorldScene.cpp | 370 +++++++++++------- .../Classes/HelloWorldScene.h | 39 +- 2 files changed, 257 insertions(+), 152 deletions(-) diff --git a/template/xcode4/cocos2dx_chipmunk.xctemplate/Classes/HelloWorldScene.cpp b/template/xcode4/cocos2dx_chipmunk.xctemplate/Classes/HelloWorldScene.cpp index 6539ae54ea..f733db3937 100644 --- a/template/xcode4/cocos2dx_chipmunk.xctemplate/Classes/HelloWorldScene.cpp +++ b/template/xcode4/cocos2dx_chipmunk.xctemplate/Classes/HelloWorldScene.cpp @@ -14,25 +14,65 @@ using namespace cocos2d; using namespace CocosDenshion; enum { - kTagBatchNode = 1, + kTagParentNode = 1, }; -static void -eachShape(void *ptr, void* unused) +// callback to remove Shapes from the Space +void removeShape( cpBody *body, cpShape *shape, void *data ) { - cpShape *shape = (cpShape*) ptr; - CCSprite *sprite = (CCSprite*)shape->data; - if( sprite ) - { - cpBody *body = shape->body; - - // TIP: cocos2d and chipmunk uses the same struct to store it's position - // chipmunk uses: cpVect, and cocos2d uses CGPoint but in reality the are the same - // since v0.7.1 you can mix them if you want. - sprite->setPosition(CCPointMake(body->p.x, body->p.y)); - - sprite->setRotation((float) CC_RADIANS_TO_DEGREES( -body->a )); - } + cpShapeFree( shape ); +} + +ChipmunkPhysicsSprite::ChipmunkPhysicsSprite() +: m_pBody(NULL) +{ + +} + +ChipmunkPhysicsSprite::~ChipmunkPhysicsSprite() +{ + cpBodyEachShape(m_pBody, removeShape, NULL); + cpBodyFree( m_pBody ); +} + +void ChipmunkPhysicsSprite::setPhysicsBody(cpBody * body) +{ + m_pBody = body; +} + +// this method will only get called if the sprite is batched. +// return YES if the physics values (angles, position ) changed +// If you return NO, then nodeToParentTransform won't be called. +bool ChipmunkPhysicsSprite::isDirty(void) +{ + return true; +} + +CCAffineTransform ChipmunkPhysicsSprite::nodeToParentTransform(void) +{ + CCFloat x = m_pBody->p.x; + CCFloat y = m_pBody->p.y; + + if ( !getIsRelativeAnchorPoint() ) { + x += m_tAnchorPointInPoints.x; + y += m_tAnchorPointInPoints.y; + } + + // Make matrix + CCFloat c = m_pBody->rot.x; + CCFloat s = m_pBody->rot.y; + + if( ! CCPoint::CCPointEqualToPoint(m_tAnchorPointInPoints, CCPointZero) ){ + x += c*-m_tAnchorPointInPoints.x + -s*-m_tAnchorPointInPoints.y; + y += s*-m_tAnchorPointInPoints.x + c*-m_tAnchorPointInPoints.y; + } + + // Rot, Translate Matrix + m_tTransform = CCAffineTransformMake( c, s, + -s, c, + x, y ); + + return m_tTransform; } HelloWorld::HelloWorld() @@ -45,145 +85,195 @@ HelloWorld::~HelloWorld() CCScene* HelloWorld::scene() { - // 'scene' is an autorelease object. - CCScene *scene = CCScene::node(); - - // 'layer' is an autorelease object. - HelloWorld *layer = HelloWorld::node(); - - // add layer as a child to scene - scene->addChild(layer); - - // return the scene - return scene; -} + // 'scene' is an autorelease object. + CCScene *scene = CCScene::node(); + // 'layer' is an autorelease object. + HelloWorld *layer = HelloWorld::node(); -void HelloWorld::addNewSpriteX(float x, float y) -{ - int posx, posy; - - CCSpriteBatchNode *batch = (CCSpriteBatchNode*) getChildByTag(kTagBatchNode); - - posx = (CCRANDOM_0_1() * 200); - posy = (CCRANDOM_0_1() * 200); - - posx = (posx % 4) * 85; - posy = (posy % 3) * 121; - - CCSprite *sprite = CCSprite::spriteWithBatchNode(batch, CCRectMake(posx, posy, 85, 121)); - batch->addChild(sprite); - - sprite->setPosition(ccp(x, y)); - - int num = 4; - cpVect verts[] = { - cpv(-24,-54), - cpv(-24, 54), - cpv( 24, 54), - cpv( 24,-54), - }; - - cpBody *body = cpBodyNew(1.0f, cpMomentForPoly(1.0f, num, verts, cpv(0, 0))); - - // TIP: - // since v0.7.1 you can assign CGPoint to chipmunk instead of cpVect. - // cpVect == CGPoint - body->p = cpv(x, y); - cpSpaceAddBody(space, body); - - cpShape* shape = cpPolyShapeNew(body, num, verts, cpv(0, 0)); - shape->e = 0.5f; shape->u = 0.5f; - shape->data = sprite; - cpSpaceAddShape(space, shape); + // add layer as a child to scene + scene->addChild(layer); + + // return the scene + return scene; } bool HelloWorld::init() { - bool ret = false; - - if (ret = CCLayer::init()) - { - setIsTouchEnabled(true); - - CCSize wins = CCDirector::sharedDirector()->getWinSize(); - cpInitChipmunk(); - - cpBody *staticBody = cpBodyNew(INFINITY, INFINITY); - space = cpSpaceNew(); - cpSpaceResizeStaticHash(space, 400.0f, 40); - cpSpaceResizeActiveHash(space, 100, 600); - - space->gravity = cpv(0, 0); - space->elasticIterations = space->iterations; - - cpShape *shape; - - // bottom - shape = cpSegmentShapeNew(staticBody, cpv(0,0), cpv(wins.width,0), 0.0f); - shape->e = 1.0f; shape->u = 1.0f; - cpSpaceAddStaticShape(space, shape); - - // top - shape = cpSegmentShapeNew(staticBody, cpv(0,wins.height), cpv(wins.width,wins.height), 0.0f); - shape->e = 1.0f; shape->u = 1.0f; - cpSpaceAddStaticShape(space, shape); - - // left - shape = cpSegmentShapeNew(staticBody, cpv(0,0), cpv(0,wins.height), 0.0f); - shape->e = 1.0f; shape->u = 1.0f; - cpSpaceAddStaticShape(space, shape); - - // right - shape = cpSegmentShapeNew(staticBody, cpv(wins.width,0), cpv(wins.width,wins.height), 0.0f); - shape->e = 1.0f; shape->u = 1.0f; - cpSpaceAddStaticShape(space, shape); - - CCSpriteBatchNode *batch = CCSpriteBatchNode::batchNodeWithFile("grossini_dance_atlas.png", 100); - addChild(batch, 0, kTagBatchNode); - - addNewSpriteX(200, 200); - - schedule(schedule_selector(HelloWorld::step)); - } - - return ret; + if (!CCLayer::init()) + { + return false; + } + + // enable events + setIsTouchEnabled(true); + setIsAccelerometerEnabled(true); + + CCSize s = CCDirector::sharedDirector()->getWinSize(); + + // title + CCLabelTTF *label = CCLabelTTF::labelWithString("Multi touch the screen", "Marker Felt", 36); + label->setPosition(ccp( s.width / 2, s.height - 30)); + this->addChild(label, -1); + + // init physics + initPhysics(); + +#if 1 + // Use batch node. Faster + CCSpriteBatchNode *parent = CCSpriteBatchNode::batchNodeWithFile("Images/grossini_dance_atlas.png", 100); + m_pSpriteTexture = parent->getTexture(); +#else + // doesn't use batch node. Slower + m_pSpriteTexture = CCTextureCache::sharedTextureCache()->addImage("Images/grossini_dance_atlas.png"); + CCNode *parent = CCNode::node(); +#endif + addChild(parent, 0, kTagParentNode); + + addNewSpriteAtPosition(ccp(200,200)); + + scheduleUpdate(); + + return true; } void HelloWorld::onEnter() { - CCLayer::onEnter(); + CCLayer::onEnter(); } -void HelloWorld::step(ccTime delta) +HelloWorld::~HelloWorld() { - int steps = 2; - CGFloat dt = delta/(CGFloat)steps; - - for(int i=0; iactiveShapes, &eachShape, NULL); - cpSpaceHashEach(space->staticShapes, &eachShape, NULL); + // manually Free rogue shapes + for( int i=0;i<4;i++) { + cpShapeFree( m_pWalls[i] ); + } + + cpSpaceFree( m_pSpace ); + } - -void HelloWorld::ccTouchesEnded(CCSet *touches, CCEvent *event) +void HelloWorld::initPhysics() { - CCSetIterator it; - CCTouch *touch; - - for (it = touches->begin(); it != touches->end(); it++) { - touch = (CCTouch*)(*it); - - if (! touch) { - break; - } - - CCPoint location = touch->locationInView(touch->view()); - location = CCDirector::sharedDirector()->convertToGL(location); - addNewSpriteX(location.x, location.y); - } + CCSize s = CCDirector::sharedDirector()->getWinSize(); + + // init chipmunk + cpInitChipmunk(); + + m_pSpace = cpSpaceNew(); + + m_pSpace->gravity = cpv(0, -100); + + // + // rogue shapes + // We have to free them manually + // + // bottom + m_pWalls[0] = cpSegmentShapeNew( m_pSpace->staticBody, cpv(0,0), cpv(s.width,0), 0.0f); + + // top + m_pWalls[1] = cpSegmentShapeNew( m_pSpace->staticBody, cpv(0,s.height), cpv(s.width,s.height), 0.0f); + + // left + m_pWalls[2] = cpSegmentShapeNew( m_pSpace->staticBody, cpv(0,0), cpv(0,s.height), 0.0f); + + // right + m_pWalls[3] = cpSegmentShapeNew( m_pSpace->staticBody, cpv(s.width,0), cpv(s.width,s.height), 0.0f); + + for( int i=0;i<4;i++) { + m_pWalls[i]->e = 1.0f; + m_pWalls[i]->u = 1.0f; + cpSpaceAddStaticShape(m_pSpace, m_pWalls[i] ); + } } +void HelloWorld::update(ccTime delta) +{ + // Should use a fixed size step based on the animation interval. + int steps = 2; + CCFloat dt = CCDirector::sharedDirector()->getAnimationInterval()/(CCFloat)steps; + + for(int i=0; iinitWithTexture(m_pSpriteTexture, CCRectMake(posx, posy, 85, 121)); + sprite->autorelease(); + + parent->addChild(sprite); + + sprite->setPosition(pos); + + int num = 4; + cpVect verts[] = { + cpv(-24,-54), + cpv(-24, 54), + cpv( 24, 54), + cpv( 24,-54), + }; + + cpBody *body = cpBodyNew(1.0f, cpMomentForPoly(1.0f, num, verts, cpvzero)); + + body->p = cpv(pos.x, pos.y); + cpSpaceAddBody(m_pSpace, body); + + cpShape* shape = cpPolyShapeNew(body, num, verts, cpvzero); + shape->e = 0.5f; shape->u = 0.5f; + cpSpaceAddShape(m_pSpace, shape); + + sprite->setPhysicsBody(body); +} + +void HelloWorld::ccTouchesEnded(CCSet* touches, CCEvent* event) +{ + //Add a new body/atlas sprite at the touched location + CCSetIterator it; + CCTouch* touch; + + for( it = touches->begin(); it != touches->end(); it++) + { + touch = (CCTouch*)(*it); + + if(!touch) + break; + + CCPoint location = touch->locationInView(); + + location = CCDirector::sharedDirector()->convertToGL(location); + + addNewSpriteAtPosition( location ); + } +} + +void HelloWorld::didAccelerate(CCAcceleration* pAccelerationValue) +{ + static float prevX=0, prevY=0; + +#define kFilterFactor 0.05f + + float accelX = (float) pAccelerationValue->x * kFilterFactor + (1- kFilterFactor)*prevX; + float accelY = (float) pAccelerationValue->y * kFilterFactor + (1- kFilterFactor)*prevY; + + prevX = accelX; + prevY = accelY; + + CCPoint v = ccp( accelX, accelY); + v = ccpMult(v, 200); + m_pSpace->gravity = cpv(v.x, v.y); +} + + diff --git a/template/xcode4/cocos2dx_chipmunk.xctemplate/Classes/HelloWorldScene.h b/template/xcode4/cocos2dx_chipmunk.xctemplate/Classes/HelloWorldScene.h index 0c5cf16215..7765930ec0 100644 --- a/template/xcode4/cocos2dx_chipmunk.xctemplate/Classes/HelloWorldScene.h +++ b/template/xcode4/cocos2dx_chipmunk.xctemplate/Classes/HelloWorldScene.h @@ -14,23 +14,38 @@ // include Chipmunk headers #include "chipmunk.h" +class ChipmunkPhysicsSprite : public cocos2d::CCSprite +{ +public: + ChipmunkPhysicsSprite(); + virtual ~ChipmunkPhysicsSprite(); + void setPhysicsBody(cpBody* body); + virtual bool isDirty(void); + virtual cocos2d::CCAffineTransform nodeToParentTransform(void); +private: + cpBody* m_pBody; // strong ref +}; + // HelloWorld Layer class HelloWorld : public cocos2d::CCLayer { public: - HelloWorld(); - ~HelloWorld(); - - static cocos2d::CCScene* scene(); - void step(cocos2d::ccTime dt); - void addNewSpriteX(float x, float y); - virtual void onEnter(); - virtual void ccTouchesEnded(cocos2d::CCSet* touches, cocos2d::CCEvent *event); - - LAYER_NODE_FUNC(HelloWorld); + HelloWorld(); + ~HelloWorld(); + + static cocos2d::CCScene* scene(); + LAYER_NODE_FUNC(HelloWorld); + void initPhysics(); + void addNewSpriteAtPosition(CCPoint p); + void update(ccTime dt); + virtual void ccTouchesEnded(CCSet* touches, CCEvent* event); + virtual void didAccelerate(CCAcceleration* pAccelerationValue); + private: - bool init(); - cpSpace *space; + CCTexture2D* m_pSpriteTexture; // weak ref + cpSpace* m_pSpace; // strong ref + cpShape* m_pWalls[4]; + }; #endif // __HELLOW_WORLD_H__ From 77d9b811be6a52a3832c53a8344e29ff0ab94a00 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 2 May 2012 14:06:40 +0800 Subject: [PATCH 11/14] issue #1194: Updated ChipmunkAccelTouchTest. --- .../ChipmunkAccelTouchTest.cpp | 52 +++++++++---------- .../ChipmunkAccelTouchTest.h | 10 ++-- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/tests/tests/ChipmunkAccelTouchTest/ChipmunkAccelTouchTest.cpp b/tests/tests/ChipmunkAccelTouchTest/ChipmunkAccelTouchTest.cpp index b91417fac3..f25ce5b0c9 100644 --- a/tests/tests/ChipmunkAccelTouchTest/ChipmunkAccelTouchTest.cpp +++ b/tests/tests/ChipmunkAccelTouchTest/ChipmunkAccelTouchTest.cpp @@ -17,20 +17,20 @@ void removeShape( cpBody *body, cpShape *shape, void *data ) } ChipmunkPhysicsSprite::ChipmunkPhysicsSprite() -: body_(NULL) +: m_pBody(NULL) { } ChipmunkPhysicsSprite::~ChipmunkPhysicsSprite() { - cpBodyEachShape(body_, removeShape, NULL); - cpBodyFree( body_ ); + cpBodyEachShape(m_pBody, removeShape, NULL); + cpBodyFree( m_pBody ); } void ChipmunkPhysicsSprite::setPhysicsBody(cpBody * body) { - body_ = body; + m_pBody = body; } // this method will only get called if the sprite is batched. @@ -43,8 +43,8 @@ bool ChipmunkPhysicsSprite::isDirty(void) CCAffineTransform ChipmunkPhysicsSprite::nodeToParentTransform(void) { - CCFloat x = body_->p.x; - CCFloat y = body_->p.y; + CCFloat x = m_pBody->p.x; + CCFloat y = m_pBody->p.y; if ( !getIsRelativeAnchorPoint() ) { x += m_tAnchorPointInPoints.x; @@ -52,8 +52,8 @@ CCAffineTransform ChipmunkPhysicsSprite::nodeToParentTransform(void) } // Make matrix - CCFloat c = body_->rot.x; - CCFloat s = body_->rot.y; + CCFloat c = m_pBody->rot.x; + CCFloat s = m_pBody->rot.y; if( ! CCPoint::CCPointEqualToPoint(m_tAnchorPointInPoints, CCPointZero) ){ x += c*-m_tAnchorPointInPoints.x + -s*-m_tAnchorPointInPoints.y; @@ -90,10 +90,10 @@ ChipmunkAccelTouchTestLayer::ChipmunkAccelTouchTestLayer() #if 1 // Use batch node. Faster CCSpriteBatchNode *parent = CCSpriteBatchNode::batchNodeWithFile("Images/grossini_dance_atlas.png", 100); - spriteTexture_ = parent->getTexture(); + m_pSpriteTexture = parent->getTexture(); #else // doesn't use batch node. Slower - spriteTexture_ = CCTextureCache::sharedTextureCache()->addImage("Images/grossini_dance_atlas.png"); + m_pSpriteTexture = CCTextureCache::sharedTextureCache()->addImage("Images/grossini_dance_atlas.png"); CCNode *parent = CCNode::node(); #endif addChild(parent, 0, kTagParentNode); @@ -107,10 +107,10 @@ ChipmunkAccelTouchTestLayer::~ChipmunkAccelTouchTestLayer() { // manually Free rogue shapes for( int i=0;i<4;i++) { - cpShapeFree( walls_[i] ); + cpShapeFree( m_pWalls[i] ); } - cpSpaceFree( space_ ); + cpSpaceFree( m_pSpace ); } @@ -121,30 +121,30 @@ void ChipmunkAccelTouchTestLayer::initPhysics() // init chipmunk cpInitChipmunk(); - space_ = cpSpaceNew(); + m_pSpace = cpSpaceNew(); - space_->gravity = cpv(0, -100); + m_pSpace->gravity = cpv(0, -100); // // rogue shapes // We have to free them manually // // bottom - walls_[0] = cpSegmentShapeNew( space_->staticBody, cpv(0,0), cpv(s.width,0), 0.0f); + m_pWalls[0] = cpSegmentShapeNew( m_pSpace->staticBody, cpv(0,0), cpv(s.width,0), 0.0f); // top - walls_[1] = cpSegmentShapeNew( space_->staticBody, cpv(0,s.height), cpv(s.width,s.height), 0.0f); + m_pWalls[1] = cpSegmentShapeNew( m_pSpace->staticBody, cpv(0,s.height), cpv(s.width,s.height), 0.0f); // left - walls_[2] = cpSegmentShapeNew( space_->staticBody, cpv(0,0), cpv(0,s.height), 0.0f); + m_pWalls[2] = cpSegmentShapeNew( m_pSpace->staticBody, cpv(0,0), cpv(0,s.height), 0.0f); // right - walls_[3] = cpSegmentShapeNew( space_->staticBody, cpv(s.width,0), cpv(s.width,s.height), 0.0f); + m_pWalls[3] = cpSegmentShapeNew( m_pSpace->staticBody, cpv(s.width,0), cpv(s.width,s.height), 0.0f); for( int i=0;i<4;i++) { - walls_[i]->e = 1.0f; - walls_[i]->u = 1.0f; - cpSpaceAddStaticShape(space_, walls_[i] ); + m_pWalls[i]->e = 1.0f; + m_pWalls[i]->u = 1.0f; + cpSpaceAddStaticShape(m_pSpace, m_pWalls[i] ); } } @@ -155,7 +155,7 @@ void ChipmunkAccelTouchTestLayer::update(ccTime delta) CCFloat dt = CCDirector::sharedDirector()->getAnimationInterval()/(CCFloat)steps; for(int i=0; iinitWithTexture(spriteTexture_, CCRectMake(posx, posy, 85, 121)); + sprite->initWithTexture(m_pSpriteTexture, CCRectMake(posx, posy, 85, 121)); sprite->autorelease(); parent->addChild(sprite); @@ -212,11 +212,11 @@ void ChipmunkAccelTouchTestLayer::addNewSpriteAtPosition(CCPoint pos) cpBody *body = cpBodyNew(1.0f, cpMomentForPoly(1.0f, num, verts, cpvzero)); body->p = cpv(pos.x, pos.y); - cpSpaceAddBody(space_, body); + cpSpaceAddBody(m_pSpace, body); cpShape* shape = cpPolyShapeNew(body, num, verts, cpvzero); shape->e = 0.5f; shape->u = 0.5f; - cpSpaceAddShape(space_, shape); + cpSpaceAddShape(m_pSpace, shape); sprite->setPhysicsBody(body); } @@ -261,7 +261,7 @@ void ChipmunkAccelTouchTestLayer::didAccelerate(CCAcceleration* pAccelerationVal CCPoint v = ccp( accelX, accelY); v = ccpMult(v, 200); - space_->gravity = cpv(v.x, v.y); + m_pSpace->gravity = cpv(v.x, v.y); } void ChipmunkAccelTouchTestScene::runThisTest() diff --git a/tests/tests/ChipmunkAccelTouchTest/ChipmunkAccelTouchTest.h b/tests/tests/ChipmunkAccelTouchTest/ChipmunkAccelTouchTest.h index 5614b7df78..51a24c2a28 100644 --- a/tests/tests/ChipmunkAccelTouchTest/ChipmunkAccelTouchTest.h +++ b/tests/tests/ChipmunkAccelTouchTest/ChipmunkAccelTouchTest.h @@ -22,11 +22,11 @@ public: void update(ccTime dt); virtual void ccTouchesEnded(CCSet* touches, CCEvent* event); virtual void didAccelerate(CCAcceleration* pAccelerationValue); - CCTexture2D *spriteTexture_; // weak ref - cpSpace *space_; // strong ref - - cpShape *walls_[4]; +private: + CCTexture2D* m_pSpriteTexture; // weak ref + cpSpace* m_pSpace; // strong ref + cpShape* m_pWalls[4]; }; class ChipmunkPhysicsSprite : public CCSprite @@ -38,7 +38,7 @@ public: virtual bool isDirty(void); virtual CCAffineTransform nodeToParentTransform(void); private: - cpBody *body_; // strong ref + cpBody* m_pBody; // strong ref }; class ChipmunkAccelTouchTestScene : public TestScene From 99bc442dade86b5b425d0dabcf61610b8e326ba9 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 2 May 2012 14:17:14 +0800 Subject: [PATCH 12/14] #issue #1194: Updated chipmuck template for ios platform. --- .../Classes/HelloWorldScene.cpp | 24 +++++++------------ .../Classes/HelloWorldScene.h | 12 +++++----- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/template/xcode4/cocos2dx_chipmunk.xctemplate/Classes/HelloWorldScene.cpp b/template/xcode4/cocos2dx_chipmunk.xctemplate/Classes/HelloWorldScene.cpp index f733db3937..7798090d26 100644 --- a/template/xcode4/cocos2dx_chipmunk.xctemplate/Classes/HelloWorldScene.cpp +++ b/template/xcode4/cocos2dx_chipmunk.xctemplate/Classes/HelloWorldScene.cpp @@ -81,6 +81,13 @@ HelloWorld::HelloWorld() HelloWorld::~HelloWorld() { + // manually Free rogue shapes + for( int i=0;i<4;i++) { + cpShapeFree( m_pWalls[i] ); + } + + cpSpaceFree( m_pSpace ); + } CCScene* HelloWorld::scene() @@ -121,7 +128,7 @@ bool HelloWorld::init() #if 1 // Use batch node. Faster - CCSpriteBatchNode *parent = CCSpriteBatchNode::batchNodeWithFile("Images/grossini_dance_atlas.png", 100); + CCSpriteBatchNode *parent = CCSpriteBatchNode::batchNodeWithFile("grossini_dance_atlas.png", 100); m_pSpriteTexture = parent->getTexture(); #else // doesn't use batch node. Slower @@ -137,21 +144,6 @@ bool HelloWorld::init() return true; } -void HelloWorld::onEnter() -{ - CCLayer::onEnter(); -} - -HelloWorld::~HelloWorld() -{ - // manually Free rogue shapes - for( int i=0;i<4;i++) { - cpShapeFree( m_pWalls[i] ); - } - - cpSpaceFree( m_pSpace ); - -} void HelloWorld::initPhysics() { diff --git a/template/xcode4/cocos2dx_chipmunk.xctemplate/Classes/HelloWorldScene.h b/template/xcode4/cocos2dx_chipmunk.xctemplate/Classes/HelloWorldScene.h index 7765930ec0..a32ab05ff7 100644 --- a/template/xcode4/cocos2dx_chipmunk.xctemplate/Classes/HelloWorldScene.h +++ b/template/xcode4/cocos2dx_chipmunk.xctemplate/Classes/HelloWorldScene.h @@ -31,18 +31,18 @@ class HelloWorld : public cocos2d::CCLayer { public: HelloWorld(); ~HelloWorld(); - + bool init(); static cocos2d::CCScene* scene(); LAYER_NODE_FUNC(HelloWorld); void initPhysics(); - void addNewSpriteAtPosition(CCPoint p); - void update(ccTime dt); - virtual void ccTouchesEnded(CCSet* touches, CCEvent* event); - virtual void didAccelerate(CCAcceleration* pAccelerationValue); + void addNewSpriteAtPosition(cocos2d::CCPoint p); + void update(cocos2d::ccTime dt); + virtual void ccTouchesEnded(cocos2d::CCSet* touches, cocos2d::CCEvent* event); + virtual void didAccelerate(cocos2d::CCAcceleration* pAccelerationValue); private: - CCTexture2D* m_pSpriteTexture; // weak ref + cocos2d::CCTexture2D* m_pSpriteTexture; // weak ref cpSpace* m_pSpace; // strong ref cpShape* m_pWalls[4]; From 547bd6910d48a2b669d513d7d92e8cc33bf402d0 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 2 May 2012 14:29:36 +0800 Subject: [PATCH 13/14] fixed #1194: Updated ios template. --- .../Classes/AppDelegate.cpp | 1 + .../cocos2dx_lua.xctemplate/Resources/hello.lua | 16 +++++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/template/xcode4/cocos2dx_lua.xctemplate/Classes/AppDelegate.cpp b/template/xcode4/cocos2dx_lua.xctemplate/Classes/AppDelegate.cpp index 3eec69f5e6..e3e1bb345f 100644 --- a/template/xcode4/cocos2dx_lua.xctemplate/Classes/AppDelegate.cpp +++ b/template/xcode4/cocos2dx_lua.xctemplate/Classes/AppDelegate.cpp @@ -19,6 +19,7 @@ #endif USING_NS_CC; +using namespace std; using namespace CocosDenshion; AppDelegate::AppDelegate() diff --git a/template/xcode4/cocos2dx_lua.xctemplate/Resources/hello.lua b/template/xcode4/cocos2dx_lua.xctemplate/Resources/hello.lua index 7126baced9..3fa0545712 100644 --- a/template/xcode4/cocos2dx_lua.xctemplate/Resources/hello.lua +++ b/template/xcode4/cocos2dx_lua.xctemplate/Resources/hello.lua @@ -30,12 +30,13 @@ local function creatDog() spriteDog.isPaused = false spriteDog:setPosition(0, winSize.height / 4 * 3) - local animFrames = CCMutableArray_CCSpriteFrame__:new(2) + local animFrames = CCArray:arrayWithCapacity(2) + animFrames:addObject(frame0) animFrames:addObject(frame1) - local animation = CCAnimation:animationWithFrames(animFrames, 0.5) - local animate = CCAnimate:actionWithAnimation(animation, false); + local animation = CCAnimation:animationWithSpriteFrames(animFrames, 0.5) + local animate = CCAnimate:actionWithAnimation(animation); spriteDog:runAction(CCRepeatForever:actionWithAction(animate)) -- moving dog at every frame @@ -47,10 +48,11 @@ local function creatDog() else x = x + 1 end + spriteDog:setPositionX(x) end - CCScheduler:sharedScheduler():scheduleScriptFunc(tick, 0, false) + CCDirector:sharedDirector():getScheduler():scheduleScriptFunc(tick, 0, false) return spriteDog end @@ -110,7 +112,7 @@ local function createLayerFram() end local function onTouchEnded(x, y) - cclog("onTouchEnded") + cclog("onTouchEnded: %0.2f, %0.2f", x, y) touchBeginPoint = nil spriteDog.isPaused = false end @@ -151,7 +153,7 @@ local function createLayerMenu() end -- add a popup menu - local menuPopupItem = CCMenuItemImage:itemFromNormalImage("menu2.png", "menu2.png") + local menuPopupItem = CCMenuItemImage:itemWithNormalImage("menu2.png", "menu2.png") menuPopupItem:setPosition(0, 0) menuPopupItem:registerScriptHandler(menuCallbackClosePopup) menuPopup = CCMenu:menuWithItem(menuPopupItem) @@ -160,7 +162,7 @@ local function createLayerMenu() layerMenu:addChild(menuPopup) -- add the left-bottom "tools" menu to invoke menuPopup - local menuToolsItem = CCMenuItemImage:itemFromNormalImage("menu1.png", "menu1.png") + local menuToolsItem = CCMenuItemImage:itemWithNormalImage("menu1.png", "menu1.png") menuToolsItem:setPosition(0, 0) menuToolsItem:registerScriptHandler(menuCallbackOpenPopup) menuTools = CCMenu:menuWithItem(menuToolsItem) From a666dc7edbabcc28c76f3a87a2870b70e69ee6cd Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 2 May 2012 14:31:46 +0800 Subject: [PATCH 14/14] fixed #1194: Updated template file -- cocos2d_chipmunk.xctemplate/Classes/HelloWorldScene.cpp. --- .../cocos2dx_chipmunk.xctemplate/Classes/HelloWorldScene.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template/xcode4/cocos2dx_chipmunk.xctemplate/Classes/HelloWorldScene.cpp b/template/xcode4/cocos2dx_chipmunk.xctemplate/Classes/HelloWorldScene.cpp index 7798090d26..4ed0410564 100644 --- a/template/xcode4/cocos2dx_chipmunk.xctemplate/Classes/HelloWorldScene.cpp +++ b/template/xcode4/cocos2dx_chipmunk.xctemplate/Classes/HelloWorldScene.cpp @@ -132,7 +132,7 @@ bool HelloWorld::init() m_pSpriteTexture = parent->getTexture(); #else // doesn't use batch node. Slower - m_pSpriteTexture = CCTextureCache::sharedTextureCache()->addImage("Images/grossini_dance_atlas.png"); + m_pSpriteTexture = CCTextureCache::sharedTextureCache()->addImage("grossini_dance_atlas.png"); CCNode *parent = CCNode::node(); #endif addChild(parent, 0, kTagParentNode);