Reduce font size for long GP names to avoid clipping (long translations can still cause clipping though)

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@6912 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2010-12-09 02:06:44 +00:00
parent 3cca0b7666
commit 3a149c5a78

View File

@ -17,6 +17,7 @@
#include "graphics/irr_driver.hpp"
#include "guiengine/engine.hpp"
#include "guiengine/scalable_font.hpp"
#include "guiengine/widgets/icon_button_widget.hpp"
#include "io/file_manager.hpp"
@ -127,6 +128,13 @@ void IconButtonWidget::add()
m_label->setTextAlignment(EGUIA_CENTER, EGUIA_UPPERLEFT);
m_label->setTabStop(false);
m_label->setNotClipped(true);
const int max_w = m_label->getAbsolutePosition().getWidth();
if (!word_wrap &&
(int)GUIEngine::getFont()->getDimension(message.c_str()).Width > max_w + 4) // arbitrarily allow for 4 pixels
{
m_label->setOverrideFont( GUIEngine::getSmallFont() );
}
}
// ---- IDs
@ -193,4 +201,17 @@ void IconButtonWidget::setLabel(stringw new_label)
if (m_label == NULL) return;
m_label->setText( new_label.c_str() );
const bool word_wrap = (m_properties[PROP_WORD_WRAP] == "true");
const int max_w = m_label->getAbsolutePosition().getWidth();
if (!word_wrap &&
(int)GUIEngine::getFont()->getDimension(new_label.c_str()).Width > max_w + 4) // arbitrarily allow for 4 pixels
{
m_label->setOverrideFont( GUIEngine::getSmallFont() );
}
else
{
m_label->setOverrideFont( NULL );
}
}