Gamedev Framework (gf)  0.3.0
A C++11 framework for 2D games
ViewContainer.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016 Julien Bernard
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_VIEW_CONTAINER_H
22 #define GF_VIEW_CONTAINER_H
23 
24 #include <vector>
25 
26 #include "Portability.h"
27 #include "Vector.h"
28 
29 namespace gf {
30 #ifndef DOXYGEN_SHOULD_SKIP_THIS
31 inline namespace v1 {
32 #endif
33 
34  class AdaptativeView;
35  struct Event;
36 
37  /**
38  * @ingroup graphics
39  * @brief A container of views
40  *
41  * A view manager handles several adaptive views. It can update all the
42  * views at the same time. All it needs is the events that come from the
43  * window.
44  *
45  * Here is a full example with two adaptive views:
46  *
47  * ~~~{.cc}
48  * // ...
49  *
50  * gf::ViewContainer views;
51  *
52  * gf::ExtendView extendView;
53  * extendView.setSize({ 1000.0f, 1000.0f });
54  * views.addView(extendView);
55  *
56  * gf::ScreenView screenView;
57  * views.addView(screenView);
58  *
59  * // initialize the views with the initial screen size
60  * views.onScreenResize(screenSize);
61  *
62  * // ...
63  *
64  * while (window.isOpen()) {
65  * gf::Event event;
66  *
67  * while (window.pollEvent(event)) {
68  * // ...
69  *
70  * views.update(event);
71  * }
72  *
73  * // ...
74  *
75  * renderer.clear();
76  *
77  * renderer.setView(extendView);
78  * renderer.draw(...);
79  *
80  * renderer.setView(screenView);
81  * renderer.draw(...);
82  *
83  * renderer.display();
84  * }
85  * ~~~
86  *
87  * @sa gf::AdaptativeView
88  */
90  public:
91  /**
92  * @brief Add a view to the container
93  *
94  * @param view An adaptive view
95  */
96  void addView(AdaptativeView& view);
97 
98  /**
99  * @brief Update the views thanks to the event
100  *
101  * Internally it calls onScreenResize() if a resize event occurs.
102  *
103  * @param event An event
104  */
105  void processEvent(const Event& event);
106 
107  /**
108  * @brief Update the views with the new screen size
109  *
110  * @param screenSize The new size of the screen
111  *
112  * @sa gf::AdaptativeView::onScreenResize()
113  */
114  void onScreenResize(Vector2u screenSize);
115 
116  /**
117  * @brief Set the initial screen size
118  *
119  * @param screenSize The initial size of the screen
120  */
121  void setInitialScreenSize(Vector2u screenSize);
122 
123  private:
124  std::vector<AdaptativeView*> m_views;
125  };
126 
127 #ifndef DOXYGEN_SHOULD_SKIP_THIS
128 }
129 #endif
130 }
131 
132 #endif // GF_VIEW_CONTAINER_H
void setInitialScreenSize(Vector2u screenSize)
Set the initial screen size.
void addView(AdaptativeView &view)
Add a view to the container.
A container of views.
Definition: ViewContainer.h:89
void onScreenResize(Vector2u screenSize)
Update the views with the new screen size.
Definition: Action.h:34
void processEvent(const Event &event)
Update the views thanks to the event.
Defines a system event and its parameters.
Definition: Event.h:115
#define GF_API
Definition: Portability.h:35
Adaptative view.
Definition: View.h:345