issue #5110, refactor UITextBMFont

This commit is contained in:
andyque 2014-05-14 16:02:31 +08:00
parent 76cefcaa3f
commit 437b30487c
4 changed files with 26 additions and 10 deletions

View File

@ -932,7 +932,7 @@ void WidgetPropertiesReader0250::setPropsForLabelBMFontFromJsonDictionary(Widget
labelBMFont->setFntFile(cmf_tp); labelBMFont->setFntFile(cmf_tp);
const char* text = DICTOOL->getStringValue_json(options, "text"); const char* text = DICTOOL->getStringValue_json(options, "text");
labelBMFont->setText(text); labelBMFont->setString(text);
setColorPropsForWidgetFromJsonDictionary(widget,options); setColorPropsForWidgetFromJsonDictionary(widget,options);
} }
@ -2020,7 +2020,7 @@ void WidgetPropertiesReader0300::setPropsForLabelBMFontFromJsonDictionary(Widget
} }
const char* text = DICTOOL->getStringValue_json(options, "text"); const char* text = DICTOOL->getStringValue_json(options, "text");
labelBMFont->setText(text); labelBMFont->setString(text);
setColorPropsForWidgetFromJsonDictionary(widget,options); setColorPropsForWidgetFromJsonDictionary(widget,options);
} }

View File

@ -60,7 +60,7 @@ namespace cocostudio
} }
const char* text = DICTOOL->getStringValue_json(options, "text"); const char* text = DICTOOL->getStringValue_json(options, "text");
labelBMFont->setText(text); labelBMFont->setString(text);
WidgetReader::setColorPropsFromJsonDictionary(widget, options); WidgetReader::setColorPropsFromJsonDictionary(widget, options);

View File

@ -64,7 +64,7 @@ TextBMFont* TextBMFont::create(const std::string &text, const std::string &filen
if (widget && widget->init()) if (widget && widget->init())
{ {
widget->setFntFile(filename); widget->setFntFile(filename);
widget->setText(text); widget->setString(text);
widget->autorelease(); widget->autorelease();
return widget; return widget;
} }
@ -88,10 +88,10 @@ void TextBMFont::setFntFile(const std::string& fileName)
_labelBMFontRenderer->setBMFontFilePath(fileName); _labelBMFontRenderer->setBMFontFilePath(fileName);
updateRGBAToRenderer(_labelBMFontRenderer); updateRGBAToRenderer(_labelBMFontRenderer);
_fntFileHasInit = true; _fntFileHasInit = true;
setText(_stringValue); setString(_stringValue);
} }
void TextBMFont::setText(const std::string& value) void TextBMFont::setString(const std::string& value)
{ {
_stringValue = value; _stringValue = value;
if (!_fntFileHasInit) if (!_fntFileHasInit)
@ -103,11 +103,16 @@ void TextBMFont::setText(const std::string& value)
_labelBMFontRendererAdaptDirty = true; _labelBMFontRendererAdaptDirty = true;
} }
const std::string TextBMFont::getStringValue() const std::string& TextBMFont::getString()const
{ {
return _stringValue; return _stringValue;
} }
ssize_t TextBMFont::getStringLength()
{
return _labelBMFontRenderer->getStringLength();
}
void TextBMFont::onSizeChanged() void TextBMFont::onSizeChanged()
{ {
Widget::onSizeChanged(); Widget::onSizeChanged();
@ -186,7 +191,7 @@ void TextBMFont::copySpecialProperties(Widget *widget)
if (labelBMFont) if (labelBMFont)
{ {
setFntFile(labelBMFont->_fntFileName); setFntFile(labelBMFont->_fntFileName);
setText(labelBMFont->_stringValue); setString(labelBMFont->_stringValue);
} }
} }

View File

@ -62,10 +62,21 @@ public:
void setFntFile(const std::string& fileName); void setFntFile(const std::string& fileName);
/** set string value for labelbmfont*/ /** set string value for labelbmfont*/
void setText(const std::string& value); CC_DEPRECATED_ATTRIBUTE void setText(const std::string& value){this->setString(value);}
void setString(const std::string& value);
/** get string value for labelbmfont*/ /** get string value for labelbmfont*/
const std::string getStringValue(); CC_DEPRECATED_ATTRIBUTE const std::string& getStringValue()const{return this->getString();}
const std::string& getString()const;
/**
* Gets the string length of the label.
* Note: This length will be larger than the raw string length,
* if you want to get the raw string length, you should call this->getString().size() instead
*
* @return string length.
*/
ssize_t getStringLength();
virtual const Size& getVirtualRendererSize() const override; virtual const Size& getVirtualRendererSize() const override;
virtual Node* getVirtualRenderer() override; virtual Node* getVirtualRenderer() override;