code:
/****************************************************************************
Copyright (c) 2010 cocos2d-x.org

http://www.cocos2d-x.org

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/

#ifndef __CC_APPLICATION_H__
#define __CC_APPLICATION_H__

#include "platform/CCApplication_platform.h"

#endif	// __CC_APPLICATION_H__


code:
/****************************************************************************
Copyright (c) 2010 ForzeField Studios S.L. http://forzefield.com
Copyright (c) 2010 cocos2d-x.org

http://www.cocos2d-x.org

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CCARRAY_H__
#define __CCARRAY_H__

#include "support/data_support/ccCArray.h"

/** @def CCARRAY_FOREACH
A convience macro to iterate over a CCArray using. It is faster than the "fast enumeration" interface.
@since v0.99.4
*/

/*
In cocos2d-iphone 1.0.0, This macro have been update to like this:

#define CCARRAY_FOREACH(__array__, __object__)												\
if (__array__ && __array__->data->num > 0)													\
for(id *__arr__ = __array__->data->arr, *end = __array__->data->arr + __array__->data->num-1;	\
__arr__ <= end && ((__object__ = *__arr__) != nil || true);										\
__arr__++)

I found that it's not work in C++. So it keep what it's look like in version 1.0.0-rc3. ---By Bin
*/
#define CCARRAY_FOREACH(__array__, __object__)												\
    if (__array__ && __array__->data->num > 0)													\
    for(CCObject** arr = __array__->data->arr, **end = __array__->data->arr + __array__->data->num-1;	\
    arr <= end && ((__object__ = *arr) != NULL/* || true*/);										\
    arr++)

namespace cocos2d
{

class CC_DLL CCArray : public CCObject
{
public:
    ~CCArray();
	/** Create an array */
    static CCArray* array();
	/** Create an array with capacity */
    static CCArray* arrayWithCapacity(unsigned int capacity);
	/** Create an array with an existing array */
    static CCArray* arrayWithArray(CCArray* otherArray);

	/** Initializes an array */
    bool init();
	/** Initializes an array with capacity */
    bool initWithCapacity(unsigned int capacity);
	/** Initializes an array with an existing array */
    bool initWithArray(CCArray* otherArray);

    // Querying an Array

	/** Returns element count of the array */
    unsigned int count();
	/** Returns capacity of the array */
    unsigned int capacity();
	/** Returns index of a certain object, return UINT_MAX if doesn't contain the object */
    unsigned int indexOfObject(CCObject* object);
	/** Returns an element with a certain index */
    CCObject* objectAtIndex(unsigned int index);
	/** Returns last element */
    CCObject* lastObject();
	/** Returns a random element */
    CCObject* randomObject();
	/** Returns a Boolean value that indicates whether object is present in array. */
    bool containsObject(CCObject* object);

    // Adding Objects

	/** Add a certain object */
    void addObject(CCObject* object);
	/** Add all elements of an existing array */
    void addObjectsFromArray(CCArray* otherArray);
	/** Insert a certain object at a certain index */
    void insertObject(CCObject* object, unsigned int index);

    // Removing Objects

	/** Remove last object */
    void removeLastObject();
	/** Remove a certain object */
    void removeObject(CCObject* object);
	/** Remove an element with a certain index */
    void removeObjectAtIndex(unsigned int index);
	/** Remove all elements */
    void removeObjectsInArray(CCArray* otherArray);
	/** Remove all objects */
    void removeAllObjects();
	/** Fast way to remove a certain object */
    void fastRemoveObject(CCObject* object);
	/** Fast way to remove an element with a certain index */
    void fastRemoveObjectAtIndex(unsigned int index);

    // Rearranging Content

	/** Swap two elements */
    void exchangeObject(CCObject* object1, CCObject* object2);
	/** Swap two elements with certain indexes */
    void exchangeObjectAtIndex(unsigned int index1, unsigned int index2);
	/** Revers the array */
    void reverseObjects();
	/* Shrinks the array so the memory footprint corresponds with the number of items */
    void reduceMemoryFootprint();

public:
    ccArray* data;

private:
	CCArray() : data(NULL) {};
};

}

#endif // __CCARRAY_H__

license: mit


code:
/****************************************************************************
Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2008-2010 Ricardo Quesada
Copyright (c) 2011      Zynga Inc.

http://www.cocos2d-x.org

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/

#ifndef __CCATLAS_NODE_H__
#define __CCATLAS_NODE_H__

#include "CCNode.h"
#include "CCProtocols.h"
#include "ccTypes.h"

namespace   cocos2d {
class CCTextureAtlas;

/** @brief CCAtlasNode is a subclass of CCNode that implements the CCRGBAProtocol and
CCTextureProtocol protocol

It knows how to render a TextureAtlas object.
If you are going to render a TextureAtlas consider subclassing CCAtlasNode (or a subclass of CCAtlasNode)

All features from CCNode are valid, plus the following features:
- opacity and RGB colors
*/
class CC_DLL CCAtlasNode : public CCNode, public CCRGBAProtocol, public CCTextureProtocol
{
protected:

	//! chars per row
	unsigned int m_uItemsPerRow;
	//! chars per column
	unsigned int m_uItemsPerColumn;

	//! width of each char
	unsigned int	m_uItemWidth;
	//! height of each char
	unsigned int	m_uItemHeight;

	ccColor3B	m_tColorUnmodified;

	CC_PROPERTY(CCTextureAtlas*, m_pTextureAtlas, TextureAtlas);

	// protocol variables
	CC_PROPERTY(bool, m_bIsOpacityModifyRGB, IsOpacityModifyRGB)
	CC_PROPERTY(ccBlendFunc, m_tBlendFunc, BlendFunc);
	CC_PROPERTY(GLubyte, m_cOpacity, Opacity);
	CC_PROPERTY_PASS_BY_REF(ccColor3B, m_tColor, Color);

	// quads to draw
	CC_PROPERTY(unsigned int, m_uQuadsToDraw, QuadsToDraw);

public:
	CCAtlasNode();
	virtual ~CCAtlasNode();

	/** creates a CCAtlasNode  with an Atlas file the width and height of each item and the quantity of items to render*/
	static CCAtlasNode * atlasWithTileFile(const char* tile,unsigned int tileWidth, unsigned int tileHeight,
		unsigned int itemsToRender);

	/** initializes an CCAtlasNode  with an Atlas file the width and height of each item and the quantity of items to render*/
	bool initWithTileFile(const char* tile, unsigned int tileWidth, unsigned int tileHeight, unsigned int itemsToRender);

	/** updates the Atlas (indexed vertex array).
	* Shall be overriden in subclasses
	*/
	virtual void updateAtlasValues();

	virtual void draw();

	// CC Texture protocol

	/** returns the used texture*/
	virtual CCTexture2D* getTexture(void);

	/** sets a new texture. it will be retained*/
	virtual void setTexture(CCTexture2D *texture);

private :
	void calculateMaxItems();
	void updateBlendFunc();
	void updateOpacityModifyRGB();

};
}//namespace   cocos2d

#endif // __CCATLAS_NODE_H__


code:
/****************************************************************************
Copyright (c) 2010 cocos2d-x.org

http://www.cocos2d-x.org

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __AUTORELEASEPOOL_H__
#define __AUTORELEASEPOOL_H__

#include "CCObject.h"
#include "CCMutableArray.h"

namespace cocos2d {
class CC_DLL CCAutoreleasePool : public CCObject
{
	CCMutableArray<CCObject*>*	m_pManagedObjectArray;
public:
	CCAutoreleasePool(void);
	~CCAutoreleasePool(void);

	void addObject(CCObject *pObject);
	void removeObject(CCObject *pObject);

	void clear();
};

class CC_DLL CCPoolManager
{
	CCMutableArray<CCAutoreleasePool*>*	m_pReleasePoolStack;
	CCAutoreleasePool*					m_pCurReleasePool;

	CCAutoreleasePool* getCurReleasePool();
public:
	CCPoolManager();
	~CCPoolManager();
	void finalize();
	void push();
	void pop();

	void removeObject(CCObject* pObject);
	void addObject(CCObject* pObject);

	static CCPoolManager* getInstance();

	friend class CCAutoreleasePool;
};

}

#endif //__AUTORELEASEPOOL_H__


code:
/****************************************************************************
Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2008-2010 Ricardo Quesada
Copyright (c) 2011      Zynga Inc.

http://www.cocos2d-x.org

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/

#ifndef __CCCAMERA_H__
#define __CCCAMERA_H__

#include "CCObject.h"
#include "ccMacros.h"
#include <string>
namespace   cocos2d {
	/**
	A CCCamera is used in every CCNode.
	Useful to look at the object from different views.
	The OpenGL gluLookAt() function is used to locate the
	camera.

	If the object is transformed by any of the scale, rotation or
	position attributes, then they will override the camera.

	IMPORTANT: Either your use the camera or the rotation/scale/position properties. You can't use both.
	World coordinates won't work if you use the camera.

	Limitations:

	- Some nodes, like CCParallaxNode, CCParticle uses world node coordinates, and they won't work properly if you move them (or any of their ancestors)
	using the camera.

	- It doesn't work on batched nodes like CCSprite objects when they are parented to a CCSpriteBatchNode object.

	- It is recommended to use it ONLY if you are going to create 3D effects. For 2D effecs, use the action CCFollow or position/scale/rotate.

	*/
	class CC_DLL CCCamera : public CCObject
	{
	protected:
		float m_fEyeX;
		float m_fEyeY;
		float m_fEyeZ;

		float m_fCenterX;
		float m_fCenterY;
		float m_fCenterZ;

		float m_fUpX;
		float m_fUpY;
		float m_fUpZ;

		bool m_bDirty;
	public:
		CCCamera(void);
		~CCCamera(void);

		void init(void);

		char * description(void);

		/** sets the dirty value */
		inline void setDirty(bool bValue) { m_bDirty = bValue; }
		/** get the dirty value */
		inline bool getDirty(void) { return m_bDirty; }

		/** sets the camera in the default position */
		void restore(void);
		/** Sets the camera using gluLookAt using its eye, center and up_vector */
		void locate(void);
		/** sets the eye values in points */
		void setEyeXYZ(float fEyeX, float fEyeY, float fEyeZ);
		/** sets the center values in points */
		void setCenterXYZ(float fCenterX, float fCenterY, float fCenterZ);
		/** sets the up values */
		void setUpXYZ(float fUpX, float fUpY, float fUpZ);

		/** get the eye vector values in points */
		void getEyeXYZ(float *pEyeX, float *pEyeY, float *pEyeZ);
		/** get the center vector values int points */
		void getCenterXYZ(float *pCenterX, float *pCenterY, float *pCenterZ);
		/** get the up vector values */
		void getUpXYZ(float *pUpX, float *pUpY, float *pUpZ);
	public:
		/** returns the Z eye */
		static float getZEye();

	private:
		DISALLOW_COPY_AND_ASSIGN(CCCamera);
	};

}//namespace   cocos2d

