2016-06-07 14:02:33 +02:00
|
|
|
/* Copyright (C) 2016 Wildfire Games.
|
2009-04-18 19:00:33 +02:00
|
|
|
* This file is part of 0 A.D.
|
|
|
|
*
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2004-06-03 20:38:14 +02:00
|
|
|
#include "precompiled.h"
|
2013-07-01 06:15:09 +02:00
|
|
|
|
2004-05-29 06:06:50 +02:00
|
|
|
#include "CCheckBox.h"
|
|
|
|
|
2015-08-21 19:08:41 +02:00
|
|
|
#include "graphics/FontMetrics.h"
|
2005-07-24 10:29:02 +02:00
|
|
|
#include "ps/CLogger.h"
|
2013-10-18 18:15:42 +02:00
|
|
|
#include "ps/CStrIntern.h"
|
2004-05-29 06:06:50 +02:00
|
|
|
|
2016-06-21 16:38:06 +02:00
|
|
|
/**
|
|
|
|
* TODO: Since there is no call to DrawText, the checkbox won't render any text.
|
|
|
|
* Thus the font, caption, textcolor and other settings have no effect.
|
|
|
|
*/
|
2004-05-29 06:06:50 +02:00
|
|
|
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");
|
2009-11-03 22:46:35 +01:00
|
|
|
AddSetting(GUIST_CStrW, "font");
|
2013-07-01 06:15:09 +02:00
|
|
|
AddSetting(GUIST_CStrW, "sound_disabled");
|
|
|
|
AddSetting(GUIST_CStrW, "sound_enter");
|
|
|
|
AddSetting(GUIST_CStrW, "sound_leave");
|
|
|
|
AddSetting(GUIST_CStrW, "sound_pressed");
|
|
|
|
AddSetting(GUIST_CStrW, "sound_released");
|
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");
|
2011-02-18 23:36:39 +01:00
|
|
|
AddSetting(GUIST_CStrW, "tooltip");
|
2005-01-01 13:06:17 +01:00
|
|
|
AddSetting(GUIST_CStr, "tooltip_style");
|
2004-05-29 06:06:50 +02:00
|
|
|
|
|
|
|
AddText(new SGUIText());
|
|
|
|
}
|
|
|
|
|
|
|
|
CCheckBox::~CCheckBox()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCheckBox::SetupText()
|
|
|
|
{
|
|
|
|
if (!GetGUI())
|
|
|
|
return;
|
|
|
|
|
2015-08-21 19:08:41 +02:00
|
|
|
ENSURE(m_GeneratedTexts.size() == 1);
|
2004-05-29 06:06:50 +02:00
|
|
|
|
2009-11-03 22:46:35 +01:00
|
|
|
CStrW font;
|
|
|
|
if (GUI<CStrW>::GetSetting(this, "font", font) != PSRETURN_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!
|
2009-11-03 22:46:35 +01:00
|
|
|
font = L"default";
|
2005-07-24 10:29:02 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2015-08-21 19:08:41 +02:00
|
|
|
float buffer_zone = 0.f;
|
2005-07-24 10:29:02 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-08-21 19:08:41 +02:00
|
|
|
void CCheckBox::HandleMessage(SGUIMessage& Message)
|
2004-05-29 06:06:50 +02:00
|
|
|
{
|
|
|
|
// 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;
|
|
|
|
|
2013-12-29 21:46:02 +01:00
|
|
|
// Switch to opposite.
|
2004-05-29 06:06:50 +02:00
|
|
|
GUI<bool>::GetSetting(this, "checked", checked);
|
|
|
|
checked = !checked;
|
|
|
|
GUI<bool>::SetSetting(this, "checked", checked);
|
2013-12-29 21:46:02 +01:00
|
|
|
break;
|
|
|
|
}
|
2004-05-29 06:06:50 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-21 19:08:41 +02:00
|
|
|
void CCheckBox::Draw()
|
2004-05-29 06:06:50 +02:00
|
|
|
{
|
2014-01-02 04:28:15 +01:00
|
|
|
float bz = GetBufferedZ();
|
2005-07-24 10:29:02 +02:00
|
|
|
bool checked;
|
|
|
|
int cell_id;
|
2015-08-21 19:08:41 +02:00
|
|
|
CGUISpriteInstance* sprite;
|
|
|
|
CGUISpriteInstance* sprite_over;
|
|
|
|
CGUISpriteInstance* sprite_pressed;
|
|
|
|
CGUISpriteInstance* sprite_disabled;
|
2014-01-02 04:28:15 +01:00
|
|
|
|
2005-07-24 10:29:02 +02:00
|
|
|
GUI<bool>::GetSetting(this, "checked", checked);
|
|
|
|
GUI<int>::GetSetting(this, "cell_id", cell_id);
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-08-21 19:08:41 +02:00
|
|
|
DrawButton(m_CachedActualSize,
|
2004-12-17 01:05:37 +01:00
|
|
|
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
|
|
|
}
|