Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions include/SFML/Graphics/Rect.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.h>

#include <SFML/System/Vector2.h>


////////////////////////////////////////////////////////////
/// sfFloatRect and sfIntRect are utility classes for
Expand Down Expand Up @@ -77,5 +79,27 @@ CSFML_GRAPHICS_API sfBool sfIntRect_contains(const sfIntRect* rect, int x, int y
CSFML_GRAPHICS_API sfBool sfFloatRect_intersects(const sfFloatRect* rect1, const sfFloatRect* rect2, sfFloatRect* intersection);
CSFML_GRAPHICS_API sfBool sfIntRect_intersects(const sfIntRect* rect1, const sfIntRect* rect2, sfIntRect* intersection);

////////////////////////////////////////////////////////////
/// \brief Get the position of the rectangle's top-left corner
///
/// \return Position of rectangle
///
/// \see getSize
///
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API sfVector2f sfFloatRect_getPosition(const sfFloatRect* rect);
CSFML_GRAPHICS_API sfVector2i sfIntRect_getPosition(const sfIntRect* rect);

////////////////////////////////////////////////////////////
/// \brief Get the size of the rectangle
///
/// \return Size of rectangle
///
/// \see getPosition
///
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API sfVector2f sfFloatRect_getSize(const sfFloatRect* rect);
CSFML_GRAPHICS_API sfVector2i sfIntRect_getSize(const sfIntRect* rect);


#endif // SFML_RECT_H
41 changes: 41 additions & 0 deletions src/SFML/Graphics/Rect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@
#include <SFML/Internal.h>


namespace
{
sfVector2f toCType(const sf::Vector2f& vector)
{
sfVector2f vec = {vector.x, vector.y};
return vec;
}

sfVector2i toCType(const sf::Vector2i& vector)
{
sfVector2i vec = {vector.x, vector.y};
return vec;
}
}

////////////////////////////////////////////////////////////
/// Check if a point is inside a rectangle's area
////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -98,3 +113,29 @@ sfBool sfIntRect_intersects(const sfIntRect* rect1, const sfIntRect* rect2, sfIn
return SFMLRect1.intersects(SFMLRect2);
}
}


////////////////////////////////////////////////////////////
/// Get the position of the rectangle's top-left corner
////////////////////////////////////////////////////////////
sfVector2f sfFloatRect_getPosition(const sfFloatRect* rect)
{
return toCType(sf::FloatRect(rect->left, rect->top, rect->width, rect->height).getPosition());
}
sfVector2i sfIntRect_getPosition(const sfIntRect* rect)
{
return toCType(sf::IntRect(rect->left, rect->top, rect->width, rect->height).getPosition());
}


////////////////////////////////////////////////////////////
/// Get the size of the rectangle
////////////////////////////////////////////////////////////
sfVector2f sfFloatRect_getSize(const sfFloatRect* rect)
{
return toCType(sf::FloatRect(rect->left, rect->top, rect->width, rect->height).getSize());
}
sfVector2i sfIntRect_getSize(const sfIntRect* rect)
{
return toCType(sf::IntRect(rect->left, rect->top, rect->width, rect->height).getSize());
}