Improved buttons to have their size depend on text contents; made the 'enter' key trigger a PA_FIRE action

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@4388 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2010-01-02 20:55:19 +00:00
parent e8e8b1c876
commit 2dd0a904b6
8 changed files with 45 additions and 11 deletions

View File

@ -62,7 +62,7 @@
<spacer height="10" width="10"/>
<button id="apply_resolution" width="40%" height="30"
<button id="apply_resolution" height="35"
I18N="In the video settings menu" text="Apply video changes" />
</box>

View File

@ -27,7 +27,7 @@
<list id="players" proportion="5" width="75%" align="center"/>
<spacer width="20" height="25"/>
<button id="addplayer" x="20" width="35%" height="30"
<button id="addplayer" x="20" height="35"
I18N="In players configuration menu"
text="Add Player" align="center"/>
<!--

View File

@ -314,10 +314,10 @@ void Widget::readCoords(Widget* parent)
{
IGUIFont* font = (m_title_font ? GUIEngine::getTitleFont() : GUIEngine::getFont());
core::dimension2d< u32 > dim = font->getDimension( m_text.c_str() );
label_w = dim.Width;
label_w = dim.Width + getWidthNeededAroundLabel();
// FIXME - won't work with multiline labels. thus, for now, when multiple
// lines are required, we need to specify a height explicitely
label_h = dim.Height;
label_h = dim.Height + getHeightNeededAroundLabel();
}
// ---- read dimension

View File

@ -174,6 +174,14 @@ namespace GUIEngine
bool m_reserve_id;
/** When inferring widget size from its label length, this method will be called to
* if/how much space must be added to the raw label's size for the widget to be large enough */
virtual int getWidthNeededAroundLabel() const { return 0; }
/** When inferring widget size from its label length, this method will be called to
* if/how much space must be added to the raw label's size for the widget to be large enough */
virtual int getHeightNeededAroundLabel() const { return 0; }
public:
/**
* This is set to NULL by default; set to something else in a widget to mean

View File

@ -30,6 +30,14 @@ namespace GUIEngine
/** A text button widget. See guiengine/engine.hpp for a detailed overview */
class ButtonWidget : public Widget
{
/** When inferring widget size from its label length, this method will be called to
* if/how much space must be added to the raw label's size for the widget to be large enough */
virtual int getWidthNeededAroundLabel() const { return 35; }
/** When inferring widget size from its label length, this method will be called to
* if/how much space must be added to the raw label's size for the widget to be large enough */
virtual int getHeightNeededAroundLabel() const { return 16; }
public:
ButtonWidget();
virtual ~ButtonWidget() {}

View File

@ -38,6 +38,15 @@ namespace GUIEngine
EventPropagation transmitEvent(Widget* w, std::string& originator, const int playerID);
EventPropagation rightPressed(const int playerID);
EventPropagation leftPressed(const int playerID);
/** When inferring widget size from its label length, this method will be called to
* if/how much space must be added to the raw label's size for the widget to be large enough */
virtual int getWidthNeededAroundLabel() const { return 25; }
/** When inferring widget size from its label length, this method will be called to
* if/how much space must be added to the raw label's size for the widget to be large enough */
virtual int getHeightNeededAroundLabel() const { return 16; }
public:
SpinnerWidget(const bool gauge=false);

View File

@ -30,6 +30,14 @@ namespace GUIEngine
/** A text field widget. See guiengine/engine.hpp for a detailed overview */
class TextBoxWidget : public Widget
{
/** When inferring widget size from its label length, this method will be called to
* if/how much space must be added to the raw label's size for the widget to be large enough */
virtual int getWidthNeededAroundLabel() const { return 10; }
/** When inferring widget size from its label length, this method will be called to
* if/how much space must be added to the raw label's size for the widget to be large enough */
virtual int getHeightNeededAroundLabel() const { return 10; }
public:
TextBoxWidget();
~TextBoxWidget()

View File

@ -264,7 +264,7 @@ void InputManager::dispatchInput(Input::InputType type, int deviceID, int btnID,
bool action_found = m_device_manager->translateInput( type, deviceID, btnID, axisDirection, value, &player, &action);
// in menus, some keyboard keys are standard (before each player selected his device)
// FIXME: should enter always work to accept for a player using keyboard?
// So if a key could not be mapped to any known binding, fall back to check the defaults.
if (!action_found && StateManager::get()->getGameState() != GUIEngine::GAME && type == Input::IT_KEYBOARD &&
m_mode == MENU && m_device_manager->getAssignMode() == NO_ASSIGN)
{
@ -275,6 +275,7 @@ void InputManager::dispatchInput(Input::InputType type, int deviceID, int btnID,
else if (btnID == KEY_LEFT) action = PA_LEFT;
else if (btnID == KEY_RIGHT) action = PA_RIGHT;
else if (btnID == KEY_SPACE) action = PA_FIRE;
else if (btnID == KEY_RETURN) action = PA_FIRE;
if (btnID == KEY_RETURN && GUIEngine::ModalDialog::isADialogActive())
{