1 /* Copyright (C) 2015 Wildfire Games.
2 * This file is part of 0 A.D.
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
18 #include "precompiled.h"
26 AddSetting(GUIST_float
, "buffer_zone");
27 AddSetting(GUIST_CGUIString
, "caption");
28 AddSetting(GUIST_int
, "cell_id");
29 AddSetting(GUIST_CStrW
, "font");
30 AddSetting(GUIST_CStrW
, "sound_disabled");
31 AddSetting(GUIST_CStrW
, "sound_enter");
32 AddSetting(GUIST_CStrW
, "sound_leave");
33 AddSetting(GUIST_CStrW
, "sound_pressed");
34 AddSetting(GUIST_CStrW
, "sound_released");
35 AddSetting(GUIST_CGUISpriteInstance
, "sprite");
36 AddSetting(GUIST_CGUISpriteInstance
, "sprite_over");
37 AddSetting(GUIST_CGUISpriteInstance
, "sprite_pressed");
38 AddSetting(GUIST_CGUISpriteInstance
, "sprite_disabled");
39 AddSetting(GUIST_EAlign
, "text_align");
40 AddSetting(GUIST_EVAlign
, "text_valign");
41 AddSetting(GUIST_CColor
, "textcolor");
42 AddSetting(GUIST_CColor
, "textcolor_over");
43 AddSetting(GUIST_CColor
, "textcolor_pressed");
44 AddSetting(GUIST_CColor
, "textcolor_disabled");
45 AddSetting(GUIST_CStrW
, "tooltip");
46 AddSetting(GUIST_CStr
, "tooltip_style");
49 AddText(new SGUIText());
56 void CButton::SetupText()
61 ENSURE(m_GeneratedTexts
.size() == 1);
64 if (GUI
<CStrW
>::GetSetting(this, "font", font
) != PSRETURN_OK
|| font
.empty())
65 // Use the default if none is specified
66 // TODO Gee: (2004-08-14) Default should not be hard-coded, but be in styles!
70 GUI
<CGUIString
>::GetSetting(this, "caption", caption
);
72 float buffer_zone
= 0.f
;
73 GUI
<float>::GetSetting(this, "buffer_zone", buffer_zone
);
74 *m_GeneratedTexts
[0] = GetGUI()->GenerateText(caption
, font
, m_CachedActualSize
.GetWidth(), buffer_zone
, this);
76 CalculateTextPosition(m_CachedActualSize
, m_TextPos
, *m_GeneratedTexts
[0]);
79 void CButton::HandleMessage(SGUIMessage
& Message
)
82 IGUIButtonBehavior::HandleMessage(Message
);
83 IGUITextOwner::HandleMessage(Message
);
88 float bz
= GetBufferedZ();
90 CGUISpriteInstance
* sprite
;
91 CGUISpriteInstance
* sprite_over
;
92 CGUISpriteInstance
* sprite_pressed
;
93 CGUISpriteInstance
* sprite_disabled
;
96 // Statically initialise some strings, so we don't have to do
97 // lots of allocation every time this function is called
98 static const CStr
strSprite("sprite");
99 static const CStr
strSpriteOver("sprite_over");
100 static const CStr
strSpritePressed("sprite_pressed");
101 static const CStr
strSpriteDisabled("sprite_disabled");
102 static const CStr
strCellId("cell_id");
104 GUI
<CGUISpriteInstance
>::GetSettingPointer(this, strSprite
, sprite
);
105 GUI
<CGUISpriteInstance
>::GetSettingPointer(this, strSpriteOver
, sprite_over
);
106 GUI
<CGUISpriteInstance
>::GetSettingPointer(this, strSpritePressed
, sprite_pressed
);
107 GUI
<CGUISpriteInstance
>::GetSettingPointer(this, strSpriteDisabled
, sprite_disabled
);
108 GUI
<int>::GetSetting(this, strCellId
, cell_id
);
110 DrawButton(m_CachedActualSize
,
118 CColor color
= ChooseColor();
119 DrawText(0, color
, m_TextPos
, bz
+0.1f
);