#endif // __CCCAMERA_H__


code:
/****************************************************************************
Copyright (c) 2010 cocos2d-x.org

http://www.cocos2d-x.org

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/

#ifndef __CCDATA_H__
#define __CCDATA_H__

#include "CCObject.h"
#include <string>

namespace   cocos2d {

class CCData : public CCObject
{
public:
	CCData(void);
	~CCData(void);

	void* bytes(void);

public:
	static CCData* dataWithBytes(unsigned char *pBytes, int size);
	static CCData* dataWithContentsOfFile(const std::string &strPath);

private:
	char *m_pData;
};
}//namespace   cocos2d

#endif //__CCDATA_H__


code:
/****************************************************************************
Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2008-2010 Ricardo Quesada
Copyright (c) 2011      Zynga Inc.

http://www.cocos2d-x.org

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/

#ifndef __CCDIRECTOR_H__
#define __CCDIRECTOR_H__

#include "platform/CCPlatformMacros.h"
#include "CCObject.h"
#include "ccTypes.h"
#include "CCGeometry.h"
#include "CCMutableArray.h"
#include "CCGeometry.h"
#include "CCEGLView.h"
#include "CCGL.h"

namespace   cocos2d {

/** @typedef ccDirectorProjection
 Possible OpenGL projections used by director
 */
typedef enum {
	/// sets a 2D projection (orthogonal projection)
	kCCDirectorProjection2D,

	/// sets a 3D projection with a fovy=60, znear=0.5f and zfar=1500.
	kCCDirectorProjection3D,

	/// it calls "updateProjection" on the projection delegate.
	kCCDirectorProjectionCustom,

	/// Detault projection is 3D projection
	kCCDirectorProjectionDefault = kCCDirectorProjection3D,

	// backward compatibility stuff
	CCDirectorProjection2D = kCCDirectorProjection2D,
	CCDirectorProjection3D = kCCDirectorProjection3D,
	CCDirectorProjectionCustom = kCCDirectorProjectionCustom,
} ccDirectorProjection;

/** @typedef ccDirectorType
 Possible Director Types.
 @since v0.8.2
 */
typedef enum {
	/** Will use a Director that triggers the main loop from an NSTimer object
	 *
	 * Features and Limitations:
	 * - Integrates OK with UIKit objects
	 * - It the slowest director
	 * - The interval update is customizable from 1 to 60
	 */
	kCCDirectorTypeNSTimer,

	/** will use a Director that triggers the main loop from a custom main loop.
	 *
	 * Features and Limitations:
	 * - Faster than NSTimer Director
	 * - It doesn't integrate well with UIKit objects
	 * - The interval update can't be customizable
	 */
	kCCDirectorTypeMainLoop,

	/** Will use a Director that triggers the main loop from a thread, but the main loop will be executed on the main thread.
	 *
	 * Features and Limitations:
	 * - Faster than NSTimer Director
	 * - It doesn't integrate well with UIKit objects
	 * - The interval update can't be customizable
	 */
	kCCDirectorTypeThreadMainLoop,

	/** Will use a Director that synchronizes timers with the refresh rate of the display.
	 *
	 * Features and Limitations:
	 * - Faster than NSTimer Director
	 * - Only available on 3.1+
	 * - Scheduled timers & drawing are synchronizes with the refresh rate of the display
	 * - Integrates OK with UIKit objects
	 * - The interval update can be 1/60, 1/30, 1/15
	 */
	kCCDirectorTypeDisplayLink,

	/** Default director is the NSTimer directory */
	kCCDirectorTypeDefault = kCCDirectorTypeNSTimer,

	// backward compatibility stuff
	CCDirectorTypeNSTimer = kCCDirectorTypeNSTimer,
	CCDirectorTypeMainLoop = kCCDirectorTypeMainLoop,
	CCDirectorTypeThreadMainLoop = kCCDirectorTypeThreadMainLoop,
	CCDirectorTypeDisplayLink = kCCDirectorTypeDisplayLink,
	CCDirectorTypeDefault =kCCDirectorTypeDefault,
} ccDirectorType;

/** @typedef ccDeviceOrientation
 Possible device orientations
 */
typedef enum {
	/// Device oriented vertically, home button on the bottom
	kCCDeviceOrientationPortrait = 0, // UIDeviceOrientationPortrait,
	/// Device oriented vertically, home button on the top
    kCCDeviceOrientationPortraitUpsideDown = 1, // UIDeviceOrientationPortraitUpsideDown,
	/// Device oriented horizontally, home button on the right
    kCCDeviceOrientationLandscapeLeft = 2, // UIDeviceOrientationLandscapeLeft,
	/// Device oriented horizontally, home button on the left
    kCCDeviceOrientationLandscapeRight = 3, // UIDeviceOrientationLandscapeRight,

	// Backward compatibility stuff
	CCDeviceOrientationPortrait = kCCDeviceOrientationPortrait,
	CCDeviceOrientationPortraitUpsideDown = kCCDeviceOrientationPortraitUpsideDown,
	CCDeviceOrientationLandscapeLeft = kCCDeviceOrientationLandscapeLeft,
	CCDeviceOrientationLandscapeRight = kCCDeviceOrientationLandscapeRight,
} ccDeviceOrientation;

class CCLabelTTF;
class CCScene;
class CCEGLView;
class CCProjectionProtocol;
class CCNode;

/**
@brief Class that creates and handle the main Window and manages how
and when to execute the Scenes.

 The CCDirector is also responsible for:
  - initializing the OpenGL context
  - setting the OpenGL pixel format (default on is RGB565)
  - setting the OpenGL buffer depth (default one is 0-bit)
  - setting the projection (default one is 3D)
  - setting the orientation (default one is Protrait)

 Since the CCDirector is a singleton, the standard way to use it is by calling:
  _ CCDirector::sharedDirector()->methodName();

 The CCDirector also sets the default OpenGL context:
  - GL_TEXTURE_2D is enabled
  - GL_VERTEX_ARRAY is enabled
  - GL_COLOR_ARRAY is enabled
  - GL_TEXTURE_COORD_ARRAY is enabled
*/
class CC_DLL CCDirector : public CCObject
{
public:
	virtual bool init(void);
	virtual ~CCDirector(void);
	CCDirector(void) {}

	// attribute

	/** Get current running Scene. Director can only run one Scene at the time */
	inline CCScene* getRunningScene(void) { return m_pRunningScene; }

	/** Get the FPS value */
	inline double getAnimationInterval(void) { return m_dAnimationInterval; }
	/** Set the FPS value. */
	virtual void setAnimationInterval(double dValue) = 0;

	/** Whether or not to display the FPS on the bottom-left corner */
	inline bool isDisplayFPS(void) { return m_bDisplayFPS; }
	/** Display the FPS on the bottom-left corner */
	inline void setDisplayFPS(bool bDisplayFPS) { m_bDisplayFPS = bDisplayFPS; }

	/** Get the CCEGLView, where everything is rendered */
	inline CC_GLVIEW* getOpenGLView(void) { return m_pobOpenGLView; }
	void setOpenGLView(CC_GLVIEW *pobOpenGLView);

	inline bool isNextDeltaTimeZero(void) { return m_bNextDeltaTimeZero; }
	void setNextDeltaTimeZero(bool bNextDeltaTimeZero);

	/** Whether or not the Director is paused */
	inline bool isPaused(void) { return m_bPaused; }

    /** How many frames were called since the director started */
    inline unsigned int getFrames(void) { return m_uFrames; }

	/** Sets an OpenGL projection
	 @since v0.8.2
	 */
	inline ccDirectorProjection getProjection(void) { return m_eProjection; }
	void setProjection(ccDirectorProjection kProjection);

    /** How many frames were called since the director started */

	/** Whether or not the replaced scene will receive the cleanup message.
	 If the new scene is pushed, then the old scene won't receive the "cleanup" message.
	 If the new scene replaces the old one, the it will receive the "cleanup" message.
	 @since v0.99.0
	 */
	inline bool isSendCleanupToScene(void) { return m_bSendCleanupToScene; }

	/** This object will be visited after the main scene is visited.
	 This object MUST implement the "visit" selector.
	 Useful to hook a notification object, like CCNotifications (http://github.com/manucorporat/CCNotifications)
	 @since v0.99.5
	 */
	CCNode* getNotificationNode();
	void setNotificationNode(CCNode *node);

	// window size

	/** returns the size of the OpenGL view in points.
	It takes into account any possible rotation (device orientation) of the window
	*/
	CCSize getWinSize(void);

	/** returns the size of the OpenGL view in pixels.
	It takes into account any possible rotation (device orientation) of the window.
	On Mac winSize and winSizeInPixels return the same value.
	*/
	CCSize getWinSizeInPixels(void);

