Fix my ugly 'tab' hack in the string renderer so that the results are better in RTL languages

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@7577 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2011-02-02 00:42:57 +00:00
parent 3307b5a7f0
commit 040ad4d692

View File

@ -452,11 +452,15 @@ void ScalableFont::draw(const core::stringw& text,
core::position2d<s32> offset = position.UpperLeftCorner;
core::dimension2d<s32> text_dimension;
if (m_rtl || hcenter || vcenter || clip)
// When we use the "tab" hack, disable right-alignment, it messes up everything
bool has_tab = (text.findFirst(L'\t') != -1);
if ((m_rtl && !has_tab) || hcenter || vcenter || clip)
{
text_dimension = getDimension(text.c_str());
if (hcenter) offset.X += (position.getWidth() - text_dimension.Width) / 2;
else if (m_rtl) offset.X += (position.getWidth() - text_dimension.Width);
if (hcenter) offset.X += (position.getWidth() - text_dimension.Width) / 2;
else if (m_rtl && !has_tab) offset.X += (position.getWidth() - text_dimension.Width);
if (vcenter) offset.Y += (position.getHeight() - text_dimension.Height) / 2;
if (clip)
@ -465,7 +469,15 @@ void ScalableFont::draw(const core::stringw& text,
clippedRect.clipAgainst(*clip);
if (!clippedRect.isValid()) return;
}
} // if rtl, centered, or clip
}
if (m_rtl && has_tab)
{
const int where = text.findFirst(L'\t');
core::stringw substr = text.subString(0, where-1);
text_dimension = getDimension(text.c_str());
offset.X += (position.getWidth()/2 - text_dimension.Width);
}
// ---- collect character locations
const unsigned int text_size = text.size();