2004-05-29 06:06:50 +02:00
|
|
|
/*
|
|
|
|
CCheckBox
|
|
|
|
*/
|
|
|
|
|
2004-06-03 20:38:14 +02:00
|
|
|
#include "precompiled.h"
|
2004-05-29 06:06:50 +02:00
|
|
|
#include "GUI.h"
|
|
|
|
#include "CCheckBox.h"
|
|
|
|
|
2005-07-24 10:29:02 +02:00
|
|
|
#include "ps/Font.h"
|
|
|
|
#include "ps/CLogger.h"
|
|
|
|
|
2004-05-29 06:06:50 +02:00
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
// Constructor / Destructor
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
CCheckBox::CCheckBox()
|
|
|
|
{
|
2005-07-24 10:29:02 +02:00
|
|
|
AddSetting(GUIST_float, "buffer_zone");
|
2004-12-21 14:37:24 +01:00
|
|
|
AddSetting(GUIST_CGUIString, "caption");
|
2005-07-24 10:29:02 +02:00
|
|
|
AddSetting(GUIST_int, "cell_id");
|
2004-12-21 14:37:24 +01:00
|
|
|
AddSetting(GUIST_bool, "checked");
|
2005-07-24 10:29:02 +02:00
|
|
|
AddSetting(GUIST_CStr, "font");
|
2004-12-21 14:37:24 +01:00
|
|
|
AddSetting(GUIST_CGUISpriteInstance, "sprite");
|
2005-01-01 13:06:17 +01:00
|
|
|
AddSetting(GUIST_CGUISpriteInstance, "sprite_over");
|
|
|
|
AddSetting(GUIST_CGUISpriteInstance, "sprite_pressed");
|
|
|
|
AddSetting(GUIST_CGUISpriteInstance, "sprite_disabled");
|
2004-12-21 14:37:24 +01:00
|
|
|
AddSetting(GUIST_CGUISpriteInstance, "sprite2");
|
2005-01-01 13:06:17 +01:00
|
|
|
AddSetting(GUIST_CGUISpriteInstance, "sprite2_over");
|
|
|
|
AddSetting(GUIST_CGUISpriteInstance, "sprite2_pressed");
|
|
|
|
AddSetting(GUIST_CGUISpriteInstance, "sprite2_disabled");
|
2005-07-24 10:29:02 +02:00
|
|
|
AddSetting(GUIST_float, "square_side");
|
|
|
|
AddSetting(GUIST_CColor, "textcolor");
|
|
|
|
AddSetting(GUIST_CColor, "textcolor_over");
|
|
|
|
AddSetting(GUIST_CColor, "textcolor_pressed");
|
|
|
|
AddSetting(GUIST_CColor, "textcolor_disabled");
|
2004-12-21 14:37:24 +01:00
|
|
|
AddSetting(GUIST_CStr, "tooltip");
|
2005-01-01 13:06:17 +01:00
|
|
|
AddSetting(GUIST_CStr, "tooltip_style");
|
2004-05-29 06:06:50 +02:00
|
|
|
|
|
|
|
// Add text
|
|
|
|
AddText(new SGUIText());
|
|
|
|
}
|
|
|
|
|
|
|
|
CCheckBox::~CCheckBox()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCheckBox::SetupText()
|
|
|
|
{
|
|
|
|
if (!GetGUI())
|
|
|
|
return;
|
|
|
|
|
2005-06-28 06:06:25 +02:00
|
|
|
debug_assert(m_GeneratedTexts.size()>=1);
|
2004-05-29 06:06:50 +02:00
|
|
|
|
|
|
|
CStr font;
|
2007-02-01 15:46:14 +01:00
|
|
|
if (GUI<CStr>::GetSetting(this, "font", font) != PS_OK || font.empty())
|
2005-07-24 10:29:02 +02:00
|
|
|
// Use the default if none is specified
|
|
|
|
// TODO Gee: (2004-08-14) Default should not be hard-coded, but be in styles!
|
|
|
|
font = "default";
|
|
|
|
|
|
|
|
float square_side;
|
|
|
|
GUI<float>::GetSetting(this, "square_side", square_side);
|
|
|
|
|
2004-05-29 06:06:50 +02:00
|
|
|
CGUIString caption;
|
|
|
|
GUI<CGUIString>::GetSetting(this, "caption", caption);
|
|
|
|
|
2005-07-24 10:29:02 +02:00
|
|
|
float buffer_zone=0.f;
|
|
|
|
GUI<float>::GetSetting(this, "buffer_zone", buffer_zone);
|
|
|
|
*m_GeneratedTexts[0] = GetGUI()->GenerateText(caption, font, m_CachedActualSize.GetWidth()-square_side, 0.f, this);
|
2004-05-29 06:06:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCheckBox::HandleMessage(const SGUIMessage &Message)
|
|
|
|
{
|
|
|
|
// Important
|
|
|
|
IGUIButtonBehavior::HandleMessage(Message);
|
2005-07-24 10:29:02 +02:00
|
|
|
IGUITextOwner::HandleMessage(Message);
|
2004-05-29 06:06:50 +02:00
|
|
|
|
|
|
|
switch (Message.type)
|
|
|
|
{
|
|
|
|
case GUIM_PRESSED:
|
|
|
|
{
|
|
|
|
bool checked;
|
|
|
|
|
|
|
|
GUI<bool>::GetSetting(this, "checked", checked);
|
|
|
|
checked = !checked;
|
|
|
|
GUI<bool>::SetSetting(this, "checked", checked);
|
|
|
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCheckBox::Draw()
|
|
|
|
{
|
|
|
|
////////// Gee: janwas, this is just temp to see it
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
//////////
|
|
|
|
|
2005-07-24 10:29:02 +02:00
|
|
|
float square_side, buffer_zone;
|
|
|
|
CStr font_name;
|
|
|
|
bool checked;
|
|
|
|
int cell_id;
|
|
|
|
GUI<float>::GetSetting(this, "square_side", square_side);
|
|
|
|
GUI<float>::GetSetting(this, "buffer_zone", buffer_zone);
|
|
|
|
GUI<CStr>::GetSetting(this, "font", font_name);
|
|
|
|
GUI<bool>::GetSetting(this, "checked", checked);
|
|
|
|
GUI<int>::GetSetting(this, "cell_id", cell_id);
|
|
|
|
|
|
|
|
// Get line height
|
|
|
|
CFont font (font_name);
|
|
|
|
float line_height = (float)font.GetHeight();
|
2004-05-29 06:06:50 +02:00
|
|
|
|
|
|
|
float bz = GetBufferedZ();
|
|
|
|
|
|
|
|
// Get square
|
|
|
|
CRect rect;
|
2005-07-24 10:29:02 +02:00
|
|
|
|
|
|
|
rect.left = m_CachedActualSize.left;
|
2004-05-29 06:06:50 +02:00
|
|
|
rect.right = rect.left + square_side;
|
|
|
|
|
2005-07-24 10:29:02 +02:00
|
|
|
if (square_side >= line_height)
|
|
|
|
rect.top = m_CachedActualSize.top;
|
|
|
|
else
|
|
|
|
rect.top = m_CachedActualSize.top + line_height/2.f - square_side/2.f;
|
|
|
|
|
|
|
|
rect.bottom = rect.top + square_side;
|
2004-05-29 06:06:50 +02:00
|
|
|
|
2004-12-17 01:05:37 +01:00
|
|
|
CGUISpriteInstance *sprite, *sprite_over, *sprite_pressed, *sprite_disabled;
|
2004-05-29 06:06:50 +02:00
|
|
|
|
|
|
|
if (checked)
|
|
|
|
{
|
2004-12-17 01:05:37 +01:00
|
|
|
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite2", sprite);
|
2005-01-01 13:06:17 +01:00
|
|
|
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite2_over", sprite_over);
|
|
|
|
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite2_pressed", sprite_pressed);
|
|
|
|
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite2_disabled", sprite_disabled);
|
2004-12-15 22:24:46 +01:00
|
|
|
}
|
2004-05-29 06:06:50 +02:00
|
|
|
else
|
|
|
|
{
|
2004-12-17 01:05:37 +01:00
|
|
|
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite);
|
2005-01-01 13:06:17 +01: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);
|
2004-05-29 06:06:50 +02:00
|
|
|
}
|
|
|
|
|
2004-12-17 01:05:37 +01:00
|
|
|
DrawButton(rect,
|
|
|
|
bz,
|
|
|
|
*sprite,
|
|
|
|
*sprite_over,
|
|
|
|
*sprite_pressed,
|
2004-12-17 17:20:08 +01:00
|
|
|
*sprite_disabled,
|
2005-07-24 10:29:02 +02:00
|
|
|
cell_id);
|
2004-05-29 06:06:50 +02:00
|
|
|
|
|
|
|
CColor color = ChooseColor();
|
|
|
|
|
2005-07-24 10:29:02 +02:00
|
|
|
CPos text_pos(m_CachedActualSize.left + square_side + buffer_zone, m_CachedActualSize.top);
|
|
|
|
|
|
|
|
if (square_side > line_height)
|
|
|
|
text_pos.y += square_side/2.f - line_height/2.f;
|
|
|
|
|
|
|
|
IGUITextOwner::Draw(0, color, text_pos, bz+0.1f, m_CachedActualSize);
|
2004-05-29 06:06:50 +02:00
|
|
|
}
|