Gamedev Framework (gf)  0.19.0
A C++17 framework for 2D games
Widget.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2021 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
Decomposed transform defined by a position, a rotation and a scale.
Definition: Transformable.h:95
bool isDisabled() const noexcept
Check if the widget is disabled.
Definition: Widget.h:82
The default widget state.
The widget is selected.
WidgetState getState() const noexcept
Get the state of the widget.
Definition: Widget.h:127
The widgets abstract class.
Definition: Widget.h:55
The namespace for gf classes.
Definition: Action.h:35
WidgetState
State of a widget.
Definition: Widget.h:45
The widget is disabled.
bool isSelected() const
Check if the widget is selected.
Definition: Widget.h:110
General purpose math vector.
Definition: Vector.h:61
bool isDefault() const noexcept
Check if the widget is in default state.
Definition: Widget.h:96