Gamedev Framework (gf)  0.11.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_localScreenSize(0, 0)
106  , m_localViewport(0.0f, 0.0f, 1.0f, 1.0f)
107  {
108 
109  }
110 
116  explicit FitView(const RectF& rect)
117  : AdaptativeView(rect)
118  , m_localScreenSize(0, 0)
119  , m_localViewport(0.0f, 0.0f, 1.0f, 1.0f)
120  {
121 
122  }
123 
130  FitView(Vector2f center, Vector2f size)
131  : AdaptativeView(center, size)
132  , m_localScreenSize(0, 0)
133  , m_localViewport(0.0f, 0.0f, 1.0f, 1.0f)
134  {
135 
136  }
137 
138  virtual void onScreenSizeChange(Vector2u screenSize) override;
139 
140  protected:
141  virtual void onSizeChange(Vector2f size) override;
142  virtual void onViewportChange(const RectF& viewport) override;
143 
144  void updateView();
145 
146  private:
147  Vector2u m_localScreenSize;
148  RectF m_localViewport;
149  };
150 
162  class GF_API FillView : public AdaptativeView {
163  public:
170  : AdaptativeView()
171  , m_localSize(1000.0f, 1000.0f)
172  , m_localScreenSize(0, 0)
173  {
174 
175  }
176 
182  explicit FillView(const RectF& rect)
183  : AdaptativeView(rect)
184  , m_localSize(rect.getSize())
185  , m_localScreenSize(0, 0)
186  {
187 
188  }
189 
196  FillView(Vector2f center, Vector2f size)
197  : AdaptativeView(center, size)
198  , m_localSize(size)
199  , m_localScreenSize(0, 0)
200  {
201 
202  }
203 
204  virtual void onScreenSizeChange(Vector2u screenSize) override;
205 
206  protected:
207  virtual void onSizeChange(Vector2f size) override;
208  virtual void onViewportChange(const RectF& viewport) override;
209 
210  void updateView();
211 
212  private:
213  Vector2f m_localSize;
214  Vector2u m_localScreenSize;
215  };
216 
229  class GF_API ExtendView : public AdaptativeView {
230  public:
237  : AdaptativeView()
238  , m_localSize(1000.0f, 1000.0f)
239  , m_localScreenSize(0, 0)
240  {
241 
242  }
243 
249  explicit ExtendView(const RectF& rect)
250  : AdaptativeView(rect)
251  , m_localSize(rect.getSize())
252  , m_localScreenSize(0, 0)
253  {
254 
255  }
256 
264  : AdaptativeView(center, size)
265  , m_localSize(size)
266  , m_localScreenSize(0, 0)
267  {
268 
269  }
270 
271  virtual void onScreenSizeChange(Vector2u screenSize) override;
272 
273  protected:
274  virtual void onSizeChange(Vector2f size) override;
275  virtual void onViewportChange(const RectF& viewport) override;
276 
277  void updateView();
278 
279  private:
280  Vector2f m_localSize;
281  Vector2u m_localScreenSize;
282  };
283 
284 
297  class GF_API LockedView : public AdaptativeView {
298  public:
305  : AdaptativeView()
306  , m_localSize(0.0f, 0.0f)
307  , m_localScreenSize(0, 0)
308  , m_localViewport(0.0f, 0.0f, 1.0f, 1.0f)
309  {
310 
311  }
312 
318  explicit LockedView(const RectF& rect)
319  : AdaptativeView(rect)
320  , m_localSize(rect.getSize())
321  , m_localViewport(0.0f, 0.0f, 1.0f, 1.0f)
322  {
323 
324  }
325 
333  : AdaptativeView(center, size)
334  , m_localSize(size)
335  , m_localViewport(0.0f, 0.0f, 1.0f, 1.0f)
336  {
337 
338  }
339 
340  virtual void onScreenSizeChange(Vector2u screenSize) override;
341 
342  protected:
343  virtual void onSizeChange(Vector2f size) override;
344  virtual void onViewportChange(const RectF& viewport) override;
345 
346  void updateView();
347 
348  private:
349  Vector2f m_localSize;
350  Vector2u m_localScreenSize;
351  RectF m_localViewport;
352  };
353 
369  class GF_API ScreenView : public AdaptativeView {
370  public:
375  : AdaptativeView()
376  , m_localScreenSize(0, 0)
377  {
378 
379  }
380 
381  virtual void onScreenSizeChange(Vector2u screenSize) override;
382  virtual void onViewportChange(const RectF& viewport) override;
383 
384  void updateView();
385 
386  private:
387  Vector2u m_localScreenSize;
388  };
389 
390 #ifndef DOXYGEN_SHOULD_SKIP_THIS
391 }
392 #endif
393 }
394 
395 #endif // GF_VIEWS_H
FitView(Vector2f center, Vector2f size)
Construct the view from its center and size.
Definition: Views.h:130
FitView()
Default constructor.
Definition: Views.h:103
FillView(Vector2f center, Vector2f size)
Construct the view from its center and size.
Definition: Views.h:196
Screen view.
Definition: Views.h:369
Fit view.
Definition: Views.h:96
ScreenView()
Default constructor.
Definition: Views.h:374
StretchView()
Default constructor.
Definition: Views.h:52
FitView(const RectF &rect)
Construct the view from a rectangle.
Definition: Views.h:116
LockedView()
Default constructor.
Definition: Views.h:304
StretchView(const RectF &rect)
Construct the view from a rectangle.
Definition: Views.h:63
ExtendView()
Default constructor.
Definition: Views.h:236
Fill view.
Definition: Views.h:162
LockedView(Vector2f center, Vector2f size)
Construct the view from its center and size.
Definition: Views.h:332
ExtendView(Vector2f center, Vector2f size)
Construct the view from its center and size.
Definition: Views.h:263
The namespace for gf classes.
Definition: Action.h:35
ExtendView(const RectF &rect)
Construct the view from a rectangle.
Definition: Views.h:249
Extend view.
Definition: Views.h:229
LockedView(const RectF &rect)
Construct the view from a rectangle.
Definition: Views.h:318
FillView(const RectF &rect)
Construct the view from a rectangle.
Definition: Views.h:182
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:169
Locked view.
Definition: Views.h:297