Changeset View
Changeset View
Standalone View
Standalone View
source/gui/CSlider.cpp
Show First 20 Lines • Show All 107 Lines • ▼ Show 20 Lines | void CSlider::HandleMessage(SGUIMessage& Message) | ||||
} | } | ||||
default: | default: | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
void CSlider::Draw() | void CSlider::Draw() | ||||
{ | { | ||||
CGUISpriteInstance* sprite; | CGUISpriteInstance& sprite = GUI<CGUISpriteInstance>::GetSetting(this, "sprite_bar"); | ||||
CGUISpriteInstance* sprite_button; | CGUISpriteInstance& sprite_button = GUI<CGUISpriteInstance>::GetSetting(this, "sprite"); | ||||
int cell_id; | int cell_id; | ||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_bar", sprite); | |||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite_button); | |||||
GUI<int>::GetSetting(this, "cell_id", cell_id); | GUI<int>::GetSetting(this, "cell_id", cell_id); | ||||
CRect slider_line(m_CachedActualSize); | CRect slider_line(m_CachedActualSize); | ||||
slider_line.left += m_ButtonSide / 2.0f; | slider_line.left += m_ButtonSide / 2.0f; | ||||
slider_line.right -= m_ButtonSide / 2.0f; | slider_line.right -= m_ButtonSide / 2.0f; | ||||
float bz = GetBufferedZ(); | float bz = GetBufferedZ(); | ||||
GetGUI()->DrawSprite(*sprite, cell_id, bz, slider_line); | m_pGUI->DrawSprite(sprite, cell_id, bz, slider_line); | ||||
GetGUI()->DrawSprite(*sprite_button, cell_id, bz, GetButtonRect()); | m_pGUI->DrawSprite(sprite_button, cell_id, bz, GetButtonRect()); | ||||
} | } | ||||
void CSlider::UpdateValue() | void CSlider::UpdateValue() | ||||
{ | { | ||||
GUI<float>::SetSetting(this, "value", m_Value); | GUI<float>::SetSetting(this, "value", m_Value); | ||||
ScriptEvent("valuechange"); | ScriptEvent("valuechange"); | ||||
} | } | ||||
CRect CSlider::GetButtonRect() | CRect CSlider::GetButtonRect() | ||||
{ | { | ||||
float ratio = m_MaxValue > m_MinValue ? (m_Value - m_MinValue) / (m_MaxValue - m_MinValue) : 0.0f; | float ratio = m_MaxValue > m_MinValue ? (m_Value - m_MinValue) / (m_MaxValue - m_MinValue) : 0.0f; | ||||
float x = m_CachedActualSize.left + ratio * (m_CachedActualSize.GetWidth() - m_ButtonSide); | float x = m_CachedActualSize.left + ratio * (m_CachedActualSize.GetWidth() - m_ButtonSide); | ||||
float y = m_CachedActualSize.top + (m_CachedActualSize.GetHeight() - m_ButtonSide) / 2.0; | float y = m_CachedActualSize.top + (m_CachedActualSize.GetHeight() - m_ButtonSide) / 2.0; | ||||
return CRect(x, y, x + m_ButtonSide, y + m_ButtonSide); | return CRect(x, y, x + m_ButtonSide, y + m_ButtonSide); | ||||
} | } |
Wildfire Games · Phabricator