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