2011-03-19 10:59:01 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010-2011 cocos2d-x.org
|
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
2011-07-01 15:48:05 +08:00
|
|
|
Copyright (c) 2011 Zynga Inc.
|
2011-03-19 10:59:01 +08:00
|
|
|
|
|
|
|
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.
|
2010-07-07 15:15:30 +08:00
|
|
|
****************************************************************************/
|
2010-07-08 14:00:06 +08:00
|
|
|
|
|
|
|
#ifndef __CCATLAS_NODE_H__
|
|
|
|
#define __CCATLAS_NODE_H__
|
|
|
|
|
2011-03-19 10:59:01 +08:00
|
|
|
#include "CCNode.h"
|
|
|
|
#include "CCProtocols.h"
|
|
|
|
#include "ccTypes.h"
|
2010-07-22 18:39:40 +08:00
|
|
|
|
2011-03-19 10:59:01 +08:00
|
|
|
namespace cocos2d {
|
2010-07-22 18:39:40 +08:00
|
|
|
class CCTextureAtlas;
|
2010-07-08 14:00:06 +08:00
|
|
|
|
2010-09-29 09:44:57 +08:00
|
|
|
/** @brief CCAtlasNode is a subclass of CCNode that implements the CCRGBAProtocol and
|
2010-07-08 14:00:06 +08:00
|
|
|
CCTextureProtocol protocol
|
|
|
|
|
|
|
|
It knows how to render a TextureAtlas object.
|
|
|
|
If you are going to render a TextureAtlas consider subclassing CCAtlasNode (or a subclass of CCAtlasNode)
|
|
|
|
|
|
|
|
All features from CCNode are valid, plus the following features:
|
|
|
|
- opacity and RGB colors
|
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
class CC_DLL CCAtlasNode : public CCNode, public CCRGBAProtocol, public CCTextureProtocol
|
2010-07-08 14:00:06 +08:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
|
2010-09-29 12:03:21 +08:00
|
|
|
//! chars per row
|
2011-07-01 15:48:05 +08:00
|
|
|
unsigned int m_uItemsPerRow;
|
2010-09-29 12:03:21 +08:00
|
|
|
//! chars per column
|
2011-07-01 15:48:05 +08:00
|
|
|
unsigned int m_uItemsPerColumn;
|
2010-07-08 14:00:06 +08:00
|
|
|
|
2010-09-29 12:03:21 +08:00
|
|
|
//! width of each char
|
2011-07-01 15:48:05 +08:00
|
|
|
unsigned int m_uItemWidth;
|
2010-09-29 12:03:21 +08:00
|
|
|
//! height of each char
|
2011-07-01 15:48:05 +08:00
|
|
|
unsigned int m_uItemHeight;
|
2010-07-08 14:00:06 +08:00
|
|
|
|
|
|
|
ccColor3B m_tColorUnmodified;
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_PROPERTY(CCTextureAtlas*, m_pTextureAtlas, TextureAtlas);
|
2010-07-08 14:00:06 +08:00
|
|
|
|
2010-07-20 13:49:13 +08:00
|
|
|
// protocol variables
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_PROPERTY(bool, m_bIsOpacityModifyRGB, IsOpacityModifyRGB)
|
|
|
|
CC_PROPERTY(ccBlendFunc, m_tBlendFunc, BlendFunc);
|
|
|
|
CC_PROPERTY(GLubyte, m_cOpacity, Opacity);
|
2011-08-17 21:19:57 +08:00
|
|
|
CC_PROPERTY_PASS_BY_REF(ccColor3B, m_tColor, Color);
|
2010-07-20 13:49:13 +08:00
|
|
|
|
2011-07-12 11:20:41 +08:00
|
|
|
// quads to draw
|
|
|
|
CC_PROPERTY(unsigned int, m_uQuadsToDraw, QuadsToDraw);
|
2012-03-14 14:55:17 +08:00
|
|
|
// color uniform
|
|
|
|
GLint m_nUniformColor;
|
2010-07-08 14:00:06 +08:00
|
|
|
public:
|
|
|
|
CCAtlasNode();
|
2010-08-06 16:05:19 +08:00
|
|
|
virtual ~CCAtlasNode();
|
2010-07-08 14:00:06 +08:00
|
|
|
|
|
|
|
/** creates a CCAtlasNode with an Atlas file the width and height of each item and the quantity of items to render*/
|
2011-07-01 15:48:05 +08:00
|
|
|
static CCAtlasNode * atlasWithTileFile(const char* tile,unsigned int tileWidth, unsigned int tileHeight,
|
|
|
|
unsigned int itemsToRender);
|
2010-07-08 14:00:06 +08:00
|
|
|
|
|
|
|
/** initializes an CCAtlasNode with an Atlas file the width and height of each item and the quantity of items to render*/
|
2011-07-01 15:48:05 +08:00
|
|
|
bool initWithTileFile(const char* tile, unsigned int tileWidth, unsigned int tileHeight, unsigned int itemsToRender);
|
2010-07-08 14:00:06 +08:00
|
|
|
|
|
|
|
/** updates the Atlas (indexed vertex array).
|
|
|
|
* Shall be overriden in subclasses
|
|
|
|
*/
|
2010-08-11 18:09:10 +08:00
|
|
|
virtual void updateAtlasValues();
|
2010-07-08 14:00:06 +08:00
|
|
|
|
2012-03-20 23:30:18 +08:00
|
|
|
virtual void draw(void);
|
2010-07-08 14:00:06 +08:00
|
|
|
|
2011-03-19 10:59:01 +08:00
|
|
|
// CC Texture protocol
|
|
|
|
|
|
|
|
/** returns the used texture*/
|
|
|
|
virtual CCTexture2D* getTexture(void);
|
|
|
|
|
|
|
|
/** sets a new texture. it will be retained*/
|
|
|
|
virtual void setTexture(CCTexture2D *texture);
|
2010-07-19 16:45:53 +08:00
|
|
|
|
|
|
|
private :
|
|
|
|
void calculateMaxItems();
|
|
|
|
void updateBlendFunc();
|
|
|
|
void updateOpacityModifyRGB();
|
2010-07-08 14:00:06 +08:00
|
|
|
|
|
|
|
};
|
2011-03-19 10:59:01 +08:00
|
|
|
}//namespace cocos2d
|
2010-07-08 14:00:06 +08:00
|
|
|
|
|
|
|
#endif // __CCATLAS_NODE_H__
|
|
|
|
|
|
|
|
|