Fixed bounding rect of sf::Text ignoring whitespaces (216)

This commit is contained in:
Laurent Gomila 2013-07-11 22:40:14 +02:00
parent 947ab5fd87
commit 5c431b4b93

View File

@ -251,6 +251,7 @@ void Text::updateGeometry()
float y = static_cast<float>(m_characterSize);
// Create one quad for each character
float minY = static_cast<float>(m_characterSize);
Uint32 prevChar = 0;
for (std::size_t i = 0; i < m_string.getSize(); ++i)
{
@ -275,10 +276,24 @@ void Text::updateGeometry()
// Handle special characters
switch (curChar)
{
case L' ' : x += hspace; continue;
case L'\t' : x += hspace * 4; continue;
case L'\n' : y += vspace; x = 0; continue;
case L'\v' : y += vspace * 4; continue;
case L' ' :
x += hspace;
continue;
case L'\t' :
x += hspace * 4;
continue;
case L'\n' :
if (x > m_bounds.width)
m_bounds.width = x;
y += vspace;
x = 0;
continue;
case L'\v' :
y += vspace * 4;
continue;
}
// Extract the current glyph's description
@ -302,6 +317,10 @@ void Text::updateGeometry()
// Advance to the next character
x += glyph.advance;
// Update the minimum Y coordinate
if (y + top < minY)
minY = y + top;
}
// If we're using the underlined style, add the last line
@ -316,8 +335,12 @@ void Text::updateGeometry()
m_vertices.append(Vertex(Vector2f(0, bottom), m_color, Vector2f(1, 1)));
}
// Recompute the bounding rectangle
m_bounds = m_vertices.getBounds();
// Update the bounding rectangle
m_bounds.left = 0;
m_bounds.top = minY;
if (x > m_bounds.width)
m_bounds.width = x;
m_bounds.height = y - minY;
}
} // namespace sf