Adding a progress bar to download addons.

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@5660 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
xapantu 2010-07-06 14:39:45 +00:00
parent 53d19f2e43
commit ad9eb86671
13 changed files with 212 additions and 15 deletions

View File

@ -75,7 +75,14 @@ when the border that intersect at this corner are enabled.
<!-- TODO : buttons could support 'pressed' state -->
<element type="progress" state="fill" image="glass/glassprogress_fill.png"
left_border="80" right_border="80" top_border="0" bottom_border="36"
preserve_h_aspect_ratios="true" />
<element type="progress" state="neutral" image="glass/glassbutton.png"
left_border="80" right_border="80" top_border="0" bottom_border="36"
preserve_h_aspect_ratios="true" />
<element type="tab" state="neutral" image="glass/glasstab.png"
left_border="75" right_border="75" top_border="0" bottom_border="15"
hborder_out_portion="0.2" />
@ -178,4 +185,4 @@ when the border that intersect at this corner are enabled.
<color type="text_field" state="neutral" a="255" r="215" g="215" b="215" />
<color type="text_field" state="focused" a="255" r="0" g="150" b="0" />
</skin>
</skin>

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

View File

@ -117,6 +117,8 @@ supertuxkart_SOURCES = \
guiengine/widgets/spinner_widget.hpp \
guiengine/widgets/text_box_widget.cpp \
guiengine/widgets/text_box_widget.hpp \
guiengine/widgets/progress_bar_widget.cpp \
guiengine/widgets/progress_bar_widget.hpp \
input/device_manager.cpp \
input/device_manager.hpp \
input/input.cpp \

View File

@ -52,6 +52,7 @@
\li \ref widget9
\li \ref widget10
\li \ref widget11
\li \ref widget12
\ref props
\li \ref prop1
@ -207,6 +208,15 @@
\note Contents must be set programmatically.
\subsection widget12 WTYPE_PROGRESS
<em> Name in XML files: </em> \c "progressbar"
Display a progress bar (e.g. for downloads).
\note The value must be set programmatically.
\n
\n
\n
\section props Properties

View File

