Gamedev Framework (gf)  0.19.0
A C++17 framework for 2D games
WidgetContainer.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_CONTAINER_H
23 #define GF_WIDGET_CONTAINER_H
24 
25 #include <vector>
26 
27 #include "GraphicsApi.h"
28 #include "Ref.h"
29 #include "RenderStates.h"
30 
31 namespace gf {
32 #ifndef DOXYGEN_SHOULD_SKIP_THIS
33 inline namespace v1 {
34 #endif
35 
36  class Widget;
37  class RenderTarget;
38 
45  class GF_GRAPHICS_API WidgetContainer {
46  public:
51 
61  void render(RenderTarget &target, const RenderStates& states = RenderStates());
62 
68  void pointTo(Vector2f coords);
69 
75  void addWidget(Widget& widget);
76 
84  Widget *removeWidget(Widget *widget);
85 
89  void triggerAction();
90 
94  void selectNextWidget();
95 
99  void selectPreviousWidget();
100 
104  void clear();
105 
106  private:
107  void unselectCurrentlySelected();
108 
109  void computePreviousIndex();
110  void computeNextIndex();
111 
112  Widget& getCurrent();
113 
114  private:
115  std::vector<Ref<Widget>> m_widgets;
116  std::size_t m_selectedWidgetIndex;
117  bool m_widgetIsSelected;
118  };
119 
120 #ifndef DOXYGEN_SHOULD_SKIP_THIS
121 }
122 #endif
123 }
124 
125 #endif // WIDGETS_WIDGET_CONTAINER_H
Base class for all render targets (window, texture, ...)
Definition: RenderTarget.h:102
Define the states used for drawing to a RenderTarget.
Definition: RenderStates.h:82
The widgets abstract class.
Definition: Widget.h:55
The namespace for gf classes.
Definition: Action.h:35
General purpose math vector.
Definition: Vector.h:61
A collection of widgets.
Definition: WidgetContainer.h:45