|  | Gamedev Framework (gf)
    0.10.0
    A C++14 framework for 2D games | 
2D camera that defines what region is shown on screen More...
#include <gf/View.h>

| Public Member Functions | |
| View () | |
| Default constructor.  More... | |
| View (const RectF &rect) | |
| Construct the view from a rectangle.  More... | |
| View (Vector2f center, Vector2f size) | |
| Construct the view from its center and size.  More... | |
| virtual | ~View () | 
| Destructor.  More... | |
| RectF | getBounds () const | 
| Get the non-rotated bounds.  More... | |
| void | setCenter (Vector2f center) | 
| Set the center of the view.  More... | |
| Vector2f | getCenter () const | 
| Get the center of the view.  More... | |
| void | setSize (Vector2f size) | 
| Set the size of the view.  More... | |
| Vector2f | getSize () const | 
| Get the size of the view.  More... | |
| void | setRotation (float angle) | 
| Set the orientation of the view.  More... | |
| float | getRotation () const | 
| Get the current orientation of the view.  More... | |
| void | setViewport (const RectF &viewport) | 
| Set the target viewport.  More... | |
| const RectF & | getViewport () const | 
| Get the target viewport rectangle of the view.  More... | |
| void | reset (const RectF &rect) | 
| Reset the view to the given rectangle.  More... | |
| void | move (Vector2f offset) | 
| Move the view relatively to its current position.  More... | |
| void | rotate (float angle) | 
| Rotate the view relatively to its current orientation.  More... | |
| void | zoom (float factor) | 
| Resize the view rectangle relatively to its current size.  More... | |
| void | zoom (float factor, Vector2f fixed) | 
| Resize the view rectangle relatively to its current size and a fixed point.  More... | |
| Matrix3f | getTransform () const | 
| Get the projection transform of the view.  More... | |
| Matrix3f | getInverseTransform () const | 
| Get the inverse projection transform of the view.  More... | |
| Protected Member Functions | |
| void | setSizeNoCallback (Vector2f size) | 
| Set the world size, without calling onSizeChange()  More... | |
| virtual void | onSizeChange (Vector2f size) | 
| Callback when the world has just been resized.  More... | |
| void | setViewportNoCallback (const RectF &viewport) | 
| Set the viewport, without calling onViewportChange()  More... | |
| virtual void | onViewportChange (const RectF &viewport) | 
| Callback when the viewport has just been changed.  More... | |
2D camera that defines what region is shown on screen
gf::View defines a camera in the 2D scene. This is a very powerful concept: you can scroll, rotate or zoom the entire scene without altering the way that your drawable objects are drawn.
A view is composed of a source rectangle, which defines what part of the 2D scene is shown, and a target viewport, which defines where the contents of the source rectangle will be displayed on the render target (window or texture).
The viewport allows to map the scene to a custom part of the render target, and can be used for split-screen or for displaying a minimap, for example. If the source rectangle has not the same size as the viewport, its contents will be stretched to fit in.
To apply a view, you have to assign it to the render target. Then, every objects drawn in this render target will be affected by the view until you use another view.
Usage example:
| gf::View::View | ( | ) | 
Default constructor.
This constructor creates a default view of \((0, 0, 1000, 1000)\).
| 
 | explicit | 
Construct the view from a rectangle.
| rect | Rectangle defining the zone to display | 
Construct the view from its center and size.
| center | Center of the zone to display | 
| size | Size of the zone to display | 
| 
 | virtual | 
Destructor.
| RectF gf::View::getBounds | ( | ) | const | 
Get the non-rotated bounds.
| 
 | inline | 
| Matrix3f gf::View::getInverseTransform | ( | ) | const | 
Get the inverse projection transform of the view.
This function is meant for internal use only.
| 
 | inline | 
Get the current orientation of the view.
| 
 | inline | 
| Matrix3f gf::View::getTransform | ( | ) | const | 
Get the projection transform of the view.
This function is meant for internal use only.
| 
 | inline | 
Get the target viewport rectangle of the view.
| void gf::View::move | ( | Vector2f | offset | ) | 
Move the view relatively to its current position.
| offset | Move offset | 
| 
 | protectedvirtual | 
Callback when the world has just been resized.
This callback is called when setSize() is called.
| size | The new size of the visible world | 
Reimplemented in gf::LockedView, gf::ExtendView, gf::FillView, and gf::FitView.
| 
 | protectedvirtual | 
Callback when the viewport has just been changed.
| viewport | The new viewport | 
Reimplemented in gf::ScreenView, gf::LockedView, gf::ExtendView, gf::FillView, and gf::FitView.
| void gf::View::reset | ( | const RectF & | rect | ) | 
Reset the view to the given rectangle.
Note that this function resets the rotation angle to 0.
| rect | Rectangle defining the zone to display | 
| void gf::View::rotate | ( | float | angle | ) | 
Rotate the view relatively to its current orientation.
| angle | Angle to rotate, in radians | 
| 
 | inline | 
| 
 | inline | 
Set the orientation of the view.
The default rotation of a view is 0 radians.
| angle | New angle, in radians | 
| 
 | inline | 
| 
 | inlineprotected | 
Set the world size, without calling onSizeChange()
This function is meant for adaptative views so that they can adapt the world size without having a callback infinite loop.
| size | The new world size | 
| void gf::View::setViewport | ( | const RectF & | viewport | ) | 
Set the target viewport.
The viewport is the rectangle into which the contents of the view are displayed, expressed as a factor (between 0 and 1) of the size of the RenderTarget to which the view is applied.
For example, a view which takes the left side of the target would be defined with:
By default, a view has a viewport which covers the entire target.
| viewport | New viewport rectangle | 
| 
 | protected | 
Set the viewport, without calling onViewportChange()
This function is meant for adaptative views so that they can adapt the viewport without having a callback infinite loop.
| viewport | The new viewport | 
| void gf::View::zoom | ( | float | factor | ) | 
Resize the view rectangle relatively to its current size.
Resizing the view simulates a zoom, as the zone displayed on screen grows or shrinks. factor is a multiplier:
| factor | Zoom factor to apply | 
| void gf::View::zoom | ( | float | factor, | 
| Vector2f | fixed | ||
| ) | 
Resize the view rectangle relatively to its current size and a fixed point.
Resizing the view simulates a zoom, as the zone displayed on screen grows or shrinks. factor is a multiplier:
Additionally, a fixed point is used as the center of the zoom. It is the only point that stays at the same place in the view.
| factor | Zoom factor to apply | 
| fixed | The center of the zoom | 
 1.8.13
 1.8.13