Gamedev Framework (gf)
1.2.0
A C++17 framework for 2D games
include
gf
Widget.h
1
/*
2
* Gamedev Framework (gf)
3
* Copyright (C) 2016-2022 Julien Bernard
4
* Copyright (C) 2018 Lilian Franchi
5
*
6
* This software is provided 'as-is', without any express or implied
7
* warranty. In no event will the authors be held liable for any damages
8
* arising from the use of this software.
9
*
10
* Permission is granted to anyone to use this software for any purpose,
11
* including commercial applications, and to alter it and redistribute it
12
* freely, subject to the following restrictions:
13
*
14
* 1. The origin of this software must not be misrepresented; you must not
15
* claim that you wrote the original software. If you use this software
16
* in a product, an acknowledgment in the product documentation would be
17
* appreciated but is not required.
18
* 2. Altered source versions must be plainly marked as such, and must not be
19
* misrepresented as being the original software.
20
* 3. This notice may not be removed or altered from any source distribution.
21
*/
22
#ifndef GF_WIDGET_H
23
#define GF_WIDGET_H
24
25
#include <functional>
26
27
#include "GraphicsApi.h"
28
#include "Transformable.h"
29
#include "Vector.h"
30
31
namespace
gf
{
32
#ifndef DOXYGEN_SHOULD_SKIP_THIS
33
inline
namespace
v1 {
34
#endif
35
36
struct
RenderStates;
37
class
RenderTarget;
38
45
enum class
WidgetState
{
46
Disabled
,
47
Default
,
48
Selected
,
49
};
50
55
class
GF_GRAPHICS_API
Widget
:
public
Transformable
{
56
public
:
62
Widget
();
63
70
virtual
bool
contains
(
Vector2f
coords) = 0;
71
75
void
setDisabled
();
76
82
bool
isDisabled
() const noexcept {
83
return
m_state ==
WidgetState::Disabled
;
84
}
85
89
void
setDefault
();
90
96
bool
isDefault
() const noexcept {
97
return
m_state ==
WidgetState::Default
;
98
}
99
103
void
setSelected
();
104
110
bool
isSelected
()
const
{
111
return
m_state ==
WidgetState::Selected
;
112
}
113
120
void
setState
(
WidgetState
state);
121
127
WidgetState
getState
() const noexcept {
128
return
m_state;
129
}
130
137
void
setCallback
(std::function<
void
()> callback);
138
144
void
triggerCallback
();
145
146
protected
:
150
virtual
void
onStateChanged
();
151
157
virtual
void
triggered
();
158
159
private
:
160
WidgetState
m_state;
161
std::function<void()> m_callback;
162
};
163
164
#ifndef DOXYGEN_SHOULD_SKIP_THIS
165
}
166
#endif
167
}
168
169
#endif
// GF_WIDGET_H
gf::Transformable
Decomposed transform defined by a position, a rotation and a scale.
Definition:
Transformable.h:95
gf::Widget
The widgets abstract class.
Definition:
Widget.h:55
gf::Widget::getState
WidgetState getState() const noexcept
Get the state of the widget.
Definition:
Widget.h:127
gf::Widget::setCallback
void setCallback(std::function< void()> callback)
Set the callback of the widget.
gf::Widget::setSelected
void setSelected()
Select the widget.
gf::Widget::triggered
virtual void triggered()
Function called when the callback is triggered.
gf::Widget::onStateChanged
virtual void onStateChanged()
Function called when the state changes.
gf::Widget::isDisabled
bool isDisabled() const noexcept
Check if the widget is disabled.
Definition:
Widget.h:82
gf::Widget::isDefault
bool isDefault() const noexcept
Check if the widget is in default state.
Definition:
Widget.h:96
gf::Widget::Widget
Widget()
Constructor.
gf::Widget::triggerCallback
void triggerCallback()
Execute the callback function.
gf::Widget::setDisabled
void setDisabled()
Disable the widget.
gf::Widget::setState
void setState(WidgetState state)
Set the state of the widget directly.
gf::Widget::contains
virtual bool contains(Vector2f coords)=0
Check if the widget contains the coordinates.
gf::Widget::setDefault
void setDefault()
Set the widget to it's default state.
gf::Widget::isSelected
bool isSelected() const
Check if the widget is selected.
Definition:
Widget.h:110
gf::WidgetState
WidgetState
State of a widget.
Definition:
Widget.h:45
gf::WidgetState::Default
@ Default
The default widget state.
gf::WidgetState::Selected
@ Selected
The widget is selected.
gf::WidgetState::Disabled
@ Disabled
The widget is disabled.
gf
The namespace for gf classes.
gf::Vector< float, 2 >
Generated by
1.9.4