	/** returns the display size of the OpenGL view in pixels.
	It doesn't take into account any possible rotation of the window.
	*/
	CCSize getDisplaySizeInPixels(void);

	/** changes the projection size */
	void reshapeProjection(const CCSize& newWindowSize);

	/** converts a UIKit coordinate to an OpenGL coordinate
	 Useful to convert (multi) touches coordinates to the current layout (portrait or landscape)
	 */
	CCPoint convertToGL(const CCPoint& obPoint);

	/** converts an OpenGL coordinate to a UIKit coordinate
	 Useful to convert node points to window points for calls such as glScissor
	 */
	CCPoint convertToUI(const CCPoint& obPoint);

	/// XXX: missing description
	float getZEye(void);

	// Scene Management

	/**Enters the Director's main loop with the given Scene.
	 * Call it to run only your FIRST scene.
	 * Don't call it if there is already a running scene.
	 */
	void runWithScene(CCScene *pScene);

	/**Suspends the execution of the running scene, pushing it on the stack of suspended scenes.
	 * The new scene will be executed.
	 * Try to avoid big stacks of pushed scenes to reduce memory allocation.
	 * ONLY call it if there is a running scene.
	 */
	void pushScene(CCScene *pScene);

	/**Pops out a scene from the queue.
	 * This scene will replace the running one.
	 * The running scene will be deleted. If there are no more scenes in the stack the execution is terminated.
	 * ONLY call it if there is a running scene.
	 */
	void popScene(void);

	/** Replaces the running scene with a new one. The running scene is terminated.
	 * ONLY call it if there is a running scene.
	 */
	void replaceScene(CCScene *pScene);

	/** Ends the execution, releases the running scene.
	 It doesn't remove the OpenGL view from its parent. You have to do it manually.
	 */

	/* end is key word of lua, use other name to export to lua. */
	inline void endToLua(void){end();}

	void end(void);

	/** Pauses the running scene.
	 The running scene will be _drawed_ but all scheduled timers will be paused
	 While paused, the draw rate will be 4 FPS to reduce CPU consumption
	 */
	void pause(void);

	/** Resumes the paused scene
	 The scheduled timers will be activated again.
	 The "delta time" will be 0 (as if the game wasn't paused)
	 */
	void resume(void);

	/** Stops the animation. Nothing will be drawn. The main loop won't be triggered anymore.
	 If you don't want to pause your animation call [pause] instead.
	 */
	virtual void stopAnimation(void) = 0;

	/** The main loop is triggered again.
	 Call this function only if [stopAnimation] was called earlier
	 @warning Don't call this function to start the main loop. To run the main loop call runWithScene
	 */
	virtual void startAnimation(void) = 0;

	/** Draw the scene.
	This method is called every frame. Don't call it manually.
	*/
	void drawScene(void);

	// Memory Helper

	/** Removes cached all cocos2d cached data.
	 It will purge the CCTextureCache, CCSpriteFrameCache, CCLabelBMFont cache
	 @since v0.99.3
	 */
	void purgeCachedData(void);

	// OpenGL Helper

	/** sets the OpenGL default values */
	void setGLDefaultValues(void);

	/** enables/disables OpenGL alpha blending */
	void setAlphaBlending(bool bOn);

	/** enables/disables OpenGL depth test */
	void setDepthTest(bool bOn);

	virtual void mainLoop(void) = 0;

	// Profiler
	void showProfilers(void);

	/** rotates the screen if an orientation different than Portrait is used */
	void applyOrientation(void);

	ccDeviceOrientation getDeviceOrientation(void);
	void setDeviceOrientation(ccDeviceOrientation kDeviceOrientation);

	/** The size in pixels of the surface. It could be different than the screen size.
	High-res devices might have a higher surface size than the screen size.
	Only available when compiled using SDK >= 4.0.
	@since v0.99.4
	*/
	void setContentScaleFactor(CGFloat scaleFactor);
	CGFloat getContentScaleFactor(void);

	/** Will enable Retina Display on devices that supports it.
	It will enable Retina Display on iPhone4 and iPod Touch 4.
	It will return YES, if it could enabled it, otherwise it will return NO.

	This is the recommened way to enable Retina Display.
	@since v0.99.5
	*/
	bool enableRetinaDisplay(bool enabled);
    bool isRetinaDisplay() { return m_bRetinaDisplay; }

	/** There are 4 types of Director.
	- kCCDirectorTypeNSTimer (default)
	- kCCDirectorTypeMainLoop
	- kCCDirectorTypeThreadMainLoop
	- kCCDirectorTypeDisplayLink

	Each Director has it's own benefits, limitations.
	Now we only support DisplayLink director, so it has not effect.

	This method should be called before any other call to the director.

	@since v0.8.2
	*/
	static bool setDirectorType(ccDirectorType obDirectorType);

public:
	/** returns a shared instance of the director */
	static CCDirector* sharedDirector(void);
	void resetDirector();

protected:

	void purgeDirector();
	bool m_bPurgeDirecotorInNextLoop; // this flag will be set to true in end()

	void updateContentScaleFactor(void);

	void setNextScene(void);

#if CC_DIRECTOR_FAST_FPS
	/** shows the FPS in the screen */
	void showFPS(void);
#else
	void showFPS(void) {}
#endif // CC_DIRECTOR_FAST_FPS

/** calculates delta time since last time it was called */	void calculateDeltaTime();protected:
	/* The CCEGLView, where everything is rendered */
    CC_GLVIEW	*m_pobOpenGLView;

	double m_dAnimationInterval;
	double m_dOldAnimationInterval;

	/* landscape mode ? */
	bool m_bLandscape;

	bool m_bDisplayFPS;
	ccTime m_fAccumDt;
	ccTime m_fFrameRate;
#if	CC_DIRECTOR_FAST_FPS
	CCLabelTTF *m_pFPSLabel;
#endif

	/* is the running scene paused */
	bool m_bPaused;

    /* How many frames were called since the director started */
	unsigned int m_uTotalFrames;
    unsigned int m_uFrames;

	/* The running scene */
	CCScene *m_pRunningScene;

	/* will be the next 'runningScene' in the next frame
	 nextScene is a weak reference. */
	CCScene *m_pNextScene;

	/* If YES, then "old" scene will receive the cleanup message */
	bool	m_bSendCleanupToScene;

	/* scheduled scenes */
	CCMutableArray<CCScene*> *m_pobScenesStack;

	/* last time the main loop was updated */
	struct cc_timeval *m_pLastUpdate;

	/* delta time since last tick to main loop */
	ccTime m_fDeltaTime;

	/* whether or not the next delta time will be zero */
	bool m_bNextDeltaTimeZero;

	/* projection used */
	ccDirectorProjection m_eProjection;

	/* window size in points */
	CCSize	m_obWinSizeInPoints;

	/* window size in pixels */
	CCSize m_obWinSizeInPixels;

	/* content scale factor */
	CGFloat	m_fContentScaleFactor;

	/* store the fps string */
	char *m_pszFPS;

	/* This object will be visited after the scene. Useful to hook a notification node */
	CCNode *m_pNotificationNode;

	/* Projection protocol delegate */
	CCProjectionProtocol *m_pProjectionDelegate;

	/* The device orientation */
	ccDeviceOrientation	m_eDeviceOrientation;
	/* contentScaleFactor could be simulated */
	bool m_bIsContentScaleSupported;

	bool m_bRetinaDisplay;

#if CC_ENABLE_PROFILERS
	ccTime m_fAccumDtForProfiler;
#endif
};

/**
 @brief DisplayLinkDirector is a Director that synchronizes timers with the refresh rate of the display.

 Features and Limitations:
  - Scheduled timers & drawing are synchronizes with the refresh rate of the display
  - Only supports animation intervals of 1/60 1/30 & 1/15

 @since v0.8.2
 */
class CCDisplayLinkDirector : public CCDirector
{
public:
	CCDisplayLinkDirector(void)
		: m_bInvalid(false)
	{}

	virtual void mainLoop(void);
	virtual void setAnimationInterval(double dValue);
	virtual void startAnimation(void);
	virtual void stopAnimation();

protected:
	bool m_bInvalid;
};

}//namespace   cocos2d

#endif // __CCDIRECTOR_H__


code:
/****************************************************************************
Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2008-2010 Ricardo Quesada
Copyright (c) 2011      Zynga Inc.

http://www.cocos2d-x.org

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/

#ifndef __CCDRAWING_PRIMITIVES__
#define __CCDRAWING_PRIMITIVES__

/**
 @file
 Drawing OpenGL ES primitives.
 - ccDrawPoint
 - ccDrawLine
 - ccDrawPoly
 - ccDrawCircle
 - ccDrawQuadBezier
 - ccDrawCubicBezier

 You can change the color, width and other property by calling the
 glColor4ub(), glLineWidth(), glPointSize().

 @warning These functions draws the Line, Point, Polygon, immediately. They aren't batched. If you are going to make a game that depends on these primitives, I suggest creating a batch.
 */

#include "CCGeometry.h"	// for CCPoint
namespace   cocos2d {

/** draws a point given x and y coordinate measured in points */
void CC_DLL ccDrawPoint( const CCPoint& point );

/** draws an array of points.
 @since v0.7.2
 */
void CC_DLL ccDrawPoints( const CCPoint *points, unsigned int numberOfPoints );

/** draws a line given the origin and destination point measured in points */
void CC_DLL ccDrawLine( const CCPoint& origin, const CCPoint& destination );

/** draws a poligon given a pointer to CCPoint coordiantes and the number of vertices measured in points.
The polygon can be closed or open
*/
void CC_DLL ccDrawPoly( const CCPoint *vertices, int numOfVertices, bool closePolygon );

/** draws a poligon given a pointer to CCPoint coordiantes and the number of vertices measured in points.
The polygon can be closed or open and optionally filled with current GL color
*/
void CC_DLL ccDrawPoly( const CCPoint *vertices, int numOfVertices, bool closePolygon , bool fill);

/** draws a circle given the center, radius and number of segments. */
void CC_DLL ccDrawCircle( const CCPoint& center, float radius, float angle, int segments, bool drawLineToCenter);

/** draws a quad bezier path
 @since v0.8
 */
void CC_DLL ccDrawQuadBezier(const CCPoint& origin, const CCPoint& control, const CCPoint& destination, int segments);

/** draws a cubic bezier path
 @since v0.8
 */
void CC_DLL ccDrawCubicBezier(const CCPoint& origin, const CCPoint& control1, const CCPoint& control2, const CCPoint& destination, int segments);
}//namespace   cocos2d

