Allow labels to resize up on setText

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@8093 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria
2011-03-27 23:07:23 +00:00
parent f84d425878
commit aba8b2df34
13 changed files with 45 additions and 32 deletions

View File

@@ -116,22 +116,34 @@ void LabelWidget::add()
// ----------------------------------------------------------------------------
/** Sets the text. This is the function used by overloaded functions
* as well. It takes esp. care of horizontal scrolling by adding
* spaces to the left and right of the string, so that it appears
* that the text is appearing from the left and going to the right.
* Then a character is removed on the left, resulting in the text
* appearing to scroll from the left.
* as well.
* It is important that the scrolling speed (if any) is set before
* calling this function!
* \param text The string to use as text for this widget.
*/
void LabelWidget::setText(const wchar_t *text)
void LabelWidget::setText(const wchar_t *text, bool expandIfNeeded)
{
m_scroll_offset = 0;
if (expandIfNeeded)
{
const int fwidth = (m_title_font ? GUIEngine::getTitleFont() : GUIEngine::getFont())->getDimension(text).Width;
core::rect<s32> rect = m_element->getRelativePosition();
if (rect.getWidth() < fwidth)
{
rect.LowerRightCorner.X = rect.UpperLeftCorner.X + fwidth;
m_element->setRelativePosition(rect);
m_element->updateAbsolutePosition();
//((IGUIStaticText*)m_element)->setBackgroundColor( video::SColor(255,255,0,0) );
}
}
if (m_scroll_speed > 0)
{
m_scroll_offset = (float)m_element->getAbsolutePosition().getWidth();
//m_scroll_offset = (float)m_element->getAbsolutePosition().getWidth();
m_scroll_offset = m_w;
}
Widget::setText(text);

View File

@@ -54,14 +54,14 @@ namespace GUIEngine
} // setColor
virtual void setText(const wchar_t *text);
virtual void setText(const wchar_t *text, bool expandAsNeeded);
virtual void update(float dt);
// --------------------------------------------------------------------
/** Overloaded function which takes a stringw. */
virtual void setText(const irr::core::stringw &s)
virtual void setText(const irr::core::stringw &s, bool expandAsNeeded)
{
setText(s.c_str());
setText(s.c_str(), expandAsNeeded);
}
// --------------------------------------------------------------------

View File

@@ -71,7 +71,7 @@ void AddonsScreen::init()
w_list->setIcons(m_icon_bank);
getWidget<GUIEngine::LabelWidget>("update_status")
->setText(_("Updating the list..."));
->setText(_("Updating the list..."), false);
m_type = "kart";
loadList();
} // init
@@ -105,7 +105,7 @@ void AddonsScreen::loadList()
}
getWidget<GUIEngine::RibbonWidget>("category")->setActivated();
getWidget<GUIEngine::LabelWidget>("update_status")->setText("");
getWidget<GUIEngine::LabelWidget>("update_status")->setText("", false);
if(m_type == "kart")
getWidget<GUIEngine::RibbonWidget>("category")->select("tab_kart",
PLAYER_ID_GAME_MASTER);

View File

@@ -63,13 +63,13 @@ AddonsLoading::AddonsLoading(const float w, const float h,
}
core::stringw name = _("Name: %i", m_addon.getName().c_str() );
getWidget<LabelWidget>("name")->setText(name);
getWidget<LabelWidget>("name")->setText(name, false);
core::stringw desc = _("Description: %i", m_addon.getDescription().c_str());
getWidget<LabelWidget>("description")->setText(desc);
getWidget<LabelWidget>("description")->setText(desc, false);
core::stringw version = _("Version: %d", m_addon.getVersion());
getWidget<LabelWidget>("version")->setText(version);
getWidget<LabelWidget>("version")->setText(version, false);
} // AddonsLoading
@@ -115,7 +115,7 @@ void AddonsLoading::onUpdate(float delta)
m_progress->setValue((int)(progress*100.0f));
if(progress<0)
{
m_state->setText(_("Download failed.\n"));
m_state->setText(_("Download failed.\n"), false);
m_back_button->setText(_("Back"));
return;
}
@@ -165,7 +165,7 @@ void AddonsLoading::doInstall()
core::stringw msg = StringUtils::insertValues(
_("Problems installing the addon '%s'."),
core::stringw(m_addon.getName().c_str()));
m_state->setText(msg.c_str());
m_state->setText(msg.c_str(), false);
}
}
else
@@ -176,7 +176,7 @@ void AddonsLoading::doInstall()
core::stringw msg = StringUtils::insertValues(
_("Problems removing the addon '%s'."),
core::stringw(m_addon.getName().c_str()));
m_state->setText(msg.c_str());
m_state->setText(msg.c_str(), false);
}
}

View File

@@ -73,7 +73,7 @@ void ConfirmResolutionDialog::updateMessage()
//std::cout << stringc(msg.c_str()).c_str() << std::endl;
LabelWidget* countdown_message = getWidget<LabelWidget>("title");
countdown_message->setText( msg.c_str() );
countdown_message->setText( msg.c_str(), false );
}
// ------------------------------------------------------------------------------------------------------

View File

