Skip to content

Commit

Permalink
Moved sf::Rect from the Graphics to the System package.
Browse files Browse the repository at this point in the history
  • Loading branch information
Maximilian Wagenbach committed Sep 26, 2015
1 parent c4be28b commit b706e0c
Show file tree
Hide file tree
Showing 16 changed files with 262 additions and 230 deletions.
1 change: 0 additions & 1 deletion include/SFML/Graphics.hpp
Expand Up @@ -39,7 +39,6 @@
#include <SFML/Graphics/Glyph.hpp>
#include <SFML/Graphics/Image.hpp>
#include <SFML/Graphics/PrimitiveType.hpp>
#include <SFML/Graphics/Rect.hpp>
#include <SFML/Graphics/RectangleShape.hpp>
#include <SFML/Graphics/RenderStates.hpp>
#include <SFML/Graphics/RenderTarget.hpp>
Expand Down
2 changes: 1 addition & 1 deletion include/SFML/Graphics/Font.hpp
Expand Up @@ -31,7 +31,7 @@
#include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/Glyph.hpp>
#include <SFML/Graphics/Texture.hpp>
#include <SFML/Graphics/Rect.hpp>
#include <SFML/System/Rect.hpp>
#include <SFML/System/Vector2.hpp>
#include <SFML/System/String.hpp>
#include <map>
Expand Down
2 changes: 1 addition & 1 deletion include/SFML/Graphics/Glyph.hpp
Expand Up @@ -29,7 +29,7 @@
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/Rect.hpp>
#include <SFML/System/Rect.hpp>


namespace sf
Expand Down
2 changes: 1 addition & 1 deletion include/SFML/Graphics/Image.hpp
Expand Up @@ -28,9 +28,9 @@
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/System/Rect.hpp>
#include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/Color.hpp>
#include <SFML/Graphics/Rect.hpp>
#include <string>
#include <vector>

Expand Down
221 changes: 2 additions & 219 deletions include/SFML/Graphics/Rect.hpp
Expand Up @@ -22,227 +22,10 @@
//
////////////////////////////////////////////////////////////

#ifndef SFML_RECT_HPP
#define SFML_RECT_HPP

////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/System/Vector2.hpp>
#include <algorithm>
#include <SFML/System/Rect.hpp>


