From 62ee51e383729136c8a8056e2a289c1b14f9e799 Mon Sep 17 00:00:00 2001 From: auria Date: Wed, 30 Dec 2009 18:00:23 +0000 Subject: [PATCH] Cleanup up a few font-related harcoded constants or duplicated code git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@4366 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- data/gui/License.txt | 2 ++ src/guiengine/engine.cpp | 8 +++++++- src/guiengine/engine.hpp | 3 +++ src/guiengine/widgets/dynamic_ribbon_widget.cpp | 2 +- src/guiengine/widgets/icon_button_widget.cpp | 2 +- src/guiengine/widgets/ribbon_widget.cpp | 3 +-- src/states_screens/dialogs/add_device_dialog.cpp | 2 +- src/states_screens/dialogs/enter_player_name_dialog.cpp | 2 +- src/states_screens/dialogs/player_info_dialog.cpp | 4 ++-- src/states_screens/dialogs/press_a_key_dialog.cpp | 4 ++-- src/states_screens/dialogs/race_over_dialog.cpp | 2 +- src/states_screens/dialogs/race_paused_dialog.cpp | 2 +- 12 files changed, 23 insertions(+), 13 deletions(-) diff --git a/data/gui/License.txt b/data/gui/License.txt index 6127f7c29..fc7d73b39 100644 --- a/data/gui/License.txt +++ b/data/gui/License.txt @@ -15,6 +15,8 @@ Okolaks font by Gluk, released under Open Font License title_font, by Marianne Gagnon (Auria), released under CC-BY-SA 3+ +screen*.png, by Marianne Gagnon (Auria), including elements from the public domain Tango icon set + ==== Glass Skin by Auria, under CC-BY-SA 3+ diff --git a/src/guiengine/engine.cpp b/src/guiengine/engine.cpp index 0cb18f2ea..8fc4f1428 100644 --- a/src/guiengine/engine.cpp +++ b/src/guiengine/engine.cpp @@ -88,7 +88,13 @@ namespace GUIEngine // otherwise check if the focus is the given widget return g_focus_for_player[playerID]->isSameIrrlichtWidgetAs(w); } - + + int getFontHeight() + { + // FIXME: this needs to be reset when changing resolution + static int fh = g_font->getDimension( L"X" ).Height; + return fh; + } // ----------------------------------------------------------------------------- void clear() { diff --git a/src/guiengine/engine.hpp b/src/guiengine/engine.hpp index 4bb9a6f77..349b202ef 100644 --- a/src/guiengine/engine.hpp +++ b/src/guiengine/engine.hpp @@ -258,6 +258,9 @@ namespace GUIEngine inline AbstractStateManager* getStateManager() { return Private::g_state_manager; } inline Skin* getSkin() { return Private::g_skin; } + /** Returns the height of the font in pixels */ + int getFontHeight(); + float getLatestDt(); /** Add a cutscene to the list of screens known by the gui engine */ diff --git a/src/guiengine/widgets/dynamic_ribbon_widget.cpp b/src/guiengine/widgets/dynamic_ribbon_widget.cpp index aa6de97e9..11bdf1018 100644 --- a/src/guiengine/widgets/dynamic_ribbon_widget.cpp +++ b/src/guiengine/widgets/dynamic_ribbon_widget.cpp @@ -60,7 +60,7 @@ void DynamicRibbonWidget::add() if (m_has_label) { // FIXME - won't work with multiline labels. - m_label_height = GUIEngine::getFont()->getDimension( L"X" ).Height; + m_label_height = GUIEngine::getFontHeight(); } else { diff --git a/src/guiengine/widgets/icon_button_widget.cpp b/src/guiengine/widgets/icon_button_widget.cpp index 7de6c2518..dfe89f37d 100644 --- a/src/guiengine/widgets/icon_button_widget.cpp +++ b/src/guiengine/widgets/icon_button_widget.cpp @@ -70,7 +70,7 @@ void IconButtonWidget::add() 0 : atoi(m_properties[PROP_EXTEND_LABEL].c_str()) ); widget_size = rect(x - label_extra_size/2, y + h, x + w + label_extra_size/2, y + h*2); - m_label = GUIEngine::getGUIEnv()->addStaticText(message.c_str(), widget_size, false, false /* word wrap */, m_parent); + m_label = GUIEngine::getGUIEnv()->addStaticText(message.c_str(), widget_size, false, true /* word wrap */, m_parent); m_label->setTextAlignment(EGUIA_CENTER, EGUIA_UPPERLEFT); m_label->setTabStop(false); } diff --git a/src/guiengine/widgets/ribbon_widget.cpp b/src/guiengine/widgets/ribbon_widget.cpp index 793519e09..5c618719e 100644 --- a/src/guiengine/widgets/ribbon_widget.cpp +++ b/src/guiengine/widgets/ribbon_widget.cpp @@ -159,9 +159,8 @@ void RibbonWidget::add() { // how much space to keep for the label under the button const bool has_label = m_children[i].m_text.size() > 0; - const int needed_space_under_button = has_label ? 30 : 10; // quite arbitrary for now + const int needed_space_under_button = has_label ? GUIEngine::getFontHeight() : 10; - // For now, the image stretches to keep the aspect ratio of the widget (FIXME, doesn't work) float imageRatio = (float)m_children[i].w/(float)m_children[i].h; // size of the image diff --git a/src/states_screens/dialogs/add_device_dialog.cpp b/src/states_screens/dialogs/add_device_dialog.cpp index a3293874e..38d795093 100644 --- a/src/states_screens/dialogs/add_device_dialog.cpp +++ b/src/states_screens/dialogs/add_device_dialog.cpp @@ -35,7 +35,7 @@ using namespace irr::core; AddDeviceDialog::AddDeviceDialog() : ModalDialog(0.7f, 0.7f) { IGUIFont* font = GUIEngine::getFont(); - const int textHeight = font->getDimension(L"X").Height; + const int textHeight = GUIEngine::getFontHeight(); const int buttonHeight = textHeight + 10; const int y_bottom = m_area.getHeight() - 2*(buttonHeight + 10) - 20; diff --git a/src/states_screens/dialogs/enter_player_name_dialog.cpp b/src/states_screens/dialogs/enter_player_name_dialog.cpp index e4420fe92..57ccb641b 100644 --- a/src/states_screens/dialogs/enter_player_name_dialog.cpp +++ b/src/states_screens/dialogs/enter_player_name_dialog.cpp @@ -47,7 +47,7 @@ EnterPlayerNameDialog::EnterPlayerNameDialog(const float w, const float h) : // ---- IGUIFont* font = GUIEngine::getFont(); - const int textHeight = font->getDimension(L"X").Height; + const int textHeight = GUIEngine::getFontHeight(); const int textAreaYFrom = m_area.getHeight()/2 - textHeight/2; diff --git a/src/states_screens/dialogs/player_info_dialog.cpp b/src/states_screens/dialogs/player_info_dialog.cpp index 45edf3786..7c28d61ef 100644 --- a/src/states_screens/dialogs/player_info_dialog.cpp +++ b/src/states_screens/dialogs/player_info_dialog.cpp @@ -46,7 +46,7 @@ void PlayerInfoDialog::showRegularDialog() const int y4 = m_area.getHeight()*5/6; IGUIFont* font = GUIEngine::getFont(); - const int textHeight = font->getDimension(L"X").Height; + const int textHeight = GUIEngine::getFontHeight(); const int buttonHeight = textHeight + 10; { @@ -122,7 +122,7 @@ void PlayerInfoDialog::showConfirmDialog() IGUIFont* font = GUIEngine::getFont(); - const int textHeight = font->getDimension(L"X").Height; + const int textHeight = GUIEngine::getFontHeight(); const int buttonHeight = textHeight + 10; diff --git a/src/states_screens/dialogs/press_a_key_dialog.cpp b/src/states_screens/dialogs/press_a_key_dialog.cpp index c39ddb355..8449882ff 100644 --- a/src/states_screens/dialogs/press_a_key_dialog.cpp +++ b/src/states_screens/dialogs/press_a_key_dialog.cpp @@ -41,8 +41,8 @@ PressAKeyDialog::PressAKeyDialog(const float w, const float h) : widget->add(); - IGUIFont* font = GUIEngine::getFont(); - const int textHeight = font->getDimension(L"X").Height; + //IGUIFont* font = GUIEngine::getFont(); + const int textHeight = GUIEngine::getFontHeight(); ButtonWidget* widget2 = new ButtonWidget(); widget2->m_properties[PROP_ID] = "cancel"; diff --git a/src/states_screens/dialogs/race_over_dialog.cpp b/src/states_screens/dialogs/race_over_dialog.cpp index 6c8e69604..e45d26c9e 100644 --- a/src/states_screens/dialogs/race_over_dialog.cpp +++ b/src/states_screens/dialogs/race_over_dialog.cpp @@ -45,7 +45,7 @@ RaceOverDialog::RaceOverDialog(const float percentWidth, const float percentHeig //const int h = m_area.getHeight(); IGUIFont* font = GUIEngine::getFont(); - const int text_height = font->getDimension(L"X").Height; + const int text_height = GUIEngine::getFontHeight(); const int button_h = text_height + 6; const int margin_between_buttons = 12; diff --git a/src/states_screens/dialogs/race_paused_dialog.cpp b/src/states_screens/dialogs/race_paused_dialog.cpp index a38487f21..dd83ba934 100644 --- a/src/states_screens/dialogs/race_paused_dialog.cpp +++ b/src/states_screens/dialogs/race_paused_dialog.cpp @@ -41,7 +41,7 @@ RacePausedDialog::RacePausedDialog(const float percentWidth, const float percent RaceManager::getWorld()->pause(); IGUIFont* font = GUIEngine::getTitleFont(); - const int text_height = font->getDimension(L"X").Height; + const int text_height = GUIEngine::getFontHeight(); IGUIFont* titlefont = GUIEngine::getTitleFont(); const int title_height = font->getDimension(L"X").Height;