@@ -100,7 +100,7 @@ void EnterPlayerNameDialog::onEnterPressedInternal()
if (!success)
{
LabelWidget* label = getWidget<LabelWidget>("title");
label->setText(_("Cannot add a player with this name."));
label->setText(_("Cannot add a player with this name."), false);
sfx_manager->quickSound( "use_anvil" );
return;
}
@@ -115,7 +115,7 @@ void EnterPlayerNameDialog::onEnterPressedInternal()
else
{
LabelWidget* label = getWidget<LabelWidget>("title");
label->setText(_("Cannot add a player with this name."));
label->setText(_("Cannot add a player with this name."), false);
sfx_manager->quickSound( "use_anvil" );
}
}

View File

@@ -97,7 +97,7 @@ GPInfoDialog::GPInfoDialog(const std::string& gpIdent, const float w, const floa
}
LabelWidget* widget = new LabelWidget();
widget->setText(translations->fribidize(lineText));
widget->setText(translations->fribidize(lineText), false);
widget->m_x = 20;
widget->m_y = from_y;
widget->m_w = m_area.getWidth()/2 - 20;

View File

@@ -35,7 +35,7 @@ MessageDialog::MessageDialog(irr::core::stringw msg, IConfirmDialogListener* lis
m_listener = listener;
LabelWidget* message = getWidget<LabelWidget>("title");
message->setText( msg.c_str() );
message->setText( msg.c_str(), false );
}
// ------------------------------------------------------------------------------------------------------
@@ -48,7 +48,7 @@ MessageDialog::MessageDialog(irr::core::stringw msg) :
m_listener = NULL;
LabelWidget* message = getWidget<LabelWidget>("title");
message->setText( msg.c_str() );
message->setText( msg.c_str(), false );
ButtonWidget* yesbtn = getWidget<ButtonWidget>("confirm");
yesbtn->setVisible(false);

View File

@@ -335,7 +335,7 @@ RaceOverDialog::RaceOverDialog(const float percentWidth,
unlocked_label->m_y = label_y;
unlocked_label->m_w = m_area.getWidth() - button_h*2 - 60;
unlocked_label->m_h = button_h;
unlocked_label->setText( _("You unlocked a new feature!") );
unlocked_label->setText( _("You unlocked a new feature!"), false );
unlocked_label->setParent(m_irrlicht_window);
m_widgets.push_back(unlocked_label);
unlocked_label->add();

View File

@@ -150,7 +150,7 @@ void GrandPrixWin::init()
unlocked_label->m_y = y_from;
unlocked_label->m_w = message_width;
unlocked_label->m_h = label_height;
unlocked_label->setText(message);
unlocked_label->setText(message, false);
//const irr::video::SColor orange(255, 255, 126, 21);
//unlocked_label->setColor(orange);

View File

@@ -341,7 +341,7 @@ public:
// ---- Kart name label
m_kart_name = new LabelWidget();
m_kart_name->setText(props->getName());
m_kart_name->setText(props->getName(), false);
m_kart_name->m_properties[PROP_TEXT_ALIGN] = "center";
m_kart_name->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_kartname", m_playerID);
m_kart_name->m_x = kart_name_x;
@@ -784,7 +784,7 @@ public:
w3->clearModels();
w3->addModel( model, Vec3(0.0f, -12.0f, 0.0f), Vec3(35.0f, 35.0f, 35.0f) );
w3->update(0);
m_parent->m_kart_widgets[playerID].m_kart_name->setText( _("Random Kart") );
m_parent->m_kart_widgets[playerID].m_kart_name->setText( _("Random Kart"), false );
}
else if (selectionID == ID_LOCKED)
{
@@ -793,7 +793,8 @@ public:
Vec3(0,0,0), Vec3(15.0f, 15.0f, 15.0f) );
w3->update(0);
m_parent->m_kart_widgets[playerID].m_kart_name->setText( _("Locked : solve active challenges to gain access to more!") );
m_parent->m_kart_widgets[playerID].m_kart_name->setText(
_("Locked : solve active challenges to gain access to more!"), false );
}
else
{
@@ -816,7 +817,7 @@ public:
kart_model.getWheelGraphicsPosition(3) );
w3->update(0);
m_parent->m_kart_widgets[playerID].m_kart_name->setText( selectionText.c_str() );
m_parent->m_kart_widgets[playerID].m_kart_name->setText( selectionText.c_str(), false );
}
else
{

View File

@@ -129,7 +129,7 @@ void MainMenuScreen::onUpdate(float delta, irr::video::IVideoDriver* driver)
if(w->scrolledOff())
{
const core::stringw &news_text = network_http->getNextNewsMessage();
w->setText(news_text);
w->setText(news_text, true);
}
IconButtonWidget* lang_combo = this->getWidget<IconButtonWidget>("lang_combo");

View File

@@ -112,7 +112,7 @@ void OptionsScreenInput2::init()
deleteBtn->moveIrrlichtElement();
LabelWidget* label = this->getWidget<LabelWidget>("title");
label->setText( m_config->getName().c_str() );
label->setText( m_config->getName().c_str(), false );
GUIEngine::ListWidget* actions = this->getWidget<GUIEngine::ListWidget>("actions");
assert( actions != NULL );