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 __CCTEXTURE_CACHE_H__
#define __CCTEXTURE_CACHE_H__

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

#if CC_ENABLE_CACHE_TEXTTURE_DATA
    #include "CCImage.h"
    #include <list>
#endif

namespace   cocos2d {
class CCLock;
class CCImage;

/** @brief Singleton that handles the loading of textures
* Once the texture is loaded, the next time it will return
* a reference of the previously loaded texture reducing GPU & CPU memory
*/
class CC_DLL CCTextureCache : public CCObject
{
protected:
	CCMutableDictionary<std::string, CCTexture2D*> * m_pTextures;
	//pthread_mutex_t				*m_pDictLock;

private:
	// @todo void addImageWithAsyncObject(CCAsyncObject* async);
    void addImageAsyncCallBack(ccTime dt);

public:

	CCTextureCache();
	virtual ~CCTextureCache();

	char * description(void);

	/** Retruns ths shared instance of the cache */
	static CCTextureCache * sharedTextureCache();

	/** purges the cache. It releases the retained instance.
	@since v0.99.0
	*/
	static void purgeSharedTextureCache();

	/** Returns a Texture2D object given an file image
	* If the file image was not previously loaded, it will create a new CCTexture2D
	*  object and it will return it. It will use the filename as a key.
	* Otherwise it will return a reference of a previosly loaded image.
	* Supported image extensions: .png, .bmp, .tiff, .jpeg, .pvr, .gif
	*/
	CCTexture2D* addImage(const char* fileimage);

	/* Returns a Texture2D object given a file image
	* If the file image was not previously loaded, it will create a new CCTexture2D object and it will return it.
	* Otherwise it will load a texture in a new thread, and when the image is loaded, the callback will be called with the Texture2D as a parameter.
	* The callback will be called from the main thread, so it is safe to create any cocos2d object from the callback.
	* Supported image extensions: .png, .jpg
	* @since v0.8
	*/

	void addImageAsync(const char *path, CCObject *target, SEL_CallFuncO selector);

	/* Returns a Texture2D object given an CGImageRef image
	* If the image was not previously loaded, it will create a new CCTexture2D object and it will return it.
	* Otherwise it will return a reference of a previously loaded image
	* The "key" parameter will be used as the "key" for the cache.
	* If "key" is nil, then a new texture will be created each time.
	* @since v0.8
	*/
	// @todo CGImageRef CCTexture2D* addCGImage(CGImageRef image, string &  key);
	/** Returns a Texture2D object given an UIImage image
	* If the image was not previously loaded, it will create a new CCTexture2D object and it will return it.
	* Otherwise it will return a reference of a previously loaded image
	* The "key" parameter will be used as the "key" for the cache.
	* If "key" is nil, then a new texture will be created each time.
	*/
	CCTexture2D* addUIImage(CCImage *image, const char *key);

	/** Returns an already created texture. Returns nil if the texture doesn't exist.
	@since v0.99.5
	*/
	CCTexture2D* textureForKey(const char* key);
	/** Purges the dictionary of loaded textures.
	* Call this method if you receive the "Memory Warning"
	* In the short term: it will free some resources preventing your app from being killed
	* In the medium term: it will allocate more resources
	* In the long term: it will be the same
	*/
	void removeAllTextures();

	/** Removes unused textures
	* Textures that have a retain count of 1 will be deleted
	* It is convinient to call this method after when starting a new Scene
	* @since v0.8
	*/
	void removeUnusedTextures();

	/** Deletes a texture from the cache given a texture
	*/
	void removeTexture(CCTexture2D* texture);

	/** Deletes a texture from the cache given a its key name
	@since v0.99.4
	*/
	void removeTextureForKey(const char *textureKeyName);

	/** Output to CCLOG the current contents of this CCTextureCache
	* This will attempt to calculate the size of each texture, and the total texture memory in use
	*
	* @since v1.0
	*/
	void dumpCachedTextureInfo();

#ifdef CC_SUPPORT_PVRTC
	/** Returns a Texture2D object given an PVRTC RAW filename
	* If the file image was not previously loaded, it will create a new CCTexture2D
	*  object and it will return it. Otherwise it will return a reference of a previosly loaded image
	*
	* It can only load square images: width == height, and it must be a power of 2 (128,256,512...)
	* bpp can only be 2 or 4. 2 means more compression but lower quality.
	* hasAlpha: whether or not the image contains alpha channel
	*/
	CCTexture2D* addPVRTCImage(const char* fileimage, int bpp, bool hasAlpha, int width);
#endif // CC_SUPPORT_PVRTC

	/** Returns a Texture2D object given an PVR filename
	* If the file image was not previously loaded, it will create a new CCTexture2D
	*  object and it will return it. Otherwise it will return a reference of a previosly loaded image
	*/
	CCTexture2D* addPVRImage(const char* filename);

    /** Reload all textures
    It's only useful when the value of CC_ENABLE_CACHE_TEXTTURE_DATA is 1
    */
    static void reloadAllTextures();
};

#if CC_ENABLE_CACHE_TEXTTURE_DATA

class VolatileTexture
{
typedef enum {
	kInvalid = 0,
	kImageFile,
	kImageData,
	kString,
}ccCachedImageType;

public:
    VolatileTexture(CCTexture2D *t);
    ~VolatileTexture();

    static void addImageTexture(CCTexture2D *tt, const char* imageFileName, CCImage::EImageFormat format);
    static void addStringTexture(CCTexture2D *tt, const char* text, const CCSize& dimensions, CCTextAlignment alignment, const char *fontName, float fontSize);
	static void addDataTexture(CCTexture2D *tt, void* data, CCTexture2DPixelFormat pixelFormat, const CCSize& contentSize);

    static void removeTexture(CCTexture2D *t);
    static void reloadAllTextures();

public:
    static std::list<VolatileTexture*> textures;
    static bool isReloading;

protected:
    CCTexture2D *texture;

	ccCachedImageType m_eCashedImageType;

	void *m_pTextureData;
	CCSize m_TextureSize;
	CCTexture2DPixelFormat m_PixelFormat;

    std::string m_strFileName;
    CCImage::EImageFormat m_FmtImage;

    CCSize          m_size;
    CCTextAlignment m_alignment;
    std::string     m_strFontName;
    std::string     m_strText;
    float           m_fFontSize;
};

#endif

}//namespace   cocos2d

#endif //__CCTEXTURE_CACHE_H__


code:
/****************************************************************************
Copyright (c) 2011 Jirka Fajfr for cocos2d-x
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 __CCPVRTEXTURE_H__
#define __CCPVRTEXTURE_H__

#include "CCStdC.h"

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

namespace   cocos2d {

//Forward definition for CCData
class CCData;

/**
 @brief Structure which can tell where mimap begins and how long is it
*/
struct CCPVRMipmap {
	unsigned char *address;
	unsigned int len;
};

/**
 @brief Detemine how many mipmaps can we have.
 Its same as define but it respects namespaces
*/
enum {
	CC_PVRMIPMAP_MAX = 16,
};

/** CCTexturePVR

 Object that loads PVR images.

 Supported PVR formats:
    - RGBA8888
    - BGRA8888
    - RGBA4444
    - RGBA5551
    - RGB565
    - A8
    - I8
    - AI88
    - PVRTC 4BPP
    - PVRTC 2BPP

 Limitations:
    Pre-generated mipmaps, such as PVR textures with mipmap levels embedded in file,
    are only supported if all individual sprites are of _square_ size.
    To use mipmaps with non-square textures, instead call CCTexture2D#generateMipmap on the sheet texture itself
    (and to save space, save the PVR sprite sheet without mip maps included).
*/
class CC_DLL CCTexturePVR : public CCObject
{
public:

	CCTexturePVR();
	virtual ~CCTexturePVR();

	/** initializes a CCTexturePVR with a path */
	bool initWithContentsOfFile(const char* path);

	/** creates and initializes a CCTexturePVR with a path */
	static CCTexturePVR * pvrTextureWithContentsOfFile(const char* path);

	CC_PROPERTY_READONLY(GLuint, m_uName, Name)
	CC_PROPERTY_READONLY(unsigned int, m_uWidth, Width)
	CC_PROPERTY_READONLY(unsigned int, m_uHeight, Height)
	CC_PROPERTY_READONLY(CCTexture2DPixelFormat, m_eFormat, Format)
	CC_PROPERTY_READONLY(bool, m_bHasAlpha, HasAlpha)

	// cocos2d integration
	CC_PROPERTY(bool, m_bRetainName, RetainName);

protected:

	/*
		Unpacks data (data of pvr texture file) and determine
		how many mipmaps it uses (m_uNumberOfMipmaps). Adresses
		of mimaps (m_asMipmaps). And basic data like size, format
		and alpha presence
	*/
    bool unpackPVRData(unsigned char* data, unsigned int len);

	/*
		Binds all mipmaps to the GL state machine as separate
		textures
	*/
	bool createGLTexture();

	/*
		Index to the tableFormats array. Which tells us what exact
		format is file which initializes this object.
	*/
	unsigned int m_uTableFormatIndex;

	/*
		How many mipmaps do we have. It must be at least one
		when proper initialization finishes
	*/
	unsigned int m_uNumberOfMipmaps;

	/*
		Makrs for mipmaps. Each entry contains position in file
		and lenght of data which represents one mipmap.
	*/
	struct CCPVRMipmap m_asMipmaps[CC_PVRMIPMAP_MAX];
};
}//namespace   cocos2d

#endif //__CCPVRTEXTURE_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 __CCTILE_MAP_ATLAS__
#define __CCTILE_MAP_ATLAS__
#include <string>
#include <map>
#include "CCAtlasNode.h"
namespace cocos2d {

	typedef std::map<std::string, int> StringToIntegerDictionary;
	typedef std::pair<std::string, int> StringToIntegerPair;
	struct sImageTGA;
	/** @brief CCTileMapAtlas is a subclass of CCAtlasNode.

	It knows how to render a map based of tiles.
	The tiles must be in a .PNG format while the map must be a .TGA file.

	For more information regarding the format, please see this post:
	http://www.cocos2d-iphone.org/archives/27

	All features from CCAtlasNode are valid in CCTileMapAtlas

	IMPORTANT:
	This class is deprecated. It is maintained for compatibility reasons only.
	You SHOULD not use this class.
	Instead, use the newer TMX file format: CCTMXTiledMap
	*/
	class CC_DLL CCTileMapAtlas : public CCAtlasNode
	{
		/** TileMap info */
		CC_PROPERTY(struct sImageTGA*, m_pTGAInfo, TGAInfo);
	public:
		CCTileMapAtlas();
		virtual ~CCTileMapAtlas();
		/** creates a CCTileMap with a tile file (atlas) with a map file and the width and height of each tile in points.
		The tile file will be loaded using the TextureMgr.
		*/
		static CCTileMapAtlas * tileMapAtlasWithTileFile(const char *tile, const char *mapFile, int tileWidth, int tileHeight);
		/** initializes a CCTileMap with a tile file (atlas) with a map file and the width and height of each tile in points.
		The file will be loaded using the TextureMgr.
		*/
		bool initWithTileFile(const char *tile, const char *mapFile, int tileWidth, int tileHeight);
		/** returns a tile from position x,y.
		For the moment only channel R is used
		*/
		ccColor3B tileAt(const ccGridSize& position);
		/** sets a tile at position x,y.
		For the moment only channel R is used
		*/
		void setTile(const ccColor3B& tile, const ccGridSize& position);
		/** dealloc the map from memory */
		void releaseMap();
	private:
		void loadTGAfile(const char *file);
		void calculateItemsToRender();
		void updateAtlasValueAt(const ccGridSize& pos, const ccColor3B& value, unsigned int index);
		void updateAtlasValues();