#endif // __CCDRAWING_PRIMITIVES__


code:
/****************************************************************************
Copyright (c) 2010 cocos2d-x.org

http://www.cocos2d-x.org

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/

#ifndef __CC_EGLVIEW_H__
#define __CC_EGLVIEW_H__

#include "../platform/CCEGLView_platform.h"

#endif	// end of __CC_EGLVIEW_H__


code:
/****************************************************************************
Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2010      Ricardo Quesada

http://www.cocos2d-x.org

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "platform/CCGL.h"


code:
/****************************************************************************
Copyright (c) 2010 cocos2d-x.org

http://www.cocos2d-x.org

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/

#ifndef __COCOS_CGGEMETRY_H__
#define __COCOS_CGGEMETRY_H__

#include "CCCommon.h"

namespace   cocos2d {

typedef float CGFloat;

class CC_DLL CCPoint
{
public:
	float x;
	float y;

public:

	CCPoint();
	CCPoint(float x, float y);

public:
	static bool CCPointEqualToPoint(const CCPoint& point1, const CCPoint& point2);
};

class CC_DLL CCSize
{
public:
	float width;
	float height;

public:
	CCSize();
	CCSize(float width, float height);

public:
	static bool CCSizeEqualToSize(const CCSize& size1, const CCSize& size2);
};

class CC_DLL CCRect
{
public:
	CCPoint origin;
	CCSize  size;

public:
	CCRect();
	CCRect(float x, float y, float width, float height);

public:
	//! return the leftmost x-value of 'rect'
	static CGFloat CCRectGetMinX(const CCRect& rect);

	//! return the rightmost x-value of 'rect'
	static CGFloat CCRectGetMaxX(const CCRect& rect);

	//! return the midpoint x-value of 'rect'
	static CGFloat CCRectGetMidX(const CCRect& rect);

	//! Return the bottommost y-value of `rect'
	static CGFloat CCRectGetMinY(const CCRect& rect);

	//! Return the topmost y-value of `rect'
	static CGFloat CCRectGetMaxY(const CCRect& rect);

	//! Return the midpoint y-value of `rect'
	static CGFloat CCRectGetMidY(const CCRect& rect);

	static bool CCRectEqualToRect(const CCRect& rect1, const CCRect& rect2);

    static bool CCRectContainsPoint(const CCRect& rect, const CCPoint& point);

	static bool CCRectIntersectsRect(const CCRect& rectA, const CCRect& rectB);
};

#define CCPointMake(x, y) CCPoint((x), (y))
#define CCSizeMake(width, height) CCSize((width), (height))
#define CCRectMake(x, y, width, height) CCRect((x), (y), (width), (height))

const CCPoint CCPointZero = CCPointMake(0,0);

/* The "zero" size -- equivalent to CCSizeMake(0, 0). */
const CCSize CCSizeZero = CCSizeMake(0,0);

/* The "zero" rectangle -- equivalent to CCRectMake(0, 0, 0, 0). */
const CCRect CCRectZero = CCRectMake(0,0,0,0);

}//namespace   cocos2d

#endif // __COCOS_CGGEMETRY_H__


code:
/****************************************************************************
Copyright (c) 2010 cocos2d-x.org

http://www.cocos2d-x.org

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/

#ifndef __CC_IME_DELEGATE_H__
#define __CC_IME_DELEGATE_H__

#include "CCGeometry.h"

NS_CC_BEGIN;

typedef struct
{
    CCRect  begin;              // the soft keyboard rectangle when animatin begin
    CCRect  end;                // the soft keyboard rectangle when animatin end
    float     duration;           // the soft keyboard animation duration
} CCIMEKeyboardNotificationInfo;

/**
@brief	Input method editor delegate.
*/
class CC_DLL CCIMEDelegate
{
public:
    virtual ~CCIMEDelegate();

    virtual bool attachWithIME();
    virtual bool detachWithIME();

protected:
    friend class CCIMEDispatcher;

    /**
    @brief	Decide the delegate instance is ready for receive ime message or not.

    Called by CCIMEDispatcher.
    */
    virtual bool canAttachWithIME() { return false; }
    /**
    @brief	When the delegate detach with IME, this method call by CCIMEDispatcher.
    */
    virtual void didAttachWithIME() {}

    /**
    @brief	Decide the delegate instance can stop receive ime message or not.
    */
    virtual bool canDetachWithIME() { return false; }

    /**
    @brief	When the delegate detach with IME, this method call by CCIMEDispatcher.
    */
    virtual void didDetachWithIME() {}

    /**
    @brief	Called by CCIMEDispatcher when some text input from IME.
    */
    virtual void insertText(const char * text, int len) {CC_UNUSED_PARAM(text);CC_UNUSED_PARAM(len);}

    /**
    @brief	Called by CCIMEDispatcher when user clicked the backward key.
    */
    virtual void deleteBackward() {}

    /**
    @brief	Called by CCIMEDispatcher for get text which delegate already has.
    */
    virtual const char * getContentText() { return 0; }

    //////////////////////////////////////////////////////////////////////////
    // keyboard show/hide notification
    //////////////////////////////////////////////////////////////////////////
    virtual void keyboardWillShow(CCIMEKeyboardNotificationInfo& info)   {CC_UNUSED_PARAM(info);}
    virtual void keyboardDidShow(CCIMEKeyboardNotificationInfo& info)    {CC_UNUSED_PARAM(info);}
    virtual void keyboardWillHide(CCIMEKeyboardNotificationInfo& info)   {CC_UNUSED_PARAM(info);}
    virtual void keyboardDidHide(CCIMEKeyboardNotificationInfo& info)    {CC_UNUSED_PARAM(info);}

protected:
    CCIMEDelegate();
};

NS_CC_END;

#endif	// __CC_IME_DELEGATE_H__


code:
/****************************************************************************
Copyright (c) 2010 cocos2d-x.org

http://www.cocos2d-x.org

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/

#ifndef __CC_IME_DISPATCHER_H__
#define __CC_IME_DISPATCHER_H__

#include "CCIMEDelegate.h"

NS_CC_BEGIN;

/**
@brief	Input Method Edit Message Dispatcher.
*/
class CC_DLL CCIMEDispatcher
{
public:
    ~CCIMEDispatcher();

    /**
    @brief Returns the shared CCIMEDispatcher object for the system.
    */
    static CCIMEDispatcher* sharedDispatcher();

//     /**
//     @brief Release all CCIMEDelegates from shared dispatcher.
//     */
//     static void purgeSharedDispatcher();

    /**
    @brief dispatch the input text from ime
    */
    void dispatchInsertText(const char * pText, int nLen);

    /**
    @brief	dispatch the delete backward operation
    */
    void dispatchDeleteBackward();

    /**
    @brief	get the content text, which current CCIMEDelegate which attached with IME has.
    */
    const char * getContentText();

    //////////////////////////////////////////////////////////////////////////
    // dispatch keyboard notification
    //////////////////////////////////////////////////////////////////////////
    void dispatchKeyboardWillShow(CCIMEKeyboardNotificationInfo& info);
    void dispatchKeyboardDidShow(CCIMEKeyboardNotificationInfo& info);
    void dispatchKeyboardWillHide(CCIMEKeyboardNotificationInfo& info);
    void dispatchKeyboardDidHide(CCIMEKeyboardNotificationInfo& info);

protected:
    friend class CCIMEDelegate;

    /**
    @brief add delegate to concern ime msg
    */
    void addDelegate(CCIMEDelegate * pDelegate);

    /**
    @brief	attach the pDeleate with ime.
    @return If the old delegate can detattach with ime and the new delegate
            can attach with ime, return true, otherwise return false.
    */
    bool attachDelegateWithIME(CCIMEDelegate * pDelegate);
    bool detachDelegateWithIME(CCIMEDelegate * pDelegate);

    /**
    @brief remove the delegate from the delegates who concern ime msg
    */
    void removeDelegate(CCIMEDelegate * pDelegate);

private:
    CCIMEDispatcher();

    class Impl;
    Impl * m_pImpl;
};

NS_CC_END;

#endif	// __CC_IME_DISPATCHER_H__


code:
/****************************************************************************
Copyright (c) 2010 cocos2d-x.org

http://www.cocos2d-x.org

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/

#ifndef __CCKEYPAD_DELEGATE_H__
#define __CCKEYPAD_DELEGATE_H__

#include "CCObject.h"

namespace   cocos2d {

class CC_DLL CCKeypadDelegate
{
public:
    // The back key clicked
    virtual void keyBackClicked() {}

    // The menu key clicked. only avialble on wophone & android
    virtual void keyMenuClicked() {};
};

/**
@brief
CCKeypadHandler
Object than contains the CCKeypadDelegate.
*/
class CC_DLL CCKeypadHandler : public CCObject
{
public:
    virtual ~CCKeypadHandler(void);

    /** delegate */
    CCKeypadDelegate* getDelegate();
    void setDelegate(CCKeypadDelegate *pDelegate);

    /** initializes a CCKeypadHandler with a delegate */
    virtual bool initWithDelegate(CCKeypadDelegate *pDelegate);

public:
    /** allocates a CCKeypadHandler with a delegate */
    static CCKeypadHandler* handlerWithDelegate(CCKeypadDelegate *pDelegate);

protected:
    CCKeypadDelegate* m_pDelegate;
};

} //namespace   cocos2d

