Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/gui/CButton.cpp
Show First 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | void CButton::SetupText() | ||||
ENSURE(m_GeneratedTexts.size() == 1); | ENSURE(m_GeneratedTexts.size() == 1); | ||||
CStrW font; | CStrW font; | ||||
if (GUI<CStrW>::GetSetting(this, "font", font) != PSRETURN_OK || font.empty()) | if (GUI<CStrW>::GetSetting(this, "font", font) != PSRETURN_OK || font.empty()) | ||||
// Use the default if none is specified | // Use the default if none is specified | ||||
// TODO Gee: (2004-08-14) Default should not be hard-coded, but be in styles! | // TODO Gee: (2004-08-14) Default should not be hard-coded, but be in styles! | ||||
font = L"default"; | font = L"default"; | ||||
CGUIString* caption = nullptr; | const CGUIString& caption = GUI<CGUIString>::GetSetting(this, "caption"); | ||||
GUI<CGUIString>::GetSettingPointer(this, "caption", caption); | |||||
float buffer_zone = 0.f; | float buffer_zone = 0.f; | ||||
GUI<float>::GetSetting(this, "buffer_zone", buffer_zone); | GUI<float>::GetSetting(this, "buffer_zone", buffer_zone); | ||||
m_GeneratedTexts[0] = CGUIText(m_pGUI, *caption, font, m_CachedActualSize.GetWidth(), buffer_zone, this); | m_GeneratedTexts[0] = CGUIText(m_pGUI, caption, font, m_CachedActualSize.GetWidth(), buffer_zone, this); | ||||
CalculateTextPosition(m_CachedActualSize, m_TextPos, m_GeneratedTexts[0]); | CalculateTextPosition(m_CachedActualSize, m_TextPos, m_GeneratedTexts[0]); | ||||
} | } | ||||
void CButton::HandleMessage(SGUIMessage& Message) | void CButton::HandleMessage(SGUIMessage& Message) | ||||
{ | { | ||||
// Important | // Important | ||||
IGUIButtonBehavior::HandleMessage(Message); | IGUIButtonBehavior::HandleMessage(Message); | ||||
IGUITextOwner::HandleMessage(Message); | IGUITextOwner::HandleMessage(Message); | ||||
} | } | ||||
void CButton::Draw() | void CButton::Draw() | ||||
{ | { | ||||
float bz = GetBufferedZ(); | float bz = GetBufferedZ(); | ||||
CGUISpriteInstance* sprite; | |||||
CGUISpriteInstance* sprite_over; | |||||
CGUISpriteInstance* sprite_pressed; | |||||
CGUISpriteInstance* sprite_disabled; | |||||
int cell_id; | int cell_id; | ||||
// Statically initialise some strings, so we don't have to do | // Statically initialise some strings, so we don't have to do | ||||
// lots of allocation every time this function is called | // lots of allocation every time this function is called | ||||
static const CStr strSprite("sprite"); | static const CStr strSprite("sprite"); | ||||
static const CStr strSpriteOver("sprite_over"); | static const CStr strSpriteOver("sprite_over"); | ||||
static const CStr strSpritePressed("sprite_pressed"); | static const CStr strSpritePressed("sprite_pressed"); | ||||
static const CStr strSpriteDisabled("sprite_disabled"); | static const CStr strSpriteDisabled("sprite_disabled"); | ||||
static const CStr strCellId("cell_id"); | static const CStr strCellId("cell_id"); | ||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, strSprite, sprite); | CGUISpriteInstance& sprite = GUI<CGUISpriteInstance>::GetSetting(this, strSprite); | ||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, strSpriteOver, sprite_over); | CGUISpriteInstance& sprite_over = GUI<CGUISpriteInstance>::GetSetting(this, strSpriteOver); | ||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, strSpritePressed, sprite_pressed); | CGUISpriteInstance& sprite_pressed = GUI<CGUISpriteInstance>::GetSetting(this, strSpritePressed); | ||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, strSpriteDisabled, sprite_disabled); | CGUISpriteInstance& sprite_disabled = GUI<CGUISpriteInstance>::GetSetting(this, strSpriteDisabled); | ||||
GUI<int>::GetSetting(this, strCellId, cell_id); | GUI<int>::GetSetting(this, strCellId, cell_id); | ||||
DrawButton(m_CachedActualSize, | DrawButton(m_CachedActualSize, bz, sprite, sprite_over, sprite_pressed, sprite_disabled, cell_id); | ||||
bz, | |||||
*sprite, | |||||
*sprite_over, | |||||
*sprite_pressed, | |||||
*sprite_disabled, | |||||
cell_id); | |||||
CGUIColor color = ChooseColor(); | CGUIColor color = ChooseColor(); | ||||
DrawText(0, color, m_TextPos, bz+0.1f); | DrawText(0, color, m_TextPos, bz+0.1f); | ||||
} | } |
Wildfire Games · Phabricator