代码:
/** @brief LabelTTF is a subclass of TextureNode that knows how to render text labels
*LabelTTF是一个知道如何绘制文本标签纹理节点的子类
* All features from TextureNode are valid in LabelTTF
*所有纹理节点的特性在LabelTTF中都是有效的
* LabelTTF objects are slow. Consider using LabelAtlas or LabelBMFont instead.
*LabelTTf对象效率不高,建议用LabelAtLas或者LabelBMFont代替
* Custom ttf file can be put in assets/ or external storage that the Application can access.
*通常ttf文件放在assertsh或者其他程序能够使用的存储中
* @code
* LabelTTF *label1 = LabelTTF::create("alignment left", "A Damn Mess", fontSize, blockSize,
* TextHAlignment::LEFT, TextVAlignment::CENTER);
* LabelTTF *label2 = LabelTTF::create("alignment right", "/mnt/sdcard/Scissor Cuts.ttf", fontSize, blockSize,
* TextHAlignment::LEFT, TextVAlignment::CENTER);
* @endcode
*
*/
class CC_DLL CC_DEPRECATED_ATTRIBUTE LabelTTF : public Node, public LabelProtocol, public BlendProtocol
{
public:
/**
* @js ctor
*/
LabelTTF();
/**
* @js NA
* @lua NA
*/
virtual ~LabelTTF();
/** creates a Label from a fontname, alignment, dimension in points and font size in points
@since v2.0.1
*/
// 创建一个LabelTTF对象
static LabelTTF * create(const std::string& string, const std::string& fontName, float fontSize,
const Size& dimensions = Size::ZERO, TextHAlignment hAlignment = TextHAlignment::CENTER,
TextVAlignment vAlignment = TextVAlignment::TOP);
/** Create a lable with string and a font definition*/
// 通过字体定义创建一个Label对象
static LabelTTF * createWithFontDefinition(const std::string& string, FontDefinition &textDefinition);
/** initializes the LabelTTF with a font name, alignment, dimension and font size */
// 初始化
bool initWithString(const std::string& string, const std::string& fontName, float fontSize,
const Size& dimensions = Size::ZERO, TextHAlignment hAlignment = TextHAlignment::LEFT,
TextVAlignment vAlignment = TextVAlignment::TOP);
/** initializes the LabelTTF with a font name, alignment, dimension and font size */
bool initWithStringAndTextDefinition(const std::string& string, FontDefinition &textDefinition);
/** set the text definition used by this label */
// 设置文本定义
void setTextDefinition(const FontDefinition& theDefinition);
/** get the text definition used by this label */
// 字体定义
const FontDefinition& getTextDefinition() const;
/** enable or disable shadow for the label */
// 字体的阴影是否可用
void enableShadow(const Size &shadowOffset, float shadowOpacity, float shadowBlur, bool mustUpdateTexture = true);
/** disable shadow rendering */
// 阴影渲染不可用
void disableShadow(bool mustUpdateTexture = true);
/** enable or disable stroke */
// 描边是否可用
void enableStroke(const Color3B &strokeColor, float strokeSize, bool mustUpdateTexture = true);
/** disable stroke */
// 设置描边不可用
void disableStroke(bool mustUpdateTexture = true);
/** set text tinting */
// 设置文本的着色
void setFontFillColor(const Color3B &tintColor, bool mustUpdateTexture = true);
/** Creates an label.
*/
// 创建一个Label
static LabelTTF * create();
/** changes the string to render
* @warning Changing the string is as expensive as creating a new LabelTTF. To obtain better performance use LabelAtlas
*/
// 设置文本
virtual void setString(const std::string &label) override;
// 得到文本
virtual const std::string& getString(void) const override ;
// 得到水平对齐模式
TextHAlignment getHorizontalAlignment() const;
// 设置水平对齐模式
void setHorizontalAlignment(TextHAlignment alignment);
// 得到竖直对齐模式
TextVAlignment getVerticalAlignment() const;
// 设置竖直对齐模式
void setVerticalAlignment(TextVAlignment verticalAlignment);
// 得到面积
const Size& getDimensions() const;
// 设置面积
void setDimensions(const Size &dim);
// 得到字体的尺寸
float getFontSize() const;
// 设置字体的尺寸
void setFontSize(float fontSize);
// 得到字体的名字
const std::string& getFontName() const;
// 设置字体的名字
void setFontName(const std::string& fontName);
// 设置混合函数
virtual void setBlendFunc(const BlendFunc &blendFunc) override;
// 得到混合函数
virtual const BlendFunc &getBlendFunc() const override;
// 设置是否水平翻转
virtual void setFlippedX(bool flippedX);
// 得到是否垂直翻转
virtual void setFlippedY(bool flippedY);
// 得到边界框
virtual Rect getBoundingBox() const override;
/**
* @js NA
* @lua NA
*/
// 得到描述
virtual std::string getDescription() const override;
// 访问
virtual void visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) override;
// 得到原始尺寸
virtual const Size& getContentSize() const override;
protected:
Label* _renderLabel;
bool _contentDirty;
};