2003-11-03 08:22:45 -08:00
|
|
|
/*
|
|
|
|
|
CButton
|
|
|
|
|
by Gustav Larsson
|
|
|
|
|
gee@pyro.nu
|
|
|
|
|
*/
|
|
|
|
|
|
2004-06-03 11:38:14 -07:00
|
|
|
#include "precompiled.h"
|
2003-11-03 08:22:45 -08:00
|
|
|
#include "GUI.h"
|
2004-05-28 21:06:50 -07:00
|
|
|
#include "CButton.h"
|
2003-11-03 08:22:45 -08:00
|
|
|
|
2003-11-24 18:47:12 -08:00
|
|
|
#include "ogl.h"
|
|
|
|
|
|
2003-11-03 08:22:45 -08:00
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
|
// Constructor / Destructor
|
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
|
CButton::CButton()
|
|
|
|
|
{
|
2005-01-01 04:06:17 -08:00
|
|
|
AddSetting(GUIST_float, "buffer_zone");
|
2004-12-28 04:17:04 -08:00
|
|
|
AddSetting(GUIST_CGUIString, "caption");
|
2005-07-23 15:27:55 -07:00
|
|
|
AddSetting(GUIST_int, "cell_id");
|
2004-12-28 04:17:04 -08:00
|
|
|
AddSetting(GUIST_CStr, "font");
|
2004-12-15 13:24:46 -08:00
|
|
|
AddSetting(GUIST_CGUISpriteInstance, "sprite");
|
2005-01-01 04:06:17 -08:00
|
|
|
AddSetting(GUIST_CGUISpriteInstance, "sprite_over");
|
|
|
|
|
AddSetting(GUIST_CGUISpriteInstance, "sprite_pressed");
|
|
|
|
|
AddSetting(GUIST_CGUISpriteInstance, "sprite_disabled");
|
|
|
|
|
AddSetting(GUIST_EAlign, "text_align");
|
|
|
|
|
AddSetting(GUIST_EVAlign, "text_valign");
|
2004-12-28 04:17:04 -08:00
|
|
|
AddSetting(GUIST_CColor, "textcolor");
|
2005-01-01 04:06:17 -08:00
|
|
|
AddSetting(GUIST_CColor, "textcolor_over");
|
|
|
|
|
AddSetting(GUIST_CColor, "textcolor_pressed");
|
|
|
|
|
AddSetting(GUIST_CColor, "textcolor_disabled");
|
2004-12-28 04:17:04 -08:00
|
|
|
AddSetting(GUIST_CStr, "tooltip");
|
2005-01-01 04:06:17 -08:00
|
|
|
AddSetting(GUIST_CStr, "tooltip_style");
|
2004-05-28 21:06:50 -07:00
|
|
|
|
|
|
|
|
// Add text
|
|
|
|
|
AddText(new SGUIText());
|
2003-11-03 08:22:45 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CButton::~CButton()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2004-05-28 21:06:50 -07:00
|
|
|
void CButton::SetupText()
|
|
|
|
|
{
|
|
|
|
|
if (!GetGUI())
|
|
|
|
|
return;
|
|
|
|
|
|
2005-06-27 21:06:25 -07:00
|
|
|
debug_assert(m_GeneratedTexts.size()>=1);
|
2004-05-28 21:06:50 -07:00
|
|
|
|
|
|
|
|
CStr font;
|
2004-07-31 06:37:35 -07:00
|
|
|
if (GUI<CStr>::GetSetting(this, "font", font) != PS_OK || font.Length()==0)
|
|
|
|
|
// Use the default if none is specified
|
2004-08-30 19:09:58 -07:00
|
|
|
// TODO Gee: (2004-08-14) Default should not be hard-coded, but be in styles!
|
2004-08-27 15:08:30 -07:00
|
|
|
font = "default";
|
2004-07-31 06:37:35 -07:00
|
|
|
|
2004-05-28 21:06:50 -07:00
|
|
|
CGUIString caption;
|
|
|
|
|
GUI<CGUIString>::GetSetting(this, "caption", caption);
|
|
|
|
|
|
2004-12-28 04:38:45 -08:00
|
|
|
float buffer_zone=0.f;
|
2005-01-01 04:06:17 -08:00
|
|
|
GUI<float>::GetSetting(this, "buffer_zone", buffer_zone);
|
2004-12-28 04:38:45 -08:00
|
|
|
*m_GeneratedTexts[0] = GetGUI()->GenerateText(caption, font, m_CachedActualSize.GetWidth(), buffer_zone, this);
|
2004-05-28 21:06:50 -07:00
|
|
|
|
2004-12-28 04:17:04 -08:00
|
|
|
CalculateTextPosition(m_CachedActualSize, m_TextPos, *m_GeneratedTexts[0]);
|
2004-05-28 21:06:50 -07:00
|
|
|
}
|
|
|
|
|
|
2003-12-26 22:26:03 -08:00
|
|
|
void CButton::HandleMessage(const SGUIMessage &Message)
|
2003-11-03 08:22:45 -08:00
|
|
|
{
|
2003-11-24 18:47:12 -08:00
|
|
|
// Important
|
2003-11-23 18:18:41 -08:00
|
|
|
IGUIButtonBehavior::HandleMessage(Message);
|
2004-05-28 21:06:50 -07:00
|
|
|
IGUITextOwner::HandleMessage(Message);
|
2005-02-04 23:25:16 -08:00
|
|
|
/*
|
2003-12-26 22:26:03 -08:00
|
|
|
switch (Message.type)
|
2003-11-03 08:22:45 -08:00
|
|
|
{
|
|
|
|
|
case GUIM_PRESSED:
|
2004-07-11 09:22:35 -07:00
|
|
|
// GetGUI()->TEMPmessage = "Button " + string((const TCHAR*)m_Name) + " was pressed!";
|
2003-11-03 08:22:45 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2005-02-04 23:25:16 -08:00
|
|
|
*/
|
2003-11-03 08:22:45 -08:00
|
|
|
}
|
|
|
|
|
|
2003-12-26 22:26:03 -08:00
|
|
|
void CButton::Draw()
|
2003-11-03 08:22:45 -08:00
|
|
|
{
|
2004-05-28 21:06:50 -07:00
|
|
|
float bz = GetBufferedZ();
|
|
|
|
|
|
2004-12-16 16:05:37 -08:00
|
|
|
CGUISpriteInstance *sprite, *sprite_over, *sprite_pressed, *sprite_disabled;
|
2004-12-18 05:32:00 -08:00
|
|
|
int cell_id;
|
2004-05-28 21:06:50 -07:00
|
|
|
|
2004-12-16 16:05:37 -08:00
|
|
|
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite);
|
2005-01-01 04:06:17 -08:00
|
|
|
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_over", sprite_over);
|
|
|
|
|
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_pressed", sprite_pressed);
|
|
|
|
|
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_disabled", sprite_disabled);
|
|
|
|
|
GUI<int>::GetSetting(this, "cell_id", cell_id);
|
2004-12-15 13:24:46 -08:00
|
|
|
|
|
|
|
|
DrawButton(m_CachedActualSize,
|
|
|
|
|
bz,
|
2004-12-16 16:05:37 -08:00
|
|
|
*sprite,
|
|
|
|
|
*sprite_over,
|
|
|
|
|
*sprite_pressed,
|
2004-12-17 08:20:08 -08:00
|
|
|
*sprite_disabled,
|
2004-12-18 05:32:00 -08:00
|
|
|
cell_id);
|
2004-05-28 21:06:50 -07:00
|
|
|
|
|
|
|
|
CColor color = ChooseColor();
|
|
|
|
|
IGUITextOwner::Draw(0, color, m_TextPos, bz+0.1f);
|
2003-11-24 09:13:37 -08:00
|
|
|
}
|