代码:
/**
* @addtogroup _2d
* @{
*/
/**
* @brief Possible GlyphCollection used by Label.
*
* Specify a collections of characters to be load when Label created.
* Consider using DYNAMIC.
*/
enum class GlyphCollection {
DYNAMIC,
NEHE,
ASCII,
CUSTOM
};
/**
* @struct TTFConfig
* @see `GlyphCollection`
*/
// ttf配置信息
typedef struct _ttfConfig
{
std::string fontFilePath;
int fontSize;
GlyphCollection glyphs;
const char *customGlyphs;
bool distanceFieldEnabled;
int outlineSize;
_ttfConfig(const char* filePath = "",int size = 12, const GlyphCollection& glyphCollection = GlyphCollection::DYNAMIC,
const char *customGlyphCollection = nullptr,bool useDistanceField = false,int outline = 0)
:fontFilePath(filePath)
,fontSize(size)
,glyphs(glyphCollection)
,customGlyphs(customGlyphCollection)
,distanceFieldEnabled(useDistanceField)
,outlineSize(outline)
{
if(outline > 0)
{
distanceFieldEnabled = false;
}
}
}TTFConfig;
/**
* @brief Label is a subclass of SpriteBatchNode that knows how to render text labels.
*Label是一个知道如何绘制文本的的spriteBathNode
* Label can be created with:Label可以通过如下方式创建
* - A true type font file.一个确定类型的文本文件
* - A bitmap font file.一个位图文本文件
* - A char map file.一个字符映射文件
* - The built in system font.通过系统字体创建
*
* Bitmap Font supported editors:
* - http://glyphdesigner.71squared.com/ (Commercial, Mac OS X)
* - http://www.n4te.com/hiero/hiero.jnlp (Free, Java)
* - http://slick.cokeandcode.com/demos/hiero.jnlp (Free, Java)
* - http://www.angelcode.com/products/bmfont/ (Free, Windows only)
* @js NA
*/
class CC_DLL Label : public SpriteBatchNode, public LabelProtocol
{
public:
static const int DistanceFieldFontSize;
/// @name Creators
/// @{
/**
* Allocates and initializes a Label, with default settings.
*
* @return An automatically released Label object.
*/
static Label* create();
/**
* Allocates and initializes a Label, base on platform-dependent API.
*
* @param text The initial text.
* @param font A font file or a font family name.
* @param fontSize The font size. This value must be > 0.
* @param dimensions
* @param hAlignment The text horizontal alignment.
* @param vAlignment The text vertical alignment.
*
* @warning It will generate texture by the platform-dependent code.
*
* @return An automatically released Label object.
*/
// 通过系统字体创建一个Label对象
static Label* createWithSystemFont(const std::string& text, const std::string& font, float fontSize,
const Size& dimensions = Size::ZERO, TextHAlignment hAlignment = TextHAlignment::LEFT,
TextVAlignment vAlignment = TextVAlignment::TOP);
/**
* Allocates and initializes a Label, base on FreeType2.
*
* @param text The initial text.
* @param fontFilePath A font file.
* @param fontSize The font size. This value must be > 0.
* @param dimensions
* @param hAlignment The text horizontal alignment.
* @param vAlignment The text vertical alignment.
*
* @return An automatically released Label object.
*/
// 通过ttf文件创建一个Label对象
static Label * createWithTTF(const std::string& text, const std::string& fontFilePath, float fontSize,
const Size& dimensions = Size::ZERO, TextHAlignment hAlignment = TextHAlignment::LEFT,
TextVAlignment vAlignment = TextVAlignment::TOP);
/**
* Allocates and initializes a Label, base on FreeType2.
*
* @para