Gamedev Framework (gf)  0.12.0
A C++14 framework for 2D games
Widget.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2019 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 "Transformable.h"
28 #include "Vector.h"
29 
30 namespace gf {
31 #ifndef DOXYGEN_SHOULD_SKIP_THIS
32 inline namespace v1 {
33 #endif
34 
35  struct RenderStates;
36  class RenderTarget;
37 
44  enum class WidgetState {
45  Disabled,
46  Default,
47  Selected,
48  };
49 
54  class GF_API Widget : public Transformable {
55  public:
61  Widget();
62 
69  virtual bool contains(Vector2f coords) = 0;
70 
74  void setDisabled();
75 
81  bool isDisabled() const noexcept {
82  return m_state == WidgetState::Disabled;
83  }
84 
88  void setDefault();
89 
95  bool isDefault() const noexcept {
96  return m_state == WidgetState::Default;
97  }
98 
102  void setSelected();
103 
109  bool isSelected() const {
110  return m_state == WidgetState::Selected;
111  }
112 
119  void setState(WidgetState state);
120 
126  WidgetState getState() const noexcept {
127  return m_state;
128  }
129 
136  void setCallback(std::function<void()> callback);
137 
143  void triggerCallback();
144 
145  protected:
149  virtual void onStateChanged();
150 
156  virtual void triggered();
157 
158  private:
159  WidgetState m_state;
160  std::function<void()> m_callback;
161  };
162 
163 #ifndef DOXYGEN_SHOULD_SKIP_THIS
164 }
165 #endif
166 }
167 
168 #endif // GF_WIDGET_H
Decomposed transform defined by a position, a rotation and a scale.
Definition: Transformable.h:95
WidgetState
State of a widget.
Definition: Widget.h:44
The button is active once.
bool isDisabled() const noexcept
Check if the widget is disabled.
Definition: Widget.h:81
WidgetState getState() const noexcept
Get the state of the widget.
Definition: Widget.h:126
The widgets abstract class.
Definition: Widget.h:54
The default widget state.
The widget is disabled.
The namespace for gf classes.
Definition: Action.h:35
bool isSelected() const
Check if the widget is selected.
Definition: Widget.h:109
bool isDefault() const noexcept
Check if the widget is in default state.
Definition: Widget.h:95
The widget is selected.