Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
CButton.h
Go to the documentation of this file.
1/* Copyright (C) 2026 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/CGUISetting.h"
22#include "gui/CGUISprite.h"
29#include "maths/Vector2D.h"
30#include "ps/CStr.h"
31
32class CGUI;
33class CSize2D;
34
35class CButton : public IGUIObject, public IGUITextOwner, public IGUIButtonBehavior
36{
38public:
39 CButton(CGUI& pGUI);
40
41 /**
42 * @see IGUIObject#ResetStates()
43 */
44 virtual void ResetStates();
45
46 /**
47 * @see IGUIObject#HandleSizeChanged()
48 */
49 virtual void HandleSizeChanged();
50
51 /**
52 * @return the object text size.
53 */
55
57
58 /**
59 * @see IGUIObject#HandleMessage()
60 */
61 virtual void HandleMessage(SGUIMessage& Message);
62
63 /**
64 * Draws the Button
65 */
66 virtual void Draw(CCanvas2D& canvas);
67
68 /**
69 * @see IGUIObject#IsMouseOver()
70 */
71 virtual bool IsMouseOver() const;
72
73protected:
74 /**
75 * Sets up text, should be called every time changes has been
76 * made that can change the visual.
77 */
78 void SetupText();
79
80 /**
81 * Picks the text color depending on current object settings.
82 */
83 const CGUIColor& ChooseColor();
84
85 /**
86 * Placement of text.
87 */
89
90 virtual void CreateJSObject();
91
92 // Settings
105};
106
107#endif // INCLUDED_CBUTTON
#define GUI_OBJECT(obj)
Definition: IGUIObject.h:53
Definition: CButton.h:36
CVector2D m_TextPos
Placement of text.
Definition: CButton.h:88
virtual void HandleMessage(SGUIMessage &Message)
Definition: CButton.cpp:83
virtual void CreateJSObject()
Creates the JS object representing this page upon first use.
CGUISimpleSetting< CStrW > m_Font
Definition: CButton.h:95
CSize2D GetPreferredTextSize()
Definition: CButton.cpp:78
virtual bool IsMouseOver() const
Definition: CButton.cpp:101
virtual void Draw(CCanvas2D &canvas)
Draws the Button.
Definition: CButton.cpp:90
CGUISimpleSetting< CGUISpriteInstance > m_Sprite
Definition: CButton.h:96
CGUIMouseEventMask m_MouseEventMask
Definition: CButton.h:104
const CGUIColor & ChooseColor()
Picks the text color depending on current object settings.
Definition: CButton.cpp:110
CGUISimpleSetting< CGUISpriteInstance > m_SpriteOver
Definition: CButton.h:97
virtual void ResetStates()
Definition: CButton.cpp:60
CGUISimpleSetting< CGUIColor > m_TextColorOver
Definition: CButton.h:101
virtual void HandleSizeChanged()
Definition: CButton.cpp:66
CGUISimpleSetting< float > m_BufferZone
Definition: CButton.h:93
CGUISimpleSetting< CGUIColor > m_TextColor
Definition: CButton.h:100
void SetupText()
Sets up text, should be called every time changes has been made that can change the visual.
Definition: CButton.cpp:52
CGUISimpleSetting< CGUISpriteInstance > m_SpritePressed
Definition: CButton.h:98
CGUISimpleSetting< CGUIColor > m_TextColorPressed
Definition: CButton.h:102
CGUISimpleSetting< CGUIString > m_Caption
Definition: CButton.h:94
CSize2D GetTextSize()
Definition: CButton.cpp:72
CGUISimpleSetting< CGUISpriteInstance > m_SpriteDisabled
Definition: CButton.h:99
CGUISimpleSetting< CGUIColor > m_TextColorDisabled
Definition: CButton.h:103
CButton(CGUI &pGUI)
Definition: CButton.cpp:32
Definition: Canvas2D.h:36
A custom shape that changes the object's "over-ability", and thus where one can click on it.
Definition: MouseEventMask.h:42
The main object that represents a whole GUI page.
Definition: CGUI.h:80
Definition: Size2D.h:25
Definition: Vector2D.h:32
Appends button behaviours to the IGUIObject.
Definition: IGUIButtonBehavior.h:43
GUI object such as a button or an input-box.
Definition: IGUIObject.h:63
Framework for handling Output text.
Definition: IGUITextOwner.h:55
Same as the CColor class, but this one can also parse colors predefined in the GUI page (such as "yel...
Definition: CGUIColor.h:31
Message send to IGUIObject::HandleMessage() in order to give life to Objects manually with a derived ...
Definition: SGUIMessage.h:73