Gamedev Framework (gf)  0.8.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 "Vector.h"
27 
28 namespace gf {
29 #ifndef DOXYGEN_SHOULD_SKIP_THIS
30 inline namespace v1 {
31 #endif
32 
33  struct RenderStates;
34  class RenderTarget;
35 
42  enum class WidgetState {
43  Disabled,
44  Default,
45  Selected,
46  };
47 
52  class GF_API Widget {
53  public:
59  Widget();
60 
64  virtual ~Widget();
65 
72  virtual void render(RenderTarget &target, const RenderStates &states) = 0;
73 
80  virtual bool contains(Vector2f coords) = 0;
81 
85  void setDisabled();
86 
92  bool isDisabled() const noexcept {
93  return m_state == WidgetState::Disabled;
94  }
95 
99  void setDefault();
100 
106  bool isDefault() const noexcept {
107  return m_state == WidgetState::Default;
108  }
109 
113  void setSelected();
114 
120  bool isSelected() const {
121  return m_state == WidgetState::Selected;
122  }
123 
130  void setState(WidgetState state);
131 
137  WidgetState getState() const noexcept {
138  return m_state;
139  }
140 
147  void setCallback(std::function<void()> callback);
148 
154  void triggerCallback();
155 
156  protected:
162  virtual void triggered();
163 
164  private:
165  WidgetState m_state;
166  std::function<void()> m_callback;
167  };
168 
169 #ifndef DOXYGEN_SHOULD_SKIP_THIS
170 }
171 #endif
172 }
173 
174 #endif // GF_WIDGET_H
WidgetState
State of a widget.
Definition: Widget.h:42
The button is active once.
bool isDisabled() const noexcept
Check if the widget is disabled.
Definition: Widget.h:92
Base class for all render targets (window, texture, ...)
Definition: RenderTarget.h:66
Define the states used for drawing to a RenderTarget.
Definition: RenderStates.h:82
WidgetState getState() const noexcept
Get the state of the widget.
Definition: Widget.h:137
The widgets abstract class.
Definition: Widget.h:52
The default widget state.
The widget is disabled.
The namespace for gf classes.
Definition: Action.h:34
bool isSelected() const
Check if the widget is selected.
Definition: Widget.h:120
bool isDefault() const noexcept
Check if the widget is in default state.
Definition: Widget.h:106
The widget is selected.