#endif // __CCKEYPAD_DELEGATE_H__


code:
/****************************************************************************
Copyright (c) 2010 cocos2d-x.org

http://www.cocos2d-x.org

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/

#ifndef __CCKEYPAD_DISPATCHER_H__
#define __CCKEYPAD_DISPATCHER_H__

#include "CCKeypadDelegate.h"
#include "CCMutableArray.h"

namespace   cocos2d {

typedef enum {
    // the back key clicked msg
    kTypeBackClicked = 1,
    kTypeMenuClicked,
} ccKeypadMSGType;

struct _ccCArray;
/**
@class CCKeypadDispatcher
@brief Dispatch the keypad message from the phone
*/
class CC_DLL CCKeypadDispatcher : public CCObject
{
public:
    CCKeypadDispatcher();
    ~CCKeypadDispatcher();

    /**
    @brief Returns the shared CCKeypadDispatcher object for the system.
    */
    static CCKeypadDispatcher* sharedDispatcher();

    /**
    @brief Release the shared CCKeypadDispatcher object from the system.
    */
    static void purgeSharedDispatcher();

    /**
    @brief add delegate to concern keypad msg
    */
    void addDelegate(CCKeypadDelegate* pDelegate);

    /**
    @brief remove the delegate from the delegates who concern keypad msg
    */
    void removeDelegate(CCKeypadDelegate* pDelegate);

    /**
    @brief force add the delegate
    */
    void forceAddDelegate(CCKeypadDelegate* pDelegate);

    /**
    @brief force remove the delegate
    */
    void forceRemoveDelegate(CCKeypadDelegate* pDelegate);

    /**
    @brief dispatch the key pad msg
    */
    bool dispatchKeypadMSG(ccKeypadMSGType nMsgType);

protected:

    typedef CCMutableArray<CCKeypadHandler*> KeypadDelegateArray;

    KeypadDelegateArray* m_pDelegates;
    bool m_bLocked;
    bool m_bToAdd;
    bool m_bToRemove;

    struct _ccCArray *m_pHandlersToAdd;
    struct _ccCArray *m_pHandlersToRemove;
};

} // namespace   cocos2d

#endif //__CCKEYPAD_DISPATCHER_H__


code:
/****************************************************************************
Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2008-2010 Ricardo Quesada
Copyright (c) 2011      Zynga Inc.

http://www.cocos2d-x.org

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CCLABEL_ATLAS_H__
#define __CCLABEL_ATLAS_H__
#include "CCAtlasNode.h"
namespace cocos2d{

	/** @brief CCLabelAtlas is a subclass of CCAtlasNode.

	It can be as a replacement of CCLabel since it is MUCH faster.

	CCLabelAtlas versus CCLabel:
	- CCLabelAtlas is MUCH faster than CCLabel
	- CCLabelAtlas "characters" have a fixed height and width
	- CCLabelAtlas "characters" can be anything you want since they are taken from an image file

	A more flexible class is CCLabelBMFont. It supports variable width characters and it also has a nice editor.
	*/
	class CC_DLL CCLabelAtlas : public CCAtlasNode, public CCLabelProtocol
	{
	public:
		CCLabelAtlas()
			:m_sString("")
		{}
		virtual ~CCLabelAtlas()
		{
			m_sString.clear();
		}
		/** creates the CCLabelAtlas with a string, a char map file(the atlas), the width and height of each element and the starting char of the atlas */
		static CCLabelAtlas * labelWithString(const char *label, const char *charMapFile, unsigned int itemWidth, unsigned int itemHeight, unsigned char startCharMap);

		/** initializes the CCLabelAtlas with a string, a char map file(the atlas), the width and height of each element and the starting char of the atlas */
		bool initWithString(const char *label, const char *charMapFile, unsigned int itemWidth, unsigned int itemHeight, unsigned char startCharMap);
		// super methods
		virtual void updateAtlasValues();
		virtual void setString(const char *label);
		virtual const char* getString(void);
#if CC_LABELATLAS_DEBUG_DRAW
		virtual void draw();
#endif

		virtual CCLabelProtocol* convertToLabelProtocol() { return (CCLabelProtocol*)this; }
	protected:
		// string to render
		std::string m_sString;
		// the first char in the charmap
		unsigned char m_cMapStartChar;
	};
}// namespace cocos2d

#endif //__CCLABEL_ATLAS_H__


code:
/****************************************************************************
Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2008-2010 Ricardo Quesada
Copyright (c) 2011      Zynga Inc.

http://www.cocos2d-x.org

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

Use any of these editors to generate BMFonts:
  http://glyphdesigner.71squared.com/ (Commercial, Mac OS X)
  http://www.n4te.com/hiero/hiero.jnlp (Free, Java)
  http://slick.cokeandcode.com/demos/hiero.jnlp (Free, Java)
  http://www.angelcode.com/products/bmfont/ (Free, Windows only)

****************************************************************************/
#ifndef __CCBITMAP_FONT_ATLAS_H__
#define __CCBITMAP_FONT_ATLAS_H__

#include "CCSpriteBatchNode.h"
#include <map>
#include <vector>

namespace cocos2d{

	struct _KerningHashElement;

	/**
    @struct ccBMFontDef
    BMFont definition
	*/
	typedef struct _BMFontDef {
		//! ID of the character
		unsigned int charID;
		//! origin and size of the font
		CCRect rect;
		//! The X amount the image should be offset when drawing the image (in pixels)
		int xOffset;
		//! The Y amount the image should be offset when drawing the image (in pixels)
		int yOffset;
		//! The amount to move the current position after drawing the character (in pixels)
		int xAdvance;
	} ccBMFontDef;

    /** @struct ccBMFontPadding
    BMFont padding
	@since v0.8.2
	*/
	typedef struct _BMFontPadding {
		/// padding left
		int	left;
		/// padding top
		int top;
		/// padding right
		int right;
		/// padding bottom
		int bottom;
	} ccBMFontPadding;

	/** @brief CCBMFontConfiguration has parsed configuration of the the .fnt file
	@since v0.8
	*/
	class CC_DLL CCBMFontConfiguration : public CCObject
	{
		// XXX: Creating a public interface so that the bitmapFontArray[] is accesible
	public://@public
		//! The characters building up the font
        std::map<unsigned int, ccBMFontDef>* m_pBitmapFontArray;

		//! FNTConfig: Common Height
		unsigned int m_uCommonHeight;
		//! Padding
		ccBMFontPadding	m_tPadding;
		//! atlas name
		std::string m_sAtlasName;
		//! values for kerning
		struct _KerningHashElement	*m_pKerningDictionary;
	public:
		CCBMFontConfiguration();
		virtual ~CCBMFontConfiguration();
		char * description();
		/** allocates a CCBMFontConfiguration with a FNT file */
		static CCBMFontConfiguration * configurationWithFNTFile(const char *FNTfile);
		/** initializes a BitmapFontConfiguration with a FNT file */
		bool initWithFNTfile(const char *FNTfile);
	private:
		void parseConfigFile(const char *controlFile);
		void parseCharacterDefinition(std::string line, ccBMFontDef *characterDefinition);
		void parseInfoArguments(std::string line);
		void parseCommonArguments(std::string line);
		void parseImageFileName(std::string line, const char *fntFile);
		void parseKerningCapacity(std::string line);
		void parseKerningEntry(std::string line);
		void purgeKerningDictionary();
	};

	/** @brief CCLabelBMFont is a subclass of CCSpriteSheet.

	Features:
	- Treats each character like a CCSprite. This means that each individual character can be:
	- rotated
	- scaled
	- translated
	- tinted
	- chage the opacity
	- It can be used as part of a menu item.
	- anchorPoint can be used to align the "label"
	- Supports AngelCode text format

	Limitations:
	- All inner characters are using an anchorPoint of (0.5f, 0.5f) and it is not recommend to change it
	because it might affect the rendering

	CCLabelBMFont implements the protocol CCLabelProtocol, like CCLabel and CCLabelAtlas.
	CCLabelBMFont has the flexibility of CCLabel, the speed of CCLabelAtlas and all the features of CCSprite.
	If in doubt, use CCLabelBMFont instead of CCLabelAtlas / CCLabel.

	Supported editors:
    http://glyphdesigner.71squared.com/ (Commercial, Mac OS X)
    http://www.n4te.com/hiero/hiero.jnlp (Free, Java)
    http://slick.cokeandcode.com/demos/hiero.jnlp (Free, Java)
    http://www.angelcode.com/products/bmfont/ (Free, Windows only)

	@since v0.8
	*/

	class CC_DLL CCLabelBMFont : public CCSpriteBatchNode, public CCLabelProtocol, public CCRGBAProtocol
	{
		/** conforms to CCRGBAProtocol protocol */
		CC_PROPERTY(GLubyte, m_cOpacity, Opacity)
		/** conforms to CCRGBAProtocol protocol */
		CC_PROPERTY_PASS_BY_REF(ccColor3B, m_tColor, Color)
		/** conforms to CCRGBAProtocol protocol */
		CC_PROPERTY(bool, m_bIsOpacityModifyRGB, IsOpacityModifyRGB)
	protected:
		// string to render
		unsigned short* m_sString;
		std::string m_sString_initial;
		CCBMFontConfiguration *m_pConfiguration;
		CCTextAlignment m_pAlignment;
		float m_fWidth;
		bool m_bLineBreakWithoutSpaces;
	public:
		CCLabelBMFont()
			: m_cOpacity(0)
			, m_bIsOpacityModifyRGB(false)
            , m_pConfiguration(NULL)
			, m_bLineBreakWithoutSpaces(false)
		{}
		virtual ~CCLabelBMFont();
		/** Purges the cached data.
		Removes from memory the cached configurations and the atlas name dictionary.
		@since v0.99.3
		*/
		static void purgeCachedData();
		/** creates a bitmap font altas with an initial string and the FNT file */
		static CCLabelBMFont * labelWithString(const char *str, const char *fntFile);
		static CCLabelBMFont * labelWithString(const char *str, const char *fntFile, CCTextAlignment alignment, float width);

