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 : #ifndef INCLUDED_CBUTTON
19 : #define INCLUDED_CBUTTON
20 :
21 : #include "gui/CGUISprite.h"
22 : #include "gui/ObjectBases/IGUIButtonBehavior.h"
23 : #include "gui/ObjectBases/IGUIObject.h"
24 : #include "gui/ObjectBases/IGUITextOwner.h"
25 : #include "gui/SettingTypes/CGUIString.h"
26 : #include "gui/SettingTypes/MouseEventMask.h"
27 : #include "maths/Vector2D.h"
28 :
29 : class CButton : public IGUIObject, public IGUITextOwner, public IGUIButtonBehavior
30 : {
31 0 : GUI_OBJECT(CButton)
32 : public:
33 : CButton(CGUI& pGUI);
34 : virtual ~CButton();
35 :
36 : /**
37 : * @see IGUIObject#ResetStates()
38 : */
39 : virtual void ResetStates();
40 :
41 : /**
42 : * @see IGUIObject#UpdateCachedSize()
43 : */
44 : virtual void UpdateCachedSize();
45 :
46 : /**
47 : * @return the object text size.
48 : */
49 : CSize2D GetTextSize();
50 :
51 : /**
52 : * @see IGUIObject#HandleMessage()
53 : */
54 : virtual void HandleMessage(SGUIMessage& Message);
55 :
56 : /**
57 : * Draws the Button
58 : */
59 : virtual void Draw(CCanvas2D& canvas);
60 :
61 : /**
62 : * @see IGUIObject#IsMouseOver()
63 : */
64 : virtual bool IsMouseOver() const;
65 :
66 : protected:
67 : /**
68 : * Sets up text, should be called every time changes has been
69 : * made that can change the visual.
70 : */
71 : void SetupText();
72 :
73 : /**
74 : * Picks the text color depending on current object settings.
75 : */
76 : const CGUIColor& ChooseColor();
77 :
78 : /**
79 : * Placement of text.
80 : */
81 : CVector2D m_TextPos;
82 :
83 : virtual void CreateJSObject();
84 :
85 : // Settings
86 : CGUISimpleSetting<float> m_BufferZone;
87 : CGUISimpleSetting<CGUIString> m_Caption;
88 : CGUISimpleSetting<CStrW> m_Font;
89 : CGUISimpleSetting<CGUISpriteInstance> m_Sprite;
90 : CGUISimpleSetting<CGUISpriteInstance> m_SpriteOver;
91 : CGUISimpleSetting<CGUISpriteInstance> m_SpritePressed;
92 : CGUISimpleSetting<CGUISpriteInstance> m_SpriteDisabled;
93 : CGUISimpleSetting<CGUIColor> m_TextColor;
94 : CGUISimpleSetting<CGUIColor> m_TextColorOver;
95 : CGUISimpleSetting<CGUIColor> m_TextColorPressed;
96 : CGUISimpleSetting<CGUIColor> m_TextColorDisabled;
97 : CGUIMouseEventMask m_MouseEventMask;
98 : };
99 :
100 : #endif // INCLUDED_CBUTTON
|