	protected:
		//! x,y to altas dicctionary
		StringToIntegerDictionary *m_pPosToAtlasIndex;
		//! numbers of tiles to render
		int				m_nItemsToRender;
	};

}// namespace cocos2d
#endif //__CCTILE_MAP_ATLAS__


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_TOUCH_H__
#define __CC_TOUCH_H__

#include "CCObject.h"
#include "CCGeometry.h"

namespace cocos2d {

class CCTouch : public CCObject
{
public:
    CCTouch() {}
    CCTouch(float x, float y) :  m_point(x, y), m_prevPoint(x, y) {}

    CCPoint locationInView() { return m_point; }
    CCPoint previousLocationInView() { return m_prevPoint; }

    void SetTouchInfo(float x, float y)
    {
        m_prevPoint = m_point;
        m_point.x   = x;
        m_point.y   = y;
    }

private:
    CCPoint m_point;
    CCPoint	m_prevPoint;
};

class CCEvent : public CCObject
{
};

}       // end of namespace cocos2d

#endif  // __PLATFORM_TOUCH_H__


code:
/****************************************************************************
Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2009      Valentin Milea

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 __TOUCH_DISPATHCHER_CCTOUCH_DELEGATE_PROTOCOL_H__
#define __TOUCH_DISPATHCHER_CCTOUCH_DELEGATE_PROTOCOL_H__

#include "CCObject.h"
#include "ccConfig.h"

namespace   cocos2d {

class CCTouch;
class CCEvent;
class CCSet;
class CCTouchDispatcher;

class CC_DLL CCTouchDelegate
{
public:

	CCTouchDelegate() {}

	virtual ~CCTouchDelegate()
	{
	}

	virtual bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent) {CC_UNUSED_PARAM(pTouch); CC_UNUSED_PARAM(pEvent); return false;};
	// optional

	virtual void ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent) {CC_UNUSED_PARAM(pTouch); CC_UNUSED_PARAM(pEvent);}
	virtual void ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent) {CC_UNUSED_PARAM(pTouch); CC_UNUSED_PARAM(pEvent);}
	virtual void ccTouchCancelled(CCTouch *pTouch, CCEvent *pEvent) {CC_UNUSED_PARAM(pTouch); CC_UNUSED_PARAM(pEvent);}

	// optional
 	virtual void ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent) {CC_UNUSED_PARAM(pTouches); CC_UNUSED_PARAM(pEvent);}
 	virtual void ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent) {CC_UNUSED_PARAM(pTouches); CC_UNUSED_PARAM(pEvent);}
 	virtual void ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent) {CC_UNUSED_PARAM(pTouches); CC_UNUSED_PARAM(pEvent);}
 	virtual void ccTouchesCancelled(CCSet *pTouches, CCEvent *pEvent) {CC_UNUSED_PARAM(pTouches); CC_UNUSED_PARAM(pEvent);}

};
/**
 @brief
 Using this type of delegate results in two benefits:
 - 1. You don't need to deal with CCSets, the dispatcher does the job of splitting
 them. You get exactly one UITouch per call.
 - 2. You can *claim* a UITouch by returning YES in ccTouchBegan. Updates of claimed
 touches are sent only to the delegate(s) that claimed them. So if you get a move/
 ended/cancelled update you're sure it's your touch. This frees you from doing a
 lot of checks when doing multi-touch.

 (The name TargetedTouchDelegate relates to updates "targeting" their specific
 handler, without bothering the other handlers.)
 @since v0.8
 */
 class CC_DLL CCTargetedTouchDelegate : public CCTouchDelegate
 {
 public:
 	/** Return YES to claim the touch.
 	 @since v0
	 */
 	virtual bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent) { CC_UNUSED_PARAM(pTouch); CC_UNUSED_PARAM(pEvent);return false;};

 	// optional
 	virtual void ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent) {CC_UNUSED_PARAM(pTouch); CC_UNUSED_PARAM(pEvent);}
 	virtual void ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent) {CC_UNUSED_PARAM(pTouch); CC_UNUSED_PARAM(pEvent);}
 	virtual void ccTouchCancelled(CCTouch *pTouch, CCEvent *pEvent) {CC_UNUSED_PARAM(pTouch); CC_UNUSED_PARAM(pEvent);}
 };

/** @brief
 This type of delegate is the same one used by CocoaTouch. You will receive all the events (Began,Moved,Ended,Cancelled).
 @since v0.8
 */
 class CC_DLL CCStandardTouchDelegate : public CCTouchDelegate
 {
 public:
 	// optional
 	virtual void ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent) {CC_UNUSED_PARAM(pTouches); CC_UNUSED_PARAM(pEvent);}
 	virtual void ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent) {CC_UNUSED_PARAM(pTouches); CC_UNUSED_PARAM(pEvent);}
 	virtual void ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent) {CC_UNUSED_PARAM(pTouches); CC_UNUSED_PARAM(pEvent);}
    virtual void ccTouchesCancelled(CCSet *pTouches, CCEvent *pEvent) {CC_UNUSED_PARAM(pTouches); CC_UNUSED_PARAM(pEvent);}
 };

}//namespace   cocos2d

#endif // __TOUCH_DISPATHCHER_CCTOUCH_DELEGATE_PROTOCOL_H__


code:
/****************************************************************************
Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2009      Valentin Milea

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 __TOUCH_DISPATCHER_CCTOUCH_DISPATCHER_H__
#define __TOUCH_DISPATCHER_CCTOUCH_DISPATCHER_H__

#include "CCTouchDelegateProtocol.h"
#include "CCObject.h"
#include "CCMutableArray.h"
namespace   cocos2d {

typedef enum
{
	ccTouchSelectorBeganBit = 1 << 0,
	ccTouchSelectorMovedBit = 1 << 1,
	ccTouchSelectorEndedBit = 1 << 2,
	ccTouchSelectorCancelledBit = 1 << 3,
	ccTouchSelectorAllBits = ( ccTouchSelectorBeganBit | ccTouchSelectorMovedBit | ccTouchSelectorEndedBit | ccTouchSelectorCancelledBit),
} ccTouchSelectorFlag;

enum {
	CCTOUCHBEGAN,
	CCTOUCHMOVED,
	CCTOUCHENDED,
	CCTOUCHCANCELLED,

	ccTouchMax,
};

class CCSet;
class CCEvent;

struct ccTouchHandlerHelperData {
	// we only use the type
//	void (StandardTouchDelegate::*touchesSel)(CCSet*, CCEvent*);
//	void (TargetedTouchDelegate::*touchSel)(NSTouch*, CCEvent*);
	int  m_type;
};

class CC_DLL EGLTouchDelegate
{
public:
	virtual void touchesBegan(CCSet* touches, CCEvent* pEvent) = 0;
	virtual void touchesMoved(CCSet* touches, CCEvent* pEvent) = 0;
	virtual void touchesEnded(CCSet* touches, CCEvent* pEvent) = 0;
	virtual void touchesCancelled(CCSet* touches, CCEvent* pEvent) = 0;

    virtual ~EGLTouchDelegate() {}
};

class CCTouchHandler;
struct _ccCArray;
/** @brief CCTouchDispatcher.
 Singleton that handles all the touch events.
 The dispatcher dispatches events to the registered TouchHandlers.
 There are 2 different type of touch handlers:
   - Standard Touch Handlers
   - Targeted Touch Handlers

 The Standard Touch Handlers work like the CocoaTouch touch handler: a set of touches is passed to the delegate.
 On the other hand, the Targeted Touch Handlers only receive 1 touch at the time, and they can "swallow" touches (avoid the propagation of the event).

 Firstly, the dispatcher sends the received touches to the targeted touches.
 These touches can be swallowed by the Targeted Touch Handlers. If there are still remaining touches, then the remaining touches will be sent
 to the Standard Touch Handlers.

 @since v0.8.0
 */
class CC_DLL CCTouchDispatcher : public CCObject, public EGLTouchDelegate
{
public:
	~CCTouchDispatcher();
	bool init(void);
	CCTouchDispatcher()
        : m_pTargetedHandlers(NULL)
        , m_pStandardHandlers(NULL)
		, m_pHandlersToAdd(NULL)
		, m_pHandlersToRemove(NULL)

	{}

public:
	/** Whether or not the events are going to be dispatched. Default: true */
    bool isDispatchEvents(void);
	void setDispatchEvents(bool bDispatchEvents);

	/** Adds a standard touch delegate to the dispatcher's list.
	 See StandardTouchDelegate description.
	 IMPORTANT: The delegate will be retained.
	 */
	void addStandardDelegate(CCTouchDelegate *pDelegate, int nPriority);

	/** Adds a targeted touch delegate to the dispatcher's list.
	 See TargetedTouchDelegate description.
	 IMPORTANT: The delegate will be retained.
	 */
	void addTargetedDelegate(CCTouchDelegate *pDelegate, int nPriority, bool bSwallowsTouches);

	/** Removes a touch delegate.
	 The delegate will be released
	 */
	void removeDelegate(CCTouchDelegate *pDelegate);

	/** Removes all touch delegates, releasing all the delegates */
	void removeAllDelegates(void);

	/** Changes the priority of a previously added delegate. The lower the number,
    the higher the priority */
	void setPriority(int nPriority, CCTouchDelegate *pDelegate);

	void touches(CCSet *pTouches, CCEvent *pEvent, unsigned int uIndex);

	virtual void touchesBegan(CCSet* touches, CCEvent* pEvent);
	virtual void touchesMoved(CCSet* touches, CCEvent* pEvent);
	virtual void touchesEnded(CCSet* touches, CCEvent* pEvent);
	virtual void touchesCancelled(CCSet* touches, CCEvent* pEvent);

public:
	/** singleton of the CCTouchDispatcher */
	static CCTouchDispatcher* sharedDispatcher();
	CCTouchHandler* findHandler(CCTouchDelegate *pDelegate);

protected:
	void forceRemoveDelegate(CCTouchDelegate *pDelegate);
	void forceAddHandler(CCTouchHandler *pHandler, CCMutableArray<CCTouchHandler*> *pArray);
	void forceRemoveAllDelegates(void);
	void rearrangeHandlers(CCMutableArray<CCTouchHandler*> *pArray);
	CCTouchHandler* findHandler(CCMutableArray<CCTouchHandler*> *pArray, CCTouchDelegate *pDelegate);

protected:
 	CCMutableArray<CCTouchHandler*> *m_pTargetedHandlers;
 	CCMutableArray<CCTouchHandler*> *m_pStandardHandlers;

