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)
, _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)
{

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 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;

View File

@ -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;