2011-03-19 10:59:01 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010-2011 cocos2d-x.org
|
|
|
|
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
|
|
|
|
2011-03-19 10:59:01 +08:00
|
|
|
#include "CCAtlasNode.h"
|
2010-08-11 18:09:10 +08:00
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
|
|
/** @brief CCLabelAtlas is a subclass of CCAtlasNode.
|
2010-08-11 18:09:10 +08:00
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
It can be as a replacement of CCLabel since it is MUCH faster.
|
2010-08-11 18:09:10 +08:00
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
CCLabelAtlas versus CCLabel:
|
|
|
|
- CCLabelAtlas is MUCH faster than CCLabel
|
|
|
|
- CCLabelAtlas "characters" have a fixed height and width
|
|
|
|
- CCLabelAtlas "characters" can be anything you want since they are taken from an image file
|
2010-08-11 18:09:10 +08:00
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
A more flexible class is CCLabelBMFont. It supports variable width characters and it also has a nice editor.
|
|
|
|
*/
|
|
|
|
class CC_DLL CCLabelAtlas : public CCAtlasNode, public CCLabelProtocol
|
|
|
|
{
|
|
|
|
public:
|
2012-04-19 14:35:52 +08:00
|
|
|
CCLabelAtlas()
|
|
|
|
:m_sString("")
|
|
|
|
{}
|
|
|
|
virtual ~CCLabelAtlas()
|
|
|
|
{
|
|
|
|
m_sString.clear();
|
|
|
|
}
|
2012-06-14 15:13:16 +08:00
|
|
|
/** creates the CCLabelAtlas with a string, a char map file(the atlas), the width and height of each element and the starting char of the atlas
|
|
|
|
@warning: This interface will be deprecated in future.
|
|
|
|
*/
|
2012-06-14 17:18:05 +08:00
|
|
|
static CCLabelAtlas * labelWithString(const char *label, const char *charMapFile, unsigned int itemWidth, unsigned int itemHeight, unsigned int startCharMap);
|
2012-06-14 15:13:16 +08:00
|
|
|
|
|
|
|
/** creates the CCLabelAtlas with a string and a configuration file
|
|
|
|
@warning: This interface will be deprecated in future.
|
|
|
|
@since v2.0
|
|
|
|
*/
|
2012-06-14 17:18:05 +08:00
|
|
|
static CCLabelAtlas* labelWithString(const char *sring, const char *fntFile);
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** creates the CCLabelAtlas with a string, a char map file(the atlas), the width and height of each element and the starting char of the atlas */
|
2012-06-14 15:13:16 +08:00
|
|
|
static CCLabelAtlas * create(const char *label, const char *charMapFile, unsigned int itemWidth, unsigned int itemHeight, unsigned int startCharMap);
|
2012-06-08 15:29:47 +08:00
|
|
|
|
|
|
|
/** creates the CCLabelAtlas with a string and a configuration file
|
|
|
|
@since v2.0
|
|
|
|
*/
|
2012-06-14 15:13:16 +08:00
|
|
|
static CCLabelAtlas* create(const char *sring, const char *fntFile);
|
2010-12-24 17:07:31 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** initializes the CCLabelAtlas with a string, a char map file(the atlas), the width and height of each element and the starting char of the atlas */
|
2012-06-08 15:29:47 +08:00
|
|
|
bool initWithString(const char *label, const char *charMapFile, unsigned int itemWidth, unsigned int itemHeight, unsigned int startCharMap);
|
|
|
|
|
|
|
|
/** initializes the CCLabelAtlas with a string and a configuration file
|
|
|
|
@since v2.0
|
|
|
|
*/
|
|
|
|
bool initWithString(const char *string, const char *fntFile);
|
2012-04-19 14:35:52 +08:00
|
|
|
// super methods
|
|
|
|
virtual void updateAtlasValues();
|
|
|
|
virtual void setString(const char *label);
|
|
|
|
virtual const char* getString(void);
|
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
|
|
|
|
std::string m_sString;
|
|
|
|
// the first char in the charmap
|
2012-06-08 15:29:47 +08:00
|
|
|
unsigned int m_uMapStartChar;
|
2012-04-18 18:43:45 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_CC_END
|
2011-03-19 10:59:01 +08:00
|
|
|
|
|
|
|
#endif //__CCLABEL_ATLAS_H__
|