	bool m_bLocked;
	bool m_bToAdd;
	bool m_bToRemove;
 	CCMutableArray<CCTouchHandler*> *m_pHandlersToAdd;
	struct _ccCArray *m_pHandlersToRemove;
	bool m_bToQuit;
	bool m_bDispatchEvents;

	// 4, 1 for each type of event
	struct ccTouchHandlerHelperData m_sHandlerHelperData[ccTouchMax];
};
}//namespace   cocos2d

#endif // __TOUCH_DISPATCHER_CCTOUCH_DISPATCHER_H__


code:
/****************************************************************************
Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2009      Valentin Milea

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 __TOUCH_DISPATCHER_CCTOUCH_HANDLER_H__
#define __TOUCH_DISPATCHER_CCTOUCH_HANDLER_H__

#include "CCTouchDelegateProtocol.h"
#include "CCTouchDispatcher.h"
#include "CCObject.h"
#include "CCSet.h"
namespace   cocos2d {

/**
 CCTouchHandler
 Object than contains the delegate and priority of the event handler.
*/
class CC_DLL  CCTouchHandler : public CCObject
{
public:
	virtual ~CCTouchHandler(void);

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

	/** priority */
	int getPriority(void);
	void setPriority(int nPriority);

	/** enabled selectors */
	int getEnabledSelectors(void);
	void setEnalbedSelectors(int nValue);

	/** initializes a TouchHandler with a delegate and a priority */
	virtual bool initWithDelegate(CCTouchDelegate *pDelegate, int nPriority);

public:
	/** allocates a TouchHandler with a delegate and a priority */
	static CCTouchHandler* handlerWithDelegate(CCTouchDelegate *pDelegate, int nPriority);

protected:
	CCTouchDelegate *m_pDelegate;
	int m_nPriority;
	int m_nEnabledSelectors;
};

/** CCStandardTouchHandler
 It forwardes each event to the delegate.
 */
class CC_DLL  CCStandardTouchHandler : public CCTouchHandler
{
public:
	/** initializes a TouchHandler with a delegate and a priority */
	virtual bool initWithDelegate(CCTouchDelegate *pDelegate, int nPriority);

public:
	/** allocates a TouchHandler with a delegate and a priority */
	static CCStandardTouchHandler* handlerWithDelegate(CCTouchDelegate *pDelegate, int nPriority);
};

/**
 CCTargetedTouchHandler
 Object than contains the claimed touches and if it swallos touches.
 Used internally by TouchDispatcher
 */
class CC_DLL  CCTargetedTouchHandler : public CCTouchHandler
{
public:
    ~CCTargetedTouchHandler(void);

    /** whether or not the touches are swallowed */
	bool isSwallowsTouches(void);
	void setSwallowsTouches(bool bSwallowsTouches);

	/** MutableSet that contains the claimed touches */
	CCSet* getClaimedTouches(void);

	/** initializes a TargetedTouchHandler with a delegate, a priority and whether or not it swallows touches or not */
	bool initWithDelegate(CCTouchDelegate *pDelegate, int nPriority, bool bSwallow);

public:
	/** allocates a TargetedTouchHandler with a delegate, a priority and whether or not it swallows touches or not */
	static CCTargetedTouchHandler* handlerWithDelegate(CCTouchDelegate *pDelegate, int nPriority, bool bSwallow);

protected:
	bool m_bSwallowsTouches;
	CCSet *m_pClaimedTouches;
};
}//namespace   cocos2d

#endif // __TOUCH_DISPATCHER_CCTOUCH_HANDLER_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 __CCTRANSITION_H__
#define __CCTRANSITION_H__

#include "CCScene.h"
namespace   cocos2d {

//static creation function macro
//c/c++ don't support object creation of using class name
//so, all classes need creation method.
#define DECLEAR_TRANSITIONWITHDURATION(_Type)\
    static _Type* transitionWithDuration(ccTime t, CCScene* scene);

class CCActionInterval;
class CCNode;

/** @brief CCTransitionEaseScene can ease the actions of the scene protocol.
@since v0.8.2
*/
class CC_DLL CCTransitionEaseScene// : public CCObject
{
public:
	/** returns the Ease action that will be performed on a linear action.
	@since v0.8.2
	*/
	virtual CCActionInterval * easeActionWithAction(CCActionInterval * action) = 0;
};

/** Orientation Type used by some transitions
*/
typedef enum {
	/// An horizontal orientation where the Left is nearer
	kOrientationLeftOver = 0,
	/// An horizontal orientation where the Right is nearer
	kOrientationRightOver = 1,
	/// A vertical orientation where the Up is nearer
	kOrientationUpOver = 0,
	/// A vertical orientation where the Bottom is nearer
	kOrientationDownOver = 1,
} tOrientation;

/** @brief Base class for CCTransition scenes
*/
class CC_DLL CCTransitionScene : public CCScene
{

protected:
	CCScene	* m_pInScene;
	CCScene	* m_pOutScene;
	ccTime	m_fDuration;
	bool	m_bIsInSceneOnTop;
	bool	m_bIsSendCleanupToScene;

public:

	CCTransitionScene();
	virtual ~CCTransitionScene();
	virtual void draw();
	virtual void onEnter();
	virtual void onExit();
	virtual void cleanup();

	/** creates a base transition with duration and incoming scene */
	static CCTransitionScene * transitionWithDuration(ccTime t, CCScene *scene);

	/** initializes a transition with duration and incoming scene */
	virtual bool initWithDuration(ccTime t,CCScene* scene);

	/** called after the transition finishes */
	void finish(void);

	/** used by some transitions to hide the outter scene */
	void hideOutShowIn(void);

protected:
	virtual void sceneOrder();
private:
	void setNewScene(ccTime dt);

};

/** @brief A CCTransition that supports orientation like.
* Possible orientation: LeftOver, RightOver, UpOver, DownOver
*/
class CC_DLL CCTransitionSceneOriented : public CCTransitionScene
{
protected:
	tOrientation m_eOrientation;

public:
	CCTransitionSceneOriented();
	virtual ~CCTransitionSceneOriented();

	/** creates a base transition with duration and incoming scene */
	static CCTransitionSceneOriented * transitionWithDuration(ccTime t,CCScene* scene, tOrientation orientation);
	/** initializes a transition with duration and incoming scene */
	virtual bool initWithDuration(ccTime t,CCScene* scene,tOrientation orientation);
};

/** @brief CCTransitionRotoZoom:
Rotate and zoom out the outgoing scene, and then rotate and zoom in the incoming
*/
class CC_DLL CCTransitionRotoZoom : public CCTransitionScene
{
public:
	CCTransitionRotoZoom();
	virtual ~CCTransitionRotoZoom();
	virtual void onEnter();

    DECLEAR_TRANSITIONWITHDURATION(CCTransitionRotoZoom);
};

/** @brief CCTransitionJumpZoom:
Zoom out and jump the outgoing scene, and then jump and zoom in the incoming
*/
class CC_DLL CCTransitionJumpZoom : public CCTransitionScene
{
public:
	CCTransitionJumpZoom();
	virtual ~CCTransitionJumpZoom();
	virtual void onEnter();

    DECLEAR_TRANSITIONWITHDURATION(CCTransitionJumpZoom);
};

/** @brief CCTransitionMoveInL:
Move in from to the left the incoming scene.
*/
class CC_DLL CCTransitionMoveInL : public CCTransitionScene, public CCTransitionEaseScene
{
public:
	CCTransitionMoveInL();
	virtual ~CCTransitionMoveInL();
	/** initializes the scenes */
	virtual void initScenes(void);
	/** returns the action that will be performed */
	virtual CCActionInterval* action(void);

	virtual CCActionInterval* easeActionWithAction(CCActionInterval * action);

	virtual void onEnter();

    DECLEAR_TRANSITIONWITHDURATION(CCTransitionMoveInL);
};

/** @brief CCTransitionMoveInR:
Move in from to the right the incoming scene.
*/
class CC_DLL CCTransitionMoveInR : public CCTransitionMoveInL
{
public:
	CCTransitionMoveInR();
	virtual ~CCTransitionMoveInR();
	virtual void initScenes();

    DECLEAR_TRANSITIONWITHDURATION(CCTransitionMoveInR);
};

/** @brief CCTransitionMoveInT:
Move in from to the top the incoming scene.
*/
class CC_DLL CCTransitionMoveInT : public CCTransitionMoveInL
{
public:
	CCTransitionMoveInT();
	virtual ~CCTransitionMoveInT();
	virtual void initScenes();

    DECLEAR_TRANSITIONWITHDURATION(CCTransitionMoveInT);
};

/** @brief CCTransitionMoveInB:
Move in from to the bottom the incoming scene.
*/
class CC_DLL CCTransitionMoveInB : public CCTransitionMoveInL
{
public:
	CCTransitionMoveInB();
	virtual ~CCTransitionMoveInB();
	virtual void initScenes();

    DECLEAR_TRANSITIONWITHDURATION(CCTransitionMoveInB);
};

/** @brief CCTransitionSlideInL:
Slide in the incoming scene from the left border.
*/
class CC_DLL CCTransitionSlideInL : public CCTransitionScene, public CCTransitionEaseScene
{
public:
	CCTransitionSlideInL();
	virtual ~CCTransitionSlideInL();

	/** initializes the scenes */
	virtual void initScenes(void);
	/** returns the action that will be performed by the incomming and outgoing scene */
	virtual CCActionInterval* action(void);

	virtual void onEnter();

	virtual CCActionInterval* easeActionWithAction(CCActionInterval * action);

    DECLEAR_TRANSITIONWITHDURATION(CCTransitionSlideInL);
protected:
	virtual void sceneOrder();
};

/** @brief CCTransitionSlideInR:
Slide in the incoming scene from the right border.
*/
class CC_DLL CCTransitionSlideInR : public CCTransitionSlideInL
{
public:
	CCTransitionSlideInR();
	virtual ~CCTransitionSlideInR();

	/** initializes the scenes */
	virtual void initScenes(void);
	/** returns the action that will be performed by the incomming and outgoing scene */
	virtual CCActionInterval* action(void);

    DECLEAR_TRANSITIONWITHDURATION(CCTransitionSlideInR);
protected:
	virtual void sceneOrder();
};

/** @brief CCTransitionSlideInB:
Slide in the incoming scene from the bottom border.
*/
class CC_DLL CCTransitionSlideInB : public CCTransitionSlideInL
{
public:
	CCTransitionSlideInB();
	virtual ~CCTransitionSlideInB();

