Pyrogenesis  trunk
IGUIButtonBehavior.h
Go to the documentation of this file.
1 /* Copyright (C) 2015 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 /*
19 GUI Object Base - Button Behavior
20 
21 --Overview--
22 
23  Interface class that enhance the IGUIObject with
24  buttony behavior (click and release to click a button),
25  and the GUI message GUIM_PRESSED.
26  When creating a class with extended settings and
27  buttony behavior, just do a multiple inheritance.
28 
29 --More info--
30 
31  Check GUI.h
32 
33 */
34 
35 #ifndef INCLUDED_IGUIBUTTONBEHAVIOR
36 #define INCLUDED_IGUIBUTTONBEHAVIOR
37 
38 #include "GUI.h"
39 
40 class CGUISpriteInstance;
41 
42 /**
43  * Appends button behaviours to the IGUIObject.
44  * Can be used with multiple inheritance alongside
45  * IGUISettingsObject and such.
46  *
47  * @see IGUIObject
48  */
49 class IGUIButtonBehavior : virtual public IGUIObject
50 {
51 public:
53  virtual ~IGUIButtonBehavior();
54 
55  /**
56  * @see IGUIObject#HandleMessage()
57  */
58  virtual void HandleMessage(SGUIMessage& Message);
59 
60  /**
61  * This is a function that lets a button being drawn,
62  * it regards if it's over, disabled, pressed and such.
63  * You input sprite names and area and it'll output
64  * it accordingly.
65  *
66  * This class is meant to be used manually in Draw()
67  *
68  * @param rect Rectangle in which the sprite should be drawn
69  * @param z Z-value
70  * @param sprite Sprite drawn when not pressed, hovered or disabled
71  * @param sprite_over Sprite drawn when m_MouseHovering is true
72  * @param sprite_pressed Sprite drawn when m_Pressed is true
73  * @param sprite_disabled Sprite drawn when "enabled" is false
74  * @param cell_id Identifies the icon to be used (if the sprite contains
75  * cell-using images)
76  */
77  void DrawButton(const CRect& rect, const float& z, CGUISpriteInstance& sprite, CGUISpriteInstance& sprite_over, CGUISpriteInstance& sprite_pressed, CGUISpriteInstance& sprite_disabled, int cell_id);
78 
79  /**
80  * Choosing which color of the following according to object enabled/hovered/pressed status:
81  * textcolor_disabled -- disabled
82  * textcolor_pressed -- pressed
83  * textcolor_over -- hovered
84  */
86 
87 
88 protected:
89  /**
90  * @see IGUIObject#ResetStates()
91  */
92  virtual void ResetStates()
93  {
94  // Notify the gui that we aren't hovered anymore
95  UpdateMouseOver(NULL);
96  m_Pressed = false;
97  m_PressedRight = false;
98  }
99 
100  /**
101  * Everybody knows how a button works, you don't simply press it,
102  * you have to first press the button, and then release it...
103  * in between those two steps you can actually leave the button
104  * area, as long as you release it within the button area... Anyway
105  * this lets us know we are done with step one (clicking).
106  */
107  bool m_Pressed;
109 };
110 
111 #endif // INCLUDED_IGUIBUTTONBEHAVIOR
Definition: Shapes.h:36
bool m_PressedRight
Definition: IGUIButtonBehavior.h:108
Base settings, all objects possess these settings in their m_BaseSettings Instructions can be found i...
Definition: IGUIObject.h:117
CColor ChooseColor()
Choosing which color of the following according to object enabled/hovered/pressed status: textcolor_d...
Definition: IGUIButtonBehavior.cpp:134
void DrawButton(const CRect &rect, const float &z, CGUISpriteInstance &sprite, CGUISpriteInstance &sprite_over, CGUISpriteInstance &sprite_pressed, CGUISpriteInstance &sprite_disabled, int cell_id)
This is a function that lets a button being drawn, it regards if it&#39;s over, disabled, pressed and such.
Definition: IGUIButtonBehavior.cpp:166
IGUIButtonBehavior()
Definition: IGUIButtonBehavior.cpp:25
bool m_Pressed
Everybody knows how a button works, you don&#39;t simply press it, you have to first press the button...
Definition: IGUIButtonBehavior.h:107
virtual void ResetStates()
Definition: IGUIButtonBehavior.h:92
void UpdateMouseOver(IGUIObject *const &pMouseOver)
Inputes the object that is currently hovered, this function updates this object accordingly (i...
Definition: IGUIObject.cpp:190
Definition: CGUISprite.h:158
Appends button behaviours to the IGUIObject.
Definition: IGUIButtonBehavior.h:49
Message send to IGUIObject::HandleMessage() in order to give life to Objects manually with a derived ...
Definition: GUIbase.h:91
virtual ~IGUIButtonBehavior()
Definition: IGUIButtonBehavior.cpp:29
virtual void HandleMessage(SGUIMessage &Message)
Definition: IGUIButtonBehavior.cpp:33
Rectangle class used for screen rectangles.
Definition: Shapes.h:73