Fixed lose the precision of label's dimensions

This commit is contained in:
WenhaiLin 2015-01-20 11:46:43 +08:00
parent 2c5d82d772
commit f2c6a48976
3 changed files with 18 additions and 18 deletions

View File

@ -245,10 +245,10 @@ Label::Label(FontAtlas *atlas /* = nullptr */, TextHAlignment hAlignment /* = Te
, _commonLineHeight(0.0f) , _commonLineHeight(0.0f)
, _lineBreakWithoutSpaces(false) , _lineBreakWithoutSpaces(false)
, _horizontalKernings(nullptr) , _horizontalKernings(nullptr)
, _maxLineWidth(0) , _maxLineWidth(0.0f)
, _labelDimensions(Size::ZERO) , _labelDimensions(Size::ZERO)
, _labelWidth(0) , _labelWidth(0.0f)
, _labelHeight(0) , _labelHeight(0.0f)
, _hAlignment(hAlignment) , _hAlignment(hAlignment)
, _vAlignment(vAlignment) , _vAlignment(vAlignment)
, _currNumLines(-1) , _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) 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) if (height != _labelHeight || width != _labelWidth)
{ {

View File

@ -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 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. * The label's width and max line width has not always to be equal.
*/ */
void setMaxLineWidth(unsigned int maxLineWidth); void setMaxLineWidth(float maxLineWidth);
unsigned int getMaxLineWidth() { return _maxLineWidth;} float getMaxLineWidth() { return _maxLineWidth; }
/** Sets the untransformed size of the label. /** 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 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. * The label's max line width will be equal to the same value.
*/ */
void setWidth(unsigned int width) { setDimensions(width,_labelHeight);} void setWidth(float width) { setDimensions(width,_labelHeight);}
unsigned int getWidth() const { return _labelWidth; } float getWidth() const { return _labelWidth; }
/** Sets the untransformed size of the label. /** Sets the untransformed size of the label.
* The label's height be used for text align if the set value not equal zero. * 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. * 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);} void setHeight(float height){ setDimensions(_labelWidth, height); }
unsigned int getHeight() const { return _labelHeight;} float getHeight() const { return _labelHeight; }
/** Sets the untransformed size of the label in a more efficient way. */ /** 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;} const Size& getDimensions() const{ return _labelDimensions;}
/** update content immediately.*/ /** update content immediately.*/
@ -365,10 +365,10 @@ protected:
bool _lineBreakWithoutSpaces; bool _lineBreakWithoutSpaces;
int * _horizontalKernings; int * _horizontalKernings;
unsigned int _maxLineWidth; float _maxLineWidth;
Size _labelDimensions; Size _labelDimensions;
unsigned int _labelWidth; float _labelWidth;
unsigned int _labelHeight; float _labelHeight;
TextHAlignment _hAlignment; TextHAlignment _hAlignment;
TextVAlignment _vAlignment; TextVAlignment _vAlignment;

View File

@ -132,9 +132,9 @@ static bool _initWithString(const char * text, Device::TextAlign align, const ch
lastBreakLocation = i + insertCount; lastBreakLocation = i + insertCount;
} }
textSize = [lineBreak sizeWithAttributes:tokenAttributesDict]; textSize = [lineBreak sizeWithAttributes:tokenAttributesDict];
if(info->height > 0 && textSize.height > info->height) if(info->height > 0 && (int)textSize.height > info->height)
break; break;
if (textSize.width > info->width) { if ((int)textSize.width > info->width) {
if(lastBreakLocation > 0) { if(lastBreakLocation > 0) {
[lineBreak insertString:@"\r" atIndex:lastBreakLocation]; [lineBreak insertString:@"\r" atIndex:lastBreakLocation];
lastBreakLocation = 0; lastBreakLocation = 0;