	/** initializes the scenes */
	virtual void initScenes(void);
	/** returns the action that will be performed by the incomming and outgoing scene */
	virtual CCActionInterval* action(void);

    DECLEAR_TRANSITIONWITHDURATION(CCTransitionSlideInB);
protected:
	virtual void sceneOrder();
};

/** @brief CCTransitionSlideInT:
Slide in the incoming scene from the top border.
*/
class CC_DLL CCTransitionSlideInT : public CCTransitionSlideInL
{
public:
	CCTransitionSlideInT();
	virtual ~CCTransitionSlideInT();

	/** initializes the scenes */
	virtual void initScenes(void);
	/** returns the action that will be performed by the incomming and outgoing scene */
	virtual CCActionInterval* action(void);

    DECLEAR_TRANSITIONWITHDURATION(CCTransitionSlideInT);
protected:
	virtual void sceneOrder();
};

/**
@brief Shrink the outgoing scene while grow the incoming scene
*/
class CC_DLL CCTransitionShrinkGrow : public CCTransitionScene , public CCTransitionEaseScene
{
public:
	CCTransitionShrinkGrow();
	virtual ~CCTransitionShrinkGrow();

	virtual void onEnter();
	virtual CCActionInterval* easeActionWithAction(CCActionInterval * action);

    DECLEAR_TRANSITIONWITHDURATION(CCTransitionShrinkGrow);
};

/** @brief CCTransitionFlipX:
Flips the screen horizontally.
The front face is the outgoing scene and the back face is the incoming scene.
*/
class CC_DLL CCTransitionFlipX : public CCTransitionSceneOriented
{
public:
	CCTransitionFlipX();
	virtual ~CCTransitionFlipX();

	virtual void onEnter();

    static CCTransitionFlipX* transitionWithDuration(ccTime t, CCScene* s, tOrientation o = kOrientationRightOver);
};

/** @brief CCTransitionFlipY:
Flips the screen vertically.
The front face is the outgoing scene and the back face is the incoming scene.
*/
class CC_DLL CCTransitionFlipY : public CCTransitionSceneOriented
{
public:
	CCTransitionFlipY();
	virtual ~CCTransitionFlipY();

	virtual void onEnter();

    static CCTransitionFlipY* transitionWithDuration(ccTime t, CCScene* s, tOrientation o = kOrientationUpOver);
};

/** @brief CCTransitionFlipAngular:
Flips the screen half horizontally and half vertically.
The front face is the outgoing scene and the back face is the incoming scene.
*/
class CC_DLL CCTransitionFlipAngular : public CCTransitionSceneOriented
{
public:
	CCTransitionFlipAngular();
	virtual ~CCTransitionFlipAngular();

	virtual void onEnter();

    static CCTransitionFlipAngular* transitionWithDuration(ccTime t, CCScene* s, tOrientation o = kOrientationRightOver);
};

/** @brief CCTransitionZoomFlipX:
Flips the screen horizontally doing a zoom out/in
The front face is the outgoing scene and the back face is the incoming scene.
*/
class CC_DLL CCTransitionZoomFlipX : public CCTransitionSceneOriented
{
public:
	CCTransitionZoomFlipX();
	virtual ~CCTransitionZoomFlipX();

	virtual void onEnter();

    static CCTransitionZoomFlipX* transitionWithDuration(ccTime t, CCScene* s, tOrientation o = kOrientationRightOver);
};

/** @brief CCTransitionZoomFlipY:
Flips the screen vertically doing a little zooming out/in
The front face is the outgoing scene and the back face is the incoming scene.
*/
class CC_DLL CCTransitionZoomFlipY : public CCTransitionSceneOriented
{
public:
	CCTransitionZoomFlipY();
	virtual ~CCTransitionZoomFlipY();

	virtual void onEnter();

    static CCTransitionZoomFlipY* transitionWithDuration(ccTime t, CCScene* s, tOrientation o = kOrientationUpOver);
};

/** @brief CCTransitionZoomFlipAngular:
Flips the screen half horizontally and half vertically doing a little zooming out/in.
The front face is the outgoing scene and the back face is the incoming scene.
*/
class CC_DLL CCTransitionZoomFlipAngular : public CCTransitionSceneOriented
{
public:
	CCTransitionZoomFlipAngular();
	virtual ~CCTransitionZoomFlipAngular();

	virtual void onEnter();

    static CCTransitionZoomFlipAngular* transitionWithDuration(ccTime t, CCScene* s, tOrientation o = kOrientationRightOver);
};

/** @brief CCTransitionFade:
Fade out the outgoing scene and then fade in the incoming scene.'''
*/
class CC_DLL CCTransitionFade : public CCTransitionScene
{
protected:
	ccColor4B	m_tColor;

public:

	CCTransitionFade();
	virtual ~CCTransitionFade();

	/** creates the transition with a duration and with an RGB color
	* Example: FadeTransition::transitionWithDuration(2, scene, ccc3(255,0,0); // red color
	*/
	static CCTransitionFade* transitionWithDuration(ccTime duration,CCScene* scene, const ccColor3B& color = ccBLACK);
	/** initializes the transition with a duration and with an RGB color */
	virtual bool initWithDuration(ccTime t, CCScene*scene ,const ccColor3B& color);

	virtual bool initWithDuration(ccTime t,CCScene* scene);
	virtual void onEnter();
	virtual void onExit();
};

class CCRenderTexture;
/**
@brief CCTransitionCrossFade:
Cross fades two scenes using the CCRenderTexture object.
*/
class CC_DLL CCTransitionCrossFade : public CCTransitionScene
{
public :
	CCTransitionCrossFade();
	virtual ~CCTransitionCrossFade();

	virtual void draw();
	virtual void onEnter();
	virtual void onExit();

public:
    DECLEAR_TRANSITIONWITHDURATION(CCTransitionCrossFade);
};

/** @brief CCTransitionTurnOffTiles:
Turn off the tiles of the outgoing scene in random order
*/
class CC_DLL CCTransitionTurnOffTiles : public CCTransitionScene ,public CCTransitionEaseScene
{
public :
	CCTransitionTurnOffTiles();
	virtual ~CCTransitionTurnOffTiles();

	virtual void onEnter();
	virtual CCActionInterval * easeActionWithAction(CCActionInterval * action);

public:
    DECLEAR_TRANSITIONWITHDURATION(CCTransitionTurnOffTiles);
protected:
	virtual void sceneOrder();
};

/** @brief CCTransitionSplitCols:
The odd columns goes upwards while the even columns goes downwards.
*/
class CC_DLL CCTransitionSplitCols : public CCTransitionScene , public CCTransitionEaseScene
{
public:
	CCTransitionSplitCols();
	virtual ~CCTransitionSplitCols();

	virtual CCActionInterval* action(void);
	virtual void onEnter();
	virtual CCActionInterval * easeActionWithAction(CCActionInterval * action);

public:
    DECLEAR_TRANSITIONWITHDURATION(CCTransitionSplitCols);
};

/** @brief CCTransitionSplitRows:
The odd rows goes to the left while the even rows goes to the right.
*/
class CC_DLL CCTransitionSplitRows : public CCTransitionSplitCols
{
public:
	CCTransitionSplitRows();
	virtual ~CCTransitionSplitRows();

	virtual CCActionInterval* action(void);

public:
    DECLEAR_TRANSITIONWITHDURATION(CCTransitionSplitRows)
};

/** @brief CCTransitionFadeTR:
Fade the tiles of the outgoing scene from the left-bottom corner the to top-right corner.
*/
class CC_DLL CCTransitionFadeTR : public CCTransitionScene , public CCTransitionEaseScene
{
public:
	CCTransitionFadeTR();
	virtual ~CCTransitionFadeTR();
	virtual CCActionInterval* actionWithSize(const ccGridSize& size);
	virtual void onEnter();
	virtual CCActionInterval* easeActionWithAction(CCActionInterval * action);

public:
    DECLEAR_TRANSITIONWITHDURATION(CCTransitionFadeTR)
protected:
	virtual void sceneOrder();

};

/** @brief CCTransitionFadeBL:
Fade the tiles of the outgoing scene from the top-right corner to the bottom-left corner.
*/
class CC_DLL CCTransitionFadeBL : public CCTransitionFadeTR
{
public:
	CCTransitionFadeBL();
	virtual ~CCTransitionFadeBL();
	virtual CCActionInterval* actionWithSize(const ccGridSize& size);

public:
    DECLEAR_TRANSITIONWITHDURATION(CCTransitionFadeBL)
};

/** @brief CCTransitionFadeUp:
* Fade the tiles of the outgoing scene from the bottom to the top.
*/
class CC_DLL CCTransitionFadeUp : public CCTransitionFadeTR
{
public:
	CCTransitionFadeUp();
	virtual ~CCTransitionFadeUp();
	virtual CCActionInterval* actionWithSize(const ccGridSize& size);

public:
    DECLEAR_TRANSITIONWITHDURATION(CCTransitionFadeUp)
};

/** @brief CCTransitionFadeDown:
* Fade the tiles of the outgoing scene from the top to the bottom.
*/
class CC_DLL CCTransitionFadeDown : public CCTransitionFadeTR
{
public:
	CCTransitionFadeDown();
	virtual ~CCTransitionFadeDown();
	virtual CCActionInterval* actionWithSize(const ccGridSize& size);

public:
    DECLEAR_TRANSITIONWITHDURATION(CCTransitionFadeDown)
};
}//namespace   cocos2d

#endif // __CCTRANSITION_H__


code:
/****************************************************************************
Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2009      Sindesso Pty Ltd http://www.sindesso.com/

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 __CCPAGE_TURN_TRANSITION_H__
#define __CCPAGE_TURN_TRANSITION_H__

#include "CCTransition.h"
namespace   cocos2d {

/**
@brief A transition which peels back the bottom right hand corner of a scene
to transition to the scene beneath it simulating a page turn.

This uses a 3DAction so it's strongly recommended that depth buffering
is turned on in CCDirector using:

 CCDirector::sharedDirector()->setDepthBufferFormat(kDepthBuffer16);

 @since v0.8.2
*/
class CC_DLL CCTransitionPageTurn : public CCTransitionScene
{
protected:
	bool	m_bBack;

public:
	CCTransitionPageTurn();
	virtual ~CCTransitionPageTurn();

	/**
	* Creates a base transition with duration and incoming scene.
	* If back is true then the effect is reversed to appear as if the incoming
	* scene is being turned from left over the outgoing scene.
	*/
	static CCTransitionPageTurn* transitionWithDuration(ccTime t,CCScene* scene,bool backwards);

	/**
	* Creates a base transition with duration and incoming scene.
	* If back is true then the effect is reversed to appear as if the incoming
	* scene is being turned from left over the outgoing scene.
	*/
	virtual bool initWithDuration(ccTime t,CCScene* scene,bool backwards);

	CCActionInterval* actionWithSize(const ccGridSize& vector);

	virtual void onEnter();

protected:
	virtual void sceneOrder();
};
}//namespace   cocos2d

