From 76cefcaa3f379f8b086ef724912e0b36a0458456 Mon Sep 17 00:00:00 2001 From: andyque Date: Wed, 14 May 2014 15:51:50 +0800 Subject: [PATCH] issue #5110, refactor UITextAtlas --- cocos/ui/UITextAtlas.cpp | 20 ++++++++++++++------ cocos/ui/UITextAtlas.h | 17 ++++++++++++++--- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/cocos/ui/UITextAtlas.cpp b/cocos/ui/UITextAtlas.cpp index 0beb9c67b9..bce366478b 100644 --- a/cocos/ui/UITextAtlas.cpp +++ b/cocos/ui/UITextAtlas.cpp @@ -62,7 +62,7 @@ TextAtlas* TextAtlas::create() void TextAtlas::initRenderer() { - _labelAtlasRenderer = LabelAtlas::create(); + _labelAtlasRenderer = Label::create(); _labelAtlasRenderer->setAnchorPoint(Point::ANCHOR_MIDDLE); addProtectedChild(_labelAtlasRenderer, LABELATLAS_RENDERER_Z, -1); } @@ -91,25 +91,33 @@ void TextAtlas::setProperty(const std::string& stringValue, const std::string& c _itemWidth = itemWidth; _itemHeight = itemHeight; _startCharMap = startCharMap; - _labelAtlasRenderer->initWithString(stringValue, charMapFile, itemWidth, itemHeight, (int)(startCharMap[0])); + + _labelAtlasRenderer->setCharMap(_charMapFileName, _itemWidth, _itemHeight, (int)(_startCharMap[0])); + _labelAtlasRenderer->setString(stringValue); + updateContentSizeWithTextureSize(_labelAtlasRenderer->getContentSize()); _labelAtlasRendererAdaptDirty = true; - CCLOG("cs w %f, h %f", _contentSize.width, _contentSize.height); +// CCLOG("cs w %f, h %f", _contentSize.width, _contentSize.height); } -void TextAtlas::setStringValue(const std::string& value) +void TextAtlas::setString(const std::string& value) { _stringValue = value; _labelAtlasRenderer->setString(value); updateContentSizeWithTextureSize(_labelAtlasRenderer->getContentSize()); _labelAtlasRendererAdaptDirty = true; - CCLOG("cssss w %f, h %f", _contentSize.width, _contentSize.height); +// CCLOG("cssss w %f, h %f", _contentSize.width, _contentSize.height); } -const std::string& TextAtlas::getStringValue() const +const std::string& TextAtlas::getString() const { return _labelAtlasRenderer->getString(); } + +ssize_t TextAtlas::getStringLength() +{ + return _labelAtlasRenderer->getStringLength(); +} void TextAtlas::onSizeChanged() { diff --git a/cocos/ui/UITextAtlas.h b/cocos/ui/UITextAtlas.h index 2a79e84803..18942830bd 100644 --- a/cocos/ui/UITextAtlas.h +++ b/cocos/ui/UITextAtlas.h @@ -73,10 +73,21 @@ public: const std::string& startCharMap); //set string value for labelatlas. - void setStringValue(const std::string& value); + CC_DEPRECATED_ATTRIBUTE void setStringValue(const std::string& value){this->setString(value);} + void setString(const std::string& value); //get string value for labelatlas. - const std::string& getStringValue() const; + 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(); //override "getVirtualRendererSize" method of widget. virtual const Size& getVirtualRendererSize() const override; @@ -100,7 +111,7 @@ protected: virtual Widget* createCloneInstance() override; virtual void copySpecialProperties(Widget* model) override; protected: - LabelAtlas* _labelAtlasRenderer; + Label* _labelAtlasRenderer; std::string _stringValue; std::string _charMapFileName; int _itemWidth;