Gamedev Framework (gf)  0.1.0
A C++11 framework for 2D games
Views.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_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 
32  /**
33  * @ingroup graphics
34  * @brief Stretch view
35  *
36  * This view assumes that the screen is always the same size as the world.
37  * The world will then be stretched to fit the screen. There are no black
38  * bars, but the aspect ratio may not be the same after the scaling took
39  * place.
40  *
41  * ![Stretch view](@ref stretchview.png)
42  *
43  * @sa gf::AdaptativeView
44  */
46  public:
47  virtual void onScreenResize(Vector2u screenSize) override;
48  };
49 
50  /**
51  * @ingroup graphics
52  * @brief Fit view
53  *
54  * This view will always maintain the aspect ratio of the world, while
55  * scaling it as much as possible to fit the screen. One disadvantage
56  * with this strategy is that there may appear black bars.
57  *
58  * ![Fit view](@ref fitview.png)
59  *
60  * @sa gf::AdaptativeView
61  */
62  class GF_API FitView : public AdaptativeView {
63  public:
64  virtual void onScreenResize(Vector2u screenSize) override;
65  };
66 
67  /**
68  * @ingroup graphics
69  * @brief Fill view
70  *
71  * This view keeps the aspect ratio of the world, but it will always fill
72  * the whole screen which might result in parts of the world being cut off.
73  *
74  * ![Fill view](@ref fillview.png)
75  *
76  * @sa gf::AdaptativeView
77  */
78  class GF_API FillView : public AdaptativeView {
79  public:
80  virtual void onScreenResize(Vector2u screenSize) override;
81 
82  protected:
83  virtual void onWorldResize(Vector2f worldSize) override;
84 
85  private:
86  Vector2f m_worldSize;
87  };
88 
89  /**
90  * @ingroup graphics
91  * @brief Extend view
92  *
93  * This view keeps the world aspect ratio without black bars by extending
94  * the world in one direction. The world is first scaled to fit within the
95  * viewport, then the shorter dimension is lengthened to fill the viewport.
96  *
97  * ![Extend view](@ref extendview.png)
98  *
99  * @sa gf::AdaptativeView
100  */
102  public:
103  virtual void onScreenResize(Vector2u screenSize) override;
104 
105  protected:
106  virtual void onWorldResize(Vector2f worldSize) override;
107 
108  private:
109  Vector2f m_worldSize;
110  };
111 
112  /**
113  * @ingroup graphics
114  * @brief Screen view
115  *
116  * This view will always match the window size which means that no scaling
117  * happens and no black bars appear. As a disadvantage this means that the
118  * gameplay might change, because a player with a bigger screen might see
119  * more of the game, than a player with a smaller screen size.
120  *
121  * This view can be used to display [HUD](https://en.wikipedia.org/wiki/HUD_%28video_gaming%29).
122  *
123  * ![Screen view](@ref screenview.png)
124  *
125  * @sa gf::AdaptativeView
126  */
128  public:
129  virtual void onScreenResize(Vector2u screenSize) override;
130  };
131 
132 #ifndef DOXYGEN_SHOULD_SKIP_THIS
133 }
134 #endif
135 }
136 
137 #endif // GF_VIEWS_H
Vector< unsigned, 2 > Vector2u
A unsigned vector with 2 components.
Definition: Vector.h:795
virtual void onScreenResize(Vector2u screenSize) override
Callback when the screen has just been resized.
Screen view.
Definition: Views.h:127
Fit view.
Definition: Views.h:62
Vector< float, 2 > Vector2f
A float vector with 2 components.
Definition: Vector.h:741
Fill view.
Definition: Views.h:78
virtual void onWorldResize(Vector2f worldSize) override
Callback when the world has just been resized.
Definition: Action.h:34
Extend view.
Definition: Views.h:101
virtual void onScreenResize(Vector2u screenSize) override
Callback when the screen has just been resized.
virtual void onWorldResize(Vector2f worldSize) override
Callback when the world has just been resized.
virtual void onScreenResize(Vector2u screenSize) override
Callback when the screen has just been resized.
#define GF_API
Definition: Portability.h:35
Adaptative view.
Definition: View.h:345
Stretch view.
Definition: Views.h:45
virtual void onScreenResize(Vector2u screenSize) override
Callback when the screen has just been resized.
virtual void onScreenResize(Vector2u screenSize) override
Callback when the screen has just been resized.