SFML 3.1.0
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-2026 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
30#include <SFML/Graphics/Export.hpp>
31
32#include <SFML/Graphics/Rect.hpp>
33#include <SFML/Graphics/Transform.hpp>
34
35#include <SFML/System/Angle.hpp>
36#include <SFML/System/Vector2.hpp>
37
38
39 namespace sf
40{
45 class SFML_GRAPHICS_API View
46{
47 public:
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
257 private:
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//
Angle.hpp
Export.hpp
SFML_GRAPHICS_API
#define SFML_GRAPHICS_API
Definition Graphics/Export.hpp:42
Rect.hpp
Transform.hpp
Vector2.hpp
sf::Angle
Represents an angle value.
Definition Angle.hpp:35
sf::Transform
3x3 transform matrix
Definition Transform.hpp:48
sf::View::View
View(Vector2f center, Vector2f size)
Construct the view from its center and size.
sf::View::View
View(const FloatRect &rectangle)
Construct the view from a rectangle.
sf::View::rotate
void rotate(Angle angle)
Rotate the view relative to its current orientation.
sf::View::setCenter
void setCenter(Vector2f center)
Set the center of the view.
sf::View::getScissor
const FloatRect & getScissor() const
Get the scissor rectangle of the view.
sf::View::setSize
void setSize(Vector2f size)
Set the size of the view.
sf::View::zoom
void zoom(float factor)
Resize the view rectangle relative to its current size.
sf::View::getSize
Vector2f getSize() const
Get the size of the view.
sf::View::setScissor
void setScissor(const FloatRect &scissor)
Set the target scissor rectangle.
sf::View::getRotation
Angle getRotation() const
Get the current orientation of the view.
sf::View::move
void move(Vector2f offset)
Move the view relative to its current position.
sf::View::setRotation
void setRotation(Angle angle)
Set the orientation of the view.
sf::View::View
View()=default
Default constructor.
sf::View::setViewport
void setViewport(const FloatRect &viewport)
Set the target viewport.
sf::View::getViewport
const FloatRect & getViewport() const
Get the target viewport rectangle of the view.
sf::View::getInverseTransform
const Transform & getInverseTransform() const
Get the inverse projection transform of the view.
sf::View::getCenter
Vector2f getCenter() const
Get the center of the view.
sf::View::getTransform
const Transform & getTransform() const
Get the projection transform of the view.
sf
Definition AudioResource.hpp:36
sf::FloatRect
Rect< float > FloatRect
Definition Rect.hpp:147
sf::Vector2f
Vector2< float > Vector2f
Definition Vector2.hpp:213