namespace sf
{
////////////////////////////////////////////////////////////
/// \brief Utility class for manipulating 2D axis aligned rectangles
///
////////////////////////////////////////////////////////////
template <typename T>
class Rect
{
public:

////////////////////////////////////////////////////////////
/// \brief Default constructor
///
/// Creates an empty rectangle (it is equivalent to calling
/// Rect(0, 0, 0, 0)).
///
////////////////////////////////////////////////////////////
Rect();

////////////////////////////////////////////////////////////
/// \brief Construct the rectangle from its coordinates
///
/// Be careful, the last two parameters are the width
/// and height, not the right and bottom coordinates!
///
/// \param rectLeft Left coordinate of the rectangle
/// \param rectTop Top coordinate of the rectangle
/// \param rectWidth Width of the rectangle
/// \param rectHeight Height of the rectangle
///
////////////////////////////////////////////////////////////
Rect(T rectLeft, T rectTop, T rectWidth, T rectHeight);

////////////////////////////////////////////////////////////
/// \brief Construct the rectangle from position and size
///
/// Be careful, the last parameter is the size,
/// not the bottom-right corner!
///
/// \param position Position of the top-left corner of the rectangle
/// \param size Size of the rectangle
///
////////////////////////////////////////////////////////////
Rect(const Vector2<T>& position, const Vector2<T>& size);

////////////////////////////////////////////////////////////
/// \brief Construct the rectangle from another type of rectangle
///
/// This constructor doesn't replace the copy constructor,
/// it's called only when U != T.
/// A call to this constructor will fail to compile if U
/// is not convertible to T.
///
/// \param rectangle Rectangle to convert
///
////////////////////////////////////////////////////////////
template <typename U>
explicit Rect(const Rect<U>& rectangle);

////////////////////////////////////////////////////////////
/// \brief Check if a point is inside the rectangle's area
///
/// \param x X coordinate of the point to test
/// \param y Y coordinate of the point to test
///
/// \return True if the point is inside, false otherwise
///
/// \see intersects
///
////////////////////////////////////////////////////////////
bool contains(T x, T y) const;

////////////////////////////////////////////////////////////
/// \brief Check if a point is inside the rectangle's area
///
/// \param point Point to test
///
/// \return True if the point is inside, false otherwise
///
/// \see intersects
///
////////////////////////////////////////////////////////////
bool contains(const Vector2<T>& point) const;

////////////////////////////////////////////////////////////
/// \brief Check the intersection between two rectangles
///
/// \param rectangle Rectangle to test
///
/// \return True if rectangles overlap, false otherwise
///
/// \see contains
///
////////////////////////////////////////////////////////////
bool intersects(const Rect<T>& rectangle) const;

////////////////////////////////////////////////////////////
/// \brief Check the intersection between two rectangles
///
/// This overload returns the overlapped rectangle in the
/// \a intersection parameter.
///
/// \param rectangle Rectangle to test
/// \param intersection Rectangle to be filled with the intersection
///
/// \return True if rectangles overlap, false otherwise
///
/// \see contains
///
////////////////////////////////////////////////////////////
bool intersects(const Rect<T>& rectangle, Rect<T>& intersection) const;

////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
T left; ///< Left coordinate of the rectangle
T top; ///< Top coordinate of the rectangle
T width; ///< Width of the rectangle
T height; ///< Height of the rectangle
};

////////////////////////////////////////////////////////////
/// \relates Rect
/// \brief Overload of binary operator ==
///
/// This operator compares strict equality between two rectangles.
///
/// \param left Left operand (a rectangle)
/// \param right Right operand (a rectangle)
///
/// \return True if \a left is equal to \a right
///
////////////////////////////////////////////////////////////
template <typename T>
bool operator ==(const Rect<T>& left, const Rect<T>& right);

////////////////////////////////////////////////////////////
/// \relates Rect
/// \brief Overload of binary operator !=
///
/// This operator compares strict difference between two rectangles.
///
/// \param left Left operand (a rectangle)
/// \param right Right operand (a rectangle)
///
/// \return True if \a left is not equal to \a right
///
////////////////////////////////////////////////////////////
template <typename T>
bool operator !=(const Rect<T>& left, const Rect<T>& right);

#include <SFML/Graphics/Rect.inl>

// Create typedefs for the most common types
typedef Rect<int> IntRect;
typedef Rect<float> FloatRect;

} // namespace sf


#endif // SFML_RECT_HPP


