From 7395d5307b57e25fe1976f874f087f1c26974d88 Mon Sep 17 00:00:00 2001 From: auria Date: Fri, 2 Sep 2011 00:31:22 +0000 Subject: [PATCH] Improved handling of long add-on names git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@9707 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/guiengine/scalable_font.cpp | 9 +++-- src/states_screens/addons_screen.cpp | 59 +++++++++++++++++++++++----- src/states_screens/addons_screen.hpp | 1 + 3 files changed, 55 insertions(+), 14 deletions(-) diff --git a/src/guiengine/scalable_font.cpp b/src/guiengine/scalable_font.cpp index 592dadc68..5ec142b62 100644 --- a/src/guiengine/scalable_font.cpp +++ b/src/guiengine/scalable_font.cpp @@ -737,10 +737,11 @@ s32 ScalableFont::getCharacterFromPos(const wchar_t* text, s32 pixel_x) const while (text[idx]) { - const SFontArea& a = Areas[getAreaIDFromCharacter(text[idx], NULL)]; - - x += a.width + a.overhang + a.underhang + GlobalKerningWidth; - + bool use_fallback_font = false; + const SFontArea &a = getAreaFromCharacter(text[idx], &use_fallback_font); + + x += getCharWidth(a, use_fallback_font) + a.overhang + a.underhang + GlobalKerningWidth; + if (x >= pixel_x) return idx; diff --git a/src/states_screens/addons_screen.cpp b/src/states_screens/addons_screen.cpp index efbe15943..a08d04726 100644 --- a/src/states_screens/addons_screen.cpp +++ b/src/states_screens/addons_screen.cpp @@ -93,9 +93,9 @@ void AddonsScreen::init() GUIEngine::ListWidget* w_list = getWidget("list_addons"); - float wanted_icon_height = getHeight()/8.0f; - m_icon_bank->setScale(wanted_icon_height/128.0f); - w_list->setIcons(m_icon_bank, (int)(wanted_icon_height)); + m_icon_height = getHeight()/8.0f; + m_icon_bank->setScale(m_icon_height/128.0f); // 128 is the height of the image file + w_list->setIcons(m_icon_bank, (int)(m_icon_height)); m_type = "kart"; @@ -163,20 +163,59 @@ void AddonsScreen::loadList() gui::IGUIFont* font = GUIEngine::getFont(); - // first column if 0.666% of the list's width - if (font->getDimension(s.c_str()).Width > w_list->m_w*0.6666f) + // first column is 0.666% of the list's width. and icon width == icon height. + const unsigned int available_width = w_list->m_w*0.6666f - m_icon_height; + if (font->getDimension(s.c_str()).Width > available_width) { s = s.subString(0, int(AddonsScreen::getWidth()*0.018)+20); s.append("..."); } else { - //I18N: as in: The Old Island by Johannes Sjolund - s = _("%s by %s",addon->getName().c_str(),addon->getDesigner().c_str()); - if (font->getDimension(s.c_str()).Width > w_list->m_w*0.6666f) + if (addon->getDesigner().size() == 0) { - s = s.subString(0, int(AddonsScreen::getWidth()*0.018)+20); - s.append("..."); + s = addon->getName(); + } + else + { + //I18N: as in: The Old Island by Johannes Sjolund + s = _("%s by %s",addon->getName().c_str(),addon->getDesigner().c_str()); + } + + // check if text is too long to fit + if (font->getDimension(s.c_str()).Width > available_width) + { + // start by splitting on 2 lines + + //I18N: as in: The Old Island by Johannes Sjolund + s = _("%s\nby %s",addon->getName().c_str(),addon->getDesigner().c_str()); + + core::stringw final_string; + + // then check if each line is now short enough. + std::vector lines = StringUtils::split(s, '\n'); + for (unsigned int n=0; ngetDimension(lines[n].c_str()).Width > available_width) + { + // arg, still too long! cut the text so that it fits. + core::stringw line = lines[n]; + + // leave a margin of 14 pixels to account for the "..." that will be appended + int split_at = font->getCharacterFromPos(line.c_str(), available_width - 14); + line = line.subString(0, split_at); + line.append("..."); + if (final_string.size() > 0) final_string.append("\n"); + final_string.append(line); + } + else + { + if (final_string.size() > 0) final_string.append("\n"); + final_string.append(lines[n]); + } + } + + s = final_string; } s.append("\t"); s.append(addon->getDateAsString().c_str()); diff --git a/src/states_screens/addons_screen.hpp b/src/states_screens/addons_screen.hpp index 289b32327..05b9892d3 100644 --- a/src/states_screens/addons_screen.hpp +++ b/src/states_screens/addons_screen.hpp @@ -62,6 +62,7 @@ private: * addons_loading is being displayed. */ int m_selected_index; + float m_icon_height; public: /** Load the addons into the main list.*/