2011-03-19 10:59:01 +08:00
|
|
|
/****************************************************************************
|
2012-09-24 21:22:20 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2011-03-19 10:59:01 +08:00
|
|
|
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
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup base_nodes
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
class TextureAtlas;
|
2010-07-08 14:00:06 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
/** @brief AtlasNode is a subclass of Node that implements the RGBAProtocol and TextureProtocol protocol
|
2010-07-08 14:00:06 +08:00
|
|
|
|
|
|
|
It knows how to render a TextureAtlas object.
|
2013-06-20 14:13:12 +08:00
|
|
|
If you are going to render a TextureAtlas consider subclassing AtlasNode (or a subclass of AtlasNode)
|
2010-07-08 14:00:06 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
All features from Node are valid, plus the following features:
|
2010-07-08 14:00:06 +08:00
|
|
|
- opacity and RGB colors
|
|
|
|
*/
|
2013-12-06 18:07:16 +08:00
|
|
|
class CC_DLL AtlasNode : public Node, public TextureProtocol
|
2013-07-18 07:56:19 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/** creates a AtlasNode with an Atlas file the width and height of each item and the quantity of items to render*/
|
2013-12-05 17:19:01 +08:00
|
|
|
static AtlasNode * create(const std::string& filename, int tileWidth, int tileHeight, int itemsToRender);
|
2010-07-08 14:00:06 +08:00
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
/** updates the Atlas (indexed vertex array).
|
|
|
|
* Shall be overridden in subclasses
|
|
|
|
*/
|
|
|
|
virtual void updateAtlasValues();
|
|
|
|
|
2013-07-23 15:19:49 +08:00
|
|
|
void setTextureAtlas(TextureAtlas* textureAtlas);
|
|
|
|
TextureAtlas* getTextureAtlas() const;
|
|
|
|
|
2013-12-27 15:06:16 +08:00
|
|
|
void setQuadsToDraw(ssize_t quadsToDraw);
|
|
|
|
ssize_t getQuadsToDraw() const;
|
2013-07-23 15:19:49 +08:00
|
|
|
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
// Overrides
|
|
|
|
virtual void draw() override;
|
2013-07-23 18:26:26 +08:00
|
|
|
virtual Texture2D* getTexture() const override;
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual void setTexture(Texture2D *texture) override;
|
|
|
|
virtual bool isOpacityModifyRGB() const override;
|
|
|
|
virtual void setOpacityModifyRGB(bool isOpacityModifyRGB) override;
|
|
|
|
virtual const Color3B& getColor(void) const override;
|
|
|
|
virtual void setColor(const Color3B& color) override;
|
|
|
|
virtual void setOpacity(GLubyte opacity) override;
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
|
|
|
* @code
|
|
|
|
* When this function bound into js or lua,the parameter will be changed
|
|
|
|
* In js: var setBlendFunc(var src, var dst)
|
|
|
|
* @endcode
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-07-23 21:51:19 +08:00
|
|
|
virtual void setBlendFunc(const BlendFunc& blendFunc) override;
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-07-23 21:51:19 +08:00
|
|
|
virtual const BlendFunc& getBlendFunc() const override;
|
2013-07-18 07:56:19 +08:00
|
|
|
|
2013-11-15 08:21:49 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
AtlasNode();
|
|
|
|
virtual ~AtlasNode();
|
|
|
|
|
|
|
|
/** initializes an AtlasNode with an Atlas file the width and height of each item and the quantity of items to render*/
|
2013-12-05 17:19:01 +08:00
|
|
|
bool initWithTileFile(const std::string& tile, int tileWidth, int tileHeight, int itemsToRender);
|
2013-11-15 08:21:49 +08:00
|
|
|
|
|
|
|
/** initializes an AtlasNode with a texture the width and height of each item measured in points and the quantity of items to render*/
|
2013-12-05 17:19:01 +08:00
|
|
|
bool initWithTexture(Texture2D* texture, int tileWidth, int tileHeight, int itemsToRender);
|
2013-11-15 08:21:49 +08:00
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
void calculateMaxItems();
|
|
|
|
void updateBlendFunc();
|
|
|
|
void updateOpacityModifyRGB();
|
2013-11-15 08:21:49 +08:00
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
friend class Director;
|
|
|
|
void setIgnoreContentScaleFactor(bool bIgnoreContentScaleFactor);
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
//! chars per row
|
2013-12-05 17:19:01 +08:00
|
|
|
int _itemsPerRow;
|
2012-04-19 14:35:52 +08:00
|
|
|
//! chars per column
|
2013-12-05 17:19:01 +08:00
|
|
|
int _itemsPerColumn;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
//! width of each char
|
2013-12-05 17:19:01 +08:00
|
|
|
int _itemWidth;
|
2012-04-19 14:35:52 +08:00
|
|
|
//! height of each char
|
2013-12-05 17:19:01 +08:00
|
|
|
int _itemHeight;
|
2013-07-23 15:19:49 +08:00
|
|
|
|
2013-07-05 16:49:22 +08:00
|
|
|
Color3B _colorUnmodified;
|
2013-07-23 15:19:49 +08:00
|
|
|
|
|
|
|
TextureAtlas* _textureAtlas;
|
2012-04-19 14:35:52 +08:00
|
|
|
// protocol variables
|
2013-06-15 14:03:30 +08:00
|
|
|
bool _isOpacityModifyRGB;
|
2013-07-23 15:19:49 +08:00
|
|
|
BlendFunc _blendFunc;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// quads to draw
|
2013-12-27 15:06:16 +08:00
|
|
|
ssize_t _quadsToDraw;
|
2012-04-19 14:35:52 +08:00
|
|
|
// color uniform
|
2013-06-15 14:03:30 +08:00
|
|
|
GLint _uniformColor;
|
2013-06-20 14:13:12 +08:00
|
|
|
// This varible is only used for LabelAtlas FPS display. So plz don't modify its value.
|
2013-06-15 14:03:30 +08:00
|
|
|
bool _ignoreContentScaleFactor;
|
2013-11-15 08:21:49 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
CC_DISALLOW_COPY_AND_ASSIGN(AtlasNode);
|
|
|
|
|
2010-07-08 14:00:06 +08:00
|
|
|
};
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
// end of base_node group
|
|
|
|
/// @}
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
NS_CC_END
|
2010-07-08 14:00:06 +08:00
|
|
|
|
|
|
|
#endif // __CCATLAS_NODE_H__
|
|
|
|
|
|
|
|
|