////////////////////////////////////////////////////////////
/// \class sf::Rect
/// \ingroup graphics
///
/// A rectangle is defined by its top-left corner and its size.
/// It is a very simple class defined for convenience, so
/// its member variables (left, top, width and height) are public
/// and can be accessed directly, just like the vector classes
/// (Vector2 and Vector3).
///
/// To keep things simple, sf::Rect doesn't define
/// functions to emulate the properties that are not directly
/// members (such as right, bottom, center, etc.), it rather
/// only provides intersection functions.
///
/// sf::Rect uses the usual rules for its boundaries:
/// \li The left and top edges are included in the rectangle's area
/// \li The right (left + width) and bottom (top + height) edges are excluded from the rectangle's area
///
/// This means that sf::IntRect(0, 0, 1, 1) and sf::IntRect(1, 1, 1, 1)
/// don't intersect.
///
/// sf::Rect is a template and may be used with any numeric type, but
/// for simplicity the instantiations used by SFML are typedef'd:
/// \li sf::Rect<int> is sf::IntRect
/// \li sf::Rect<float> is sf::FloatRect
///
/// So that you don't have to care about the template syntax.
///
/// Usage example:
/// \code
/// // Define a rectangle, located at (0, 0) with a size of 20x5
/// sf::IntRect r1(0, 0, 20, 5);
///
/// // Define another rectangle, located at (4, 2) with a size of 18x10
/// sf::Vector2i position(4, 2);
/// sf::Vector2i size(18, 10);
/// sf::IntRect r2(position, size);
///
/// // Test intersections with the point (3, 1)
/// bool b1 = r1.contains(3, 1); // true
/// bool b2 = r2.contains(3, 1); // false
///
/// // Test the intersection between r1 and r2
/// sf::IntRect result;
/// bool b3 = r1.intersects(r2, result); // true
/// // result == (4, 2, 16, 3)
/// \endcode
///
////////////////////////////////////////////////////////////
#warning #include <SFML/Graphics/Rect.hpp> is deprected, use #include <SFML/System/Rect.hpp> instead.
2 changes: 1 addition & 1 deletion include/SFML/Graphics/RenderTarget.hpp
Expand Up @@ -30,14 +30,14 @@
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/Color.hpp>
#include <SFML/Graphics/Rect.hpp>
#include <SFML/Graphics/View.hpp>
#include <SFML/Graphics/Transform.hpp>
#include <SFML/Graphics/BlendMode.hpp>
#include <SFML/Graphics/RenderStates.hpp>
#include <SFML/Graphics/PrimitiveType.hpp>
#include <SFML/Graphics/Vertex.hpp>
#include <SFML/System/NonCopyable.hpp>
#include <SFML/System/Rect.hpp>


namespace sf
Expand Down
2 changes: 1 addition & 1 deletion include/SFML/Graphics/Sprite.hpp
Expand Up @@ -32,7 +32,7 @@
#include <SFML/Graphics/Drawable.hpp>
#include <SFML/Graphics/Transformable.hpp>
#include <SFML/Graphics/Vertex.hpp>
#include <SFML/Graphics/Rect.hpp>
#include <SFML/System/Rect.hpp>


namespace sf
Expand Down
2 changes: 1 addition & 1 deletion include/SFML/Graphics/Text.hpp
Expand Up @@ -32,8 +32,8 @@
#include <SFML/Graphics/Drawable.hpp>
#include <SFML/Graphics/Transformable.hpp>
#include <SFML/Graphics/Font.hpp>
#include <SFML/Graphics/Rect.hpp>
#include <SFML/Graphics/VertexArray.hpp>
#include <SFML/System/Rect.hpp>
#include <SFML/System/String.hpp>
#include <string>
#include <vector>
Expand Down
2 changes: 1 addition & 1 deletion include/SFML/Graphics/Transform.hpp
Expand Up @@ -29,7 +29,7 @@
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/Rect.hpp>
#include <SFML/System/Rect.hpp>
#include <SFML/System/Vector2.hpp>


Expand Down
2 changes: 1 addition & 1 deletion include/SFML/Graphics/VertexArray.hpp
Expand Up @@ -31,8 +31,8 @@
#include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/Vertex.hpp>
#include <SFML/Graphics/PrimitiveType.hpp>
#include <SFML/Graphics/Rect.hpp>
#include <SFML/Graphics/Drawable.hpp>
#include <SFML/System/Rect.hpp>
#include <vector>


Expand Down
2 changes: 1 addition & 1 deletion include/SFML/Graphics/View.hpp
Expand Up @@ -29,8 +29,8 @@
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/Rect.hpp>
#include <SFML/Graphics/Transform.hpp>
#include <SFML/System/Rect.hpp>
#include <SFML/System/Vector2.hpp>


Expand Down
1 change: 1 addition & 0 deletions include/SFML/System.hpp
Expand Up @@ -38,6 +38,7 @@
#include <SFML/System/MemoryInputStream.hpp>
#include <SFML/System/Mutex.hpp>
#include <SFML/System/NonCopyable.hpp>
#include <SFML/System/Rect.hpp>
#include <SFML/System/Sleep.hpp>
#include <SFML/System/String.hpp>
#include <SFML/System/Thread.hpp>
Expand Down

0 comments on commit b706e0c

Please sign in to comment.