Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
IGUIButtonBehavior.h
Go to the documentation of this file.
1 /* Copyright (C) 2012 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 //--------------------------------------------------------
39 // Includes / Compiler directives
40 //--------------------------------------------------------
41 #include "GUI.h"
42 
43 class CGUISpriteInstance;
44 
45 //--------------------------------------------------------
46 // Macros
47 //--------------------------------------------------------
48 
49 //--------------------------------------------------------
50 // Types
51 //--------------------------------------------------------
52 
53 //--------------------------------------------------------
54 // Declarations
55 //--------------------------------------------------------
56 
57 /**
58  * Appends button behaviours to the IGUIObject.
59  * Can be used with multiple inheritance alongside
60  * IGUISettingsObject and such.
61  *
62  * @see IGUIObject
63  */
64 class IGUIButtonBehavior : virtual public IGUIObject
65 {
66 public:
68  virtual ~IGUIButtonBehavior();
69 
70  /**
71  * @see IGUIObject#HandleMessage()
72  */
73  virtual void HandleMessage(SGUIMessage &Message);
74 
75  /**
76  * This is a function that lets a button being drawn,
77  * it regards if it's over, disabled, pressed and such.
78  * You input sprite names and area and it'll output
79  * it accordingly.
80  *
81  * This class is meant to be used manually in Draw()
82  *
83  * @param rect Rectangle in which the sprite should be drawn
84  * @param z Z-value
85  * @param sprite Sprite drawn when not pressed, hovered or disabled
86  * @param sprite_over Sprite drawn when m_MouseHovering is true
87  * @param sprite_pressed Sprite drawn when m_Pressed is true
88  * @param sprite_disabled Sprite drawn when "enabled" is false
89  * @param cell_id Identifies the icon to be used (if the sprite contains
90  * cell-using images)
91  */
92  void DrawButton(const CRect &rect,
93  const float &z,
94  CGUISpriteInstance& sprite,
95  CGUISpriteInstance& sprite_over,
96  CGUISpriteInstance& sprite_pressed,
97  CGUISpriteInstance& sprite_disabled,
98  int cell_id);
99 
100  /**
101  * Choosing which color of the following according to object enabled/hovered/pressed status:
102  * textcolor_disabled -- disabled
103  * textcolor_pressed -- pressed
104  * textcolor_over -- hovered
105  */
107 
108 
109 protected:
110  /**
111  * @see IGUIObject#ResetStates()
112  */
113  virtual void ResetStates()
114  {
115  // Notify the gui that we aren't hovered anymore
116  UpdateMouseOver(NULL);
117  m_Pressed = false;
118  m_PressedRight = false;
119  }
120 
121  /**
122  * Everybody knows how a button works, you don't simply press it,
123  * you have to first press the button, and then release it...
124  * in between those two steps you can actually leave the button
125  * area, as long as you release it within the button area... Anyway
126  * this lets us know we are done with step one (clicking).
127  */
128  bool m_Pressed;
130 };
131 
132 #endif
Definition: Overlay.h:34
Base settings, all objects possess these settings in their m_BaseSettings Instructions can be found i...
Definition: IGUIObject.h:140
CColor ChooseColor()
Choosing which color of the following according to object enabled/hovered/pressed status: textcolor_d...
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.
bool m_Pressed
Everybody knows how a button works, you don&#39;t simply press it, you have to first press the button...
virtual void ResetStates()
void UpdateMouseOver(IGUIObject *const &pMouseOver)
Inputes the object that is currently hovered, this function updates this object accordingly (i...
Definition: IGUIObject.cpp:212
Appends button behaviours to the IGUIObject.
Message send to IGUIObject::HandleMessage() in order to give life to Objects manually with a derived ...
Definition: GUIbase.h:106
virtual void HandleMessage(SGUIMessage &Message)
Rectangle class used for screen rectangles.
Definition: Overlay.h:71