Pyrogenesis  trunk
IGUIButtonBehavior.h
Go to the documentation of this file.
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 /*
19  Interface class that enhance the IGUIObject with
20  buttony behavior (click and release to click a button),
21  and the GUI message GUIM_PRESSED.
22  When creating a class with extended settings and
23  buttony behavior, just do a multiple inheritance.
24 */
25 
26 #ifndef INCLUDED_IGUIBUTTONBEHAVIOR
27 #define INCLUDED_IGUIBUTTONBEHAVIOR
28 
30 #include "ps/CStr.h"
31 
32 class CGUISpriteInstance;
33 
34 /**
35  * Appends button behaviours to the IGUIObject.
36  * Can be used with multiple inheritance alongside
37  * IGUISettingsObject and such.
38  */
40 {
42 
43 public:
45  virtual ~IGUIButtonBehavior();
46 
47  /**
48  * @see IGUIObject#HandleMessage()
49  */
50  virtual void HandleMessage(SGUIMessage& Message);
51 
52  /**
53  * This is a function that lets a button being drawn,
54  * it regards if it's over, disabled, pressed and such.
55  *
56  * @param sprite Sprite drawn when not pressed, hovered or disabled
57  * @param sprite_over Sprite drawn when m_MouseHovering is true
58  * @param sprite_pressed Sprite drawn when m_Pressed is true
59  * @param sprite_disabled Sprite drawn when "enabled" is false
60  */
61  const CGUISpriteInstance& GetButtonSprite(const CGUISpriteInstance& sprite, const CGUISpriteInstance& sprite_over, const CGUISpriteInstance& sprite_pressed, const CGUISpriteInstance& sprite_disabled) const;
62 
63 protected:
64  static const CStr EventNamePress;
65  static const CStr EventNamePressRight;
66  static const CStr EventNamePressRightDisabled;
67  static const CStr EventNameDoublePress;
68  static const CStr EventNameDoublePressRight;
69  static const CStr EventNameRelease;
70  static const CStr EventNameReleaseRight;
71 
72  /**
73  * @see IGUIObject#ResetStates()
74  */
75  virtual void ResetStates();
76 
77  /**
78  * Everybody knows how a button works, you don't simply press it,
79  * you have to first press the button, and then release it...
80  * in between those two steps you can actually leave the button
81  * area, as long as you release it within the button area... Anyway
82  * this lets us know we are done with step one (clicking).
83  */
84  bool m_Pressed;
86 
92 
93 private:
94  /**
95  * Reference to the IGUIObject.
96  * Private, because we don't want to inherit it in multiple classes.
97  */
99 };
100 
101 #endif // INCLUDED_IGUIBUTTONBEHAVIOR
CGUISimpleSetting< CStrW > m_SoundPressed
Definition: IGUIButtonBehavior.h:90
CGUISimpleSetting< CStrW > m_SoundReleased
Definition: IGUIButtonBehavior.h:91
static const CStr EventNamePressRightDisabled
Definition: IGUIButtonBehavior.h:66
static const CStr EventNameReleaseRight
Definition: IGUIButtonBehavior.h:70
IGUIObject & m_pObject
Reference to the IGUIObject.
Definition: IGUIButtonBehavior.h:98
static const CStr EventNameRelease
Definition: IGUIButtonBehavior.h:69
bool m_PressedRight
Definition: IGUIButtonBehavior.h:85
GUI object such as a button or an input-box.
Definition: IGUIObject.h:59
IGUIButtonBehavior(IGUIObject &pObject)
Definition: IGUIButtonBehavior.cpp:34
static const CStr EventNameDoublePress
Definition: IGUIButtonBehavior.h:67
static const CStr EventNamePress
Definition: IGUIButtonBehavior.h:64
CGUISimpleSetting< CStrW > m_SoundLeave
Definition: IGUIButtonBehavior.h:89
CGUISimpleSetting< CStrW > m_SoundDisabled
Definition: IGUIButtonBehavior.h:87
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:84
virtual void ResetStates()
Definition: IGUIButtonBehavior.cpp:50
static const CStr EventNameDoublePressRight
Definition: IGUIButtonBehavior.h:68
CGUISimpleSetting< CStrW > m_SoundEnter
Definition: IGUIButtonBehavior.h:88
const CGUISpriteInstance & GetButtonSprite(const CGUISpriteInstance &sprite, const CGUISpriteInstance &sprite_over, const CGUISpriteInstance &sprite_pressed, const CGUISpriteInstance &sprite_disabled) const
This is a function that lets a button being drawn, it regards if it&#39;s over, disabled, pressed and such.
Definition: IGUIButtonBehavior.cpp:141
static const CStr EventNamePressRight
Definition: IGUIButtonBehavior.h:65
Definition: CGUISprite.h:133
Appends button behaviours to the IGUIObject.
Definition: IGUIButtonBehavior.h:39
Message send to IGUIObject::HandleMessage() in order to give life to Objects manually with a derived ...
Definition: SGUIMessage.h:67
NONCOPYABLE(IGUIButtonBehavior)
virtual ~IGUIButtonBehavior()
Definition: IGUIButtonBehavior.cpp:46
virtual void HandleMessage(SGUIMessage &Message)
Definition: IGUIButtonBehavior.cpp:67