From f2c6a48976cee36e5bd40ab11d362ed581e4d6d4 Mon Sep 17 00:00:00 2001 From: WenhaiLin Date: Tue, 20 Jan 2015 11:46:43 +0800 Subject: [PATCH] Fixed lose the precision of label's dimensions --- cocos/2d/CCLabel.cpp | 10 +++++----- cocos/2d/CCLabel.h | 22 +++++++++++----------- cocos/platform/mac/CCDevice-mac.mm | 4 ++-- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/cocos/2d/CCLabel.cpp b/cocos/2d/CCLabel.cpp index 27329913b0..e9bae0ca6a 100644 --- a/cocos/2d/CCLabel.cpp +++ b/cocos/2d/CCLabel.cpp @@ -245,10 +245,10 @@ Label::Label(FontAtlas *atlas /* = nullptr */, TextHAlignment hAlignment /* = Te , _commonLineHeight(0.0f) , _lineBreakWithoutSpaces(false) , _horizontalKernings(nullptr) -, _maxLineWidth(0) +, _maxLineWidth(0.0f) , _labelDimensions(Size::ZERO) -, _labelWidth(0) -, _labelHeight(0) +, _labelWidth(0.0f) +, _labelHeight(0.0f) , _hAlignment(hAlignment) , _vAlignment(vAlignment) , _currNumLines(-1) @@ -496,7 +496,7 @@ void Label::setAlignment(TextHAlignment hAlignment,TextVAlignment vAlignment) } } -void Label::setMaxLineWidth(unsigned int maxLineWidth) +void Label::setMaxLineWidth(float maxLineWidth) { if (_labelWidth == 0 && _maxLineWidth != maxLineWidth) { @@ -505,7 +505,7 @@ void Label::setMaxLineWidth(unsigned int maxLineWidth) } } -void Label::setDimensions(unsigned int width, unsigned int height) +void Label::setDimensions(float width, float height) { if (height != _labelHeight || width != _labelWidth) { diff --git a/cocos/2d/CCLabel.h b/cocos/2d/CCLabel.h index 02844fa5f4..e6d7c4715b 100644 --- a/cocos/2d/CCLabel.h +++ b/cocos/2d/CCLabel.h @@ -183,25 +183,25 @@ public: * The label's max line width be used for force line breaks if the set value not equal zero. * The label's width and max line width has not always to be equal. */ - void setMaxLineWidth(unsigned int maxLineWidth); - unsigned int getMaxLineWidth() { return _maxLineWidth;} + void setMaxLineWidth(float maxLineWidth); + float getMaxLineWidth() { return _maxLineWidth; } /** Sets the untransformed size of the label. * The label's width be used for text align if the set value not equal zero. * The label's max line width will be equal to the same value. */ - void setWidth(unsigned int width) { setDimensions(width,_labelHeight);} - unsigned int getWidth() const { return _labelWidth; } + void setWidth(float width) { setDimensions(width,_labelHeight);} + float getWidth() const { return _labelWidth; } /** Sets the untransformed size of the label. * The label's height be used for text align if the set value not equal zero. * The text will display of incomplete when the size of label not enough to support display all text. */ - void setHeight(unsigned int height){ setDimensions(_labelWidth,height);} - unsigned int getHeight() const { return _labelHeight;} + void setHeight(float height){ setDimensions(_labelWidth, height); } + float getHeight() const { return _labelHeight; } /** Sets the untransformed size of the label in a more efficient way. */ - void setDimensions(unsigned int width,unsigned int height); + void setDimensions(float width, float height); const Size& getDimensions() const{ return _labelDimensions;} /** update content immediately.*/ @@ -365,10 +365,10 @@ protected: bool _lineBreakWithoutSpaces; int * _horizontalKernings; - unsigned int _maxLineWidth; - Size _labelDimensions; - unsigned int _labelWidth; - unsigned int _labelHeight; + float _maxLineWidth; + Size _labelDimensions; + float _labelWidth; + float _labelHeight; TextHAlignment _hAlignment; TextVAlignment _vAlignment; diff --git a/cocos/platform/mac/CCDevice-mac.mm b/cocos/platform/mac/CCDevice-mac.mm index f1c01c0c3c..fa067c566a 100644 --- a/cocos/platform/mac/CCDevice-mac.mm +++ b/cocos/platform/mac/CCDevice-mac.mm @@ -132,9 +132,9 @@ static bool _initWithString(const char * text, Device::TextAlign align, const ch lastBreakLocation = i + insertCount; } textSize = [lineBreak sizeWithAttributes:tokenAttributesDict]; - if(info->height > 0 && textSize.height > info->height) + if(info->height > 0 && (int)textSize.height > info->height) break; - if (textSize.width > info->width) { + if ((int)textSize.width > info->width) { if(lastBreakLocation > 0) { [lineBreak insertString:@"\r" atIndex:lastBreakLocation]; lastBreakLocation = 0;