/
buttonwidget.h
104 lines (84 loc) · 2.8 KB
/
buttonwidget.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/** @file buttonwidget.h Clickable button widget.
*
* @authors Copyright (c) 2013 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* LGPL: http://www.gnu.org/licenses/lgpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details. You should have received a copy of
* the GNU Lesser General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/
#ifndef LIBAPPFW_BUTTONWIDGET_H
#define LIBAPPFW_BUTTONWIDGET_H
#include <de/Action>
#include <de/Observers>
#include "../LabelWidget"
namespace de {
/**
* Clickable button widget.
*
* @ingroup gui
*/
class LIBAPPFW_PUBLIC ButtonWidget : public LabelWidget
{
public:
enum State {
Up,
Hover,
Down
};
/**
* Notified when the state of the button changes.
*/
DENG2_DEFINE_AUDIENCE(StateChange, void buttonStateChanged(ButtonWidget &button, State state))
/**
* Notified immediately before the button's action is to be triggered. Will
* occur regardless of whether an action has been set.
*/
DENG2_DEFINE_AUDIENCE(Press, void buttonPressed(ButtonWidget &button))
/**
* Notified when the button's action is triggered (could be before or after
* the action). Will not occur if no action has been defined for the
* button.
*/
DENG2_DEFINE_AUDIENCE(Triggered, void buttonActionTriggered(ButtonWidget &button))
public:
ButtonWidget(String const &name = "");
enum HoverColorMode {
ReplaceColor,
ModulateColor
};
/**
* Text color to use in the Hover state. The default is to use the normal text
* color of the button (label).
*
* @param hoverTextId Style color identifier.
*/
void setHoverTextColor(DotPath const &hoverTextId, HoverColorMode mode = ModulateColor);
void setBackgroundColor(DotPath const &bgColorId);
/**
* Sets the action of the button. It gets triggered when the button is
* pressed.
*
* @param action Action instance. Widget holds a reference.
*/
void setAction(RefArg<Action> action);
Action const *action() const;
State state() const;
// Events.
void update();
bool handleEvent(Event const &event);
protected:
void updateModelViewProjection(GLUniform &uMvp);
private:
DENG2_PRIVATE(d)
};
} // namespace de
#endif // LIBAPPFW_BUTTONWIDGET_H