Line data Source code
1 : /* Copyright (C) 2021 Wildfire Games.
2 : * This file is part of 0 A.D.
3 : *
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.
8 : *
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.
13 : *
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/>.
16 : */
17 :
18 : #include "precompiled.h"
19 :
20 : #include "CCheckBox.h"
21 :
22 : #include "gui/CGUI.h"
23 :
24 0 : CCheckBox::CCheckBox(CGUI& pGUI)
25 : : IGUIObject(pGUI),
26 : IGUIButtonBehavior(*static_cast<IGUIObject*>(this)),
27 : m_Checked(this, "checked"),
28 : m_SpriteUnchecked(this, "sprite"),
29 : m_SpriteUncheckedOver(this, "sprite_over"),
30 : m_SpriteUncheckedPressed(this, "sprite_pressed"),
31 : m_SpriteUncheckedDisabled(this, "sprite_disabled"),
32 : m_SpriteChecked(this, "sprite2"),
33 : m_SpriteCheckedOver(this, "sprite2_over"),
34 : m_SpriteCheckedPressed(this, "sprite2_pressed"),
35 0 : m_SpriteCheckedDisabled(this, "sprite2_disabled")
36 : {
37 0 : }
38 :
39 0 : CCheckBox::~CCheckBox()
40 : {
41 0 : }
42 :
43 0 : void CCheckBox::ResetStates()
44 : {
45 0 : IGUIObject::ResetStates();
46 0 : IGUIButtonBehavior::ResetStates();
47 0 : }
48 :
49 0 : void CCheckBox::HandleMessage(SGUIMessage& Message)
50 : {
51 0 : IGUIObject::HandleMessage(Message);
52 0 : IGUIButtonBehavior::HandleMessage(Message);
53 :
54 0 : switch (Message.type)
55 : {
56 0 : case GUIM_PRESSED:
57 : {
58 0 : m_Checked.Set(!m_Checked, true);
59 0 : break;
60 : }
61 :
62 0 : default:
63 0 : break;
64 : }
65 0 : }
66 :
67 0 : void CCheckBox::Draw(CCanvas2D& canvas)
68 : {
69 0 : m_pGUI.DrawSprite(
70 : m_Checked ?
71 0 : GetButtonSprite(m_SpriteChecked, m_SpriteCheckedOver, m_SpriteCheckedPressed, m_SpriteCheckedDisabled) :
72 0 : GetButtonSprite(m_SpriteUnchecked, m_SpriteUncheckedOver, m_SpriteUncheckedPressed, m_SpriteUncheckedDisabled),
73 : canvas,
74 : m_CachedActualSize);
75 0 : }
|