#endif // __CCPAGE_TURN_TRANSITION_H__


code:
/****************************************************************************
Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2009      Lam Pham

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 __CCRADIAL_TRANSITION_H__
#define __CCRADIAL_TRANSITION_H__
#include "CCTransition.h"
#include "CCProgressTimer.h"

namespace   cocos2d {

/**
 @brief A counter colock-wise radial transition to the next scene
 */
class CC_DLL CCTransitionRadialCCW : public CCTransitionScene
{
public:
	CCTransitionRadialCCW(){}
	virtual ~CCTransitionRadialCCW(){}

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

    static CCTransitionRadialCCW* transitionWithDuration(ccTime t, CCScene* scene);

protected:
	virtual void sceneOrder();
	virtual CCProgressTimerType radialType();
};

/**
 @brief A counter colock-wise radial transition to the next scene
 */
class CC_DLL CCTransitionRadialCW : public CCTransitionRadialCCW
{
public:
	CCTransitionRadialCW(){}
	virtual ~CCTransitionRadialCW(){}
    static CCTransitionRadialCW* transitionWithDuration(ccTime t, CCScene* scene);

protected:
	virtual CCProgressTimerType radialType();
};

}//namespace   cocos2d

#endif //__CCRADIAL_TRANSITION_H__


code:
/****************************************************************************
Copyright (c) 2010-2011 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 __SUPPORT_CCUSERDEFAULT_H__
#define __SUPPORT_CCUSERDEFAULT_H__

#include "CCPlatformMacros.h"

#include <string>

#if (CC_TARGET_PLATFORM == CC_PLATFORM_QT)
#include <QSettings>
#endif

NS_CC_BEGIN;

/**
 * CCUserDefault acts as a tiny database. You can save and get base type values by it.
 * For example, setBoolForKey("played", true) will add a bool value true into the database.
 * Its key is "played". You can get the value of the key by getBoolForKey("played").
 *
 * It supports the following base types:
 * bool, int, float, double, string
 */
class CC_DLL CCUserDefault
{
public:
	~CCUserDefault();

	// get value methods

	/**
	@brief Get bool value by key, if the key doesn't exist, a default value will return.
	 You can set the default value, or it is false.
	*/
	bool	getBoolForKey(const char* pKey, bool defaultValue = false);
	/**
	@brief Get integer value by key, if the key doesn't exist, a default value will return.
	 You can set the default value, or it is 0.
	*/
	int		getIntegerForKey(const char* pKey, int defaultValue = 0);
	/**
	@brief Get float value by key, if the key doesn't exist, a default value will return.
	 You can set the default value, or it is 0.0f.
	*/
	float	getFloatForKey(const char* pKey, float defaultValue=0.0f);
	/**
	@brief Get double value by key, if the key doesn't exist, a default value will return.
	 You can set the default value, or it is 0.0.
	*/
	double  getDoubleForKey(const char* pKey, double defaultValue=0.0);
	/**
	@brief Get string value by key, if the key doesn't exist, a default value will return.
	You can set the default value, or it is "".
	*/
	std::string getStringForKey(const char* pKey, const std::string & defaultValue = "");

	// set value methods

	/**
	@brief Set bool value by key.
	*/
	void	setBoolForKey(const char* pKey, bool value);
	/**
	@brief Set integer value by key.
	*/
	void	setIntegerForKey(const char* pKey, int value);
	/**
	@brief Set float value by key.
	*/
	void	setFloatForKey(const char* pKey, float value);
	/**
	@brief Set double value by key.
	*/
	void	setDoubleForKey(const char* pKey, double value);
	/**
	@brief Set string value by key.
	*/
	void	setStringForKey(const char* pKey, const std::string & value);
	/**
	 @brief Save content to xml file
	 */
	void    flush();

	static CCUserDefault* sharedUserDefault();
	static void purgeSharedUserDefault();
	const static std::string& getXMLFilePath();

private:
	CCUserDefault();

    static CCUserDefault* m_spUserDefault;

#if (CC_TARGET_PLATFORM == CC_PLATFORM_QT)
    static QSettings* m_settings;
#else
    static bool createXMLFile();
    static bool isXMLFileExist();
    static void initXMLFilePath();

    static std::string m_sFilePath;
    static bool m_sbIsFilePathInitialized;
#endif
};

NS_CC_END;

#endif // __SUPPORT_CCUSERDEFAULT_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_ZONE_H__
#define __CC_ZONE_H__
#include <stdio.h>

namespace   cocos2d {

class CCObject;

class CCZone
{
public:
	CCZone(CCObject *pObject = NULL);

public:
	CCObject *m_pCopyObject;
};
}//namespace   cocos2d

#endif // __CC_ZONE_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 __CCCONFIG_H__
#define __CCCONFIG_H__

#include "CCPlatformConfig.h"

/** @def CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL
If enabled, the texture coordinates will be calculated by using this formula:
- texCoord.left = (rect.origin.x*2+1) / (texture.wide*2);
- texCoord.right = texCoord.left + (rect.size.width*2-2)/(texture.wide*2);

The same for bottom and top.

This formula prevents artifacts by using 99% of the texture.
The "correct" way to prevent artifacts is by using the spritesheet-artifact-fixer.py or a similar tool.

Affected nodes:
- CCSprite / CCSpriteBatchNode and subclasses: CCLabelBMFont, CCTMXTiledMap
- CCLabelAtlas
- CCQuadParticleSystem
- CCTileMap

To enabled set it to 1. Disabled by default.

@since v0.99.5
*/
#ifndef CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL
#define CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL 0
#endif

/** @def CC_FONT_LABEL_SUPPORT
 If enabled, FontLabel will be used to render .ttf files.
 If the .ttf file is not found, then it will use the standard UIFont class
 If disabled, the standard UIFont class will be used.

 To disable set it to 0. Enabled by default.

 Only valid for cocos2d-ios. Not supported on cocos2d-mac
 */
#ifndef CC_FONT_LABEL_SUPPORT
#define CC_FONT_LABEL_SUPPORT	1
#endif

/** @def CC_DIRECTOR_FAST_FPS
 If enabled, then the FPS will be drawn using CCLabelAtlas (fast rendering).
 You will need to add the fps_images.png to your project.
 If disabled, the FPS will be rendered using CCLabel (slow rendering)

 To enable set it to a value different than 0. Enabled by default.
 */
#ifndef CC_DIRECTOR_FAST_FPS
#define CC_DIRECTOR_FAST_FPS	1
#endif

/** @def CC_DIRECTOR_FPS_INTERVAL
 Senconds between FPS updates.
 0.5 seconds, means that the FPS number will be updated every 0.5 seconds.
 Having a bigger number means a more reliable FPS

 Default value: 0.1f
 */
#ifndef CC_DIRECTOR_FPS_INTERVAL
#define CC_DIRECTOR_FPS_INTERVAL (0.5f)
#endif

/** @def CC_DIRECTOR_DISPATCH_FAST_EVENTS
 If enabled, and only when it is used with CCFastDirector, the main loop will wait 0.04 seconds to
 dispatch all the events, even if there are not events to dispatch.
 If your game uses lot's of events (eg: touches) it might be a good idea to enable this feature.
 Otherwise, it is safe to leave it disabled.

 To enable set it to 1. Disabled by default.

 @warning This feature is experimental
 */
#ifndef CC_DIRECTOR_DISPATCH_FAST_EVENTS
 #define CC_DIRECTOR_DISPATCH_FAST_EVENTS 0
#endif

/** @def CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD
If enabled, cocos2d-mac will run on the Display Link thread. If disabled cocos2d-mac will run in its own thread.

If enabled, the images will be drawn at the "correct" time, but the events might not be very responsive.
If disabled, some frames might be skipped, but the events will be dispatched as they arrived.

To enable set it to a 1, to disable it set to 0. Enabled by default.

Only valid for cocos2d-mac. Not supported on cocos2d-ios.

*/
#ifndef CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD
#define CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD 1
#endif

/** @def CC_COCOSNODE_RENDER_SUBPIXEL
 If enabled, the CCNode objects (CCSprite, CCLabel,etc) will be able to render in subpixels.
 If disabled, integer pixels will be used.

 To enable set it to 1. Enabled by default.
 */
#ifndef CC_COCOSNODE_RENDER_SUBPIXEL
#define CC_COCOSNODE_RENDER_SUBPIXEL 1
#endif

/** @def CC_SPRITEBATCHNODE_RENDER_SUBPIXEL
 If enabled, the CCSprite objects rendered with CCSpriteBatchNode will be able to render in subpixels.
 If disabled, integer pixels will be used.

 To enable set it to 1. Enabled by default.
 */
#ifndef CC_SPRITEBATCHNODE_RENDER_SUBPIXEL
#define CC_SPRITEBATCHNODE_RENDER_SUBPIXEL	1
#endif

/** @def CC_USES_VBO
If enabled, batch nodes (texture atlas and particle system) will use VBO instead of vertex list (VBO is recommended by Apple)

To enable set it to 1.
Enabled by default on iPhone with ARMv7 processors, iPhone Simulator and Mac
Disabled by default on iPhone with ARMv6 processors.

@since v0.99.5
*/
#ifndef CC_USES_VBO
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE)
#define CC_USES_VBO 0
#else
#define CC_USES_VBO 1
#endif
#endif

/** @def CC_NODE_TRANSFORM_USING_AFFINE_MATRIX
 If enabled, CCNode will transform the nodes using a cached Affine matrix.
 If disabled, the node will be transformed using glTranslate,glRotate,glScale.
 Using the affine matrix only requires 2 GL calls.
 Using the translate/rotate/scale requires 5 GL calls.
 But computing the Affine matrix is relative expensive.
 But according to performance tests, Affine matrix performs better.
 This parameter doesn't affect CCSpriteBatchNode nodes.

 To enable set it to a value different than 0. Enabled by default.

 */
#ifndef CC_NODE_TRANSFORM_USING_AFFINE_MATRIX
#define CC_NODE_TRANSFORM_USING_AFFINE_MATRIX 1
#endif

/** @def CC_OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA
If most of your imamges have pre-multiplied alpha, set it to 1 (if you are going to use .PNG/.JPG file images).
Only set to 0 if ALL your images by-pass Apple UIImage loading system (eg: if you use libpng or PVR images)

To enable set it to a value different than 0. Enabled by default.

@since v0.99.5
*/
#ifndef CC_OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA
#define CC_OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA 1
#endif

/** @def CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP
 Use GL_TRIANGLE_STRIP instead of GL_TRIANGLES when rendering the texture atlas.
 It seems it is the recommend way, but it is much slower, so, enable it at your own risk

 To enable set it to a value different than 0. Disabled by default.

 */
#ifndef CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP
#define CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP 0
#endif

