Added basic skinning to spinners

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3375 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2009-04-11 16:43:24 +00:00
parent b8033334d6
commit 0197d081d5
6 changed files with 37 additions and 24 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 26 KiB

View File

@ -4,7 +4,7 @@
<label width="100%" height="25" text="(P1) Keyboard 1" align="center" text_align="center" /> <label width="100%" height="25" text="(P1) Keyboard 1" align="center" text_align="center" />
<spinner id="player" width="40%" height="25" min_value="0" max_value="8" align="center"/> <spinner id="player" width="40%" height="40" min_value="0" max_value="8" align="center"/>
<model id="modelview" width="40%" proportion="3" align="center"/> <model id="modelview" width="40%" proportion="3" align="center"/>
<label width="100%" height="25" text="Wilber" align="center" text_align="center" /> <label width="100%" height="25" text="Wilber" align="center" text_align="center" />

View File

@ -47,7 +47,8 @@ void Skin::draw2DRectangle (IGUIElement *element, const video::SColor &color, co
void Skin::drawBoxFromStretchableTexture(const core::rect< s32 > &dest, ITexture* source, void Skin::drawBoxFromStretchableTexture(const core::rect< s32 > &dest, ITexture* source,
const int left_border, const int right_border, const int left_border, const int right_border,
const int top_border, const int bottom_border) const int top_border, const int bottom_border,
const float border_out_portion)
{ {
// FIXME? - lots of things here will be re-calculated every frame, which is useless since // FIXME? - lots of things here will be re-calculated every frame, which is useless since
// widgets won't move, so they'd only need to be calculated once. // widgets won't move, so they'd only need to be calculated once.
@ -91,8 +92,9 @@ void Skin::drawBoxFromStretchableTexture(const core::rect< s32 > &dest, ITexture
core::rect<s32> source_area_bottom_right = core::rect<s32>(dx, dy, texture_w, texture_h); core::rect<s32> source_area_bottom_right = core::rect<s32>(dx, dy, texture_w, texture_h);
/* /*
The dest area is split this way. Borders will go a bit beyond the The dest area is split this way. Borders can go a bit beyond the given area so
given area so components inside don't go over the borders (by half their size) components inside don't go over the borders
(how much it exceeds horizontally is specified in 'border_out_portion'. vertically is always the totality)
a----b--------------------c----+ a----b--------------------c----+
| | | | | | | |
@ -111,22 +113,24 @@ void Skin::drawBoxFromStretchableTexture(const core::rect< s32 > &dest, ITexture
const int dest_y2 = dest.LowerRightCorner.Y; const int dest_y2 = dest.LowerRightCorner.Y;
const float scale = (float)(dest_y2-dest_y)/texture_h; const float scale = (float)(dest_y2-dest_y)/texture_h;
const int dest_left_border_half = left_border*scale*0.5f; const int dest_left_border = left_border*scale;
const int dest_right_border_half = right_border*scale*0.5f; const int dest_right_border = right_border*scale;
const int dest_top_border_half = top_border*scale*0.5f; const int dest_top_border = top_border*scale;
const int dest_bottom_border_half = bottom_border*scale*0.5f; const int dest_bottom_border = bottom_border*scale;
const int ax = dest_x - dest_left_border_half; const float border_in_portion = 1 - border_out_portion;
const int ay = dest_y - dest_top_border_half;
const int bx = dest_x + dest_left_border_half; const int ax = dest_x - dest_left_border*border_out_portion;
const int ay = dest_y - dest_top_border;
const int bx = dest_x + dest_left_border*border_in_portion;
const int by = ay; const int by = ay;
const int cx = dest_x2 - dest_right_border_half; const int cx = dest_x2 - dest_right_border*border_in_portion;
const int cy = ay; const int cy = ay;
const int dx = ax; const int dx = ax;
const int dy = dest_y + dest_top_border_half; const int dy = dest_y;
const int ex = bx; const int ex = bx;
const int ey = dy; const int ey = dy;
@ -134,11 +138,11 @@ void Skin::drawBoxFromStretchableTexture(const core::rect< s32 > &dest, ITexture
const int fx = cx; const int fx = cx;
const int fy = dy; const int fy = dy;
const int gx = dest_x2 + dest_right_border_half; const int gx = dest_x2 + dest_right_border*border_out_portion;
const int gy = dy; const int gy = dy;
const int hx = ax; const int hx = ax;
const int hy = dest_y2 - dest_bottom_border_half; const int hy = dest_y2;
const int ix = bx; const int ix = bx;
const int iy = hy; const int iy = hy;
@ -150,7 +154,7 @@ void Skin::drawBoxFromStretchableTexture(const core::rect< s32 > &dest, ITexture
const int ky = hy; const int ky = hy;
const int lx = bx; const int lx = bx;
const int ly = dest_y2 + dest_bottom_border_half; const int ly = dest_y2 + dest_bottom_border;
const int mx = cx; const int mx = cx;
const int my = ly; const int my = ly;
@ -268,20 +272,33 @@ void Skin::drawRibbonChild(const core::rect< s32 > &rect, const Widget* widget,
void Skin::drawSpinnerBody(const core::rect< s32 > &rect, const Widget* widget, const bool pressed, const bool focused) void Skin::drawSpinnerBody(const core::rect< s32 > &rect, const Widget* widget, const bool pressed, const bool focused)
{ {
// FIXME - move these numbers to a config file
const int left_border = 110;
const int right_border = 110;
const int border_above = 0;
const int border_below = 36;
drawBoxFromStretchableTexture(rect, (focused || pressed ? m_tex_fspinner : m_tex_spinner),
left_border, right_border,
border_above, border_below, 0);
/*
if(focused) if(focused)
GUIEngine::getDriver()->draw2DRectangle( SColor(255, 255, 0, 0), rect ); GUIEngine::getDriver()->draw2DRectangle( SColor(255, 255, 0, 0), rect );
else else
GUIEngine::getDriver()->draw2DRectangle( SColor(255, 150, 0, 0), rect ); GUIEngine::getDriver()->draw2DRectangle( SColor(255, 150, 0, 0), rect );
*/
} }
void Skin::drawSpinnerChild(const core::rect< s32 > &rect, const Widget* widget, const bool pressed, bool focused) void Skin::drawSpinnerChild(const core::rect< s32 > &rect, const Widget* widget, const bool pressed, bool focused)
{ {
/*
if(pressed) if(pressed)
GUIEngine::getDriver()->draw2DRectangle( SColor(255, 255, 0, 0), rect ); GUIEngine::getDriver()->draw2DRectangle( SColor(255, 255, 0, 0), rect );
else if(focused) else if(focused)
GUIEngine::getDriver()->draw2DRectangle( SColor(255, 150, 0, 0), rect ); GUIEngine::getDriver()->draw2DRectangle( SColor(255, 150, 0, 0), rect );
else else
GUIEngine::getDriver()->draw2DRectangle( SColor(255, 0, 150, 0), rect ); GUIEngine::getDriver()->draw2DRectangle( SColor(255, 0, 150, 0), rect );
*/
} }
void Skin::process3DPane(IGUIElement *element, const core::rect< s32 > &rect, const bool pressed) void Skin::process3DPane(IGUIElement *element, const core::rect< s32 > &rect, const bool pressed)

View File

@ -29,7 +29,8 @@ class Skin : public IGUISkin
void drawBoxFromStretchableTexture(const core::rect< s32 > &dest, ITexture* source, void drawBoxFromStretchableTexture(const core::rect< s32 > &dest, ITexture* source,
const int left_border, const int right_border, const int left_border, const int right_border,
const int top_border, const int bottom_border); const int top_border, const int bottom_border,
const float border_out_portion = 0.5);
public: public:
Skin(IGUISkin* fallback_skin); Skin(IGUISkin* fallback_skin);

View File

@ -115,11 +115,6 @@ void Widget::readCoords(Widget* parent)
int abs_y = -1, percent_y = -1; int abs_y = -1, percent_y = -1;
if(convertToCoord(y, &abs_y, &percent_y )) if(convertToCoord(y, &abs_y, &percent_y ))
{ {
if(abs_y < -1)
{
std::cout << "abs_y = " << abs_y << ", y=" << (parent_y + (parent_h - abs_y)) << std::endl;
}
if(abs_y > -1) this->y = parent_y + abs_y; if(abs_y > -1) this->y = parent_y + abs_y;
else if(abs_y < -1) this->y = parent_y + (parent_h + abs_y); else if(abs_y < -1) this->y = parent_y + (parent_h + abs_y);
else if(percent_y > -1) this->y = parent_y + parent_h*percent_y/100; else if(percent_y > -1) this->y = parent_y + parent_h*percent_y/100;
@ -617,7 +612,7 @@ void SpinnerWidget::add()
// left arrow // left arrow
rect<s32> subsize_left_arrow = rect<s32>(0 ,0, h, h); rect<s32> subsize_left_arrow = rect<s32>(0 ,0, h, h);
IGUIButton * left_arrow = GUIEngine::getGUIEnv()->addButton(subsize_left_arrow, btn, ++id_counter_2, L"<<"); IGUIButton * left_arrow = GUIEngine::getGUIEnv()->addButton(subsize_left_arrow, btn, ++id_counter_2, L" ");
m_children[0].m_element = left_arrow; m_children[0].m_element = left_arrow;
m_children[0].m_type = WTYPE_BUTTON; m_children[0].m_type = WTYPE_BUTTON;
left_arrow->setTabStop(false); left_arrow->setTabStop(false);
@ -659,7 +654,7 @@ void SpinnerWidget::add()
// right arrow // right arrow
rect<s32> subsize_right_arrow = rect<s32>(w-h, 0, w, h); rect<s32> subsize_right_arrow = rect<s32>(w-h, 0, w, h);
IGUIButton * right_arrow = GUIEngine::getGUIEnv()->addButton(subsize_right_arrow, btn, ++id_counter_2, L">>"); IGUIButton * right_arrow = GUIEngine::getGUIEnv()->addButton(subsize_right_arrow, btn, ++id_counter_2, L" ");
right_arrow->setTabStop(false); right_arrow->setTabStop(false);
m_children[2].m_element = right_arrow; m_children[2].m_element = right_arrow;
m_children[2].m_type = WTYPE_BUTTON; m_children[2].m_type = WTYPE_BUTTON;