Improved text alignment when text is larger than the allowed image width.

This commit is contained in:
Pieter Hulshoff 2016-07-23 11:05:48 +02:00
parent d1263ccc92
commit 92b0ca41c3

View File

@ -78,6 +78,9 @@ void Text::draw()
imageHeight = (float)font->getHeight();
float scale = (float)baseViewInfo.FontSize / (float)imageHeight;
unsigned int textIndexMax = 0;
unsigned int emptySpace = 0;
// determine image width
for(unsigned int i = 0; i < textData_.size(); ++i)
{
@ -90,9 +93,14 @@ void Text::draw()
}
if ((imageWidth + glyph.advance)*scale > imageMaxWidth )
break;
{
imageWidth -= emptySpace;
break;
}
imageWidth += glyph.advance;
textIndexMax = i;
emptySpace = glyph.advance - glyph.maxX;
imageWidth += glyph.advance;
}
}
@ -119,7 +127,7 @@ void Text::draw()
SDL_Rect rect;
rect.x = static_cast<int>(xOrigin);
for(unsigned int i = 0; i < textData_.size(); ++i)
for(unsigned int i = 0; i <= textIndexMax; ++i)
{
Font::GlyphInfo glyph;
@ -146,10 +154,6 @@ void Text::draw()
rect.x += static_cast<int>(glyph.advance * scale);
if((static_cast<float>(rect.x) - xOrigin) > imageMaxWidth)
{
break;
}
}
}
}