/** @def CC_TEXTURE_NPOT_SUPPORT
 If enabled, NPOT textures will be used where available. Only 3rd gen (and newer) devices support NPOT textures.
 NPOT textures have the following limitations:
	- They can't have mipmaps
	- They only accept GL_CLAMP_TO_EDGE in GL_TEXTURE_WRAP_{S,T}

 To enable set it to a value different than 0. Disabled by default.

 This value governs only the PNG, GIF, BMP, images.
 This value DOES NOT govern the PVR (PVR.GZ, PVR.CCZ) files. If NPOT PVR is loaded, then it will create an NPOT texture ignoring this value.

 @deprecated This value will be removed in 1.1 and NPOT textures will be loaded by default if the device supports it.

 @since v0.99.2
 */
#ifndef CC_TEXTURE_NPOT_SUPPORT
#define CC_TEXTURE_NPOT_SUPPORT 0
#endif

/** @def CC_USE_LA88_LABELS_ON_NEON_ARCH
If enabled, it will use LA88 (16-bit textures) on Neon devices for CCLabelTTF objects.
If it is disabled, or if it is used on another architecture it will use A8 (8-bit textures).
On Neon devices, LA88 textures are 6% faster than A8 textures, but then will consume 2x memory.

This feature is disabled by default.

Platforms: Only used on ARM Neon architectures like iPhone 3GS or newer and iPad.

@since v0.99.5
*/
#ifndef CC_USE_LA88_LABELS_ON_NEON_ARCH
#define CC_USE_LA88_LABELS_ON_NEON_ARCH 0
#endif

/** @def CC_SPRITE_DEBUG_DRAW
 If enabled, all subclasses of CCSprite will draw a bounding box
 Useful for debugging purposes only. It is recommened to leave it disabled.

 To enable set it to a value different than 0. Disabled by default:
 0 -- disabled
 1 -- draw bounding box
 2 -- draw texture box
 0 -- disabled
 1 -- draw bounding box
 2 -- draw texture box
*/
#ifndef CC_SPRITE_DEBUG_DRAW
#define CC_SPRITE_DEBUG_DRAW 0
#endif

/** @def CC_SPRITEBATCHNODE_DEBUG_DRAW
If enabled, all subclasses of CCSprite that are rendered using an CCSpriteBatchNode draw a bounding box.
Useful for debugging purposes only. It is recommened to leave it disabled.

To enable set it to a value different than 0. Disabled by default.
*/
#ifndef CC_SPRITEBATCHNODE_DEBUG_DRAW
#define CC_SPRITEBATCHNODE_DEBUG_DRAW 0
#endif

/** @def CC_LABELBMFONT_DEBUG_DRAW
If enabled, all subclasses of CCLabelBMFont will draw a bounding box
Useful for debugging purposes only. It is recommened to leave it disabled.

To enable set it to a value different than 0. Disabled by default.
*/
#ifndef CC_LABELBMFONT_DEBUG_DRAW
#define CC_LABELBMFONT_DEBUG_DRAW 0
#endif

/** @def CC_LABELATLAS_DEBUG_DRAW
 If enabled, all subclasses of LabeltAtlas will draw a bounding box
 Useful for debugging purposes only. It is recommened to leave it disabled.

 To enable set it to a value different than 0. Disabled by default.
 */
#ifndef CC_LABELATLAS_DEBUG_DRAW
#define CC_LABELATLAS_DEBUG_DRAW 0
#endif

/** @def CC_ENABLE_PROFILERS
 If enabled, will activate various profilers withing cocos2d. This statistical data will be output to the console
 once per second showing average time (in milliseconds) required to execute the specific routine(s).
 Useful for debugging purposes only. It is recommened to leave it disabled.

 To enable set it to a value different than 0. Disabled by default.
 */
#ifndef CC_ENABLE_PROFILERS
#define CC_ENABLE_PROFILERS 0
#endif

/** Enable Lua engine debug log */
#ifndef CC_LUA_ENGINE_DEBUG
#define CC_LUA_ENGINE_DEBUG 0
#endif

#endif // __CCCONFIG_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 __CCMACROS_H__
#define __CCMACROS_H__

#ifndef _USE_MATH_DEFINES
#define _USE_MATH_DEFINES
#endif

#include "CCCommon.h"
#include "CCStdC.h"

#ifndef CCAssert
#define CCAssert(cond, msg)         CC_ASSERT(cond)
#endif  // CCAssert

#include "ccConfig.h"

/** @def CC_SWAP
simple macro that swaps 2 variables
*/
#define CC_SWAP(x, y, type)	\
{	type temp = (x);		\
	x = y; y = temp;		\
}

/** @def CCRANDOM_MINUS1_1
 returns a random float between -1 and 1
 */
#define CCRANDOM_MINUS1_1() ((2.0f*((float)rand()/RAND_MAX))-1.0f)

/** @def CCRANDOM_0_1
 returns a random float between 0 and 1
 */
#define CCRANDOM_0_1() ((float)rand()/RAND_MAX)

/** @def CC_DEGREES_TO_RADIANS
 converts degrees to radians
 */
#define CC_DEGREES_TO_RADIANS(__ANGLE__) ((__ANGLE__) * 0.01745329252f) // PI / 180

/** @def CC_RADIANS_TO_DEGREES
 converts radians to degrees
 */
#define CC_RADIANS_TO_DEGREES(__ANGLE__) ((__ANGLE__) * 57.29577951f) // PI * 180

/** @def CC_BLEND_SRC
default gl blend src function. Compatible with premultiplied alpha images.
*/
#if CC_OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA
    #define CC_BLEND_SRC GL_ONE
    #define CC_BLEND_DST GL_ONE_MINUS_SRC_ALPHA
#else
    #define CC_BLEND_SRC GL_SRC_ALPHA
    #define CC_BLEND_DST GL_ONE_MINUS_SRC_ALPHA
#endif // ! CC_OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA

/** @def CC_BLEND_DST
 default gl blend dst function. Compatible with premultiplied alpha images.
 */
#define CC_BLEND_DST GL_ONE_MINUS_SRC_ALPHA

/** @def CC_ENABLE_DEFAULT_GL_STATES
 GL states that are enabled:
	- GL_TEXTURE_2D
	- GL_VERTEX_ARRAY
	- GL_TEXTURE_COORD_ARRAY
	- GL_COLOR_ARRAY
 */
#define CC_ENABLE_DEFAULT_GL_STATES() {				\
	glEnableClientState(GL_VERTEX_ARRAY);			\
	glEnableClientState(GL_COLOR_ARRAY);			\
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);	\
	glEnable(GL_TEXTURE_2D);						\
}

/** @def CC_DISABLE_DEFAULT_GL_STATES
 Disable default GL states:
	- GL_TEXTURE_2D
	- GL_VERTEX_ARRAY
	- GL_TEXTURE_COORD_ARRAY
	- GL_COLOR_ARRAY
 */
#define CC_DISABLE_DEFAULT_GL_STATES() {			\
	glDisable(GL_TEXTURE_2D);						\
	glDisableClientState(GL_COLOR_ARRAY);			\
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);	\
	glDisableClientState(GL_VERTEX_ARRAY);			\
}

#ifndef FLT_EPSILON
#define FLT_EPSILON     1.192092896e-07F
#endif // FLT_EPSILON

#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
	        TypeName(const TypeName&);\
			void operator=(const TypeName&)

/****************************/
/** RETINA DISPLAY ENABLED **/
/****************************/

/** @def CC_CONTENT_SCALE_FACTOR
On Mac it returns 1;
On iPhone it returns 2 if RetinaDisplay is On. Otherwise it returns 1
*/
#define CC_CONTENT_SCALE_FACTOR() CCDirector::sharedDirector()->getContentScaleFactor()

/** @def CC_RECT_PIXELS_TO_POINTS
Converts a rect in pixels to points
*/
#define CC_RECT_PIXELS_TO_POINTS(__pixels__)																		\
    CCRectMake( (__pixels__).origin.x / CC_CONTENT_SCALE_FACTOR(), (__pixels__).origin.y / CC_CONTENT_SCALE_FACTOR(),	\
    (__pixels__).size.width / CC_CONTENT_SCALE_FACTOR(), (__pixels__).size.height / CC_CONTENT_SCALE_FACTOR() )

/** @def CC_RECT_POINTS_TO_PIXELS
Converts a rect in points to pixels
*/
#define CC_RECT_POINTS_TO_PIXELS(__points__)																		\
    CCRectMake( (__points__).origin.x * CC_CONTENT_SCALE_FACTOR(), (__points__).origin.y * CC_CONTENT_SCALE_FACTOR(),	\
    (__points__).size.width * CC_CONTENT_SCALE_FACTOR(), (__points__).size.height * CC_CONTENT_SCALE_FACTOR() )

/**
Helper marcos which converts 4-byte little/big endian
integral number to the machine native number representation

It should work same as apples CFSwapInt32LittleToHost(..)
*/

/// when define returns true it means that our architecture uses big endian
#define CC_HOST_IS_BIG_ENDIAN (bool)(*(unsigned short *)"\0\xff" < 0x100)
#define CC_SWAP32(i)  ((i & 0x000000ff) << 24 | (i & 0x0000ff00) << 8 | (i & 0x00ff0000) >> 8 | (i & 0xff000000) >> 24)
#define CC_SWAP16(i)  ((i & 0x00ff) << 8 | (i &0xff00) >> 8)
#define CC_SWAP_INT32_LITTLE_TO_HOST(i) ((CC_HOST_IS_BIG_ENDIAN == true)? CC_SWAP32(i) : (i) )
#define CC_SWAP_INT16_LITTLE_TO_HOST(i) ((CC_HOST_IS_BIG_ENDIAN == true)? CC_SWAP16(i) : (i) )
#define CC_SWAP_INT32_BIG_TO_HOST(i)    ((CC_HOST_IS_BIG_ENDIAN == true)? (i) : CC_SWAP32(i) )
#define CC_SWAP_INT16_BIG_TO_HOST(i)    ((CC_HOST_IS_BIG_ENDIAN == true)? (i):  CC_SWAP16(i) )

#endif // __CCMACROS_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 __CCTYPES_H__
#define __CCTYPES_H__

#include "CCGeometry.h"

#include "CCGL.h"