@ -92,6 +92,10 @@ void Screen::parseScreenFileDiv(irr::io::IrrXMLReader* xml, ptr_vector<Widget>&
{
append_to.push_back(new SpinnerWidget(true));
}
else if (!strcmp("progressbar", xml->getNodeName()))
{
append_to.push_back(new ProgressBarWidget());
}
else if (!strcmp("icon-button", xml->getNodeName()))
{
append_to.push_back(new IconButtonWidget());

View File

@ -642,7 +642,47 @@ void Skin::drawButton(Widget* w, const core::rect< s32 > &rect, const bool press
}
}
}
/**
* @param focused whether this element is focus by the master player (focus for other players is not supported)
*/
void Skin::drawProgress(Widget* w, const core::rect< s32 > &rect, const bool pressed, const bool focused)
{
core::rect< s32 > sized_rect = rect;
// if within an appearing dialog, grow
if (m_dialog && m_dialog_size < 1.0f && w->m_parent != NULL && w->m_parent->getType() == gui::EGUIET_WINDOW)
{
core::position2d<u32> center = core::position2d<u32>(irr_driver->getFrameSize()/2);
const float texture_size = sin(m_dialog_size*M_PI*0.5f);
sized_rect.UpperLeftCorner.X = center.X + (int)(((int)rect.UpperLeftCorner.X - (int)center.X)*texture_size);
sized_rect.UpperLeftCorner.Y = center.Y + (int)(((int)rect.UpperLeftCorner.Y - (int)center.Y)*texture_size);
sized_rect.LowerRightCorner.X = center.X + (int)(((int)rect.LowerRightCorner.X - (int)center.X)*texture_size);
sized_rect.LowerRightCorner.Y = center.Y + (int)(((int)rect.LowerRightCorner.Y - (int)center.Y)*texture_size);
drawBoxFromStretchableTexture(w, sized_rect, SkinConfig::m_render_params["progress::neutral"],
w->m_deactivated);
}
else
{
ProgressBarWidget * progress = (ProgressBarWidget*)w;
drawBoxFromStretchableTexture(w, rect, SkinConfig::m_render_params["progress::neutral"],
w->m_deactivated);
//the " - 10" is a dirty hack to avoid to have the right arrow before the left one
//FIXME
core::rect<s32> rect2 = rect;
rect2.LowerRightCorner.X -= (rect.getWidth() - 10) - progress->getValue()*rect.getWidth()/100;
drawBoxFromStretchableTexture(w, rect2,
SkinConfig::m_render_params["progress::fill"],
w->m_deactivated);
#if 0
GUIEngine::getDriver()->draw2DImage(SkinConfig::m_render_params["progress::fill"].getImage(), sized_rect,
core::rect<s32>(0,0,progress->m_w, progress->m_h),
0 /* no clipping */, colors, true);
#endif
}
}
void Skin::drawRibbon(const core::rect< s32 > &rect, Widget* widget, const bool pressed, bool focused)
{
}
@ -1379,6 +1419,10 @@ void Skin::process3DPane(IGUIElement *element, const core::rect< s32 > &rect, co
{
drawButton(widget, rect, pressed, focused);
}
else if(type == WTYPE_PROGRESS)
{
drawProgress(widget, rect, pressed, focused);
}
else if(type == WTYPE_RIBBON)
{
drawRibbon(rect, widget, pressed, focused);

View File

@ -250,6 +250,7 @@ namespace GUIEngine
// my utility methods, to work around irrlicht's very Windows-95-like-look-enforcing skin system
void process3DPane(irr::gui::IGUIElement *element, const irr::core::rect< irr::s32 > &rect, const bool pressed);
void drawButton(Widget* w, const irr::core::rect< irr::s32 > &rect, const bool pressed, const bool focused);
void drawProgress(Widget* w, const irr::core::rect< irr::s32 > &rect, const bool pressed, const bool focused);
void drawRibbon(const irr::core::rect< irr::s32 > &rect, Widget* widget, const bool pressed, bool focused);
void drawRibbonChild(const irr::core::rect< irr::s32 > &rect, Widget* widget, const bool pressed, bool focused);
void drawSpinnerChild(const irr::core::rect< irr::s32 > &rect, Widget* widget, const bool pressed, bool focused);

View File

@ -47,7 +47,8 @@ namespace GUIEngine
WTYPE_DYNAMIC_RIBBON,
WTYPE_MODEL_VIEW,
WTYPE_LIST,
WTYPE_TEXTBOX
WTYPE_TEXTBOX,
WTYPE_PROGRESS
};
enum BadgeType
@ -119,6 +120,7 @@ namespace GUIEngine
friend class Skin;
friend class RibbonWidget;
friend class SpinnerWidget;
friend class ProgressBarWidget;
friend class DynamicRibbonWidget;
/** When true, this widget shall use a bigger and more colourful font */

View File

@ -6,6 +6,7 @@
#include "guiengine/widgets/list_widget.hpp"
#include "guiengine/widgets/dynamic_ribbon_widget.hpp"
#include "guiengine/widgets/spinner_widget.hpp"
#include "guiengine/widgets/progress_bar_widget.hpp"
#include "guiengine/widgets/ribbon_widget.hpp"
#include "guiengine/widgets/model_view_widget.hpp"
#include "guiengine/widgets/text_box_widget.hpp"

View File

@ -0,0 +1,60 @@
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2009 Marianne Gagnon
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "guiengine/engine.hpp"
#include "guiengine/widgets/progress_bar_widget.hpp"
#include "utils/string_utils.hpp"
#include <string.h>
using namespace GUIEngine;
using namespace irr::core;
// -----------------------------------------------------------------------------
ProgressBarWidget::ProgressBarWidget() : Widget(WTYPE_PROGRESS)
{
m_value = 0;
}
// -----------------------------------------------------------------------------
void ProgressBarWidget::add()
{
rect<s32> widget_size = rect<s32>(m_x, m_y, m_x + m_w, m_y + m_h);
stringw& message = m_text;
m_element = GUIEngine::getGUIEnv()->addButton(widget_size, m_parent, getNewID(), message.c_str(), L"");
m_id = m_element->getID();
m_element->setTabOrder(m_id);
m_element->setTabGroup(false);
}
// -----------------------------------------------------------------------------
void ProgressBarWidget::setValue(int value)
{
m_value = value;
setLabel(std::string(StringUtils::toString(value) + "\%").c_str());
}
// -----------------------------------------------------------------------------
void ProgressBarWidget::setLabel(irr::core::stringw label)
{
m_element->setText( label.c_str() );
m_text = label;
}
// -----------------------------------------------------------------------------

View File

@ -0,0 +1,68 @@
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2009 Marianne Gagnon
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_PROGRESS_BAR_HPP
#define HEADER_PROGRESS_BAR_HPP
/**
* \defgroup widgets Guiengine/Widgets
*/
#include <irrlicht.h>
#include "guiengine/widget.hpp"
#include "utils/ptr_vector.hpp"
namespace GUIEngine
{
/**
* \brief A progress bar widget.
* \ingroup widgets
*/
class ProgressBarWidget : 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 4; }
/** Change the label on the widget */
void setLabel(const irr::core::stringw label);
int m_value;
public:
ProgressBarWidget();
virtual ~ProgressBarWidget() {}
/** Change the value of the widget, it must be a percent. */
void setValue(int value);
void add();
/** Get the current value of the widget. */
int getValue() {return m_value; };
};
}
#endif

View File

@ -105,17 +105,6 @@ AddonsLoading::AddonsLoading(Addons * id, const float w, const float h) :
m_children.push_back(version);
version->add();
m_progress = new LabelWidget();
m_progress->m_x = 180;
m_progress->m_y = m_area.getHeight()-45;
m_progress->m_text = "";
m_progress->m_w = m_area.getWidth() - 180;
m_progress->m_h = 25;
m_progress->setParent(m_irrlicht_window);
m_children.push_back(m_progress);
m_progress->add();
this->loadInfo();
}
@ -195,6 +184,15 @@ GUIEngine::EventPropagation AddonsLoading::processEvent(const std::string& event
}
if(eventSource == "install")
{
m_progress = new ProgressBarWidget();
m_progress->m_x = 180;
m_progress->m_y = m_area.getHeight()-45;
m_progress->m_w = 250;
m_progress->m_h = 35;
m_progress->setParent(m_irrlicht_window);
m_children.push_back(m_progress);
m_progress->add();
m_back_button->setDeactivated();
m_next->setDeactivated();
m_previous->setDeactivated();
@ -216,7 +214,7 @@ void AddonsLoading::onUpdate(float delta)
}
if(m_percent_update)
{
m_progress->setText(std::string(StringUtils::toString(addons->getDownloadState()) + "\% downloaded").c_str());
m_progress->setValue(addons->getDownloadState());
}
pthread_mutex_unlock(&(mutex_can_install));
}

View File

@ -34,7 +34,7 @@ private:
GUIEngine::LabelWidget * description;
GUIEngine::LabelWidget * version;
GUIEngine::LabelWidget * author;
GUIEngine::LabelWidget * m_progress;
GUIEngine::ProgressBarWidget * m_progress;
GUIEngine::ButtonWidget * m_back_button;
GUIEngine::ButtonWidget * install_button;
GUIEngine::IconButtonWidget * icon;