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_RECT_HPP
\r
26 #define SFML_RECT_HPP
\r
28 ////////////////////////////////////////////////////////////
\r
30 ////////////////////////////////////////////////////////////
\r
31 #include <algorithm>
\r
36 ////////////////////////////////////////////////////////////
\r
37 /// Rect is an utility class for manipulating rectangles.
\r
38 /// Template parameter defines the type of coordinates (integer, float, ...)
\r
39 ////////////////////////////////////////////////////////////
\r
40 template <typename T>
\r
45 ////////////////////////////////////////////////////////////
\r
46 /// Default constructor
\r
48 ////////////////////////////////////////////////////////////
\r
51 ////////////////////////////////////////////////////////////
\r
52 /// Construct the rectangle from its coordinates
\r
54 /// \param LeftCoord : Left coordinate of the rectangle
\r
55 /// \param TopCoord : Top coordinate of the rectangle
\r
56 /// \param RightCoord : Right coordinate of the rectangle
\r
57 /// \param BottomCoord : Bottom coordinate of the rectangle
\r
59 ////////////////////////////////////////////////////////////
\r
60 Rect(T LeftCoord, T TopCoord, T RightCoord, T BottomCoord);
\r
62 ////////////////////////////////////////////////////////////
\r
63 /// Get the width of the rectangle
\r
65 /// \return Width of rectangle
\r
67 ////////////////////////////////////////////////////////////
\r
70 ////////////////////////////////////////////////////////////
\r
71 /// Get the height of the rectangle
\r
73 /// \return Height of rectangle
\r
75 ////////////////////////////////////////////////////////////
\r
76 T GetHeight() const;
\r
78 ////////////////////////////////////////////////////////////
\r
79 /// Move the whole rectangle by the given offset
\r
81 /// \param OffsetX : Horizontal offset
\r
82 /// \param OffsetY : Vertical offset
\r
84 ////////////////////////////////////////////////////////////
\r
85 void Offset(T OffsetX, T OffsetY);
\r
87 ////////////////////////////////////////////////////////////
\r
88 /// Check if a point is inside the rectangle's area
\r
90 /// \param X : X coordinate of the point to test
\r
91 /// \param Y : Y coordinate of the point to test
\r
93 /// \return True if the point is inside
\r
95 ////////////////////////////////////////////////////////////
\r
96 bool Contains(T X, T Y) const;
\r
98 ////////////////////////////////////////////////////////////
\r
99 /// Check intersection between two rectangles
\r
101 /// \param Rectangle : Rectangle to test
\r
102 /// \param OverlappingRect : Rectangle to be filled with overlapping rect (NULL by default)
\r
104 /// \return True if rectangles overlap
\r
106 ////////////////////////////////////////////////////////////
\r
107 bool Intersects(const Rect<T>& Rectangle, Rect<T>* OverlappingRect = NULL) const;
\r
109 ////////////////////////////////////////////////////////////
\r
111 ////////////////////////////////////////////////////////////
\r
112 T Left; ///< Left coordinate of the rectangle
\r
113 T Top; ///< Top coordinate of the rectangle
\r
114 T Right; ///< Right coordinate of the rectangle
\r
115 T Bottom; ///< Bottom coordinate of the rectangle
\r
118 #include <SFML/Graphics/Rect.inl>
\r
120 // Define the most common types
\r
121 typedef Rect<int> IntRect;
\r
122 typedef Rect<float> FloatRect;
\r
127 #endif // SFML_RECT_HPP
\r