Gamedev Framework (gf)  0.12.0
A C++14 framework for 2D games
WidgetContainer.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_CONTAINER_H
23 #define GF_WIDGET_CONTAINER_H
24 
25 #include <vector>
26 
27 #include "Ref.h"
28 #include "RenderStates.h"
29 
30 namespace gf {
31 #ifndef DOXYGEN_SHOULD_SKIP_THIS
32 inline namespace v1 {
33 #endif
34 
35  class Widget;
36  class RenderTarget;
37 
44  class GF_API WidgetContainer {
45  public:
50 
60  void render(RenderTarget &target, const RenderStates& states = RenderStates());
61 
67  void pointTo(Vector2f coords);
68 
74  void addWidget(Widget& widget);
75 
83  Widget *removeWidget(Widget *widget);
84 
88  void triggerAction();
89 
93  void selectNextWidget();
94 
98  void selectPreviousWidget();
99 
100  private:
101  void unselectCurrentlySelected();
102 
103  void computePreviousIndex();
104  void computeNextIndex();
105 
106  Widget& getCurrent();
107 
108  private:
109  std::vector<Ref<Widget>> m_widgets;
110  std::size_t m_selectedWidgetIndex;
111  bool m_widgetIsSelected;
112  };
113 
114 #ifndef DOXYGEN_SHOULD_SKIP_THIS
115 }
116 #endif
117 }
118 
119 #endif // WIDGETS_WIDGET_CONTAINER_H
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
The widgets abstract class.
Definition: Widget.h:54
The namespace for gf classes.
Definition: Action.h:35
A collection of widgets.
Definition: WidgetContainer.h:44