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-04 10:59:35 +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.
|
|
|
|
****************************************************************************/
|
|
|
|
#ifndef __CCLABEL_ATLAS_H__
|
|
|
|
#define __CCLABEL_ATLAS_H__
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2012-06-19 13:50:11 +08:00
|
|
|
#include "base_nodes/CCAtlasNode.h"
|
2010-08-11 18:09:10 +08:00
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup GUI
|
|
|
|
* @{
|
|
|
|
* @addtogroup label
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
/** @brief LabelAtlas is a subclass of AtlasNode.
|
2010-08-11 18:09:10 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
It can be as a replacement of Label since it is MUCH faster.
|
2010-08-11 18:09:10 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
LabelAtlas versus Label:
|
|
|
|
- LabelAtlas is MUCH faster than Label
|
|
|
|
- LabelAtlas "characters" have a fixed height and width
|
|
|
|
- LabelAtlas "characters" can be anything you want since they are taken from an image file
|
2010-08-11 18:09:10 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
A more flexible class is LabelBMFont. It supports variable width characters and it also has a nice editor.
|
2012-04-18 18:43:45 +08:00
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
class CC_DLL LabelAtlas : public AtlasNode, public LabelProtocol
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-06-20 14:13:12 +08:00
|
|
|
LabelAtlas()
|
2013-06-15 14:03:30 +08:00
|
|
|
:_string("")
|
2012-04-19 14:35:52 +08:00
|
|
|
{}
|
2013-06-20 14:13:12 +08:00
|
|
|
virtual ~LabelAtlas()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_string.clear();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
/** creates the LabelAtlas with a string, a char map file(the atlas), the width and height of each element and the starting char of the atlas */
|
|
|
|
static LabelAtlas * create(const char *string, const char *charMapFile, unsigned int itemWidth, unsigned int itemHeight, unsigned int startCharMap);
|
2012-06-08 15:29:47 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
/** creates the LabelAtlas with a string and a configuration file
|
2012-06-08 15:29:47 +08:00
|
|
|
@since v2.0
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
static LabelAtlas* create(const char *string, const char *fntFile);
|
2010-12-24 17:07:31 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
/** initializes the LabelAtlas with a string, a char map file(the atlas), the width and height of each element and the starting char of the atlas */
|
2012-07-23 22:49:11 +08:00
|
|
|
bool initWithString(const char *string, const char *charMapFile, unsigned int itemWidth, unsigned int itemHeight, unsigned int startCharMap);
|
2012-06-08 15:29:47 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
/** initializes the LabelAtlas with a string and a configuration file
|
2012-06-08 15:29:47 +08:00
|
|
|
@since v2.0
|
|
|
|
*/
|
|
|
|
bool initWithString(const char *string, const char *fntFile);
|
2013-02-27 09:38:30 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
/** initializes the LabelAtlas with a string, a texture, the width and height in points of each element and the starting char of the atlas */
|
|
|
|
bool initWithString(const char* string, Texture2D* texture, unsigned int itemWidth, unsigned int itemHeight, unsigned int startCharMap);
|
2013-02-27 09:38:30 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// super methods
|
|
|
|
virtual void updateAtlasValues();
|
|
|
|
virtual void setString(const char *label);
|
|
|
|
virtual const char* getString(void);
|
2013-02-28 11:55:36 +08:00
|
|
|
|
2011-07-12 11:20:41 +08:00
|
|
|
#if CC_LABELATLAS_DEBUG_DRAW
|
2012-04-19 14:35:52 +08:00
|
|
|
virtual void draw();
|
2011-07-12 11:20:41 +08:00
|
|
|
#endif
|
2010-08-31 11:20:37 +08:00
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
protected:
|
2012-04-19 14:35:52 +08:00
|
|
|
// string to render
|
2013-06-15 14:03:30 +08:00
|
|
|
std::string _string;
|
2012-04-19 14:35:52 +08:00
|
|
|
// the first char in the charmap
|
2013-06-15 14:03:30 +08:00
|
|
|
unsigned int _mapStartChar;
|
2012-04-18 18:43:45 +08:00
|
|
|
};
|
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
// end of GUI group
|
|
|
|
/// @}
|
|
|
|
/// @}
|
|
|
|
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
NS_CC_END
|
2011-03-19 10:59:01 +08:00
|
|
|
|
|
|
|
#endif //__CCLABEL_ATLAS_H__
|