		/** init a bitmap font altas with an initial string and the FNT file */
		bool initWithString(const char *str, const char *fntFile, CCTextAlignment alignment, float width);
		bool initWithString(const char *str, const char *fntFile);
		/** updates the font chars based on the string to render */
		void createFontChars();
		// super method
		virtual void setString(const char *label);
		virtual void setString(const char *label, bool fromUpdate);
		virtual void updateString(bool fromUpdate);
		virtual const char* getString(void);
        virtual void setCString(const char *label);
		virtual void setAnchorPoint(const CCPoint& var);
		virtual void updateLabel();
		virtual void setAlignment(CCTextAlignment alignment);
		virtual void setWidth(float width);
		virtual void setLineBreakWithoutSpace(bool breakWithoutSpace);

#if CC_LABELBMFONT_DEBUG_DRAW
		virtual void draw();
#endif // CC_LABELBMFONT_DEBUG_DRAW
	private:
		char * atlasNameFromFntFile(const char *fntFile);
		int kerningAmountForFirst(unsigned short first, unsigned short second);

	};

	/** Free function that parses a FNT file a place it on the cache
	*/
	CC_DLL CCBMFontConfiguration * FNTConfigLoadFile( const char *file );
	/** Purges the FNT config cache
	*/
	CC_DLL void FNTConfigRemoveCache( void );
}// namespace cocos2d

#endif //__CCBITMAP_FONT_ATLAS_H__


code:
/****************************************************************************
Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2008-2010 Ricardo Quesada

http://www.cocos2d-x.org

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CCLABEL_H__
#define __CCLABEL_H__
#include "CCSprite.h"
#include "CCTexture2D.h"

namespace cocos2d{

	/** @brief CCLabelTTF is a subclass of CCTextureNode that knows how to render text labels
	*
	* All features from CCTextureNode are valid in CCLabelTTF
	*
	* CCLabelTTF objects are slow. Consider using CCLabelAtlas or CCLabelBMFont instead.
	*/
	class CC_DLL CCLabelTTF : public CCSprite, public CCLabelProtocol
	{
	public:
		CCLabelTTF();
		virtual ~CCLabelTTF();
		char * description();
		/** creates a CCLabelTTF from a fontname, alignment, dimension and font size */
		static CCLabelTTF * labelWithString(const char *label, const CCSize& dimensions, CCTextAlignment alignment, const char *fontName, float fontSize);
		/** creates a CCLabelTTF from a fontname and font size */
		static CCLabelTTF * labelWithString(const char *label, const char *fontName, float fontSize);
		/** initializes the CCLabelTTF with a font name, alignment, dimension and font size */
		bool initWithString(const char *label, const CCSize& dimensions, CCTextAlignment alignment, const char *fontName, float fontSize);
		/** initializes the CCLabelTTF with a font name and font size */
		bool initWithString(const char *label, const char *fontName, float fontSize);

		/** changes the string to render
		* @warning Changing the string is as expensive as creating a new CCLabelTTF. To obtain better performance use CCLabelAtlas
		*/
		virtual void setString(const char *label);
		virtual const char* getString(void);

		virtual CCLabelProtocol* convertToLabelProtocol() { return (CCLabelProtocol*)this; }
	protected:
		CCSize m_tDimensions;
		CCTextAlignment m_eAlignment;
        std::string * m_pFontName;
		float m_fFontSize;
        std::string * m_pString;
	};

} //namespace cocos2d
#endif //__CCLABEL_H__


code:
/****************************************************************************
Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2008-2010 Ricardo Quesada
Copyright (c) 2011      Zynga Inc.

http://www.cocos2d-x.org

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/

#ifndef __CCLAYER_H__
#define __CCLAYER_H__

#include "CCNode.h"
#include "CCProtocols.h"
#include "CCTouchDelegateProtocol.h"
#include "CCAccelerometerDelegate.h"
#include "CCKeypadDelegate.h"
#include "CCMutableArray.h"

namespace   cocos2d {

class CCTouchScriptHandlerEntry;

//
// CCLayer
//
/** @brief CCLayer is a subclass of CCNode that implements the TouchEventsDelegate protocol.

All features from CCNode are valid, plus the following new features:
- It can receive iPhone Touches
- It can receive Accelerometer input
*/
class CC_DLL CCLayer : public CCNode, public CCTouchDelegate, public CCAccelerometerDelegate, public CCKeypadDelegate
{
public:
	CCLayer();
	virtual ~CCLayer();
	bool init();
	static CCLayer *node(void);

	virtual void onEnter();
	virtual void onExit();
    virtual void onEnterTransitionDidFinish();

    // default implements are used to call script callback if exist
	virtual bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent);
    virtual void ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent);
    virtual void ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent);
    virtual void ccTouchCancelled(CCTouch *pTouch, CCEvent *pEvent);

	// default implements are used to call script callback if exist
	virtual void ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent);
	virtual void ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent);
	virtual void ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent);
	virtual void ccTouchesCancelled(CCSet *pTouches, CCEvent *pEvent);

    virtual void didAccelerate(CCAcceleration* pAccelerationValue) {CC_UNUSED_PARAM(pAccelerationValue);}

	/** If isTouchEnabled, this method is called onEnter. Override it to change the
	way CCLayer receives touch events.
	( Default: CCTouchDispatcher::sharedDispatcher()->addStandardDelegate(this,0); )
	Example:
	void CCLayer::registerWithTouchDispatcher()
	{
	CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this,INT_MIN+1,true);
	}
	@since v0.8.0
	*/
	virtual void registerWithTouchDispatcher(void);

    /** Register script touch events handler */
    void registerScriptTouchHandler(int nHandler, bool bIsMultiTouches = false, int nPriority = INT_MIN, bool bSwallowsTouches = false);
    /** Unregister script touch events handler */
    void unregisterScriptTouchHandler(void);

	/** whether or not it will receive Touch events.
	You can enable / disable touch events with this property.
	Only the touches of this node will be affected. This "method" is not propagated to it's children.
	@since v0.8.1
	*/
	CC_PROPERTY(bool, m_bIsTouchEnabled, IsTouchEnabled)
	/** whether or not it will receive Accelerometer events
	You can enable / disable accelerometer events with this property.
	@since v0.8.1
	*/
	CC_PROPERTY(bool, m_bIsAccelerometerEnabled, IsAccelerometerEnabled)
    /** whether or not it will receive keypad events
    You can enable / disable accelerometer events with this property.
    it's new in cocos2d-x
    */
    CC_PROPERTY(bool, m_bIsKeypadEnabled, IsKeypadEnabled)

private:
    // Script touch events handler
    CCTouchScriptHandlerEntry* m_pScriptHandlerEntry;
    int  excuteScriptTouchHandler(int nEventType, CCTouch *pTouch);
    int  excuteScriptTouchHandler(int nEventType, CCSet *pTouches);
};

// for the subclass of CCLayer, each has to implement the static "node" method
#define LAYER_NODE_FUNC(layer) \
static layer* node() \
{ \
layer *pRet = new layer(); \
if (pRet && pRet->init()) \
{ \
pRet->autorelease(); \
return pRet; \
} \
else \
{ \
delete pRet; \
pRet = NULL; \
return NULL; \
} \
};

#define LAYER_NODE_FUNC_PARAM(layer,__PARAMTYPE__,__PARAM__) \
	static layer* node(__PARAMTYPE__ __PARAM__) \
{ \
	layer *pRet = new layer(); \
	if (pRet && pRet->init(__PARAM__)) \
{ \
	pRet->autorelease(); \
	return pRet; \
	} \
else \
{ \
	delete pRet; \
	pRet = NULL; \
	return NULL; \
	} \
	};

//
// CCLayerColor
//
/** @brief CCLayerColor is a subclass of CCLayer that implements the CCRGBAProtocol protocol.

All features from CCLayer are valid, plus the following new features:
- opacity
- RGB colors
*/
class CC_DLL CCLayerColor : public CCLayer , public CCRGBAProtocol, public CCBlendProtocol
{
protected:
	ccVertex2F m_pSquareVertices[4];
	ccColor4B  m_pSquareColors[4];

public:

	CCLayerColor();
	virtual ~CCLayerColor();

	virtual void draw();
	virtual void setContentSize(const CCSize& var);

	/** creates a CCLayer with color, width and height in Points */
	static CCLayerColor * layerWithColorWidthHeight(const ccColor4B& color, GLfloat width, GLfloat height);
	/** creates a CCLayer with color. Width and height are the window size. */
	static CCLayerColor * layerWithColor(const ccColor4B& color);

	/** initializes a CCLayer with color, width and height in Points */
	virtual bool initWithColorWidthHeight(const ccColor4B& color, GLfloat width, GLfloat height);
	/** initializes a CCLayer with color. Width and height are the window size. */
	virtual bool initWithColor(const ccColor4B& color);

	/** change width in Points*/
	void changeWidth(GLfloat w);
	/** change height in Points*/
	void changeHeight(GLfloat h);
	/** change width and height in Points
	@since v0.8
	*/
	void changeWidthAndHeight(GLfloat w ,GLfloat h);

	/** Opacity: conforms to CCRGBAProtocol protocol */
	CC_PROPERTY(GLubyte, m_cOpacity, Opacity)
	/** Color: conforms to CCRGBAProtocol protocol */
	CC_PROPERTY_PASS_BY_REF(ccColor3B, m_tColor, Color)
	/** BlendFunction. Conforms to CCBlendProtocol protocol */
	CC_PROPERTY(ccBlendFunc, m_tBlendFunc, BlendFunc)

