Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/gui/CProgressBar.cpp
Show All 16 Lines | |||||
#include "precompiled.h" | #include "precompiled.h" | ||||
#include "CProgressBar.h" | #include "CProgressBar.h" | ||||
#include "gui/CGUI.h" | #include "gui/CGUI.h" | ||||
CProgressBar::CProgressBar(CGUI& pGUI) | CProgressBar::CProgressBar(CGUI& pGUI) | ||||
: IGUIObject(pGUI) | : IGUIObject(pGUI), | ||||
{ | m_SpriteBackground(), | ||||
AddSetting<CGUISpriteInstance>("sprite_background"); | m_SpriteBar(), | ||||
AddSetting<CGUISpriteInstance>("sprite_bar"); | m_Caption() | ||||
AddSetting<float>("caption"); // aka value from 0 to 100 | { | ||||
RegisterSetting("sprite_background", m_SpriteBackground); | |||||
RegisterSetting("sprite_bar", m_SpriteBar); | |||||
RegisterSetting("caption", m_Caption); // aka value from 0 to 100 | |||||
} | } | ||||
CProgressBar::~CProgressBar() | CProgressBar::~CProgressBar() | ||||
{ | { | ||||
} | } | ||||
void CProgressBar::HandleMessage(SGUIMessage& Message) | void CProgressBar::HandleMessage(SGUIMessage& Message) | ||||
{ | { | ||||
// Important | // Important | ||||
IGUIObject::HandleMessage(Message); | IGUIObject::HandleMessage(Message); | ||||
switch (Message.type) | switch (Message.type) | ||||
{ | { | ||||
case GUIM_SETTINGS_UPDATED: | case GUIM_SETTINGS_UPDATED: | ||||
// Update scroll-bar | // Update scroll-bar | ||||
// TODO Gee: (2004-09-01) Is this really updated each time it should? | // TODO Gee: (2004-09-01) Is this really updated each time it should? | ||||
if (Message.value == CStr("caption")) | if (Message.value == "caption") | ||||
{ | { | ||||
const float value = GetSetting<float>("caption"); | if (m_Caption > 100.f) | ||||
if (value > 100.f) | |||||
SetSetting<float>("caption", 100.f, true); | SetSetting<float>("caption", 100.f, true); | ||||
else if (value < 0.f) | else if (m_Caption < 0.f) | ||||
SetSetting<float>("caption", 0.f, true); | SetSetting<float>("caption", 0.f, true); | ||||
} | } | ||||
break; | break; | ||||
default: | default: | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
void CProgressBar::Draw() | void CProgressBar::Draw() | ||||
{ | { | ||||
CGUISpriteInstance& sprite_bar = GetSetting<CGUISpriteInstance>("sprite_bar"); | |||||
CGUISpriteInstance& sprite_background = GetSetting<CGUISpriteInstance>("sprite_background"); | |||||
float bz = GetBufferedZ(); | float bz = GetBufferedZ(); | ||||
int cell_id = 0; | int cell_id = 0; | ||||
const float value = GetSetting<float>("caption"); | |||||
m_pGUI.DrawSprite(sprite_background, cell_id, bz, m_CachedActualSize); | m_pGUI.DrawSprite(m_SpriteBackground, cell_id, bz, m_CachedActualSize); | ||||
// Get size of bar (notice it is drawn slightly closer, to appear above the background) | // Get size of bar (notice it is drawn slightly closer, to appear above the background) | ||||
CRect bar_size(m_CachedActualSize.left, m_CachedActualSize.top, | CRect bar_size(m_CachedActualSize.left, m_CachedActualSize.top, | ||||
m_CachedActualSize.left+m_CachedActualSize.GetWidth()*(value/100.f), m_CachedActualSize.bottom); | m_CachedActualSize.left+m_CachedActualSize.GetWidth()*(m_Caption/100.f), m_CachedActualSize.bottom); | ||||
m_pGUI.DrawSprite(sprite_bar, cell_id, bz+0.01f, bar_size); | m_pGUI.DrawSprite(m_SpriteBar, cell_id, bz+0.01f, bar_size); | ||||
} | } |
Wildfire Games · Phabricator