From 4692c67b7892fae2e2a87112ee3f6846518c736e Mon Sep 17 00:00:00 2001 From: Dhilan007 Date: Thu, 8 May 2014 21:30:12 +0800 Subject: [PATCH] issue #4660:remove unnecessary API. --- cocos/2d/CCLabel.cpp | 48 +++++++++++-------------------- cocos/2d/CCLabel.h | 5 ++-- cocos/2d/CCLabelTextFormatter.cpp | 6 ++-- 3 files changed, 22 insertions(+), 37 deletions(-) diff --git a/cocos/2d/CCLabel.cpp b/cocos/2d/CCLabel.cpp index f74510fa73..2661352b48 100644 --- a/cocos/2d/CCLabel.cpp +++ b/cocos/2d/CCLabel.cpp @@ -301,7 +301,7 @@ void Label::reset() TTFConfig temp; _fontConfig = temp; - _fontDirty = false; + _systemFontDirty = false; _systemFont = "Helvetica"; _systemFontSize = 12; @@ -472,6 +472,13 @@ void Label::setString(const std::string& text) { _originalUTF8String = text; _contentDirty = true; + + std::u16string utf16String; + if (StringUtils::UTF8ToUTF16(_originalUTF8String, utf16String)) + { + _originalUTF16String = utf16String; + _currentUTF16String = utf16String; + } } void Label::setAlignment(TextHAlignment hAlignment,TextVAlignment vAlignment) @@ -646,25 +653,6 @@ bool Label::computeHorizontalKernings(const std::u16string& stringToRender) return true; } -bool Label::setOriginalString(const std::u16string& stringToSet) -{ - _originalUTF16String = stringToSet; - return true; -} - -bool Label::setCurrentString(const std::u16string& stringToSet) -{ - _currentUTF16String = stringToSet; - computeStringNumLines(); - - // compute the advances - if (_fontAtlas) - { - computeHorizontalKernings(stringToSet); - } - return true; -} - void Label::updateQuads() { int index; @@ -939,11 +927,10 @@ void Label::setFontDefinition(const FontDefinition& textDefinition) void Label::updateContent() { - std::u16string utf16String; - if (StringUtils::UTF8ToUTF16(_originalUTF8String, utf16String)) + computeStringNumLines(); + if (_fontAtlas) { - setCurrentString(utf16String); - setOriginalString(utf16String); + computeHorizontalKernings(_originalUTF16String); } if (_textSprite) @@ -1019,7 +1006,7 @@ void Label::updateFont() } _contentDirty = true; - _fontDirty = false; + _systemFontDirty = false; } void Label::drawTextSprite(Renderer *renderer, bool parentTransformUpdated) @@ -1058,7 +1045,7 @@ void Label::visit(Renderer *renderer, const Matrix &parentTransform, bool parent { return; } - if (_fontDirty) + if (_systemFontDirty) { updateFont(); } @@ -1119,7 +1106,7 @@ void Label::setSystemFontName(const std::string& systemFont) if (systemFont != _systemFont) { _systemFont = systemFont; - _fontDirty = true; + _systemFontDirty = true; } } @@ -1128,16 +1115,15 @@ void Label::setSystemFontSize(float fontSize) if (_systemFontSize != fontSize) { _systemFontSize = fontSize; - _fontDirty = true; + _systemFontDirty = true; } } ///// PROTOCOL STUFF Sprite * Label::getLetter(int letterIndex) { - if (_fontDirty) + if (_systemFontDirty || _currentLabelType == LabelType::STRING_TEXTURE) { - updateFont(); return nullptr; } @@ -1313,7 +1299,7 @@ std::string Label::getDescription() const const Size& Label::getContentSize() const { - if (_fontDirty) + if (_systemFontDirty) { const_cast(this)->updateFont(); } diff --git a/cocos/2d/CCLabel.h b/cocos/2d/CCLabel.h index 1e92da49a8..eaffb636e1 100644 --- a/cocos/2d/CCLabel.h +++ b/cocos/2d/CCLabel.h @@ -287,8 +287,7 @@ protected: virtual void alignText(); bool computeHorizontalKernings(const std::u16string& stringToRender); - bool setCurrentString(const std::u16string& stringToSet); - bool setOriginalString(const std::u16string& stringToSet); + void computeStringNumLines(); void updateQuads(); @@ -311,7 +310,7 @@ protected: bool _isOpacityModifyRGB; bool _contentDirty; - bool _fontDirty; + bool _systemFontDirty; std::string _systemFont; float _systemFontSize; LabelType _currentLabelType; diff --git a/cocos/2d/CCLabelTextFormatter.cpp b/cocos/2d/CCLabelTextFormatter.cpp index 40a240f50b..6a0a7aed63 100644 --- a/cocos/2d/CCLabelTextFormatter.cpp +++ b/cocos/2d/CCLabelTextFormatter.cpp @@ -34,9 +34,7 @@ NS_CC_BEGIN bool LabelTextFormatter::multilineText(Label *theLabel) { - //int strLen = theLabel->getStringLength(); auto limit = theLabel->_limitShowCount; - auto strWhole = theLabel->_currentUTF16String; std::vector multiline_string; @@ -175,7 +173,9 @@ bool LabelTextFormatter::multilineText(Label *theLabel) std::u16string strNew(multiline_string.begin(), multiline_string.end()); - theLabel->setCurrentString(strNew); + theLabel->_originalUTF16String = strNew; + theLabel->computeStringNumLines(); + theLabel->computeHorizontalKernings(theLabel->_originalUTF16String); return true; }