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