Gamedev Framework (gf)  0.11.0
A C++14 framework for 2D games
Widget.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2018 Lilian Franchi
4  *
5  * This software is provided 'as-is', without any express or implied
6  * warranty. In no event will the authors be held liable for any damages
7  * arising from the use of this software.
8  *
9  * Permission is granted to anyone to use this software for any purpose,
10  * including commercial applications, and to alter it and redistribute it
11  * freely, subject to the following restrictions:
12  *
13  * 1. The origin of this software must not be misrepresented; you must not
14  * claim that you wrote the original software. If you use this software
15  * in a product, an acknowledgment in the product documentation would be
16  * appreciated but is not required.
17  * 2. Altered source versions must be plainly marked as such, and must not be
18  * misrepresented as being the original software.
19  * 3. This notice may not be removed or altered from any source distribution.
20  */
21 #ifndef GF_WIDGET_H
22 #define GF_WIDGET_H
23 
24 #include <functional>
25 
26 #include "Transformable.h"
27 #include "Vector.h"
28 
29 namespace gf {
30 #ifndef DOXYGEN_SHOULD_SKIP_THIS
31 inline namespace v1 {
32 #endif
33 
34  struct RenderStates;
35  class RenderTarget;
36 
43  enum class WidgetState {
44  Disabled,
45  Default,
46  Selected,
47  };
48 
53  class GF_API Widget : public Transformable {
54  public:
60  Widget();
61 
68  virtual bool contains(Vector2f coords) = 0;
69 
73  void setDisabled();
74 
80  bool isDisabled() const noexcept {
81  return m_state == WidgetState::Disabled;
82  }
83 
87  void setDefault();
88 
94  bool isDefault() const noexcept {
95  return m_state == WidgetState::Default;
96  }
97 
101  void setSelected();
102 
108  bool isSelected() const {
109  return m_state == WidgetState::Selected;
110  }
111 
118  void setState(WidgetState state);
119 
125  WidgetState getState() const noexcept {
126  return m_state;
127  }
128 
135  void setCallback(std::function<void()> callback);
136 
142  void triggerCallback();
143 
144  protected:
148  virtual void onStateChanged();
149 
155  virtual void triggered();
156 
157  private:
158  WidgetState m_state;
159  std::function<void()> m_callback;
160  };
161 
162 #ifndef DOXYGEN_SHOULD_SKIP_THIS
163 }
164 #endif
165 }
166 
167 #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:43
The button is active once.
bool isDisabled() const noexcept
Check if the widget is disabled.
Definition: Widget.h:80
WidgetState getState() const noexcept
Get the state of the widget.
Definition: Widget.h:125
The widgets abstract class.
Definition: Widget.h:53
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:108
bool isDefault() const noexcept
Check if the widget is in default state.
Definition: Widget.h:94
The widget is selected.