Loading...
Searching...
No Matches
View.hpp
Go to the documentation of this file.
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2024 Laurent Gomila (laurent@sfml-dev.org)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages 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 freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25#pragma once
26
28// Headers
31
34
35#include <SFML/System/Angle.hpp>
37
38
39namespace sf
40{
46{
47public:
54 View() = default;
55
62 explicit View(const FloatRect& rectangle);
63
71 View(Vector2f center, Vector2f size);
72
81 void setCenter(Vector2f center);
82
91 void setSize(Vector2f size);
92
103 void setRotation(Angle angle);
104
120 void setViewport(const FloatRect& viewport);
121
144 void setScissor(const FloatRect& scissor);
145
154 [[nodiscard]] Vector2f getCenter() const;
155
164 [[nodiscard]] Vector2f getSize() const;
165
174 [[nodiscard]] Angle getRotation() const;
175
184 [[nodiscard]] const FloatRect& getViewport() const;
185
194 [[nodiscard]] const FloatRect& getScissor() const;
195
204 void move(Vector2f offset);
205
214 void rotate(Angle angle);
215
231 void zoom(float factor);
232
243 [[nodiscard]] const Transform& getTransform() const;
244
255 [[nodiscard]] const Transform& getInverseTransform() const;
256
257private:
259 // Member data
261 Vector2f m_center{500, 500};
262 Vector2f m_size{1000, 1000};
263 Angle m_rotation;
264 FloatRect m_viewport{{0, 0}, {1, 1}};
265 FloatRect m_scissor{{0, 0}, {1, 1}};
266 mutable Transform m_transform;
267 mutable Transform m_inverseTransform;
268 mutable bool m_transformUpdated{};
269 mutable bool m_invTransformUpdated{};
270};
271
272} // namespace sf
273
274
322//
#define SFML_GRAPHICS_API
Represents an angle value.
Definition Angle.hpp:35
3x3 transform matrix
Definition Transform.hpp:48
2D camera that defines what region is shown on screen
Definition View.hpp:46
View(Vector2f center, Vector2f size)
Construct the view from its center and size.
View(const FloatRect &rectangle)
Construct the view from a rectangle.
void rotate(Angle angle)
Rotate the view relatively to its current orientation.
void setCenter(Vector2f center)
Set the center of the view.
const FloatRect & getScissor() const
Get the scissor rectangle of the view.
void setSize(Vector2f size)
Set the size of the view.
void zoom(float factor)
Resize the view rectangle relatively to its current size.
Vector2f getSize() const
Get the size of the view.
void setScissor(const FloatRect &scissor)
Set the target scissor rectangle.
Angle getRotation() const
Get the current orientation of the view.
void move(Vector2f offset)
Move the view relatively to its current position.
void setRotation(Angle angle)
Set the orientation of the view.
View()=default
Default constructor.
void setViewport(const FloatRect &viewport)
Set the target viewport.
const FloatRect & getViewport() const
Get the target viewport rectangle of the view.
const Transform & getInverseTransform() const
Get the inverse projection transform of the view.
Vector2f getCenter() const
Get the center of the view.
const Transform & getTransform() const
Get the projection transform of the view.
Rect< float > FloatRect
Definition Rect.hpp:147