issue #1194: Added extension namespace, all extension classes are in cocos2d::extension namespace, added CCTextureWatcher and CCListView.

This commit is contained in:
James Chen 2012-04-27 18:47:49 +08:00
parent fd08f9852b
commit c5f7f15090
50 changed files with 944 additions and 854 deletions

View File

@ -41,7 +41,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="&quot;$(SolutionDir)cocos2dx1&quot;;&quot;$(SolutionDir)cocos2dx\actions&quot;;&quot;$(SolutionDir)cocos2dx\base_nodes&quot;;&quot;$(SolutionDir)cocos2dx\cocoa&quot;;&quot;$(SolutionDir)cocos2dx\effects&quot;;&quot;$(SolutionDir)cocos2dx\include&quot;;&quot;$(SolutionDir)cocos2dx\kazmath\include&quot;;&quot;$(SolutionDir)cocos2dx\keypad_dispatcher&quot;;&quot;$(SolutionDir)cocos2dx\label_nodes&quot;;&quot;$(SolutionDir)cocos2dx\layers_scenes_transitions_nodes&quot;;&quot;$(SolutionDir)cocos2dx\menu_nodes&quot;;&quot;$(SolutionDir)cocos2dx\misc_nodes&quot;;&quot;$(SolutionDir)cocos2dx\particle_nodes&quot;;&quot;$(SolutionDir)cocos2dx\script_support&quot;;&quot;$(SolutionDir)cocos2dx\shaders&quot;;&quot;$(SolutionDir)cocos2dx\sprite_nodes&quot;;&quot;$(SolutionDir)cocos2dx\support&quot;;&quot;$(SolutionDir)cocos2dx\text_input_node&quot;;&quot;$(SolutionDir)cocos2dx\textures&quot;;&quot;$(SolutionDir)cocos2dx\tileMap_parallax_nodes&quot;;&quot;$(SolutionDir)cocos2dx\touch_dispatcher&quot;;&quot;$(SolutionDir)cocos2dx\platform&quot;;&quot;$(SolutionDir)cocos2dx\platform\win32&quot;;&quot;$(SolutionDir)cocos2dx\platform\third_party\win32\OGLES&quot;;..\Classes"
AdditionalIncludeDirectories="&quot;$(SolutionDir)cocos2dx&quot;;&quot;$(SolutionDir)cocos2dx\actions&quot;;&quot;$(SolutionDir)cocos2dx\base_nodes&quot;;&quot;$(SolutionDir)cocos2dx\cocoa&quot;;&quot;$(SolutionDir)cocos2dx\effects&quot;;&quot;$(SolutionDir)cocos2dx\include&quot;;&quot;$(SolutionDir)cocos2dx\kazmath\include&quot;;&quot;$(SolutionDir)cocos2dx\keypad_dispatcher&quot;;&quot;$(SolutionDir)cocos2dx\label_nodes&quot;;&quot;$(SolutionDir)cocos2dx\layers_scenes_transitions_nodes&quot;;&quot;$(SolutionDir)cocos2dx\menu_nodes&quot;;&quot;$(SolutionDir)cocos2dx\misc_nodes&quot;;&quot;$(SolutionDir)cocos2dx\particle_nodes&quot;;&quot;$(SolutionDir)cocos2dx\script_support&quot;;&quot;$(SolutionDir)cocos2dx\shaders&quot;;&quot;$(SolutionDir)cocos2dx\sprite_nodes&quot;;&quot;$(SolutionDir)cocos2dx\support&quot;;&quot;$(SolutionDir)cocos2dx\text_input_node&quot;;&quot;$(SolutionDir)cocos2dx\textures&quot;;&quot;$(SolutionDir)cocos2dx\tileMap_parallax_nodes&quot;;&quot;$(SolutionDir)cocos2dx\touch_dispatcher&quot;;&quot;$(SolutionDir)cocos2dx\platform&quot;;&quot;$(SolutionDir)cocos2dx\platform\win32&quot;;&quot;$(SolutionDir)cocos2dx\platform\third_party\win32\OGLES&quot;;..\Classes"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
MinimalRebuild="true"
BasicRuntimeChecks="3"

View File

