From 437b30487cd6771ad393100864077156105f127e Mon Sep 17 00:00:00 2001 From: andyque Date: Wed, 14 May 2014 16:02:31 +0800 Subject: [PATCH] issue #5110, refactor UITextBMFont --- cocos/editor-support/cocostudio/CCSGUIReader.cpp | 4 ++-- .../TextBMFontReader/TextBMFontReader.cpp | 2 +- cocos/ui/UITextBMFont.cpp | 15 ++++++++++----- cocos/ui/UITextBMFont.h | 15 +++++++++++++-- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/cocos/editor-support/cocostudio/CCSGUIReader.cpp b/cocos/editor-support/cocostudio/CCSGUIReader.cpp index f80d20231a..dc30adc143 100644 --- a/cocos/editor-support/cocostudio/CCSGUIReader.cpp +++ b/cocos/editor-support/cocostudio/CCSGUIReader.cpp @@ -932,7 +932,7 @@ void WidgetPropertiesReader0250::setPropsForLabelBMFontFromJsonDictionary(Widget labelBMFont->setFntFile(cmf_tp); const char* text = DICTOOL->getStringValue_json(options, "text"); - labelBMFont->setText(text); + labelBMFont->setString(text); setColorPropsForWidgetFromJsonDictionary(widget,options); } @@ -2020,7 +2020,7 @@ void WidgetPropertiesReader0300::setPropsForLabelBMFontFromJsonDictionary(Widget } const char* text = DICTOOL->getStringValue_json(options, "text"); - labelBMFont->setText(text); + labelBMFont->setString(text); setColorPropsForWidgetFromJsonDictionary(widget,options); } diff --git a/cocos/editor-support/cocostudio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp index cd5ca3d85b..0558c1b072 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp @@ -60,7 +60,7 @@ namespace cocostudio } const char* text = DICTOOL->getStringValue_json(options, "text"); - labelBMFont->setText(text); + labelBMFont->setString(text); WidgetReader::setColorPropsFromJsonDictionary(widget, options); diff --git a/cocos/ui/UITextBMFont.cpp b/cocos/ui/UITextBMFont.cpp index 78648b464f..28b6e050a5 100644 --- a/cocos/ui/UITextBMFont.cpp +++ b/cocos/ui/UITextBMFont.cpp @@ -64,7 +64,7 @@ TextBMFont* TextBMFont::create(const std::string &text, const std::string &filen if (widget && widget->init()) { widget->setFntFile(filename); - widget->setText(text); + widget->setString(text); widget->autorelease(); return widget; } @@ -88,10 +88,10 @@ void TextBMFont::setFntFile(const std::string& fileName) _labelBMFontRenderer->setBMFontFilePath(fileName); updateRGBAToRenderer(_labelBMFontRenderer); _fntFileHasInit = true; - setText(_stringValue); + setString(_stringValue); } -void TextBMFont::setText(const std::string& value) +void TextBMFont::setString(const std::string& value) { _stringValue = value; if (!_fntFileHasInit) @@ -103,10 +103,15 @@ void TextBMFont::setText(const std::string& value) _labelBMFontRendererAdaptDirty = true; } -const std::string TextBMFont::getStringValue() +const std::string& TextBMFont::getString()const { return _stringValue; } + +ssize_t TextBMFont::getStringLength() +{ + return _labelBMFontRenderer->getStringLength(); +} void TextBMFont::onSizeChanged() { @@ -186,7 +191,7 @@ void TextBMFont::copySpecialProperties(Widget *widget) if (labelBMFont) { setFntFile(labelBMFont->_fntFileName); - setText(labelBMFont->_stringValue); + setString(labelBMFont->_stringValue); } } diff --git a/cocos/ui/UITextBMFont.h b/cocos/ui/UITextBMFont.h index 99fa26906f..03c3334555 100644 --- a/cocos/ui/UITextBMFont.h +++ b/cocos/ui/UITextBMFont.h @@ -62,10 +62,21 @@ public: void setFntFile(const std::string& fileName); /** 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*/ - 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 Node* getVirtualRenderer() override;