Gamedev Framework (gf)  0.9.0
A C++14 framework for 2D games
Views.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2018 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_VIEWS_H
22 #define GF_VIEWS_H
23 
24 #include "Portability.h"
25 #include "View.h"
26 
27 namespace gf {
28 #ifndef DOXYGEN_SHOULD_SKIP_THIS
29 inline namespace v1 {
30 #endif
31 
45  class GF_API StretchView : public AdaptativeView {
46  public:
53  : AdaptativeView()
54  {
55 
56  }
57 
63  explicit StretchView(const RectF& rect)
64  : AdaptativeView(rect)
65  {
66 
67  }
68 
76  : AdaptativeView(center, size)
77  {
78 
79  }
80 
81  virtual void onScreenSizeChange(Vector2u screenSize) override;
82  };
83 
96  class GF_API FitView : public AdaptativeView {
97  public:
104  : AdaptativeView()
105  , m_localViewport(0.0f, 0.0f, 1.0f, 1.0f)
106  {
107 
108  }
109 
115  explicit FitView(const RectF& rect)
116  : AdaptativeView(rect)
117  , m_localViewport(0.0f, 0.0f, 1.0f, 1.0f)
118  {
119 
120  }
121 
128  FitView(Vector2f center, Vector2f size)
129  : AdaptativeView(center, size)
130  , m_localViewport(0.0f, 0.0f, 1.0f, 1.0f)
131  {
132 
133  }
134 
135  virtual void onScreenSizeChange(Vector2u screenSize) override;
136 
137  protected:
138  virtual void onSizeChange(Vector2f size) override;
139  virtual void onViewportChange(const RectF& viewport) override;
140 
141  void updateView();
142 
143  private:
144  Vector2u m_localScreenSize;
145  RectF m_localViewport;
146  };
147 
159  class GF_API FillView : public AdaptativeView {
160  public:
167  : AdaptativeView()
168  {
169 
170  }
171 
177  explicit FillView(const RectF& rect)
178  : AdaptativeView(rect)
179  , m_localSize(rect.getSize())
180  {
181 
182  }
183 
190  FillView(Vector2f center, Vector2f size)
191  : AdaptativeView(center, size)
192  , m_localSize(size)
193  {
194 
195  }
196 
197  virtual void onScreenSizeChange(Vector2u screenSize) override;
198 
199  protected:
200  virtual void onSizeChange(Vector2f size) override;
201  virtual void onViewportChange(const RectF& viewport) override;
202 
203  void updateView();
204 
205  private:
206  Vector2f m_localSize;
207  Vector2u m_localScreenSize;
208  };
209 
222  class GF_API ExtendView : public AdaptativeView {
223  public:
230  : AdaptativeView()
231  {
232 
233  }
234 
240  explicit ExtendView(const RectF& rect)
241  : AdaptativeView(rect)
242  , m_localSize(rect.getSize())
243  {
244 
245  }
246 
254  : AdaptativeView(center, size)
255  , m_localSize(size)
256  {
257 
258  }
259 
260  virtual void onScreenSizeChange(Vector2u screenSize) override;
261 
262  protected:
263  virtual void onSizeChange(Vector2f size) override;
264  virtual void onViewportChange(const RectF& viewport) override;
265 
266  void updateView();
267 
268  private:
269  Vector2f m_localSize;
270  Vector2u m_localScreenSize;
271  };
272 
273 
286  class GF_API LockedView : public AdaptativeView {
287  public:
294  : AdaptativeView()
295  , m_localViewport(0.0f, 0.0f, 1.0f, 1.0f)
296  {
297 
298  }
299 
305  explicit LockedView(const RectF& rect)
306  : AdaptativeView(rect)
307  , m_localSize(rect.getSize())
308  , m_localViewport(0.0f, 0.0f, 1.0f, 1.0f)
309  {
310 
311  }
312 
320  : AdaptativeView(center, size)
321  , m_localSize(size)
322  , m_localViewport(0.0f, 0.0f, 1.0f, 1.0f)
323  {
324 
325  }
326 
327  virtual void onScreenSizeChange(Vector2u screenSize) override;
328 
329  protected:
330  virtual void onSizeChange(Vector2f size) override;
331  virtual void onViewportChange(const RectF& viewport) override;
332 
333  void updateView();
334 
335  private:
336  Vector2f m_localSize;
337  Vector2u m_localScreenSize;
338  RectF m_localViewport;
339  };
340 
356  class GF_API ScreenView : public AdaptativeView {
357  public:
358  virtual void onScreenSizeChange(Vector2u screenSize) override;
359  virtual void onViewportChange(const RectF& viewport) override;
360 
361  void updateView();
362 
363  private:
364  Vector2u m_localScreenSize;
365  };
366 
367 #ifndef DOXYGEN_SHOULD_SKIP_THIS
368 }
369 #endif
370 }
371 
372 #endif // GF_VIEWS_H
FitView(Vector2f center, Vector2f size)
Construct the view from its center and size.
Definition: Views.h:128
FitView()
Default constructor.
Definition: Views.h:103
FillView(Vector2f center, Vector2f size)
Construct the view from its center and size.
Definition: Views.h:190
Screen view.
Definition: Views.h:356
Fit view.
Definition: Views.h:96
StretchView()
Default constructor.
Definition: Views.h:52
FitView(const RectF &rect)
Construct the view from a rectangle.
Definition: Views.h:115
LockedView()
Default constructor.
Definition: Views.h:293
StretchView(const RectF &rect)
Construct the view from a rectangle.
Definition: Views.h:63
ExtendView()
Default constructor.
Definition: Views.h:229
Fill view.
Definition: Views.h:159
LockedView(Vector2f center, Vector2f size)
Construct the view from its center and size.
Definition: Views.h:319
ExtendView(Vector2f center, Vector2f size)
Construct the view from its center and size.
Definition: Views.h:253
The namespace for gf classes.
Definition: Action.h:34
ExtendView(const RectF &rect)
Construct the view from a rectangle.
Definition: Views.h:240
Extend view.
Definition: Views.h:222
LockedView(const RectF &rect)
Construct the view from a rectangle.
Definition: Views.h:305
FillView(const RectF &rect)
Construct the view from a rectangle.
Definition: Views.h:177
Adaptative view.
Definition: View.h:390
StretchView(Vector2f center, Vector2f size)
Construct the view from its center and size.
Definition: Views.h:75
Stretch view.
Definition: Views.h:45
FillView()
Default constructor.
Definition: Views.h:166
Locked view.
Definition: Views.h:286