Support floating point values for the progress bar.
This commit is contained in:
parent
386dc279fd
commit
89cc549ebc
@ -817,20 +817,20 @@ void Skin::drawProgress(Widget* w, const core::recti &rect,
|
|||||||
{
|
{
|
||||||
ProgressBarWidget * progress = (ProgressBarWidget*)w;
|
ProgressBarWidget * progress = (ProgressBarWidget*)w;
|
||||||
drawProgressBarInScreen(w, rect, progress->getValue(),
|
drawProgressBarInScreen(w, rect, progress->getValue(),
|
||||||
w->m_deactivated);
|
w->m_deactivated);
|
||||||
}
|
}
|
||||||
} // drawProgress
|
} // drawProgress
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
void Skin::drawProgressBarInScreen(SkinWidgetContainer* swc,
|
void Skin::drawProgressBarInScreen(SkinWidgetContainer* swc,
|
||||||
const core::rect< s32 > &rect, int progress,
|
const core::rect< s32 > &rect,
|
||||||
bool deactivated)
|
float progress, bool deactivated)
|
||||||
{
|
{
|
||||||
drawBoxFromStretchableTexture(swc, rect,
|
drawBoxFromStretchableTexture(swc, rect,
|
||||||
SkinConfig::m_render_params["progress::neutral"], deactivated);
|
SkinConfig::m_render_params["progress::neutral"], deactivated);
|
||||||
core::recti rect2 = rect;
|
core::recti rect2 = rect;
|
||||||
rect2.LowerRightCorner.X -= (rect.getWidth())
|
rect2.LowerRightCorner.X -= (rect.getWidth())
|
||||||
- progress * rect.getWidth() / 100;
|
- int(progress * rect.getWidth());
|
||||||
drawBoxFromStretchableTexture(swc, rect2,
|
drawBoxFromStretchableTexture(swc, rect2,
|
||||||
SkinConfig::m_render_params["progress::fill"], deactivated);
|
SkinConfig::m_render_params["progress::fill"], deactivated);
|
||||||
} // drawProgress
|
} // drawProgress
|
||||||
|
@ -338,7 +338,7 @@ namespace GUIEngine
|
|||||||
void drawBadgeOn(const Widget* widget, const core::rect<s32>& rect);
|
void drawBadgeOn(const Widget* widget, const core::rect<s32>& rect);
|
||||||
void drawProgressBarInScreen(SkinWidgetContainer* swc,
|
void drawProgressBarInScreen(SkinWidgetContainer* swc,
|
||||||
const core::rect< s32 > &rect,
|
const core::rect< s32 > &rect,
|
||||||
int progress, bool deactivated = false);
|
float progress, bool deactivated = false);
|
||||||
|
|
||||||
// irrlicht's callbacks
|
// irrlicht's callbacks
|
||||||
virtual void draw2DRectangle (gui::IGUIElement *element,
|
virtual void draw2DRectangle (gui::IGUIElement *element,
|
||||||
|
@ -69,23 +69,29 @@ void ProgressBarWidget::add()
|
|||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void ProgressBarWidget::setValue(int value)
|
void ProgressBarWidget::setValue(float value)
|
||||||
{
|
{
|
||||||
m_value = value;
|
m_value = value/100.0f;
|
||||||
m_target_value = value;
|
m_target_value = m_value;
|
||||||
m_previous_value = value;
|
m_previous_value = m_value;
|
||||||
if (m_show_label)
|
if (m_show_label)
|
||||||
setLabel(std::string(StringUtils::toString(value) + "%").c_str());
|
{
|
||||||
|
int percent = int(value);
|
||||||
|
setLabel(std::string(StringUtils::toString(percent) + "%").c_str());
|
||||||
|
}
|
||||||
} // setValue
|
} // setValue
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void ProgressBarWidget::moveValue(int value)
|
void ProgressBarWidget::moveValue(float value)
|
||||||
{
|
{
|
||||||
m_previous_value = m_value;
|
m_previous_value = m_value;
|
||||||
m_target_value = value;
|
m_target_value = value/100.0f;
|
||||||
if (m_show_label)
|
if (m_show_label)
|
||||||
setLabel(std::string(StringUtils::toString(value) + "%").c_str());
|
{
|
||||||
|
int percent = int(value);
|
||||||
|
setLabel(std::string(StringUtils::toString(percent) + "%").c_str());
|
||||||
|
}
|
||||||
} // moveValue
|
} // moveValue
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
@ -95,14 +101,14 @@ void ProgressBarWidget::update(float delta)
|
|||||||
if (m_target_value != m_value)
|
if (m_target_value != m_value)
|
||||||
{
|
{
|
||||||
// Compute current progress in the animation
|
// Compute current progress in the animation
|
||||||
float cur = (static_cast<float>(m_value) - m_previous_value)
|
float cur = (m_value - m_previous_value)
|
||||||
/ (m_target_value - m_previous_value);
|
/ (m_target_value - m_previous_value);
|
||||||
// Animation time: 1.0 seconds
|
// Animation time: 1.0 seconds
|
||||||
cur += delta * 10;
|
cur += delta * 10;
|
||||||
if (cur > 1)
|
if (cur > 1)
|
||||||
cur = 1;
|
cur = 1;
|
||||||
m_value = int(m_previous_value +
|
m_value = m_previous_value
|
||||||
cur * (m_target_value - m_previous_value) );
|
+ cur * (m_target_value - m_previous_value);
|
||||||
}
|
}
|
||||||
} // update
|
} // update
|
||||||
|
|
||||||
@ -115,4 +121,3 @@ void ProgressBarWidget::setLabel(irr::core::stringw label)
|
|||||||
} // setLabel
|
} // setLabel
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -44,12 +44,12 @@ namespace GUIEngine
|
|||||||
|
|
||||||
/** Change the label on the widget */
|
/** Change the label on the widget */
|
||||||
void setLabel(const irr::core::stringw label);
|
void setLabel(const irr::core::stringw label);
|
||||||
int m_value;
|
float m_value;
|
||||||
bool m_show_label;
|
bool m_show_label;
|
||||||
|
|
||||||
/** Values for animation */
|
/** Values for animation */
|
||||||
int m_target_value;
|
float m_target_value;
|
||||||
int m_previous_value;
|
float m_previous_value;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -58,10 +58,10 @@ namespace GUIEngine
|
|||||||
virtual ~ProgressBarWidget();
|
virtual ~ProgressBarWidget();
|
||||||
|
|
||||||
/** Change the value of the widget, it must be a percent. */
|
/** Change the value of the widget, it must be a percent. */
|
||||||
void setValue(int value);
|
void setValue(float value);
|
||||||
|
|
||||||
/** Change the value of the widget smooth, it must be a percent. */
|
/** Change the value of the widget smooth, it must be a percent. */
|
||||||
void moveValue(int value);
|
void moveValue(float value);
|
||||||
|
|
||||||
virtual void update(float delta);
|
virtual void update(float delta);
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ namespace GUIEngine
|
|||||||
|
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
/** Get the current value of the widget. */
|
/** Get the current value of the widget. */
|
||||||
int getValue() {return m_value; };
|
float getValue() {return m_value; };
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
/** Sets if the current fraction is shown as a percentage value
|
/** Sets if the current fraction is shown as a percentage value
|
||||||
* in the progress bar. */
|
* in the progress bar. */
|
||||||
|
@ -40,7 +40,7 @@ using namespace irr;
|
|||||||
|
|
||||||
SkillLevelWidget::SkillLevelWidget(core::recti area, const int player_id,
|
SkillLevelWidget::SkillLevelWidget(core::recti area, const int player_id,
|
||||||
bool multiplayer, bool display_icon,
|
bool multiplayer, bool display_icon,
|
||||||
const int value)
|
const float value)
|
||||||
: Widget(WTYPE_DIV)
|
: Widget(WTYPE_DIV)
|
||||||
{
|
{
|
||||||
m_player_id = player_id;
|
m_player_id = player_id;
|
||||||
@ -147,7 +147,7 @@ void SkillLevelWidget::setSize(const int x, const int y, const int w, const int
|
|||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void SkillLevelWidget::setValue(const int value)
|
void SkillLevelWidget::setValue(const float value)
|
||||||
{
|
{
|
||||||
m_bar->moveValue(value);
|
m_bar->moveValue(value);
|
||||||
}
|
}
|
||||||
|
6
src/guiengine/widgets/skill_level_widget.hpp
Normal file → Executable file
6
src/guiengine/widgets/skill_level_widget.hpp
Normal file → Executable file
@ -63,7 +63,7 @@ namespace GUIEngine
|
|||||||
|
|
||||||
SkillLevelWidget(core::recti area, const int player_id,
|
SkillLevelWidget(core::recti area, const int player_id,
|
||||||
bool multiplayer, bool display_text,
|
bool multiplayer, bool display_text,
|
||||||
const int value = 0);
|
const float value = 0);
|
||||||
|
|
||||||
virtual ~SkillLevelWidget() {};
|
virtual ~SkillLevelWidget() {};
|
||||||
|
|
||||||
@ -82,10 +82,10 @@ namespace GUIEngine
|
|||||||
void setSize(const int x, const int y, const int w, const int h);
|
void setSize(const int x, const int y, const int w, const int h);
|
||||||
|
|
||||||
/** Change the value of the widget, it must be a percent. */
|
/** Change the value of the widget, it must be a percent. */
|
||||||
void setValue(const int value);
|
void setValue(const float value);
|
||||||
|
|
||||||
/** Get the current values of the widget. */
|
/** Get the current values of the widget. */
|
||||||
int getValue() {return m_bar->getValue(); };
|
float getValue() {return m_bar->getValue(); };
|
||||||
|
|
||||||
/** Change the label of the widget */
|
/** Change the label of the widget */
|
||||||
void setLabel(const irr::core::stringw& label);
|
void setLabel(const irr::core::stringw& label);
|
||||||
|
@ -283,7 +283,7 @@ void AddonsLoading::onUpdate(float delta)
|
|||||||
if(m_progress->isVisible())
|
if(m_progress->isVisible())
|
||||||
{
|
{
|
||||||
float progress = m_download_request->getProgress();
|
float progress = m_download_request->getProgress();
|
||||||
m_progress->setValue((int)(progress*100.0f));
|
m_progress->setValue(progress*100.0f);
|
||||||
if(progress<0)
|
if(progress<0)
|
||||||
{
|
{
|
||||||
// Avoid displaying '-100%' in case of an error.
|
// Avoid displaying '-100%' in case of an error.
|
||||||
|
@ -74,7 +74,7 @@ void NetworkKartSelectionScreen::onUpdate(float dt)
|
|||||||
auto lp = LobbyProtocol::get<LobbyProtocol>();
|
auto lp = LobbyProtocol::get<LobbyProtocol>();
|
||||||
float new_value = lp->getRemainingVotingTime() / lp->getMaxVotingTime();
|
float new_value = lp->getRemainingVotingTime() / lp->getMaxVotingTime();
|
||||||
if(new_value < 0) new_value = 0;
|
if(new_value < 0) new_value = 0;
|
||||||
m_timer->moveValue(int(new_value*100));
|
m_timer->setValue(new_value*100.0f);
|
||||||
} // onUpdate
|
} // onUpdate
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@ -509,6 +509,6 @@ void TracksScreen::onUpdate(float dt)
|
|||||||
auto lp = LobbyProtocol::get<LobbyProtocol>();
|
auto lp = LobbyProtocol::get<LobbyProtocol>();
|
||||||
float new_value = lp->getRemainingVotingTime() / lp->getMaxVotingTime();
|
float new_value = lp->getRemainingVotingTime() / lp->getMaxVotingTime();
|
||||||
if (new_value < 0) new_value = 0;
|
if (new_value < 0) new_value = 0;
|
||||||
m_timer->moveValue(int(new_value * 100));
|
m_timer->setValue(new_value * 100.0f);
|
||||||
|
|
||||||
} // onUpdate
|
} // onUpdate
|
||||||
|
@ -198,7 +198,7 @@ void VoteOverview::onUpdate(float dt)
|
|||||||
auto lp = LobbyProtocol::get<LobbyProtocol>();
|
auto lp = LobbyProtocol::get<LobbyProtocol>();
|
||||||
float new_value = lp->getRemainingVotingTime() / lp->getMaxVotingTime();
|
float new_value = lp->getRemainingVotingTime() / lp->getMaxVotingTime();
|
||||||
if (new_value < 0) new_value = 0;
|
if (new_value < 0) new_value = 0;
|
||||||
m_timer->moveValue(int(new_value * 100));
|
m_timer->setValue(new_value * 100);
|
||||||
|
|
||||||
if(m_index_to_hostid.size()==0) return;
|
if(m_index_to_hostid.size()==0) return;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user