namespace   cocos2d {

/** RGB color composed of bytes 3 bytes
@since v0.8
 */
typedef struct _ccColor3B
{
	GLubyte	r;
	GLubyte	g;
	GLubyte b;
} ccColor3B;

//! helper macro that creates an ccColor3B type
static inline ccColor3B
ccc3(const GLubyte r, const GLubyte g, const GLubyte b)
{
	ccColor3B c = {r, g, b};
	return c;
}
//ccColor3B predefined colors
//! White color (255,255,255)
static const ccColor3B ccWHITE={255,255,255};
//! Yellow color (255,255,0)
static const ccColor3B ccYELLOW={255,255,0};
//! Blue color (0,0,255)
static const ccColor3B ccBLUE={0,0,255};
//! Green Color (0,255,0)
static const ccColor3B ccGREEN={0,255,0};
//! Red Color (255,0,0,)
static const ccColor3B ccRED={255,0,0};
//! Magenta Color (255,0,255)
static const ccColor3B ccMAGENTA={255,0,255};
//! Black Color (0,0,0)
static const ccColor3B ccBLACK={0,0,0};
//! Orange Color (255,127,0)
static const ccColor3B ccORANGE={255,127,0};
//! Gray Color (166,166,166)
static const ccColor3B ccGRAY={166,166,166};

/** RGBA color composed of 4 bytes
@since v0.8
*/
typedef struct _ccColor4B
{
	GLubyte r;
	GLubyte g;
	GLubyte b;
	GLubyte a;
} ccColor4B;
//! helper macro that creates an ccColor4B type
static inline ccColor4B
ccc4f(const GLubyte r, const GLubyte g, const GLubyte b, const GLubyte o)
{
	ccColor4B c = {r, g, b, o};
	return c;
}

/** RGBA color composed of 4 floats
@since v0.8
*/
typedef struct _ccColor4F {
	GLfloat r;
	GLfloat g;
	GLfloat b;
	GLfloat a;
} ccColor4F;

/** Returns a ccColor4F from a ccColor3B. Alpha will be 1.
 @since v0.99.1
 */
static inline ccColor4F ccc4FFromccc3B(ccColor3B c)
{
	ccColor4F c4 = {c.r/255.f, c.g/255.f, c.b/255.f, 1.f};
	return c4;
}

/** Returns a ccColor4F from a ccColor4B.
 @since v0.99.1
 */
static inline ccColor4F ccc4FFromccc4B(ccColor4B c)
{
	ccColor4F c4 = {c.r/255.f, c.g/255.f, c.b/255.f, c.a/255.f};
	return c4;
}

/** returns YES if both ccColor4F are equal. Otherwise it returns NO.
 @since v0.99.1
 */
static inline bool ccc4FEqual(ccColor4F a, ccColor4F b)
{
	return a.r == b.r && a.g == b.g && a.b == b.b && a.a == b.a;
}

/** A vertex composed of 2 floats: x, y
 @since v0.8
 */
typedef struct _ccVertex2F
{
	GLfloat x;
	GLfloat y;
} ccVertex2F;

static inline ccVertex2F vertex2(const float x, const float y)
{
	ccVertex2F c = {x, y};
	return c;
}

/** A vertex composed of 2 floats: x, y
 @since v0.8
 */
typedef struct _ccVertex3F
{
	GLfloat x;
	GLfloat y;
	GLfloat z;
} ccVertex3F;

static inline ccVertex3F vertex3(const float x, const float y, const float z)
{
	ccVertex3F c = {x, y, z};
	return c;
}

/** A texcoord composed of 2 floats: u, y
 @since v0.8
 */
typedef struct _ccTex2F {
	 GLfloat u;
	 GLfloat v;
} ccTex2F;

static inline ccTex2F tex2(const float u, const float v)
{
	ccTex2F t = {u , v};
	return t;
}

//! Point Sprite component
typedef struct _ccPointSprite
{
	ccVertex2F	pos;		// 8 bytes
	ccColor4B	color;		// 4 bytes
	GLfloat		size;		// 4 bytes
} ccPointSprite;

//!	A 2D Quad. 4 * 2 floats
typedef struct _ccQuad2 {
	ccVertex2F		tl;
	ccVertex2F		tr;
	ccVertex2F		bl;
	ccVertex2F		br;
} ccQuad2;

//!	A 3D Quad. 4 * 3 floats
typedef struct _ccQuad3 {
	ccVertex3F		bl;
	ccVertex3F		br;
	ccVertex3F		tl;
	ccVertex3F		tr;
} ccQuad3;

//! A 2D grid size
typedef struct _ccGridSize
{
	int	x;
	int	y;
} ccGridSize;

//! helper function to create a ccGridSize
static inline ccGridSize
ccg(const int x, const int y)
{
	ccGridSize v = {x, y};
	return v;
}

//! a Point with a vertex point, a tex coord point and a color 4B
typedef struct _ccV2F_C4B_T2F
{
	//! vertices (2F)
	ccVertex2F		vertices;
	//! colors (4B)
	ccColor4B		colors;
	//! tex coords (2F)
	ccTex2F			texCoords;
} ccV2F_C4B_T2F;

//! a Point with a vertex point, a tex coord point and a color 4F
typedef struct _ccV2F_C4F_T2F
{
	//! vertices (2F)
	ccVertex2F		vertices;
	//! colors (4F)
	ccColor4F		colors;
	//! tex coords (2F)
	ccTex2F			texCoords;
} ccV2F_C4F_T2F;

//! a Point with a vertex point, a tex coord point and a color 4B
typedef struct _ccV3F_C4B_T2F
{
	//! vertices (3F)
	ccVertex3F		vertices;			// 12 bytes
//	char __padding__[4];

	//! colors (4B)
	ccColor4B		colors;				// 4 bytes
//	char __padding2__[4];

	// tex coords (2F)
	ccTex2F			texCoords;			// 8 byts
} ccV3F_C4B_T2F;

//! 4 ccVertex2FTex2FColor4B Quad
typedef struct _ccV2F_C4B_T2F_Quad
{
	//! bottom left
	ccV2F_C4B_T2F	bl;
	//! bottom right
	ccV2F_C4B_T2F	br;
	//! top left
	ccV2F_C4B_T2F	tl;
	//! top right
	ccV2F_C4B_T2F	tr;
} ccV2F_C4B_T2F_Quad;

//! 4 ccVertex3FTex2FColor4B
typedef struct _ccV3F_C4B_T2F_Quad
{
	//! top left
	ccV3F_C4B_T2F	tl;
	//! bottom left
	ccV3F_C4B_T2F	bl;
	//! top right
	ccV3F_C4B_T2F	tr;
	//! bottom right
	ccV3F_C4B_T2F	br;
} ccV3F_C4B_T2F_Quad;

//! 4 ccVertex2FTex2FColor4F Quad
typedef struct _ccV2F_C4F_T2F_Quad
{
	//! bottom left
	ccV2F_C4F_T2F	bl;
	//! bottom right
	ccV2F_C4F_T2F	br;
	//! top left
	ccV2F_C4F_T2F	tl;
	//! top right
	ccV2F_C4F_T2F	tr;
} ccV2F_C4F_T2F_Quad;

//! Blend Function used for textures
typedef struct _ccBlendFunc
{
	//! source blend function
	GLenum src;
	//! destination blend function
	GLenum dst;
} ccBlendFunc;

//! ccResolutionType
typedef enum
{
    //! Unknonw resolution type
    kCCResolutionUnknown,
    //! iPhone resolution type
    kCCResolutioniPhone,
    //! RetinaDisplay resolution type
    kCCResolutioniPhoneRetinaDisplay,
    //! iPad resolution type
    kCCResolutioniPad,
    //! iPad Retina Display resolution type
    kCCResolutioniPadRetinaDisplay,

} ccResolutionType;

//! delta time type
//! if you want more resolution redefine it as a double
typedef float ccTime;
//typedef double ccTime;

typedef enum
{
	CCTextAlignmentLeft,
	CCTextAlignmentCenter,
	CCTextAlignmentRight,
} CCTextAlignment;

// types for animation in particle systems

// texture coordinates for a quad
typedef struct _ccT2F_Quad
{
	//! bottom left
	ccTex2F	bl;
	//! bottom right
	ccTex2F	br;
	//! top left
	ccTex2F	tl;
	//! top right
	ccTex2F	tr;
} ccT2F_Quad;

// struct that holds the size in pixels, texture coordinates and delays for animated CCParticleSystemQuad
typedef struct
{
	ccT2F_Quad texCoords;
	ccTime delay;
	CCSize size;
} ccAnimationFrameData;

}//namespace   cocos2d

#endif //__CCTYPES_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 __COCOS2D_H__
#define __COCOS2D_H__

// 0x00 HI ME LO
// 00   01 00 01
#define COCOS2D_VERSION 0x00010001

//
// all cocos2d include files
//

#include "ccConfig.h"	// should be included first
#include "CCAction.h"
#include "CCAnimation.h"
#include "CCAnimationCache.h"
#include "CCActionManager.h"
#include "CCCamera.h"
#include "CCActionCamera.h"
#include "CCProtocols.h"
#include "CCNode.h"
#include "CCDirector.h"
#include "CCUserDefault.h"
#include "CCActionInstant.h"
#include "CCActionInterval.h"
#include "CCActionEase.h"
#include "CCLabelTTF.h"
#include "CCLayer.h"
#include "CCMenu.h"
#include "CCMenuItem.h"
#include "CCParticleSystem.h"
#include "CCParticleSystemPoint.h"
#include "CCParticleSystemQuad.h"
#include "CCParticleExamples.h"
#include "CCScene.h"
#include "CCSprite.h"
#include "CCSpriteFrameCache.h"
#include "CCTextureCache.h"
#include "CCTransition.h"
#include "CCTextureAtlas.h"
#include "CCLabelAtlas.h"
#include "CCAtlasNode.h"
#include "CCActionTiledGrid.h"
#include "CCActionGrid3D.h"
#include "CCActionGrid.h"
#include "CCLabelBMFont.h"
#include "CCParallaxNode.h"
#include "CCTileMapAtlas.h"
#include "CCTMXTiledMap.h"
#include "CCTMXLayer.h"
#include "CCTMXObjectGroup.h"
#include "CCTMXXMLParser.h"
#include "CCRenderTexture.h"
#include "CCMotionStreak.h"
#include "CCActionPageTurn3D.h"
#include "CCTransitionPageTurn.h"
#include "CCTexture2D.h"
#include "CCTexturePVR.h"
#include "CCTransitionRadial.h"
#include "CCActionProgressTimer.h"
#include "CCTouchHandler.h"
#include "CCTouchDispatcher.h"
#include "CCDrawingPrimitives.h"
#include "CCScheduler.h"

// havn't implement on wophone
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WOPHONE)
#include "CCTextFieldTTF.h"
#endif

//
// cocoa includes
//
#include "CCSet.h"
#include "CCMutableArray.h"
#include "CCMutableDictionary.h"
#include "CCObject.h"
#include "CCZone.h"
#include "CCGeometry.h"
#include "CCAffineTransform.h"
#include "CCTouch.h"
#include "CCPointExtension.h"

//
// platform specific
//
#include "CCApplication.h"
#include "CCEGLView.h"
#include "CCImage.h"
#include "CCFileUtils.h"
#include "CCAccelerometer.h"

// extensions
#include "extensions/CCNotificationCenter.h"

//
// cocos2d macros
//
#include "ccTypes.h"
#include "ccMacros.h"

namespace   cocos2d {

const char* cocos2dVersion();

}//namespace   cocos2d

#endif // __COCOS2D_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.
****************************************************************************/

#include "CCKeypadDelegate.h"
#include "ccMacros.h"