@ -36,7 +36,7 @@ THE SOFTWARE.
#include "CCTransition.h"
#include "CCSpriteFrameCache.h"
#include "CCAutoreleasePool.h"
#include "platform/platform.h"
#include "platform.h"
#include "CCApplication.h"
#include "CCLabelBMFont.h"
#include "CCActionManager.h"
@ -47,17 +47,17 @@ THE SOFTWARE.
#include "CCAnimationCache.h"
#include "CCTouch.h"
#include "CCUserDefault.h"
#include "extensions/CCNotificationCenter/CCNotificationCenter.h"
#include "ccGLStateCache.h"
#include "CCShaderCache.h"
#include "kazmath/kazmath.h"
#include "kazmath/GL/matrix.h"
#include "support/CCProfiling.h"
#include "CCEGLView.h"
#include "extensions/CCNotificationCenter/CCNotificationCenter.h"
#include "extensions/CCTextureWatcher/CCTextureWatcher.h"
#include <string>
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

View File

@ -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;
};
/**

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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__ */

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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__

View File

@ -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

View File

@ -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

View File

@ -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__ */

View File

@ -0,0 +1,188 @@
#ifndef __CC_LIST_VIEW_H__
#define __CC_LIST_VIEW_H__
#include <time.h>
#include "platform.h"
#include <vector>
#include <string>
//#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<CCListViewDelegate*>(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__

View File

@ -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
NS_CC_EXT_END

View File

@ -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 <map>
#include <list>
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_
#endif // __CC_LIST_VIEW_CELL_H_

View File

@ -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

View File

@ -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__

View File

@ -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<std::string> keys = m_pTextures->allKeys();
std::vector<std::string>::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
NS_CC_EXT_END

View File

@ -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

View File

@ -1,154 +0,0 @@
#ifndef __ND_LIST_VIEW_H__
#define __ND_LIST_VIEW_H__
#include <time.h>
#include "platform.h"
#include <vector>
#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__

View File

@ -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

View File

@ -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__ */

View File

@ -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

View File

@ -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.

View File

@ -1196,30 +1196,38 @@
</File>
</Filter>
<Filter
Name="TextureWatcher"
Name="CCTextureWatcher"
>
<File
RelativePath="..\extensions\TextureWatcher\NdListView.cpp"
RelativePath="..\extensions\CCTextureWatcher\CCTextureWatcher.cpp"
>
</File>
<File
RelativePath="..\extensions\TextureWatcher\NdListView.h"
RelativePath="..\extensions\CCTextureWatcher\CCTextureWatcher.h"
>
</File>
</Filter>
<Filter
Name="CCListView"
>
<File
RelativePath="..\extensions\CCListView\CCControlDefine.h"
>
</File>
<File
RelativePath="..\extensions\TextureWatcher\NdListViewCell.cpp"
RelativePath="..\extensions\CCListView\CCListView.cpp"
>
</File>
<File
RelativePath="..\extensions\TextureWatcher\NdListViewCell.h"
RelativePath="..\extensions\CCListView\CCListView.h"
>
</File>
<File
RelativePath="..\extensions\TextureWatcher\NdTextureWatcher.cpp"
RelativePath="..\extensions\CCListView\CCListViewCell.cpp"
>
</File>
<File
RelativePath="..\extensions\TextureWatcher\NdTextureWatcher.h"
RelativePath="..\extensions\CCListView\CCListViewCell.h"
>
</File>
</Filter>

View File

@ -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);

View File

@ -194,6 +194,17 @@ const char* CCTextureCache::description()
return CCString::stringWithFormat("<CCTextureCache | Number of textures = %u>", 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");

View File

@ -65,6 +65,8 @@ public:
const char* description(void);
CCDictionary* snapshotTextures();
/** Retruns ths shared instance of the cache */
static CCTextureCache * sharedTextureCache();

View File

@ -30,7 +30,7 @@
#include "cocos2dExt.h"
USING_NS_CC;
USING_NS_CC_EXT;
#define CONTROL_SCENE_NODE_FUNC(controlScene) \
public: \

View File

@ -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;
}

View File

@ -3,7 +3,6 @@
#include "cocos2d.h"
#include "../testBasic.h"
//#import "cocos2d.h"
class SchedulerTestLayer : public CCLayer

View File

@ -166,6 +166,7 @@ TestController::TestController()
setIsTouchEnabled(true);
addChild(pMenu, 1);
}
TestController::~TestController()

View File

@ -3,7 +3,8 @@
#include "cocos2d.h"
using namespace cocos2d;
USING_NS_CC;
USING_NS_CC_EXT;
using namespace std;
class TestScene : public CCScene