From 6a9da802928e0f8aa122f6c72d7f78087aba5fcc Mon Sep 17 00:00:00 2001 From: minggo Date: Thu, 16 Aug 2012 11:43:44 +0800 Subject: [PATCH 1/2] fixed #1430: compute correct label's width or height when its value is 0 --- cocos2dx/label_nodes/CCLabelTTF.cpp | 26 ++++++++++---------------- cocos2dx/label_nodes/CCLabelTTF.h | 2 +- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/cocos2dx/label_nodes/CCLabelTTF.cpp b/cocos2dx/label_nodes/CCLabelTTF.cpp index ca20749884..b86a84014c 100644 --- a/cocos2dx/label_nodes/CCLabelTTF.cpp +++ b/cocos2dx/label_nodes/CCLabelTTF.cpp @@ -221,7 +221,7 @@ CCSize CCLabelTTF::getDimensions() return m_tDimensions; } -void CCLabelTTF::setDimensions(CCSize &dim) +void CCLabelTTF::setDimensions(const CCSize &dim) { if (dim.width != m_tDimensions.width || dim.height != m_tDimensions.height) { @@ -278,21 +278,15 @@ void CCLabelTTF::setFontName(const char *fontName) void CCLabelTTF::updateTexture() { CCTexture2D *tex; - if (m_tDimensions.width == 0 || m_tDimensions.height == 0) - { - tex = new CCTexture2D(); - tex->initWithString(m_string.c_str(), m_pFontName->c_str(), m_fFontSize * CC_CONTENT_SCALE_FACTOR()) ; - } - else - { - tex = new CCTexture2D(); - tex->initWithString(m_string.c_str(), - CC_SIZE_POINTS_TO_PIXELS(m_tDimensions), - m_hAlignment, - m_vAlignment, - m_pFontName->c_str(), - m_fFontSize * CC_CONTENT_SCALE_FACTOR()); - } + + // refer to cocos2d-x issue #1430 + tex = new CCTexture2D(); + tex->initWithString(m_string.c_str(), + CC_SIZE_POINTS_TO_PIXELS(m_tDimensions), + m_hAlignment, + m_vAlignment, + m_pFontName->c_str(), + m_fFontSize * CC_CONTENT_SCALE_FACTOR()); this->setTexture(tex); tex->release(); diff --git a/cocos2dx/label_nodes/CCLabelTTF.h b/cocos2dx/label_nodes/CCLabelTTF.h index 9ee126c316..969b8f9f90 100644 --- a/cocos2dx/label_nodes/CCLabelTTF.h +++ b/cocos2dx/label_nodes/CCLabelTTF.h @@ -119,7 +119,7 @@ public: void setVerticalAlignment(CCVerticalTextAlignment verticalAlignment); CCSize getDimensions(); - void setDimensions(CCSize &dim); + void setDimensions(const CCSize &dim); float getFontSize(); void setFontSize(float fontSize); From 416ce6b91dbd95d4d3e4f1b88031cc7be0069e5a Mon Sep 17 00:00:00 2001 From: minggo Date: Thu, 16 Aug 2012 11:45:52 +0800 Subject: [PATCH 2/2] fixed #1430: add some comment --- cocos2dx/label_nodes/CCLabelTTF.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/cocos2dx/label_nodes/CCLabelTTF.cpp b/cocos2dx/label_nodes/CCLabelTTF.cpp index b86a84014c..8ed7a89205 100644 --- a/cocos2dx/label_nodes/CCLabelTTF.cpp +++ b/cocos2dx/label_nodes/CCLabelTTF.cpp @@ -279,6 +279,7 @@ void CCLabelTTF::updateTexture() { CCTexture2D *tex; + // let system compute label's width or height when its value is 0 // refer to cocos2d-x issue #1430 tex = new CCTexture2D(); tex->initWithString(m_string.c_str(),