2019-07-26 11:57:28 -07:00
|
|
|
/* Copyright (C) 2019 Wildfire Games.
|
2009-04-18 10:00:33 -07: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 11:38:14 -07:00
|
|
|
#include "precompiled.h"
|
2013-06-30 21:15:09 -07:00
|
|
|
|
2004-05-28 21:06:50 -07:00
|
|
|
#include "CCheckBox.h"
|
|
|
|
|
|
2019-07-26 11:57:28 -07:00
|
|
|
#include "gui/CGUIColor.h"
|
2015-08-21 10:08:41 -07:00
|
|
|
#include "graphics/FontMetrics.h"
|
2005-07-24 01:29:02 -07:00
|
|
|
#include "ps/CLogger.h"
|
2013-10-18 09:15:42 -07:00
|
|
|
#include "ps/CStrIntern.h"
|
2004-05-28 21:06:50 -07:00
|
|
|
|
2016-06-21 07:38:06 -07: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.
|
|
|
|
|
*/
|
2019-08-01 13:20:24 -07:00
|
|
|
CCheckBox::CCheckBox(CGUI* pGUI)
|
2019-08-01 16:55:10 -07:00
|
|
|
: IGUIObject(pGUI), IGUITextOwner(pGUI), IGUIButtonBehavior(pGUI)
|
2004-05-28 21:06:50 -07:00
|
|
|
{
|
2019-08-03 19:20:08 -07:00
|
|
|
AddSetting<float>("buffer_zone");
|
|
|
|
|
AddSetting<CGUIString>("caption");
|
|
|
|
|
AddSetting<int>("cell_id");
|
|
|
|
|
AddSetting<bool>("checked");
|
|
|
|
|
AddSetting<CStrW>("font");
|
|
|
|
|
AddSetting<CStrW>("sound_disabled");
|
|
|
|
|
AddSetting<CStrW>("sound_enter");
|
|
|
|
|
AddSetting<CStrW>("sound_leave");
|
|
|
|
|
AddSetting<CStrW>("sound_pressed");
|
|
|
|
|
AddSetting<CStrW>("sound_released");
|
|
|
|
|
AddSetting<CGUISpriteInstance>("sprite");
|
|
|
|
|
AddSetting<CGUISpriteInstance>("sprite_over");
|
|
|
|
|
AddSetting<CGUISpriteInstance>("sprite_pressed");
|
|
|
|
|
AddSetting<CGUISpriteInstance>("sprite_disabled");
|
|
|
|
|
AddSetting<CGUISpriteInstance>("sprite2");
|
|
|
|
|
AddSetting<CGUISpriteInstance>("sprite2_over");
|
|
|
|
|
AddSetting<CGUISpriteInstance>("sprite2_pressed");
|
|
|
|
|
AddSetting<CGUISpriteInstance>("sprite2_disabled");
|
|
|
|
|
AddSetting<float>("square_side");
|
|
|
|
|
AddSetting<CGUIColor>("textcolor");
|
|
|
|
|
AddSetting<CGUIColor>("textcolor_over");
|
|
|
|
|
AddSetting<CGUIColor>("textcolor_pressed");
|
|
|
|
|
AddSetting<CGUIColor>("textcolor_disabled");
|
|
|
|
|
AddSetting<CStrW>("tooltip");
|
|
|
|
|
AddSetting<CStr>("tooltip_style");
|
2004-05-28 21:06:50 -07:00
|
|
|
|
|
|
|
|
AddText(new SGUIText());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCheckBox::~CCheckBox()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CCheckBox::SetupText()
|
|
|
|
|
{
|
2015-08-21 10:08:41 -07:00
|
|
|
ENSURE(m_GeneratedTexts.size() == 1);
|
2004-05-28 21:06:50 -07:00
|
|
|
|
2009-11-03 13:46:35 -08:00
|
|
|
CStrW font;
|
|
|
|
|
if (GUI<CStrW>::GetSetting(this, "font", font) != PSRETURN_OK || font.empty())
|
2005-07-24 01:29:02 -07: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 13:46:35 -08:00
|
|
|
font = L"default";
|
2005-07-24 01:29:02 -07:00
|
|
|
|
|
|
|
|
float square_side;
|
|
|
|
|
GUI<float>::GetSetting(this, "square_side", square_side);
|
|
|
|
|
|
Use NONCOPYABLE for most GUI classes and structs to have the compiler indicate unintended copies, refs 3028551b91 / D2163.
That is CChartData, CGUIList, CGUISeries, COListColumn, GUITooltip,
SGUIMessage, SSpriteCall, STextCall, SFeedback, IGUISetting,
CGUISetting, GUI, IGUIObject, IGUIScrollBar.
Drop copying GetSetting and SetSetting template functions for CGUIList,
CGUISeries, CClientArea, CGUIString.
Stop copying COListColumn.
Drop copying GUI<CClientArea>::GetSetting call in
IGUIObject::UpdateCachedSize() and four copying
GUI<CGUIString>::GetSetting calls in SetupText() functions.
Delete unused GUIRenderer IGLState class from 849f50a500 obsolete since
1f5b8f1c9a.
Differential Revision: https://code.wildfiregames.com/D2164
This was SVN commit r22638.
2019-08-09 17:04:17 -07:00
|
|
|
CGUIString* caption = nullptr;
|
|
|
|
|
GUI<CGUIString>::GetSettingPointer(this, "caption", caption);
|
2004-05-28 21:06:50 -07:00
|
|
|
|
2015-08-21 10:08:41 -07:00
|
|
|
float buffer_zone = 0.f;
|
2005-07-24 01:29:02 -07:00
|
|
|
GUI<float>::GetSetting(this, "buffer_zone", buffer_zone);
|
Use NONCOPYABLE for most GUI classes and structs to have the compiler indicate unintended copies, refs 3028551b91 / D2163.
That is CChartData, CGUIList, CGUISeries, COListColumn, GUITooltip,
SGUIMessage, SSpriteCall, STextCall, SFeedback, IGUISetting,
CGUISetting, GUI, IGUIObject, IGUIScrollBar.
Drop copying GetSetting and SetSetting template functions for CGUIList,
CGUISeries, CClientArea, CGUIString.
Stop copying COListColumn.
Drop copying GUI<CClientArea>::GetSetting call in
IGUIObject::UpdateCachedSize() and four copying
GUI<CGUIString>::GetSetting calls in SetupText() functions.
Delete unused GUIRenderer IGLState class from 849f50a500 obsolete since
1f5b8f1c9a.
Differential Revision: https://code.wildfiregames.com/D2164
This was SVN commit r22638.
2019-08-09 17:04:17 -07:00
|
|
|
*m_GeneratedTexts[0] = GetGUI()->GenerateText(*caption, font, m_CachedActualSize.GetWidth()-square_side, 0.f, this);
|
2004-05-28 21:06:50 -07:00
|
|
|
}
|
|
|
|
|
|
2015-08-21 10:08:41 -07:00
|
|
|
void CCheckBox::HandleMessage(SGUIMessage& Message)
|
2004-05-28 21:06:50 -07:00
|
|
|
{
|
|
|
|
|
// Important
|
|
|
|
|
IGUIButtonBehavior::HandleMessage(Message);
|
2005-07-24 01:29:02 -07:00
|
|
|
IGUITextOwner::HandleMessage(Message);
|
2004-05-28 21:06:50 -07:00
|
|
|
|
|
|
|
|
switch (Message.type)
|
|
|
|
|
{
|
|
|
|
|
case GUIM_PRESSED:
|
|
|
|
|
{
|
|
|
|
|
bool checked;
|
|
|
|
|
|
2013-12-29 12:46:02 -08:00
|
|
|
// Switch to opposite.
|
2004-05-28 21:06:50 -07:00
|
|
|
GUI<bool>::GetSetting(this, "checked", checked);
|
|
|
|
|
checked = !checked;
|
|
|
|
|
GUI<bool>::SetSetting(this, "checked", checked);
|
2013-12-29 12:46:02 -08:00
|
|
|
break;
|
|
|
|
|
}
|
2004-05-28 21:06:50 -07:00
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-21 10:08:41 -07:00
|
|
|
void CCheckBox::Draw()
|
2004-05-28 21:06:50 -07:00
|
|
|
{
|
2014-01-01 19:28:15 -08:00
|
|
|
float bz = GetBufferedZ();
|
2005-07-24 01:29:02 -07:00
|
|
|
bool checked;
|
|
|
|
|
int cell_id;
|
2015-08-21 10:08:41 -07:00
|
|
|
CGUISpriteInstance* sprite;
|
|
|
|
|
CGUISpriteInstance* sprite_over;
|
|
|
|
|
CGUISpriteInstance* sprite_pressed;
|
|
|
|
|
CGUISpriteInstance* sprite_disabled;
|
2014-01-01 19:28:15 -08:00
|
|
|
|
2005-07-24 01:29:02 -07:00
|
|
|
GUI<bool>::GetSetting(this, "checked", checked);
|
|
|
|
|
GUI<int>::GetSetting(this, "cell_id", cell_id);
|
|
|
|
|
|
2004-05-28 21:06:50 -07:00
|
|
|
if (checked)
|
|
|
|
|
{
|
2004-12-16 16:05:37 -08:00
|
|
|
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite2", sprite);
|
2005-01-01 04:06:17 -08: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 13:24:46 -08:00
|
|
|
}
|
2004-05-28 21:06:50 -07:00
|
|
|
else
|
|
|
|
|
{
|
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);
|
2004-05-28 21:06:50 -07:00
|
|
|
}
|
|
|
|
|
|
2015-08-21 10:08:41 -07:00
|
|
|
DrawButton(m_CachedActualSize,
|
2004-12-16 16:05:37 -08:00
|
|
|
bz,
|
|
|
|
|
*sprite,
|
|
|
|
|
*sprite_over,
|
|
|
|
|
*sprite_pressed,
|
2004-12-17 08:20:08 -08:00
|
|
|
*sprite_disabled,
|
2005-07-24 01:29:02 -07:00
|
|
|
cell_id);
|
2004-05-28 21:06:50 -07:00
|
|
|
}
|