	virtual void setIsOpacityModifyRGB(bool bValue) {CC_UNUSED_PARAM(bValue);}
    virtual bool getIsOpacityModifyRGB(void) { return false;}
    LAYER_NODE_FUNC(CCLayerColor);

protected:
	virtual void updateColor();
};

//
// CCLayerGradient
//
/** CCLayerGradient is a subclass of CCLayerColor that draws gradients across
the background.

All features from CCLayerColor are valid, plus the following new features:
- direction
- final color
- interpolation mode

Color is interpolated between the startColor and endColor along the given
vector (starting at the origin, ending at the terminus).  If no vector is
supplied, it defaults to (0, -1) -- a fade from top to bottom.

If 'compressedInterpolation' is disabled, you will not see either the start or end color for
non-cardinal vectors; a smooth gradient implying both end points will be still
be drawn, however.

If ' compressedInterpolation' is enabled (default mode) you will see both the start and end colors of the gradient.

@since v0.99.5
*/
class CC_DLL CCLayerGradient : public CCLayerColor
{
public:
    /** Creates a full-screen CCLayer with a gradient between start and end. */
    static CCLayerGradient* layerWithColor(const ccColor4B& start, const ccColor4B& end);

    /** Creates a full-screen CCLayer with a gradient between start and end in the direction of v. */
    static CCLayerGradient* layerWithColor(const ccColor4B& start, const ccColor4B& end, const CCPoint& v);

    /** Initializes the CCLayer with a gradient between start and end. */
    virtual bool initWithColor(const ccColor4B& start, const ccColor4B& end);

    /** Initializes the CCLayer with a gradient between start and end in the direction of v. */
    virtual bool initWithColor(const ccColor4B& start, const ccColor4B& end, const CCPoint& v);

	CC_PROPERTY_PASS_BY_REF(ccColor3B, m_startColor, StartColor)
	CC_PROPERTY_PASS_BY_REF(ccColor3B, m_endColor, EndColor)
    CC_PROPERTY(GLubyte, m_cStartOpacity, StartOpacity)
    CC_PROPERTY(GLubyte, m_cEndOpacity, EndOpacity)
	CC_PROPERTY_PASS_BY_REF(CCPoint, m_AlongVector, Vector)

    /** Whether or not the interpolation will be compressed in order to display all the colors of the gradient both in canonical and non canonical vectors
    Default: YES
    */
    CC_PROPERTY(bool, m_bCompressedInterpolation, IsCompressedInterpolation)

    LAYER_NODE_FUNC(CCLayerGradient);
protected:
    virtual void updateColor();
};

/** @brief CCMultipleLayer is a CCLayer with the ability to multiplex it's children.
Features:
- It supports one or more children
- Only one children will be active a time
*/
class CC_DLL CCLayerMultiplex : public CCLayer
{
protected:
	unsigned int m_nEnabledLayer;
	CCMutableArray<CCLayer *> * m_pLayers;
public:

	CCLayerMultiplex();
	virtual ~CCLayerMultiplex();

	/** creates a CCLayerMultiplex with one or more layers using a variable argument list. */
	static CCLayerMultiplex * layerWithLayers(CCLayer* layer, ... );

    /**
	 * lua script can not init with undetermined number of variables
	 * so add these functinons to be used with lua.
	 */
	static CCLayerMultiplex * layerWithLayer(CCLayer* layer);
	void addLayer(CCLayer* layer);
	bool initWithLayer(CCLayer* layer);

	/** initializes a MultiplexLayer with one or more layers using a variable argument list. */
	bool initWithLayers(CCLayer* layer, va_list params);
	/** switches to a certain layer indexed by n.
	The current (old) layer will be removed from it's parent with 'cleanup:YES'.
	*/
	void switchTo(unsigned int n);
	/** release the current layer and switches to another layer indexed by n.
	The current (old) layer will be removed from it's parent with 'cleanup:YES'.
	*/
	void switchToAndReleaseMe(unsigned int n);

    LAYER_NODE_FUNC(CCLayerMultiplex);
};

}//namespace   cocos2d

#endif // __CCLAYER_H__


code:
/****************************************************************************
Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2008-2010 Ricardo Quesada

http://www.cocos2d-x.org

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CCMENU_H_
#define __CCMENU_H_

#include "CCMenuItem.h"
#include "CCLayer.h"

namespace cocos2d{

	typedef enum
	{
        kCCMenuStateWaiting,
        kCCMenuStateTrackingTouch
    } tCCMenuState;

    enum {
        //* priority used by the menu
        kCCMenuTouchPriority = -128,
    };

	/** @brief A CCMenu
	*
	* Features and Limitation:
	*  - You can add MenuItem objects in runtime using addChild:
	*  - But the only accecpted children are MenuItem objects
	*/
	class CC_DLL CCMenu : public CCLayer, public CCRGBAProtocol
	{
		/** Color: conforms with CCRGBAProtocol protocol */
		CC_PROPERTY_PASS_BY_REF(ccColor3B, m_tColor, Color);
		/** Opacity: conforms with CCRGBAProtocol protocol */
		CC_PROPERTY(GLubyte, m_cOpacity, Opacity);
	public:
		CCMenu()
			: m_cOpacity(0)
			, m_pSelectedItem(NULL)
		{}
		virtual ~CCMenu(){}

        /** creates an empty CCMenu */
        static CCMenu* node();

        /** creates a CCMenu with it's items */
        static CCMenu* menuWithItems(CCMenuItem* item, ...);

		/** creates a CCMenu with it's item, then use addChild() to add
		  * other items. It is used for script, it can't init with undetermined
		  * number of variables.
		*/
		static CCMenu* menuWithItem(CCMenuItem* item);

        /** initializes an empty CCMenu */
        bool init();

		/** initializes a CCMenu with it's items */
		bool initWithItems(CCMenuItem* item, va_list args);

		/** align items vertically */
		void alignItemsVertically();
		/** align items vertically with padding
		@since v0.7.2
		*/
		void alignItemsVerticallyWithPadding(float padding);

		/** align items horizontally */
		void alignItemsHorizontally();
		/** align items horizontally with padding
		@since v0.7.2
		*/
		void alignItemsHorizontallyWithPadding(float padding);

		/** align items in rows of columns */
		void alignItemsInColumns(unsigned int columns, ...);
		void alignItemsInColumns(unsigned int columns, va_list args);

		/** align items in columns of rows */
		void alignItemsInRows(unsigned int rows, ...);
		void alignItemsInRows(unsigned int rows, va_list args);

		//super methods
		virtual void addChild(CCNode * child, int zOrder);
		virtual void addChild(CCNode * child, int zOrder, int tag);
		virtual void registerWithTouchDispatcher();

        /**
        @brief For phone event handle functions
        */
		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);

        /**
        @since v0.99.5
        override onExit
        */
        virtual void onExit();

		virtual void setIsOpacityModifyRGB(bool bValue) {CC_UNUSED_PARAM(bValue);}
	    virtual bool getIsOpacityModifyRGB(void) { return false;}

	protected:
		CCMenuItem* itemForTouch(CCTouch * touch);
		tCCMenuState m_eState;
		CCMenuItem *m_pSelectedItem;
	};
}

#endif//__CCMENU_H_


