mirror of https://github.com/axmolengine/axmol.git
issue #4636. add parameter create method to UITextBMFont
This commit is contained in:
parent
0b5c10a0fb
commit
b27fe6ecc2
|
@ -56,6 +56,20 @@ TextBMFont* TextBMFont::create()
|
|||
CC_SAFE_DELETE(widget);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
TextBMFont* TextBMFont::create(const std::string &text, const std::string &filename)
|
||||
{
|
||||
TextBMFont* widget = new TextBMFont();
|
||||
if (widget && widget->init())
|
||||
{
|
||||
widget->setFntFile(filename);
|
||||
widget->setText(text);
|
||||
widget->autorelease();
|
||||
return widget;
|
||||
}
|
||||
CC_SAFE_DELETE(widget);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void TextBMFont::initRenderer()
|
||||
{
|
||||
|
@ -63,9 +77,9 @@ void TextBMFont::initRenderer()
|
|||
addProtectedChild(_labelBMFontRenderer, LABELBMFONT_RENDERER_Z, -1);
|
||||
}
|
||||
|
||||
void TextBMFont::setFntFile(const char *fileName)
|
||||
void TextBMFont::setFntFile(const std::string& fileName)
|
||||
{
|
||||
if (!fileName || strcmp(fileName, "") == 0)
|
||||
if (fileName.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -77,12 +91,8 @@ void TextBMFont::setFntFile(const char *fileName)
|
|||
setText(_stringValue.c_str());
|
||||
}
|
||||
|
||||
void TextBMFont::setText(const char* value)
|
||||
void TextBMFont::setText(const std::string& value)
|
||||
{
|
||||
if (!value)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_stringValue = value;
|
||||
if (!_fntFileHasInit)
|
||||
{
|
||||
|
@ -92,9 +102,9 @@ void TextBMFont::setText(const char* value)
|
|||
labelBMFontScaleChangedWithSize();
|
||||
}
|
||||
|
||||
const char* TextBMFont::getStringValue()
|
||||
const std::string TextBMFont::getStringValue()
|
||||
{
|
||||
return _stringValue.c_str();
|
||||
return _stringValue;
|
||||
}
|
||||
|
||||
void TextBMFont::setAnchorPoint(const Point &pt)
|
||||
|
|
|
@ -56,14 +56,16 @@ public:
|
|||
*/
|
||||
static TextBMFont* create();
|
||||
|
||||
static TextBMFont* create(const std::string& text, const std::string& filename);
|
||||
|
||||
/** init a bitmap font atlas with an initial string and the FNT file */
|
||||
void setFntFile(const char* fileName);
|
||||
void setFntFile(const std::string& fileName);
|
||||
|
||||
/** set string value for labelbmfont*/
|
||||
void setText(const char* value);
|
||||
void setText(const std::string& value);
|
||||
|
||||
/** get string value for labelbmfont*/
|
||||
const char* getStringValue();
|
||||
const std::string getStringValue();
|
||||
virtual void setAnchorPoint(const Point &pt) override;
|
||||
virtual const Size& getContentSize() const override;
|
||||
virtual Node* getVirtualRenderer() override;
|
||||
|
|
|
@ -20,9 +20,9 @@ bool UITextBMFontTest::init()
|
|||
_uiLayer->addChild(alert);
|
||||
|
||||
// Create the TextBMFont
|
||||
TextBMFont* textBMFont = TextBMFont::create();
|
||||
textBMFont->setFntFile("cocosui/bitmapFontTest2.fnt");
|
||||
textBMFont->setText("BMFont");
|
||||
TextBMFont* textBMFont = TextBMFont::create("BMFont", "cocosui/bitmapFontTest2.fnt");
|
||||
// textBMFont->setFntFile("cocosui/bitmapFontTest2.fnt");
|
||||
// textBMFont->setText("BMFont");
|
||||
textBMFont->setPosition(Point(widgetSize.width / 2, widgetSize.height / 2.0f + textBMFont->getSize().height / 8.0f));
|
||||
_uiLayer->addChild(textBMFont);
|
||||
|
||||
|
|
Loading…
Reference in New Issue