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 "CButton.h"
|
2003-11-03 08:22:45 -08:00
|
|
|
|
2019-07-26 11:57:28 -07:00
|
|
|
#include "gui/CGUIColor.h"
|
2006-06-01 19:10:27 -07:00
|
|
|
#include "lib/ogl.h"
|
2003-11-24 18:47:12 -08:00
|
|
|
|
2019-08-01 13:20:24 -07:00
|
|
|
CButton::CButton(CGUI* pGUI)
|
2019-08-01 16:55:10 -07:00
|
|
|
: IGUIObject(pGUI), IGUIButtonBehavior(pGUI), IGUITextOwner(pGUI)
|
2003-11-03 08:22:45 -08:00
|
|
|
{
|
2019-08-03 19:20:08 -07:00
|
|
|
AddSetting<float>("buffer_zone");
|
|
|
|
|
AddSetting<CGUIString>("caption");
|
|
|
|
|
AddSetting<int>("cell_id");
|
|
|
|
|
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<EAlign>("text_align");
|
|
|
|
|
AddSetting<EVAlign>("text_valign");
|
|
|
|
|
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
|
|
|
|
|
|
|
|
// 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()
|
|
|
|
|
{
|
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())
|
2004-07-31 06:37:35 -07:00
|
|
|
// 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!
|
2009-11-03 13:46:35 -08:00
|
|
|
font = L"default";
|
2004-07-31 06:37:35 -07:00
|
|
|
|
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-01-01 04:06:17 -08: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(), 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
|
|
|
}
|
|
|
|
|
|
2015-08-21 10:08:41 -07:00
|
|
|
void CButton::HandleMessage(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);
|
2003-11-03 08:22:45 -08:00
|
|
|
}
|
|
|
|
|
|
2015-08-21 10:08:41 -07:00
|
|
|
void CButton::Draw()
|
2003-11-03 08:22:45 -08:00
|
|
|
{
|
2004-05-28 21:06:50 -07:00
|
|
|
float bz = GetBufferedZ();
|
|
|
|
|
|
2015-08-21 10:08:41 -07:00
|
|
|
CGUISpriteInstance* sprite;
|
|
|
|
|
CGUISpriteInstance* sprite_over;
|
|
|
|
|
CGUISpriteInstance* sprite_pressed;
|
|
|
|
|
CGUISpriteInstance* sprite_disabled;
|
2004-12-18 05:32:00 -08:00
|
|
|
int cell_id;
|
2004-05-28 21:06:50 -07:00
|
|
|
|
2010-01-07 11:00:56 -08:00
|
|
|
// Statically initialise some strings, so we don't have to do
|
|
|
|
|
// lots of allocation every time this function is called
|
2015-08-21 10:08:41 -07:00
|
|
|
static const CStr strSprite("sprite");
|
|
|
|
|
static const CStr strSpriteOver("sprite_over");
|
|
|
|
|
static const CStr strSpritePressed("sprite_pressed");
|
|
|
|
|
static const CStr strSpriteDisabled("sprite_disabled");
|
|
|
|
|
static const CStr strCellId("cell_id");
|
2010-01-07 11:00:56 -08:00
|
|
|
|
|
|
|
|
GUI<CGUISpriteInstance>::GetSettingPointer(this, strSprite, sprite);
|
|
|
|
|
GUI<CGUISpriteInstance>::GetSettingPointer(this, strSpriteOver, sprite_over);
|
|
|
|
|
GUI<CGUISpriteInstance>::GetSettingPointer(this, strSpritePressed, sprite_pressed);
|
|
|
|
|
GUI<CGUISpriteInstance>::GetSettingPointer(this, strSpriteDisabled, sprite_disabled);
|
|
|
|
|
GUI<int>::GetSetting(this, strCellId, 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
|
|
|
|
2019-07-26 11:57:28 -07:00
|
|
|
CGUIColor color = ChooseColor();
|
2011-07-17 10:30:07 -07:00
|
|
|
DrawText(0, color, m_TextPos, bz+0.1f);
|
2003-11-24 09:13:37 -08:00
|
|
|
}
|