code:
/****************************************************************************
Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2008-2011 Ricardo Quesada
Copyright (c) 2011      Zynga Inc.

http://www.cocos2d-x.org

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/

#ifndef __CCMENU_ITEM_H__
#define __CCMENU_ITEM_H__

#include "CCNode.h"
#include "CCProtocols.h"
#include "CCMutableArray.h"

namespace cocos2d{

    class CCLabelTTF;
    class CCLabelAtlas;
    class CCSprite;

#define kCCItemSize 32

    /** @brief CCMenuItem base class
     *
     *  Subclass CCMenuItem (or any subclass) to create your custom CCMenuItem objects.
     */
    class CC_DLL CCMenuItem : public CCNode
    {
        /** whether or not the item is selected
         @since v0.8.2
         */
        CC_PROPERTY_READONLY(bool, m_bIsSelected, IsSelected);
        CC_PROPERTY(bool, m_bIsEnabled, IsEnabled);
    public:
        CCMenuItem()
        : m_bIsSelected(false)
        , m_bIsEnabled(false)
        , m_pListener(NULL)
        , m_pfnSelector(NULL)
        , m_nScriptHandler(0)
        {}
        virtual ~CCMenuItem();
        /** Creates a CCMenuItem with a target/selector */
        static CCMenuItem * itemWithTarget(CCObject *rec, SEL_MenuHandler selector);
        /** Initializes a CCMenuItem with a target/selector */
        bool initWithTarget(CCObject *rec, SEL_MenuHandler selector);
        /** Returns the outside box */
        CCRect rect();
        /** Activate the item */
        virtual void activate();
        /** The item was selected (not activated), similar to "mouse-over" */
        virtual void selected();
        /** The item was unselected */
        virtual void unselected();

        /** Register menu handler script function */
        virtual void registerScriptHandler(int nHandler);
        virtual void unregisterScriptHandler(void);

        /** set the target/selector of the menu item*/
        void setTarget(CCObject *rec, SEL_MenuHandler selector);
    protected:
        CCObject*       m_pListener;
        SEL_MenuHandler	m_pfnSelector;
        int             m_nScriptHandler;
    };

    /** @brief An abstract class for "label" CCMenuItemLabel items
     Any CCNode that supports the CCLabelProtocol protocol can be added.
     Supported nodes:
     - CCBitmapFontAtlas
     - CCLabelAtlas
     - CCLabelTTF
     */
    class CC_DLL CCMenuItemLabel : public CCMenuItem, public CCRGBAProtocol
    {
        /** the color that will be used to disable the item */
        CC_PROPERTY_PASS_BY_REF(ccColor3B, m_tDisabledColor, DisabledColor);
        /** Label that is rendered. It can be any CCNode that implements the CCLabelProtocol */
        CC_PROPERTY(CCNode*, m_pLabel, Label);
    public:
        CCMenuItemLabel()
        : m_pLabel(NULL)
        , m_fOriginalScale(0.0)
        {}
        virtual ~CCMenuItemLabel();
        /** creates a CCMenuItemLabel with a Label, target and selector */
        static CCMenuItemLabel * itemWithLabel(CCNode*label, CCObject* target, SEL_MenuHandler selector);
        /** creates a CCMenuItemLabel with a Label. Target and selector will be nill */
        static CCMenuItemLabel* itemWithLabel(CCNode *label);
        /** initializes a CCMenuItemLabel with a Label, target and selector */
        bool initWithLabel(CCNode* label, CCObject* target, SEL_MenuHandler selector);
        /** sets a new string to the inner label */
        void setString(const char * label);
        // super methods
        virtual void activate();
        virtual void selected();
        virtual void unselected();
        /** Enable or disabled the CCMenuItemFont
         @warning setIsEnabled changes the RGB color of the font
         */
        virtual void setIsEnabled(bool enabled);
        virtual void setOpacity(GLubyte opacity);
        virtual GLubyte getOpacity();
        virtual void setColor(const ccColor3B& color);
        virtual const ccColor3B& getColor();

        virtual void setIsOpacityModifyRGB(bool bValue) {CC_UNUSED_PARAM(bValue);}
        virtual bool getIsOpacityModifyRGB(void) { return false;}
    protected:
        ccColor3B	m_tColorBackup;
        float		m_fOriginalScale;
    };

    /** @brief A CCMenuItemAtlasFont
     Helper class that creates a MenuItemLabel class with a LabelAtlas
     */
    class CC_DLL CCMenuItemAtlasFont : public CCMenuItemLabel
    {
    public:
        CCMenuItemAtlasFont(){}
        virtual ~CCMenuItemAtlasFont(){}
        /** creates a menu item from a string and atlas with a target/selector */
        static CCMenuItemAtlasFont* itemFromString(const char *value, const char *charMapFile, int itemWidth, int itemHeight, char startCharMap);
        /** creates a menu item from a string and atlas. Use it with MenuItemToggle */
        static CCMenuItemAtlasFont* itemFromString(const char *value, const char *charMapFile, int itemWidth, int itemHeight, char startCharMap, CCObject* target, SEL_MenuHandler selector);
        /** initializes a menu item from a string and atlas with a target/selector */
        bool initFromString(const char *value, const char *charMapFile, int itemWidth, int itemHeight, char startCharMap, CCObject* target, SEL_MenuHandler selector);
    };

    /** @brief A CCMenuItemFont
     Helper class that creates a CCMenuItemLabel class with a Label
     */
    class CC_DLL CCMenuItemFont : public CCMenuItemLabel
    {
    public:
        CCMenuItemFont() : m_uFontSize(0), m_strFontName(""){}
        virtual ~CCMenuItemFont(){}
        /** set default font size */
        static void setFontSize(unsigned int s);
        /** get default font size */
        static unsigned int fontSize();
        /** set the default font name */
        static void setFontName(const char *name);
        /** get the default font name */
        static const char *fontName();
        /** creates a menu item from a string without target/selector. To be used with CCMenuItemToggle */
        static CCMenuItemFont * itemFromString(const char *value);
        /** creates a menu item from a string with a target/selector */
        static CCMenuItemFont * itemFromString(const char *value, CCObject* target, SEL_MenuHandler selector);
        /** initializes a menu item from a string with a target/selector */
        bool initFromString(const char *value, CCObject* target, SEL_MenuHandler selector);

        /** set font size
         * c++ can not overload static and non-static member functions with the same parameter types
         * so change the name to setFontSizeObj
         */
        void setFontSizeObj(unsigned int s);

        /** get font size */
        unsigned int fontSizeObj();

        /** set the font name
         * c++ can not overload static and non-static member functions with the same parameter types
         * so change the name to setFontNameObj
         */
        void setFontNameObj(const char* name);

        const char* fontNameObj();

    protected:
        void recreateLabel();

        unsigned int m_uFontSize;
        std::string m_strFontName;
    };

    /** @brief CCMenuItemSprite accepts CCNode<CCRGBAProtocol> objects as items.
     The images has 3 different states:
     - unselected image
     - selected image
     - disabled image

     @since v0.8.0
     */
    class CC_DLL CCMenuItemSprite : public CCMenuItem, public CCRGBAProtocol
    {
        /** the image used when the item is not selected */
        CC_PROPERTY(CCNode*, m_pNormalImage, NormalImage);
        /** the image used when the item is selected */
        CC_PROPERTY(CCNode*, m_pSelectedImage, SelectedImage);
        /** the image used when the item is disabled */
        CC_PROPERTY(CCNode*, m_pDisabledImage, DisabledImage);
    public:
        CCMenuItemSprite()
        :m_pNormalImage(NULL)
        ,m_pSelectedImage(NULL)
        ,m_pDisabledImage(NULL)
        {}
        /** creates a menu item with a normal, selected and disabled image*/
        static CCMenuItemSprite * itemFromNormalSprite(CCNode* normalSprite, CCNode* selectedSprite, CCNode* disabledSprite = NULL);
        /** creates a menu item with a normal and selected image with target/selector */
        static CCMenuItemSprite * itemFromNormalSprite(CCNode* normalSprite, CCNode* selectedSprite, CCObject* target, SEL_MenuHandler selector);
        /** creates a menu item with a normal,selected  and disabled image with target/selector */
        static CCMenuItemSprite * itemFromNormalSprite(CCNode* normalSprite, CCNode* selectedSprite, CCNode* disabledSprite, CCObject* target, SEL_MenuHandler selector);
        /** initializes a menu item with a normal, selected  and disabled image with target/selector */
        bool initFromNormalSprite(CCNode* normalSprite, CCNode* selectedSprite, CCNode* disabledSprite, CCObject* target, SEL_MenuHandler selector);
        // super methods
        virtual void setColor(const ccColor3B& color);
        virtual const ccColor3B& getColor();
        virtual void setOpacity(GLubyte opacity);
        virtual GLubyte getOpacity();

        /**
         @since v0.99.5
         */
        virtual void selected();
        virtual void unselected();
        virtual void setIsEnabled(bool bEnabled);

        virtual void setIsOpacityModifyRGB(bool bValue) {CC_UNUSED_PARAM(bValue);}
        virtual bool getIsOpacityModifyRGB(void) { return false;}
    };

    /** @brief CCMenuItemImage accepts images as items.
     The images has 3 different states:
     - unselected image
     - selected image
     - disabled image

     For best results try that all images are of the same size
     */
    class CC_DLL CCMenuItemImage : public CCMenuItemSprite
    {
    public:
        CCMenuItemImage(){}
        virtual ~CCMenuItemImage(){}
        /** creates a menu item with a normal and selected image*/
        static CCMenuItemImage* itemFromNormalImage(const char *normalImage, const char *selectedImage);
        /** creates a menu item with a normal,selected  and disabled image*/
        static CCMenuItemImage* itemFromNormalImage(const char *normalImage, const char *selectedImage, const char *disabledImage);
        /** creates a menu item with a normal and selected image with target/selector */
        static CCMenuItemImage* itemFromNormalImage(const char *normalImage, const char *selectedImage, CCObject* target, SEL_MenuHandler selector);
        /** creates a menu item with a normal,selected  and disabled image with target/selector */
        static CCMenuItemImage* itemFromNormalImage(const char *normalImage, const char *selectedImage, const char *disabledImage, CCObject* target, SEL_MenuHandler selector);
        /** initializes a menu item with a normal, selected  and disabled image with target/selector */
        bool initFromNormalImage(const char *normalImage, const char *selectedImage, const char *disabledImage, CCObject* target, SEL_MenuHandler selector);
    };

    /** @brief A CCMenuItemToggle
     A simple container class that "toggles" it's inner items
     The inner itmes can be any MenuItem
     */
    class CC_DLL CCMenuItemToggle : public CCMenuItem, public CCRGBAProtocol
    {
        /** conforms with CCRGBAProtocol protocol */
        CC_PROPERTY(GLubyte, m_cOpacity, Opacity);
        /** conforms with CCRGBAProtocol protocol */
        CC_PROPERTY_PASS_BY_REF(ccColor3B, m_tColor, Color);
        /** returns the selected item */
        CC_PROPERTY(unsigned int, m_uSelectedIndex, SelectedIndex);
        /** CCMutableArray that contains the subitems. You can add/remove items in runtime, and you can replace the array with a new one.
         @since v0.7.2
         */
        CC_PROPERTY(CCMutableArray<CCMenuItem*>*, m_pSubItems, SubItems);
    public:
        CCMenuItemToggle()
        : m_cOpacity(0)
        , m_uSelectedIndex(0)
        , m_pSubItems(NULL)
        {}
        virtual ~CCMenuItemToggle();
        /** creates a menu item from a list of items with a target/selector */
        static CCMenuItemToggle* itemWithTarget(CCObject* target, SEL_MenuHandler selector, CCMenuItem* item, ...);
        /** initializes a menu item from a list of items with a target selector */
        bool initWithTarget(CCObject* target, SEL_MenuHandler selector, CCMenuItem* item, va_list args);

        // The follow methods offered to lua
        /** creates a menu item with a item */
        static CCMenuItemToggle* itemWithItem(CCMenuItem *item);
        /** initializes a menu item with a item */
        bool initWithItem(CCMenuItem *item);
        /** add more menu item */
        void addSubItem(CCMenuItem *item);

        /** return the selected item */
        CCMenuItem* selectedItem();
        // super methods
        virtual void activate();
        virtual void selected();
        virtual void unselected();
        virtual void setIsEnabled(bool var);

        virtual void setIsOpacityModifyRGB(bool bValue) {CC_UNUSED_PARAM(bValue);}
        virtual bool getIsOpacityModifyRGB(void) { return false;}
    };

}

#endif //__CCMENU_ITEM_H__