namespace   cocos2d {

//------------------------------------------------------------------
//
// CCKeypadHandler
//
//------------------------------------------------------------------
CCKeypadDelegate* CCKeypadHandler::getDelegate()
{
    return m_pDelegate;
}

CCKeypadHandler::~CCKeypadHandler()
{
	if (m_pDelegate)
	{
		dynamic_cast<CCObject*>(m_pDelegate)->release();
	}
}

void CCKeypadHandler::setDelegate(CCKeypadDelegate *pDelegate)
{
    if (pDelegate)
    {
		dynamic_cast<CCObject*>(pDelegate)->retain();
    }

    if (m_pDelegate)
    {
		dynamic_cast<CCObject*>(m_pDelegate)->release();
    }
    m_pDelegate = pDelegate;
}

bool CCKeypadHandler::initWithDelegate(CCKeypadDelegate *pDelegate)
{
    CCAssert(pDelegate != NULL, "It's a wrong delegate!");

    m_pDelegate = pDelegate;
    dynamic_cast<CCObject*>(pDelegate)->retain();

    return true;
}

CCKeypadHandler* CCKeypadHandler::handlerWithDelegate(CCKeypadDelegate *pDelegate)
{
    CCKeypadHandler* pHandler = new CCKeypadHandler;

    if (pHandler)
    {
        if (pHandler->initWithDelegate(pDelegate))
        {
            pHandler->autorelease();
        }
        else
        {
            CC_SAFE_RELEASE_NULL(pHandler);
        }
    }

    return pHandler;
}

}


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.
****************************************************************************/

#include "CCKeypadDispatcher.h"
#include "support/data_support/ccCArray.h"

namespace   cocos2d {

static CCKeypadDispatcher* s_KeypadDispatcher = NULL;
//------------------------------------------------------------------
//
// CCKeypadDispatcher
//
//------------------------------------------------------------------
CCKeypadDispatcher::CCKeypadDispatcher()
: m_bLocked(false)
, m_bToAdd(false)
, m_bToRemove(false)
{
    m_pDelegates = new KeypadDelegateArray;

    m_pHandlersToAdd    = ccCArrayNew(8);
    m_pHandlersToRemove = ccCArrayNew(8);
}

CCKeypadDispatcher::~CCKeypadDispatcher()
{
	CC_SAFE_RELEASE(m_pDelegates);
	if (m_pHandlersToAdd)
	{
		ccCArrayFree(m_pHandlersToAdd);
	}

	if (m_pHandlersToRemove)
	{
		ccCArrayFree(m_pHandlersToRemove);
	}
}

CCKeypadDispatcher* CCKeypadDispatcher::sharedDispatcher()
{
    if (! s_KeypadDispatcher)
    {
        s_KeypadDispatcher = new CCKeypadDispatcher;
    }

    return s_KeypadDispatcher;
}

void CCKeypadDispatcher::purgeSharedDispatcher()
{
    if (s_KeypadDispatcher)
    {
        s_KeypadDispatcher->release();
        s_KeypadDispatcher = NULL;
    }
}

void CCKeypadDispatcher::removeDelegate(CCKeypadDelegate* pDelegate)
{
    if (!pDelegate)
    {
        return;
    }
    if (! m_bLocked)
    {
        forceRemoveDelegate(pDelegate);
    }
    else
    {
        ccCArrayAppendValue(m_pHandlersToRemove, pDelegate);
        m_bToRemove = true;
    }
}

void CCKeypadDispatcher::addDelegate(CCKeypadDelegate* pDelegate)
{
    if (!pDelegate)
    {
        return;
    }

    if (! m_bLocked)
    {
        forceAddDelegate(pDelegate);
    }
    else
    {
        ccCArrayAppendValue(m_pHandlersToAdd, pDelegate);
        m_bToAdd = true;
    }
}

void CCKeypadDispatcher::forceAddDelegate(CCKeypadDelegate* pDelegate)
{
    CCKeypadHandler* pHandler = CCKeypadHandler::handlerWithDelegate(pDelegate);

    if (pHandler)
    {
        m_pDelegates->addObject(pHandler);
    }
}

void CCKeypadDispatcher::forceRemoveDelegate(CCKeypadDelegate* pDelegate)
{
    CCKeypadHandler  *pHandler;
    CCMutableArray<CCKeypadHandler*>::CCMutableArrayIterator  iter;

    for (iter = m_pDelegates->begin(); iter != m_pDelegates->end(); ++iter)
    {
        pHandler = *iter;
        if (pHandler && pHandler->getDelegate() == pDelegate)
        {
            m_pDelegates->removeObject(pHandler);
            break;
        }
    }
}

bool CCKeypadDispatcher::dispatchKeypadMSG(ccKeypadMSGType nMsgType)
{
    CCKeypadHandler  *pHandler;
    CCKeypadDelegate *pDelegate;
    CCMutableArray<CCKeypadHandler*>::CCMutableArrayIterator  iter;

    m_bLocked = true;

    if (m_pDelegates->count() > 0)
    {
        for (iter = m_pDelegates->begin(); iter != m_pDelegates->end(); ++iter)
        {
            CC_BREAK_IF(!(*iter));

            pHandler = *iter;
            pDelegate = pHandler->getDelegate();

            switch (nMsgType)
            {
            case kTypeBackClicked:
                pDelegate->keyBackClicked();
                break;
            case kTypeMenuClicked:
                pDelegate->keyMenuClicked();
                break;
            default:
                break;
            }
        }
    }

    m_bLocked = false;
    if (m_bToRemove)
    {
        m_bToRemove = false;
        for (unsigned int i = 0; i < m_pHandlersToRemove->num; ++i)
        {
            forceRemoveDelegate((CCKeypadDelegate*)m_pHandlersToRemove->arr[i]);
        }
        ccCArrayRemoveAllValues(m_pHandlersToRemove);
    }

    if (m_bToAdd)
    {
        m_bToAdd = false;
        for (unsigned int i = 0; i < m_pHandlersToAdd->num; ++i)
        {
            forceAddDelegate((CCKeypadDelegate*)m_pHandlersToAdd->arr[i]);
        }
        ccCArrayRemoveAllValues(m_pHandlersToAdd);
    }

    return true;
}

}


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.
****************************************************************************/
#include "CCLabelAtlas.h"
#include "CCTextureAtlas.h"
#include "CCPointExtension.h"
#include "CCDrawingPrimitives.h"
#include "ccConfig.h"

namespace cocos2d{

	//CCLabelAtlas - Creation & Init
	CCLabelAtlas * CCLabelAtlas::labelWithString(const char *label, const char *charMapFile, unsigned int itemWidth, int unsigned itemHeight, unsigned char startCharMap)
	{
		CCLabelAtlas *pRet = new CCLabelAtlas();
		if(pRet && pRet->initWithString(label, charMapFile, itemWidth, itemHeight, startCharMap))
		{
			pRet->autorelease();
			return pRet;
		}
		CC_SAFE_DELETE(pRet)
		return NULL;
	}

	bool CCLabelAtlas::initWithString(const char *label, const char *charMapFile, unsigned int itemWidth, unsigned int itemHeight, unsigned char startCharMap)
	{
		CCAssert(label != NULL, "");
		if (CCAtlasNode::initWithTileFile(charMapFile, itemWidth, itemHeight, strlen(label)))
		{
			m_cMapStartChar = startCharMap;
			this->setString(label);
			return true;
		}
		return false;
	}

	//CCLabelAtlas - Atlas generation
	void CCLabelAtlas::updateAtlasValues()
	{
		unsigned int n = m_sString.length();

		ccV3F_C4B_T2F_Quad quad;

		const unsigned char *s = (unsigned char*)m_sString.c_str();

        CCTexture2D *texture = m_pTextureAtlas->getTexture();
        float textureWide = (float) texture->getPixelsWide();
        float textureHigh = (float) texture->getPixelsHigh();

		for(unsigned int i = 0; i < n; i++) {
			unsigned char a = s[i] - m_cMapStartChar;
			float row = (float) (a % m_uItemsPerRow);
			float col = (float) (a / m_uItemsPerRow);

#if CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL
            // Issue #938. Don't use texStepX & texStepY
            float left		= (2 * row * m_uItemWidth + 1) / (2 * textureWide);
            float right		= left + (m_uItemWidth * 2 - 2) / (2 * textureWide);
            float top		= (2 * col * m_uItemHeight + 1) / (2 * textureHigh);
            float bottom	= top + (m_uItemHeight * 2 - 2) / (2 * textureHigh);
#else
            float left		= row * m_uItemWidth / textureWide;
            float right		= left + m_uItemWidth / textureWide;
            float top		= col * m_uItemHeight / textureHigh;
            float bottom	= top + m_uItemHeight / textureHigh;
#endif // ! CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL

            quad.tl.texCoords.u = left;
            quad.tl.texCoords.v = top;
            quad.tr.texCoords.u = right;
            quad.tr.texCoords.v = top;
            quad.bl.texCoords.u = left;
            quad.bl.texCoords.v = bottom;
            quad.br.texCoords.u = right;
            quad.br.texCoords.v = bottom;

			quad.bl.vertices.x = (float) (i * m_uItemWidth);
			quad.bl.vertices.y = 0;
			quad.bl.vertices.z = 0.0f;
			quad.br.vertices.x = (float)(i * m_uItemWidth + m_uItemWidth);
			quad.br.vertices.y = 0;
			quad.br.vertices.z = 0.0f;
			quad.tl.vertices.x = (float)(i * m_uItemWidth);
			quad.tl.vertices.y = (float)(m_uItemHeight);
			quad.tl.vertices.z = 0.0f;
			quad.tr.vertices.x = (float)(i * m_uItemWidth + m_uItemWidth);
			quad.tr.vertices.y = (float)(m_uItemHeight);
			quad.tr.vertices.z = 0.0f;

			m_pTextureAtlas->updateQuad(&quad, i);
		}
	}

	//CCLabelAtlas - CCLabelProtocol
	void CCLabelAtlas::setString(const char *label)
	{
		unsigned int len = strlen(label);
		if (len > m_pTextureAtlas->getTotalQuads())
		{
			m_pTextureAtlas->resizeCapacity(len);
		}
		m_sString.clear();
		m_sString = label;
		this->updateAtlasValues();

		CCSize s;
		s.width = (float)(len * m_uItemWidth);
		s.height = (float)(m_uItemHeight);
		this->setContentSizeInPixels(s);

		m_uQuadsToDraw = len;
	}

	const char* CCLabelAtlas::getString(void)
	{
		return m_sString.c_str();
	}

	//CCLabelAtlas - draw

#if CC_LABELATLAS_DEBUG_DRAW
	void CCLabelAtlas::draw()
	{
		CCAtlasNode::draw();

		const CCSize& s = this->getContentSize();
		CCPoint vertices[4]={
			ccp(0,0),ccp(s.width,0),
			ccp(s.width,s.height),ccp(0,s.height),
		};
		ccDrawPoly(vertices, 4, true);
	}
#endif
} // namespace cocos2d