Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/gui/CSlider.cpp
Show All 17 Lines | |||||
#include "precompiled.h" | #include "precompiled.h" | ||||
#include "CSlider.h" | #include "CSlider.h" | ||||
#include "gui/CGUI.h" | #include "gui/CGUI.h" | ||||
#include "maths/MathUtil.h" | #include "maths/MathUtil.h" | ||||
CSlider::CSlider(CGUI& pGUI) | CSlider::CSlider(CGUI& pGUI) | ||||
: IGUIObject(pGUI), m_IsPressed(false), m_ButtonSide(0) | : IGUIObject(pGUI), | ||||
{ | m_IsPressed(), | ||||
AddSetting<float>("value"); | m_ButtonSide() | ||||
AddSetting<float>("min_value"); | m_CellID(), | ||||
AddSetting<float>("max_value"); | m_MaxValue(), | ||||
AddSetting<i32>("cell_id"); | m_MinValue(), | ||||
AddSetting<CGUISpriteInstance>("sprite"); | m_Sprite(), | ||||
AddSetting<CGUISpriteInstance>("sprite_bar"); | m_SpriteBar(), | ||||
AddSetting<float>("button_width"); | m_Value(), | ||||
{ | |||||
m_Value = GetSetting<float>("value"); | RegisterSetting("button_width", m_ButtonSide); | ||||
m_MinValue = GetSetting<float>("min_value"); | RegisterSetting("cell_id", m_CellID); | ||||
m_MaxValue = GetSetting<float>("max_value"); | RegisterSetting("max_value", m_MaxValue); | ||||
m_ButtonSide = GetSetting<float>("button_width"); | RegisterSetting("min_value", m_MinValue); | ||||
RegisterSetting("sprite", m_Sprite); | |||||
RegisterSetting("sprite_bar", m_SpriteBar); | |||||
RegisterSetting("value", m_Value); | |||||
m_Value = Clamp(m_Value, m_MinValue, m_MaxValue); | m_Value = Clamp(m_Value, m_MinValue, m_MaxValue); | ||||
} | } | ||||
CSlider::~CSlider() | CSlider::~CSlider() | ||||
{ | { | ||||
} | } | ||||
Show All 9 Lines | |||||
} | } | ||||
void CSlider::HandleMessage(SGUIMessage& Message) | void CSlider::HandleMessage(SGUIMessage& Message) | ||||
{ | { | ||||
switch (Message.type) | switch (Message.type) | ||||
{ | { | ||||
case GUIM_SETTINGS_UPDATED: | case GUIM_SETTINGS_UPDATED: | ||||
{ | { | ||||
m_Value = GetSetting<float>("value"); | |||||
m_MinValue = GetSetting<float>("min_value"); | |||||
m_MaxValue = GetSetting<float>("max_value"); | |||||
m_ButtonSide = GetSetting<float>("button_width"); | |||||
m_Value = Clamp(m_Value, m_MinValue, m_MaxValue); | m_Value = Clamp(m_Value, m_MinValue, m_MaxValue); | ||||
break; | break; | ||||
} | } | ||||
case GUIM_MOUSE_WHEEL_DOWN: | case GUIM_MOUSE_WHEEL_DOWN: | ||||
{ | { | ||||
if (m_IsPressed) | if (m_IsPressed) | ||||
break; | break; | ||||
IncrementallyChangeValue(-0.01f); | IncrementallyChangeValue(-0.01f); | ||||
Show All 33 Lines | void CSlider::HandleMessage(SGUIMessage& Message) | ||||
} | } | ||||
default: | default: | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
void CSlider::Draw() | void CSlider::Draw() | ||||
{ | { | ||||
CGUISpriteInstance& sprite = GetSetting<CGUISpriteInstance>("sprite_bar"); | |||||
CGUISpriteInstance& sprite_button = GetSetting<CGUISpriteInstance>("sprite"); | |||||
const int cell_id = GetSetting<i32>("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(); | ||||
m_pGUI.DrawSprite(sprite, cell_id, bz, slider_line); | m_pGUI.DrawSprite(m_SpriteBar, m_CellID, bz, slider_line); | ||||
m_pGUI.DrawSprite(sprite_button, cell_id, bz, GetButtonRect()); | m_pGUI.DrawSprite(m_Sprite, m_CellID, bz, GetButtonRect()); | ||||
} | } | ||||
void CSlider::UpdateValue() | void CSlider::UpdateValue() | ||||
{ | { | ||||
SetSetting<float>("value", m_Value, true); | SetSetting<float>("value", m_Value, true); | ||||
ScriptEvent("valuechange"); | ScriptEvent("valuechange"); | ||||
} | } | ||||
CRect CSlider::GetButtonRect() const | CRect CSlider::GetButtonRect() const | ||||
{ | { | ||||
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