1 ////////////////////////////////////////////////////////////
\r
3 // SFML - Simple and Fast Multimedia Library
\r
4 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
\r
6 // This software is provided 'as-is', without any express or implied warranty.
\r
7 // In no event will the authors be held liable for any damages arising from the use of this software.
\r
9 // Permission is granted to anyone to use this software for any purpose,
\r
10 // including commercial applications, and to alter it and redistribute it freely,
\r
11 // subject to the following restrictions:
\r
13 // 1. The origin of this software must not be misrepresented;
\r
14 // you must not claim that you wrote the original software.
\r
15 // If you use this software in a product, an acknowledgment
\r
16 // in the product documentation would be appreciated but is not required.
\r
18 // 2. Altered source versions must be plainly marked as such,
\r
19 // and must not be misrepresented as being the original software.
\r
21 // 3. This notice may not be removed or altered from any source distribution.
\r
23 ////////////////////////////////////////////////////////////
\r
25 #ifndef SFML_VIEW_HPP
\r
26 #define SFML_VIEW_HPP
\r
28 ////////////////////////////////////////////////////////////
\r
30 ////////////////////////////////////////////////////////////
\r
31 #include <SFML/Config.hpp>
\r
32 #include <SFML/Graphics/Rect.hpp>
\r
33 #include <SFML/Graphics/Matrix3.hpp>
\r
34 #include <SFML/System/Vector2.hpp>
\r
41 ////////////////////////////////////////////////////////////
\r
42 /// This class defines a view (position, size, etc.) ;
\r
43 /// you can consider it as a 2D camera
\r
44 ////////////////////////////////////////////////////////////
\r
49 ////////////////////////////////////////////////////////////
\r
50 /// Construct the view from a rectangle
\r
52 /// \param ViewRect : Rectangle defining the position and size of the view (1000x1000 by default)
\r
54 ////////////////////////////////////////////////////////////
\r
55 explicit View(const FloatRect& ViewRect = FloatRect(0, 0, 1000, 1000));
\r
57 ////////////////////////////////////////////////////////////
\r
58 /// Construct the view from its center and half-size
\r
60 /// \param Center : Center of the view
\r
61 /// \param HalfSize : Half-size of the view (from center to corner)
\r
63 ////////////////////////////////////////////////////////////
\r
64 View(const sf::Vector2f& Center, const sf::Vector2f& HalfSize);
\r
66 ////////////////////////////////////////////////////////////
\r
67 /// Change the center of the view (take 2 values)
\r
69 /// \param X : X coordinate of the new center
\r
70 /// \param Y : Y coordinate of the new center
\r
72 ////////////////////////////////////////////////////////////
\r
73 void SetCenter(float X, float Y);
\r
75 ////////////////////////////////////////////////////////////
\r
76 /// Change the center of the view (take a vector)
\r
78 /// \param Center : New center
\r
80 ////////////////////////////////////////////////////////////
\r
81 void SetCenter(const sf::Vector2f& Center);
\r
83 ////////////////////////////////////////////////////////////
\r
84 /// Change the half-size of the view (take 2 values)
\r
86 /// \param HalfWidth : New half-width
\r
87 /// \param HalfHeight : New half-height
\r
89 ////////////////////////////////////////////////////////////
\r
90 void SetHalfSize(float HalfWidth, float HalfHeight);
\r
92 ////////////////////////////////////////////////////////////
\r
93 /// Change the half-size of the view (take a vector)
\r
95 /// \param HalfSize : New half-size
\r
97 ////////////////////////////////////////////////////////////
\r
98 void SetHalfSize(const sf::Vector2f& HalfSize);
\r
100 ////////////////////////////////////////////////////////////
\r
101 /// Rebuild the view from a rectangle
\r
103 /// \param ViewRect : Rectangle defining the position and size of the view
\r
105 ////////////////////////////////////////////////////////////
\r
106 void SetFromRect(const FloatRect& ViewRect);
\r
108 ////////////////////////////////////////////////////////////
\r
109 /// Get the center of the view
\r
111 /// \return Center of the view
\r
113 ////////////////////////////////////////////////////////////
\r
114 const sf::Vector2f& GetCenter() const;
\r
116 ////////////////////////////////////////////////////////////
\r
117 /// Get the half-size of the view
\r
119 /// \return Half-size of the view
\r
121 ////////////////////////////////////////////////////////////
\r
122 const sf::Vector2f& GetHalfSize() const;
\r
124 ////////////////////////////////////////////////////////////
\r
125 /// Get the bounding rectangle of the view
\r
127 /// \return Bounding rectangle of the view
\r
129 ////////////////////////////////////////////////////////////
\r
130 const sf::FloatRect& GetRect() const;
\r
132 ////////////////////////////////////////////////////////////
\r
133 /// Move the view (take 2 values)
\r
135 /// \param OffsetX : Offset to move the view, on X axis
\r
136 /// \param OffsetY : Offset to move the view, on Y axis
\r
138 ////////////////////////////////////////////////////////////
\r
139 void Move(float OffsetX, float OffsetY);
\r
141 ////////////////////////////////////////////////////////////
\r
142 /// Move the view (take a vector)
\r
144 /// \param Offset : Offset to move the view
\r
146 ////////////////////////////////////////////////////////////
\r
147 void Move(const sf::Vector2f& Offset);
\r
149 ////////////////////////////////////////////////////////////
\r
150 /// Resize the view rectangle to simulate a zoom / unzoom effect
\r
152 /// \param Factor : Zoom factor to apply, relative to the current zoom
\r
154 ////////////////////////////////////////////////////////////
\r
155 void Zoom(float Factor);
\r
159 friend class RenderTarget;
\r
161 ////////////////////////////////////////////////////////////
\r
162 /// Get the projection matrix of the view
\r
164 /// \return Projection matrix containing the view settings
\r
166 ////////////////////////////////////////////////////////////
\r
167 const Matrix3& GetMatrix() const;
\r
169 ////////////////////////////////////////////////////////////
\r
170 /// Recompute the view rectangle and the projection matrix
\r
172 ////////////////////////////////////////////////////////////
\r
173 void RecomputeMatrix();
\r
175 ////////////////////////////////////////////////////////////
\r
177 ////////////////////////////////////////////////////////////
\r
178 sf::Vector2f myCenter; ///< Center of the view
\r
179 sf::Vector2f myHalfSize; ///< Half-size of the view
\r
180 FloatRect myRect; ///< Rectangle defining the bounds of the view
\r
181 Matrix3 myMatrix; ///< Precomputed projection matrix corresponding to the view
\r
182 bool myNeedUpdate; ///< Internal state telling if the matrix needs to be updated
\r
188 #endif // SFML_VIEW_HPP
\r