From 8ab057550ffa7e013dddcb5750e19812b326484a Mon Sep 17 00:00:00 2001 From: Dhilan007 Date: Fri, 28 Mar 2014 15:58:28 +0800 Subject: [PATCH] fixed got wrong Rect by LabelTTF::getBoundingBox / LabelBMFont::getBoundingBox. --- cocos/2d/CCLabel.cpp | 2 +- cocos/2d/CCLabel.h | 2 +- cocos/2d/CCLabelBMFont.cpp | 11 +++++++++++ cocos/2d/CCLabelBMFont.h | 3 +++ cocos/2d/CCLabelTTF.cpp | 5 +++++ cocos/2d/CCLabelTTF.h | 2 ++ 6 files changed, 23 insertions(+), 2 deletions(-) diff --git a/cocos/2d/CCLabel.cpp b/cocos/2d/CCLabel.cpp index 27ce8d3517..d0b090c2ea 100644 --- a/cocos/2d/CCLabel.cpp +++ b/cocos/2d/CCLabel.cpp @@ -1361,7 +1361,7 @@ const Size& Label::getContentSize() const { const_cast(this)->updateContent(); } - return Node::getContentSize(); + return _contentSize; } Rect Label::getBoundingBox() const diff --git a/cocos/2d/CCLabel.h b/cocos/2d/CCLabel.h index d319b607e6..1d306cdbde 100644 --- a/cocos/2d/CCLabel.h +++ b/cocos/2d/CCLabel.h @@ -243,7 +243,7 @@ public: virtual const Size& getContentSize() const override; - virtual Rect getBoundingBox() const; + virtual Rect getBoundingBox() const override; FontAtlas* getFontAtlas() { return _fontAtlas; } /** Listen "come to background" message diff --git a/cocos/2d/CCLabelBMFont.cpp b/cocos/2d/CCLabelBMFont.cpp index bc41c21c57..6f6b5b950d 100644 --- a/cocos/2d/CCLabelBMFont.cpp +++ b/cocos/2d/CCLabelBMFont.cpp @@ -191,6 +191,17 @@ void LabelBMFont::setColor(const Color3B& color) _label->setColor(color); } +const Size& LabelBMFont::getContentSize() const +{ + const_cast(this)->setContentSize(_label->getContentSize()); + return _contentSize; +} + +Rect LabelBMFont::getBoundingBox() const +{ + return _label->getBoundingBox(); +} + //LabelBMFont - Debug draw #if CC_LABELBMFONT_DEBUG_DRAW void LabelBMFont::draw() diff --git a/cocos/2d/CCLabelBMFont.h b/cocos/2d/CCLabelBMFont.h index ae5c84f784..c5fb597c40 100644 --- a/cocos/2d/CCLabelBMFont.h +++ b/cocos/2d/CCLabelBMFont.h @@ -116,6 +116,9 @@ public: virtual void setColor(const Color3B& color) override; + virtual const Size& getContentSize() const override; + virtual Rect getBoundingBox() const override; + virtual std::string getDescription() const override; #if CC_LABELBMFONT_DEBUG_DRAW diff --git a/cocos/2d/CCLabelTTF.cpp b/cocos/2d/CCLabelTTF.cpp index 71887ca12b..581d52274b 100644 --- a/cocos/2d/CCLabelTTF.cpp +++ b/cocos/2d/CCLabelTTF.cpp @@ -278,6 +278,11 @@ const Size& LabelTTF::getContentSize() const return _contentSize; } +Rect LabelTTF::getBoundingBox() const +{ + return _renderLabel->getBoundingBox(); +} + #if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))) #pragma GCC diagnostic warning "-Wdeprecated-declarations" #elif _MSC_VER >= 1400 //vs 2005 or higher diff --git a/cocos/2d/CCLabelTTF.h b/cocos/2d/CCLabelTTF.h index d5138c2f9d..a480ba5542 100644 --- a/cocos/2d/CCLabelTTF.h +++ b/cocos/2d/CCLabelTTF.h @@ -143,6 +143,8 @@ public: virtual void setFlippedX(bool flippedX); virtual void setFlippedY(bool flippedY); + virtual Rect getBoundingBox() const override; + /** * @js NA * @lua NA