Gamedev Framework (gf)  0.17.0
A C++14 framework for 2D games
Views.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2019 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 
62  explicit StretchView(const RectF& rect)
63  : AdaptativeView(rect)
64  {
65  }
66 
74  : AdaptativeView(center, size)
75  {
76  }
77 
78  void onFramebufferSizeChange(Vector2i framebufferSize) override;
79  };
80 
93  class GF_API FitView : public AdaptativeView {
94  public:
101  : AdaptativeView()
102  , m_localFramebufferSize(0, 0)
103  , m_localViewport(gf::RectF::fromPositionSize({ 0.0f, 0.0f }, { 1.0f, 1.0f }))
104  {
105  }
106 
112  explicit FitView(const RectF& rect)
113  : AdaptativeView(rect)
114  , m_localFramebufferSize(0, 0)
115  , m_localViewport(gf::RectF::fromPositionSize({ 0.0f, 0.0f }, { 1.0f, 1.0f }))
116  {
117  }
118 
125  FitView(Vector2f center, Vector2f size)
126  : AdaptativeView(center, size)
127  , m_localFramebufferSize(0, 0)
128  , m_localViewport(gf::RectF::fromPositionSize({ 0.0f, 0.0f }, { 1.0f, 1.0f }))
129  {
130  }
131 
132  void onFramebufferSizeChange(Vector2i framebufferSize) override;
133 
134  protected:
135  void onSizeChange(Vector2f size) override;
136  void onViewportChange(const RectF& viewport) override;
137 
138  void updateView();
139 
140  private:
141  Vector2i m_localFramebufferSize;
142  RectF m_localViewport;
143  };
144 
156  class GF_API FillView : public AdaptativeView {
157  public:
164  : AdaptativeView()
165  , m_localSize(1000.0f, 1000.0f)
166  , m_localFramebufferSize(0, 0)
167  {
168  }
169 
175  explicit FillView(const RectF& rect)
176  : AdaptativeView(rect)
177  , m_localSize(rect.getSize())
178  , m_localFramebufferSize(0, 0)
179  {
180  }
181 
188  FillView(Vector2f center, Vector2f size)
189  : AdaptativeView(center, size)
190  , m_localSize(size)
191  , m_localFramebufferSize(0, 0)
192  {
193  }
194 
195  void onFramebufferSizeChange(Vector2i framebufferSize) override;
196 
197  protected:
198  void onSizeChange(Vector2f size) override;
199  void onViewportChange(const RectF& viewport) override;
200 
201  void updateView();
202 
203  private:
204  Vector2f m_localSize;
205  Vector2i m_localFramebufferSize;
206  };
207 
220  class GF_API ExtendView : public AdaptativeView {
221  public:
228  : AdaptativeView()
229  , m_localSize(1000.0f, 1000.0f)
230  , m_localFramebufferSize(0, 0)
231  {
232  }
233 
239  explicit ExtendView(const RectF& rect)
240  : AdaptativeView(rect)
241  , m_localSize(rect.getSize())
242  , m_localFramebufferSize(0, 0)
243  {
244  }
245 
253  : AdaptativeView(center, size)
254  , m_localSize(size)
255  , m_localFramebufferSize(0, 0)
256  {
257  }
258 
259  void onFramebufferSizeChange(Vector2i framebufferSize) override;
260 
261  protected:
262  void onSizeChange(Vector2f size) override;
263  void onViewportChange(const RectF& viewport) override;
264 
265  void updateView();
266 
267  private:
268  Vector2f m_localSize;
269  Vector2i m_localFramebufferSize;
270  };
271 
272 
285  class GF_API LockedView : public AdaptativeView {
286  public:
293  : AdaptativeView()
294  , m_localSize(0.0f, 0.0f)
295  , m_localFramebufferSize(0, 0)
296  , m_localViewport(gf::RectF::fromPositionSize({ 0.0f, 0.0f }, { 1.0f, 1.0f }))
297  {
298  }
299 
305  explicit LockedView(const RectF& rect)
306  : AdaptativeView(rect)
307  , m_localSize(rect.getSize())
308  , m_localViewport(gf::RectF::fromPositionSize({ 0.0f, 0.0f }, { 1.0f, 1.0f }))
309  {
310  }
311 
319  : AdaptativeView(center, size)
320  , m_localSize(size)
321  , m_localViewport(gf::RectF::fromPositionSize({ 0.0f, 0.0f }, { 1.0f, 1.0f }))
322  {
323  }
324 
325  void onFramebufferSizeChange(Vector2i framebufferSize) override;
326 
327  protected:
328  void onSizeChange(Vector2f size) override;
329  void onViewportChange(const RectF& viewport) override;
330 
331  void updateView();
332 
333  private:
334  Vector2f m_localSize;
335  Vector2i m_localFramebufferSize;
336  RectF m_localViewport;
337  };
338 
354  class GF_API ScreenView : public AdaptativeView {
355  public:
360  : AdaptativeView()
361  , m_localFramebufferSize(0, 0)
362  {
363  }
364 
365  void onFramebufferSizeChange(Vector2i framebufferSize) override;
366  void onViewportChange(const RectF& viewport) override;
367 
368  void updateView();
369 
370  private:
371  Vector2i m_localFramebufferSize;
372  };
373 
374 #ifndef DOXYGEN_SHOULD_SKIP_THIS
375 }
376 #endif
377 }
378 
379 #endif // GF_VIEWS_H
FitView(Vector2f center, Vector2f size)
Construct the view from its center and size.
Definition: Views.h:125
FitView()
Default constructor.
Definition: Views.h:100
FillView(Vector2f center, Vector2f size)
Construct the view from its center and size.
Definition: Views.h:188
Screen view.
Definition: Views.h:354
Fit view.
Definition: Views.h:93
ScreenView()
Default constructor.
Definition: Views.h:359
StretchView()
Default constructor.
Definition: Views.h:52
FitView(const RectF &rect)
Construct the view from a rectangle.
Definition: Views.h:112
LockedView()
Default constructor.
Definition: Views.h:292
StretchView(const RectF &rect)
Construct the view from a rectangle.
Definition: Views.h:62
ExtendView()
Default constructor.
Definition: Views.h:227
Fill view.
Definition: Views.h:156
LockedView(Vector2f center, Vector2f size)
Construct the view from its center and size.
Definition: Views.h:318
ExtendView(Vector2f center, Vector2f size)
Construct the view from its center and size.
Definition: Views.h:252
The namespace for gf classes.
Definition: Action.h:35
ExtendView(const RectF &rect)
Construct the view from a rectangle.
Definition: Views.h:239
Extend view.
Definition: Views.h:220
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:175
Adaptative view.
Definition: View.h:390
StretchView(Vector2f center, Vector2f size)
Construct the view from its center and size.
Definition: Views.h:73
Stretch view.
Definition: Views.h:45
FillView()
Default constructor.
Definition: Views.h:163
Locked view.
Definition: Views.h:285