skinned gauges. default value is now read from audio managers - it just doesn't work for music yet because no default value is set for music volume in preferences.

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3391 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2009-04-16 01:29:06 +00:00
parent 5ddb03e272
commit 35d046ee42
8 changed files with 106 additions and 36 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 891 B

View File

@ -81,7 +81,10 @@ public:
void deleteSFX(SFXBase *sfx);
void pauseAll();
void resumeAll();
void setMasterSFXVolume(float gain);
float getMasterSFXVolume() const { return m_masterGain; }
static bool checkError(const std::string &context);
static const std::string getErrorString(int err);
};

View File

@ -63,7 +63,10 @@ public:
m_current_music->resumeMusic(); }
void switchToFastMusic() {if(m_current_music)
m_current_music->switchToFastMusic();}
void setMasterMusicVolume(float gain);
int getMasterMusicVolume() const { return m_masterGain; }
MusicInformation *getCurrentMusic() {return m_current_music; }
MusicInformation *getMusicInformation(const std::string& filename);
void loadMusicFromOneDir(const std::string& dir);

View File

@ -30,6 +30,8 @@ Skin::Skin(IGUISkin* fallback_skin)
m_tex_ficonhighlight = GUIEngine::getDriver()->getTexture( (file_manager->getGUIDir() + "/glass_iconhighlight_focus.png").c_str() );
m_tex_squarefocus = GUIEngine::getDriver()->getTexture( (file_manager->getGUIDir() + "/glass_square_focused.png").c_str() );
m_tex_gaugefill = GUIEngine::getDriver()->getTexture( (file_manager->getGUIDir() + "/glasssgauge_fill.png").c_str() );
}
Skin::~Skin()
@ -37,19 +39,6 @@ Skin::~Skin()
m_fallback_skin->drop();
}
/*
driver->draw2DImage(texture,
core::rect<s32>(img_x1, img_y1, img_x2, img_y2),
core::rect<s32>(0,0,texture_size.Width, texture_size.Height) );
*/
void Skin::draw2DRectangle (IGUIElement *element, const video::SColor &color, const core::rect< s32 > &pos, const core::rect< s32 > *clip)
{
// scrollbar backgound
//printf("draw rectangle\n");
GUIEngine::getDriver()->draw2DRectangle( SColor(255, 0, 150, 150), pos );
}
void Skin::drawBoxFromStretchableTexture(const core::rect< s32 > &dest, ITexture* source,
const int left_border, const int right_border,
@ -455,6 +444,64 @@ void Skin::drawSpinnerChild(const core::rect< s32 > &rect, Widget* widget, const
}
void Skin::drawGauge(const core::rect< s32 > &rect, Widget* widget, 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 ? m_tex_fspinner : m_tex_spinner),
left_border, right_border,
border_above, border_below, 0);
}
void Skin::drawGaugeFill(const core::rect< s32 > &rect, Widget* widget, bool focused)
{
GaugeWidget* w = dynamic_cast<GaugeWidget*>(widget);
// the width of an handle is about 0.844 the height in the current skin. FIXME - don't hardcode.
const int handle_size = widget->h*0.844;
// the 'rect' argument will be too small, because irrlicht has no suitable gauge component, so i used a scrollbar
const core::rect< s32 > dest_area = core::rect< s32 >(widget->x+handle_size, widget->y,
widget->x + handle_size + (widget->w - 2*handle_size)*w->getValue(),
widget->y + widget->h);
const int texture_w = m_tex_gaugefill->getSize().Width;
const int texture_h = m_tex_gaugefill->getSize().Height;
const core::rect< s32 > source_area = core::rect< s32 >(0, 0, texture_w, texture_h);
GUIEngine::getDriver()->draw2DImage(m_tex_gaugefill, dest_area, source_area,
0 /* no clipping */, 0, true /* alpha */);
}
#if 0
#pragma mark -
#pragma mark irrlicht skin functions
#endif
void Skin::draw2DRectangle (IGUIElement *element, const video::SColor &color, const core::rect< s32 > &rect, const core::rect< s32 > *clip)
{
const bool focused = GUIEngine::getGUIEnv()->hasFocus(element);
const int id = element->getID();
Widget* widget = GUIEngine::getCurrentScreen()->getWidget(id);
if(widget == NULL) return;
const WidgetType type = widget->m_type;
if(type == WTYPE_GAUGE)
{
drawGauge(rect, widget, focused);
}
//printf("draw rectangle\n");
// GUIEngine::getDriver()->draw2DRectangle( SColor(255, 0, 150, 150), pos );
}
void Skin::process3DPane(IGUIElement *element, const core::rect< s32 > &rect, const bool pressed)
{
const bool focused = GUIEngine::getGUIEnv()->hasFocus(element);
@ -496,8 +543,11 @@ void Skin::process3DPane(IGUIElement *element, const core::rect< s32 > &rect, co
else if(type == WTYPE_SPINNER)
{
drawSpinnerBody(rect, widget, pressed, focused);
}
}
else if(type == WTYPE_GAUGE)
{
drawGaugeFill(rect, widget, focused);
}
}
void Skin::draw3DButtonPanePressed (IGUIElement *element, const core::rect< s32 > &rect, const core::rect< s32 > *clip)
@ -539,7 +589,6 @@ void Skin::draw3DTabButton (IGUIElement *element, bool active, const core::rect<
void Skin::draw3DToolBar (IGUIElement *element, const core::rect< s32 > &rect, const core::rect< s32 > *clip)
{
//printf("draw toolbar\n");
}
core::rect< s32 > Skin::draw3DWindowBackground (IGUIElement *element, bool drawTitleBar, video::SColor titleBarColor, const core::rect< s32 > &rect, const core::rect< s32 > *clip)
@ -550,13 +599,11 @@ core::rect< s32 > Skin::draw3DWindowBackground (IGUIElement *element, bool drawT
void Skin::drawIcon (IGUIElement *element, EGUI_DEFAULT_ICON icon, const core::position2di position, u32 starttime, u32 currenttime, bool loop, const core::rect< s32 > *clip)
{
//printf("draw icon\n");
m_fallback_skin->drawIcon(element, icon, position, starttime, currenttime, loop, clip);
/* m_fallback_skin->drawIcon(element, icon, position, starttime, currenttime, loop, clip); */
}
video::SColor Skin::getColor (EGUI_DEFAULT_COLOR color) const
{
//printf("getting color\n");
/*
EGDC_3D_DARK_SHADOW Dark shadow for three-dimensional display elements.
EGDC_3D_SHADOW Shadow color for three-dimensional display elements (for edges facing away from the light source).
@ -604,31 +651,28 @@ video::SColor Skin::getColor (EGUI_DEFAULT_COLOR color) const
const wchar_t* Skin::getDefaultText (EGUI_DEFAULT_TEXT text) const
{
//printf("getting default text\n");
return L"SuperTuxKart";
}
IGUIFont* Skin::getFont (EGUI_DEFAULT_FONT which) const
{
//printf("getting font\n");
return GUIEngine::getFont();
}
u32 Skin::getIcon (EGUI_DEFAULT_ICON icon) const
{
//printf("getting icon\n");
return m_fallback_skin->getIcon(icon);
//return m_fallback_skin->getIcon(icon);
// return m_fallback_skin->getIcon(irr::gui::EGUI_DEFAULT_ICON);
return 0;
}
s32 Skin::getSize (EGUI_DEFAULT_SIZE size) const
{
//printf("getting size\n");
return m_fallback_skin->getSize(size);
}
IGUISpriteBank* Skin::getSpriteBank () const
{
//printf("getting bank\n");
return m_fallback_skin->getSpriteBank();
}
@ -637,25 +681,21 @@ IGUISpriteBank* Skin::getSpriteBank () const
void Skin::setColor (EGUI_DEFAULT_COLOR which, video::SColor newColor)
{
m_fallback_skin->setColor(which, newColor);
//printf("setting color\n");
}
void Skin::setDefaultText (EGUI_DEFAULT_TEXT which, const wchar_t *newText)
{
m_fallback_skin->setDefaultText(which, newText);
//printf("setting default text\n");
}
void Skin::setFont (IGUIFont *font, EGUI_DEFAULT_FONT which)
{
m_fallback_skin->setFont(font, which);
//printf("setting font\n");
}
void Skin::setIcon (EGUI_DEFAULT_ICON icon, u32 index)
{
m_fallback_skin->setIcon(icon, index);
//printf("setting icon\n");
}
void Skin::setSize (EGUI_DEFAULT_SIZE which, s32 size)

View File

@ -36,6 +36,7 @@ class Skin : public IGUISkin
ITexture* m_tex_iconhighlight;
ITexture* m_tex_ficonhighlight;
ITexture* m_tex_squarefocus;
ITexture* m_tex_gaugefill;
void drawBoxFromStretchableTexture(const core::rect< s32 > &dest, ITexture* source,
const int left_border, const int right_border,
@ -54,6 +55,8 @@ public:
void drawRibbonChild(const core::rect< s32 > &rect, const Widget* widget, const bool pressed, bool focused);
void drawSpinnerChild(const core::rect< s32 > &rect, Widget* widget, const bool pressed, bool focused);
void drawSpinnerBody(const core::rect< s32 > &rect, const Widget* widget, const bool pressed, bool focused);
void drawGauge(const core::rect< s32 > &rect, Widget* widget, bool focused);
void drawGaugeFill(const core::rect< s32 > &rect, Widget* widget, bool focused);
// irrlicht's callbacks
virtual void draw2DRectangle (IGUIElement *element, const video::SColor &color, const core::rect< s32 > &pos, const core::rect< s32 > *clip);

View File

@ -267,15 +267,27 @@ namespace StateManager
{
if(name == "init")
{
GUIEngine::RibbonWidget* w = dynamic_cast<GUIEngine::RibbonWidget*>
GUIEngine::RibbonWidget* ribbon = dynamic_cast<GUIEngine::RibbonWidget*>
(GUIEngine::getCurrentScreen()->getWidget("options_choice"));
if(w != NULL)
if(ribbon != NULL)
{
const std::string& screen_name = GUIEngine::getCurrentScreen()->getName();
if(screen_name == "options_av.stkgui") w->select( "audio_video" );
else if(screen_name == "options_players.stkgui") w->select( "players" );
else if(screen_name == "options_input.stkgui") w->select( "controls" );
if(screen_name == "options_av.stkgui") ribbon->select( "audio_video" );
else if(screen_name == "options_players.stkgui") ribbon->select( "players" );
else if(screen_name == "options_input.stkgui") ribbon->select( "controls" );
}
GUIEngine::GaugeWidget* gauge = dynamic_cast<GUIEngine::GaugeWidget*>
(GUIEngine::getCurrentScreen()->getWidget("sfx_volume"));
assert(gauge != NULL);
gauge->setValue( sfx_manager->getMasterSFXVolume() );
gauge = dynamic_cast<GUIEngine::GaugeWidget*>
(GUIEngine::getCurrentScreen()->getWidget("music_volume"));
assert(gauge != NULL);
gauge->setValue( sound_manager->getMasterMusicVolume() );
}
// -- options
else if(name == "options_choice")
@ -292,7 +304,7 @@ namespace StateManager
(GUIEngine::getCurrentScreen()->getWidget("music_volume"));
assert(w != NULL);
// TODO - save value to file, load value from file, make the slider start at an actual value
// TODO - save value to file, load value from file, allow fully disabling music
sound_manager->setMasterMusicVolume( w->getValue() );
}
else if(name == "sfx_volume")
@ -301,7 +313,7 @@ namespace StateManager
(GUIEngine::getCurrentScreen()->getWidget("sfx_volume"));
assert(w != NULL);
// TODO - save value to file, load value from file, make the slider start at an actual value
// TODO - save value to file, load value from file, allow fully disabling sfx
sfx_manager->setMasterSFXVolume( w->getValue() );
}

View File

@ -273,6 +273,14 @@ float GaugeWidget::getValue()
assert(sb != NULL);
return (float)sb->getPos() / sb->getMax();
}
// -----------------------------------------------------------------------------
void GaugeWidget::setValue(const float val)
{
IGUIScrollBar* sb = dynamic_cast<IGUIScrollBar*>(m_element);
assert(sb != NULL);
sb->setPos( (int)round(sb->getMax()*val) );
}
#if 0
#pragma mark -

View File

@ -172,6 +172,7 @@ namespace GUIEngine
public:
virtual ~GaugeWidget() {}
float getValue();
void setValue(const float value);
};
class SpinnerWidget : public Widget