Fixed resizing spinners

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3729 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria
2009-07-11 15:34:30 +00:00
parent 71a2083819
commit e088c97939
3 changed files with 66 additions and 21 deletions

View File

@@ -206,26 +206,22 @@ namespace StateManager
setSize(x, y, w, h);
playerID->getIrrlichtElement()->setRelativePosition(core::rect< s32 >
(player_id_x,
player_id_y,
player_id_x + player_id_w,
player_id_y + player_id_h) );
playerName->getIrrlichtElement()->setRelativePosition(core::rect< s32 >
(player_name_x,
player_name_y,
player_name_x + player_name_w,
player_name_y + player_name_h) );
modelView->getIrrlichtElement()->setRelativePosition(core::rect< s32 >
(model_x,
model_y,
model_x + model_w,
model_y + model_h) );
kartName->getIrrlichtElement()->setRelativePosition(core::rect< s32 >
(kart_name_x,
kart_name_y,
kart_name_x + kart_name_w,
kart_name_y + kart_name_h) );
playerID->move(player_id_x,
player_id_y,
player_id_w,
player_id_h);
playerName->move(player_name_x,
player_name_y,
player_name_w,
player_name_h );
modelView->move(model_x,
model_y,
model_w,
model_h);
kartName->move(kart_name_x,
kart_name_y,
kart_name_w,
kart_name_h);
}

View File

@@ -107,6 +107,16 @@ bool Widget::convertToCoord(std::string& x, int* absolute /* out */, int* percen
return true;
}
}
void Widget::move(const int x, const int y, const int w, const int h)
{
this->x = x;
this->y = y;
this->w = w;
this->h = h;
m_element->setRelativePosition( core::rect < s32 > (x, y, x+w, y+h) );
}
// -----------------------------------------------------------------------------
/**
* Finds its x, y, w and h coords from what is specified in the XML properties.
@@ -838,6 +848,38 @@ void SpinnerWidget::add()
m_children[2].m_properties[PROP_ID] = "right";
m_children[2].id = m_children[2].m_element->getID();
}
void SpinnerWidget::move(const int x, const int y, const int w, const int h)
{
Widget::move(x, y, w, h);
rect<s32> subsize_left_arrow = rect<s32>(0 ,0, h, h);
m_children[0].m_element->setRelativePosition(subsize_left_arrow);
if(m_graphical)
{
// FIXME : code duplicated from add()
std::ostringstream icon_stream;
icon_stream << file_manager->getDataDir() << "/" << m_properties[PROP_ICON];
std::string imagefile = StringUtils::insert_values(icon_stream.str(), m_value);
ITexture* texture = irr_driver->getTexture(imagefile);
assert(texture != NULL);
const int texture_width = texture->getSize().Width;
const int free_h_space = w-h*2-texture_width; // to center image
rect<s32> subsize_label = rect<s32>(h+free_h_space/2, 0, w-h+free_h_space/2, h);
m_children[1].m_element->setRelativePosition(subsize_label);
}
else
{
rect<s32> subsize_label = rect<s32>(h, 0, w-h, h);
m_children[1].m_element->setRelativePosition(subsize_label);
}
rect<s32> subsize_right_arrow = rect<s32>(w-h, 0, w, h);
m_children[2].m_element->setRelativePosition(subsize_right_arrow);
}
// -----------------------------------------------------------------------------
bool SpinnerWidget::rightPressed()
{

View File

@@ -178,6 +178,12 @@ namespace GUIEngine
static void resetIDCounters();
/**
* Call to resize/move the widget. Not all widgets can resize gracefully.
*/
virtual void move(const int x, const int y, const int w, const int h);
bool isSelected() const { return m_selected; }
};
@@ -230,7 +236,8 @@ namespace GUIEngine
SpinnerWidget(const bool gauge=false);
virtual ~SpinnerWidget() {}
virtual void move(const int x, const int y, const int w, const int h);
void setValue(const int new_value);
void addLabel(std::string label);
void add();