From cc8d8ed07b10b2ed7a0118793154614b50e199cf Mon Sep 17 00:00:00 2001 From: Laurent Gomila Date: Fri, 10 Feb 2012 17:13:31 +0100 Subject: [PATCH] Added GetLocalBounds and GetGlobalBounds functions to drawable classes --- include/SFML/Graphics/CircleShape.h | 32 ++++++++++++++++++++++++++ include/SFML/Graphics/ConvexShape.h | 32 ++++++++++++++++++++++++++ include/SFML/Graphics/RectangleShape.h | 32 ++++++++++++++++++++++++++ include/SFML/Graphics/Sprite.h | 32 ++++++++++++++++++++++++++ include/SFML/Graphics/Text.h | 32 ++++++++++++++++++++++++++ src/SFML/Graphics/CircleShape.cpp | 32 ++++++++++++++++++++++++++ src/SFML/Graphics/ConvexShape.cpp | 32 ++++++++++++++++++++++++++ src/SFML/Graphics/RectangleShape.cpp | 32 ++++++++++++++++++++++++++ src/SFML/Graphics/Sprite.cpp | 32 ++++++++++++++++++++++++++ src/SFML/Graphics/Text.cpp | 32 ++++++++++++++++++++++++++ 10 files changed, 320 insertions(+) diff --git a/include/SFML/Graphics/CircleShape.h b/include/SFML/Graphics/CircleShape.h index 6fe003f..88cf3cc 100644 --- a/include/SFML/Graphics/CircleShape.h +++ b/include/SFML/Graphics/CircleShape.h @@ -398,5 +398,37 @@ CSFML_GRAPHICS_API float sfCircleShape_GetRadius(const sfCircleShape* shape); //////////////////////////////////////////////////////////// CSFML_GRAPHICS_API void sfCircleShape_SetPointCount(sfCircleShape* shape, unsigned int count); +//////////////////////////////////////////////////////////// +/// \brief Get the local bounding rectangle of a circle shape +/// +/// The returned rectangle is in local coordinates, which means +/// that it ignores the transformations (translation, rotation, +/// scale, ...) that are applied to the entity. +/// In other words, this function returns the bounds of the +/// entity in the entity's coordinate system. +/// +/// \param shape Shape object +/// +/// \return Local bounding rectangle of the entity +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API sfFloatRect sfCircleShape_GetLocalBounds(const sfCircleShape* shape); + +//////////////////////////////////////////////////////////// +/// \brief Get the global bounding rectangle of a circle shape +/// +/// The returned rectangle is in global coordinates, which means +/// that it takes in account the transformations (translation, +/// rotation, scale, ...) that are applied to the entity. +/// In other words, this function returns the bounds of the +/// sprite in the global 2D world's coordinate system. +/// +/// \param shape Shape object +/// +/// \return Global bounding rectangle of the entity +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API sfFloatRect sfCircleShape_GetGlobalBounds(const sfCircleShape* shape); + #endif // SFML_CIRCLESHAPE_H diff --git a/include/SFML/Graphics/ConvexShape.h b/include/SFML/Graphics/ConvexShape.h index 6804a0d..4174e39 100644 --- a/include/SFML/Graphics/ConvexShape.h +++ b/include/SFML/Graphics/ConvexShape.h @@ -398,5 +398,37 @@ CSFML_GRAPHICS_API void sfConvexShape_SetPointCount(sfConvexShape* shape, unsign //////////////////////////////////////////////////////////// CSFML_GRAPHICS_API void sfConvexShape_SetPoint(sfConvexShape* shape, unsigned int index, float x, float y); +//////////////////////////////////////////////////////////// +/// \brief Get the local bounding rectangle of a convex shape +/// +/// The returned rectangle is in local coordinates, which means +/// that it ignores the transformations (translation, rotation, +/// scale, ...) that are applied to the entity. +/// In other words, this function returns the bounds of the +/// entity in the entity's coordinate system. +/// +/// \param shape Shape object +/// +/// \return Local bounding rectangle of the entity +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API sfFloatRect sfConvexShape_GetLocalBounds(const sfConvexShape* shape); + +//////////////////////////////////////////////////////////// +/// \brief Get the global bounding rectangle of a convex shape +/// +/// The returned rectangle is in global coordinates, which means +/// that it takes in account the transformations (translation, +/// rotation, scale, ...) that are applied to the entity. +/// In other words, this function returns the bounds of the +/// sprite in the global 2D world's coordinate system. +/// +/// \param shape Shape object +/// +/// \return Global bounding rectangle of the entity +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API sfFloatRect sfConvexShape_GetGlobalBounds(const sfConvexShape* shape); + #endif // SFML_CONVEXSHAPE_H diff --git a/include/SFML/Graphics/RectangleShape.h b/include/SFML/Graphics/RectangleShape.h index 465cdf6..2526dea 100644 --- a/include/SFML/Graphics/RectangleShape.h +++ b/include/SFML/Graphics/RectangleShape.h @@ -390,5 +390,37 @@ CSFML_GRAPHICS_API void sfRectangleShape_SetSize(sfRectangleShape* shape, float //////////////////////////////////////////////////////////// CSFML_GRAPHICS_API void sfRectangleShape_GetSize(const sfRectangleShape* shape, float* width, float* height); +//////////////////////////////////////////////////////////// +/// \brief Get the local bounding rectangle of a rectangle shape +/// +/// The returned rectangle is in local coordinates, which means +/// that it ignores the transformations (translation, rotation, +/// scale, ...) that are applied to the entity. +/// In other words, this function returns the bounds of the +/// entity in the entity's coordinate system. +/// +/// \param shape Shape object +/// +/// \return Local bounding rectangle of the entity +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API sfFloatRect sfRectangleShape_GetLocalBounds(const sfRectangleShape* shape); + +//////////////////////////////////////////////////////////// +/// \brief Get the global bounding rectangle of a rectangle shape +/// +/// The returned rectangle is in global coordinates, which means +/// that it takes in account the transformations (translation, +/// rotation, scale, ...) that are applied to the entity. +/// In other words, this function returns the bounds of the +/// sprite in the global 2D world's coordinate system. +/// +/// \param shape Shape object +/// +/// \return Global bounding rectangle of the entity +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API sfFloatRect sfRectangleShape_GetGlobalBounds(const sfRectangleShape* shape); + #endif // SFML_RECTANGLESHAPE_H diff --git a/include/SFML/Graphics/Sprite.h b/include/SFML/Graphics/Sprite.h index 03c3775..082dc8a 100644 --- a/include/SFML/Graphics/Sprite.h +++ b/include/SFML/Graphics/Sprite.h @@ -300,5 +300,37 @@ CSFML_GRAPHICS_API sfIntRect sfSprite_GetTextureRect(const sfSprite* sprite); //////////////////////////////////////////////////////////// CSFML_GRAPHICS_API sfColor sfSprite_GetColor(const sfSprite* sprite); +//////////////////////////////////////////////////////////// +/// \brief Get the local bounding rectangle of a sprite +/// +/// The returned rectangle is in local coordinates, which means +/// that it ignores the transformations (translation, rotation, +/// scale, ...) that are applied to the entity. +/// In other words, this function returns the bounds of the +/// entity in the entity's coordinate system. +/// +/// \param sprite Sprite object +/// +/// \return Local bounding rectangle of the entity +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API sfFloatRect sfSprite_GetLocalBounds(const sfSprite* sprite); + +//////////////////////////////////////////////////////////// +/// \brief Get the global bounding rectangle of a sprite +/// +/// The returned rectangle is in global coordinates, which means +/// that it takes in account the transformations (translation, +/// rotation, scale, ...) that are applied to the entity. +/// In other words, this function returns the bounds of the +/// sprite in the global 2D world's coordinate system. +/// +/// \param sprite Sprite object +/// +/// \return Global bounding rectangle of the entity +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API sfFloatRect sfSprite_GetGlobalBounds(const sfSprite* sprite); + #endif // SFML_SPRITE_H diff --git a/include/SFML/Graphics/Text.h b/include/SFML/Graphics/Text.h index 6f97a1d..cb163f0 100644 --- a/include/SFML/Graphics/Text.h +++ b/include/SFML/Graphics/Text.h @@ -382,5 +382,37 @@ CSFML_GRAPHICS_API sfColor sfText_GetColor(const sfText* text); //////////////////////////////////////////////////////////// CSFML_GRAPHICS_API void sfText_FindCharacterPos(const sfText* text, size_t index, float* x, float* y); +//////////////////////////////////////////////////////////// +/// \brief Get the local bounding rectangle of a text +/// +/// The returned rectangle is in local coordinates, which means +/// that it ignores the transformations (translation, rotation, +/// scale, ...) that are applied to the entity. +/// In other words, this function returns the bounds of the +/// entity in the entity's coordinate system. +/// +/// \param text Text object +/// +/// \return Local bounding rectangle of the entity +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API sfFloatRect sfText_GetLocalBounds(const sfText* text); + +//////////////////////////////////////////////////////////// +/// \brief Get the global bounding rectangle of a text +/// +/// The returned rectangle is in global coordinates, which means +/// that it takes in account the transformations (translation, +/// rotation, scale, ...) that are applied to the entity. +/// In other words, this function returns the bounds of the +/// sprite in the global 2D world's coordinate system. +/// +/// \param text Text object +/// +/// \return Global bounding rectangle of the entity +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API sfFloatRect sfText_GetGlobalBounds(const sfText* text); + #endif // SFML_TEXT_H diff --git a/src/SFML/Graphics/CircleShape.cpp b/src/SFML/Graphics/CircleShape.cpp index 7a74d30..35d5948 100644 --- a/src/SFML/Graphics/CircleShape.cpp +++ b/src/SFML/Graphics/CircleShape.cpp @@ -314,3 +314,35 @@ void sfCircleShape_SetPointCount(sfCircleShape* shape, unsigned int count) { CSFML_CALL(shape, SetPointCount(count)); } + + +//////////////////////////////////////////////////////////// +sfFloatRect sfCircleShape_GetLocalBounds(const sfCircleShape* shape) +{ + sfFloatRect rect = {0, 0, 0, 0}; + CSFML_CHECK_RETURN(shape, rect); + + sf::FloatRect sfmlRect = shape->This.GetLocalBounds(); + rect.Left = sfmlRect.Left; + rect.Top = sfmlRect.Top; + rect.Width = sfmlRect.Width; + rect.Height = sfmlRect.Height; + + return rect; +} + + +//////////////////////////////////////////////////////////// +sfFloatRect sfCircleShape_GetGlobalBounds(const sfCircleShape* shape) +{ + sfFloatRect rect = {0, 0, 0, 0}; + CSFML_CHECK_RETURN(shape, rect); + + sf::FloatRect sfmlRect = shape->This.GetGlobalBounds(); + rect.Left = sfmlRect.Left; + rect.Top = sfmlRect.Top; + rect.Width = sfmlRect.Width; + rect.Height = sfmlRect.Height; + + return rect; +} diff --git a/src/SFML/Graphics/ConvexShape.cpp b/src/SFML/Graphics/ConvexShape.cpp index f0e6f6f..2dc0cd1 100644 --- a/src/SFML/Graphics/ConvexShape.cpp +++ b/src/SFML/Graphics/ConvexShape.cpp @@ -304,3 +304,35 @@ void sfConvexShape_SetPoint(sfConvexShape* shape, unsigned int index, float x, f { CSFML_CALL(shape, SetPoint(index, sf::Vector2f(x, y))); } + + +//////////////////////////////////////////////////////////// +sfFloatRect sfConvexShape_GetLocalBounds(const sfConvexShape* shape) +{ + sfFloatRect rect = {0, 0, 0, 0}; + CSFML_CHECK_RETURN(shape, rect); + + sf::FloatRect sfmlRect = shape->This.GetLocalBounds(); + rect.Left = sfmlRect.Left; + rect.Top = sfmlRect.Top; + rect.Width = sfmlRect.Width; + rect.Height = sfmlRect.Height; + + return rect; +} + + +//////////////////////////////////////////////////////////// +sfFloatRect sfConvexShape_GetGlobalBounds(const sfConvexShape* shape) +{ + sfFloatRect rect = {0, 0, 0, 0}; + CSFML_CHECK_RETURN(shape, rect); + + sf::FloatRect sfmlRect = shape->This.GetGlobalBounds(); + rect.Left = sfmlRect.Left; + rect.Top = sfmlRect.Top; + rect.Width = sfmlRect.Width; + rect.Height = sfmlRect.Height; + + return rect; +} diff --git a/src/SFML/Graphics/RectangleShape.cpp b/src/SFML/Graphics/RectangleShape.cpp index 76b5449..08943f0 100644 --- a/src/SFML/Graphics/RectangleShape.cpp +++ b/src/SFML/Graphics/RectangleShape.cpp @@ -310,3 +310,35 @@ void sfRectangleShape_GetSize(const sfRectangleShape* shape, float* width, float if (height) *height = size.y; } + + +//////////////////////////////////////////////////////////// +sfFloatRect sfRectangleShape_GetLocalBounds(const sfRectangleShape* shape) +{ + sfFloatRect rect = {0, 0, 0, 0}; + CSFML_CHECK_RETURN(shape, rect); + + sf::FloatRect sfmlRect = shape->This.GetLocalBounds(); + rect.Left = sfmlRect.Left; + rect.Top = sfmlRect.Top; + rect.Width = sfmlRect.Width; + rect.Height = sfmlRect.Height; + + return rect; +} + + +//////////////////////////////////////////////////////////// +sfFloatRect sfRectangleShape_GetGlobalBounds(const sfRectangleShape* shape) +{ + sfFloatRect rect = {0, 0, 0, 0}; + CSFML_CHECK_RETURN(shape, rect); + + sf::FloatRect sfmlRect = shape->This.GetGlobalBounds(); + rect.Left = sfmlRect.Left; + rect.Top = sfmlRect.Top; + rect.Width = sfmlRect.Width; + rect.Height = sfmlRect.Height; + + return rect; +} diff --git a/src/SFML/Graphics/Sprite.cpp b/src/SFML/Graphics/Sprite.cpp index b3813af..ace442f 100644 --- a/src/SFML/Graphics/Sprite.cpp +++ b/src/SFML/Graphics/Sprite.cpp @@ -240,3 +240,35 @@ sfColor sfSprite_GetColor(const sfSprite* sprite) return color; } + + +//////////////////////////////////////////////////////////// +sfFloatRect sfSprite_GetLocalBounds(const sfSprite* sprite) +{ + sfFloatRect rect = {0, 0, 0, 0}; + CSFML_CHECK_RETURN(sprite, rect); + + sf::FloatRect sfmlRect = sprite->This.GetLocalBounds(); + rect.Left = sfmlRect.Left; + rect.Top = sfmlRect.Top; + rect.Width = sfmlRect.Width; + rect.Height = sfmlRect.Height; + + return rect; +} + + +//////////////////////////////////////////////////////////// +sfFloatRect sfSprite_GetGlobalBounds(const sfSprite* sprite) +{ + sfFloatRect rect = {0, 0, 0, 0}; + CSFML_CHECK_RETURN(sprite, rect); + + sf::FloatRect sfmlRect = sprite->This.GetGlobalBounds(); + rect.Left = sfmlRect.Left; + rect.Top = sfmlRect.Top; + rect.Width = sfmlRect.Width; + rect.Height = sfmlRect.Height; + + return rect; +} diff --git a/src/SFML/Graphics/Text.cpp b/src/SFML/Graphics/Text.cpp index 872a48d..42919b3 100644 --- a/src/SFML/Graphics/Text.cpp +++ b/src/SFML/Graphics/Text.cpp @@ -269,3 +269,35 @@ void sfText_FindCharacterPos(const sfText* text, size_t index, float* x, float* if (y) *y = pos.y; } + + +//////////////////////////////////////////////////////////// +sfFloatRect sfText_GetLocalBounds(const sfText* text) +{ + sfFloatRect rect = {0, 0, 0, 0}; + CSFML_CHECK_RETURN(text, rect); + + sf::FloatRect sfmlRect = text->This.GetLocalBounds(); + rect.Left = sfmlRect.Left; + rect.Top = sfmlRect.Top; + rect.Width = sfmlRect.Width; + rect.Height = sfmlRect.Height; + + return rect; +} + + +//////////////////////////////////////////////////////////// +sfFloatRect sfText_GetGlobalBounds(const sfText* text) +{ + sfFloatRect rect = {0, 0, 0, 0}; + CSFML_CHECK_RETURN(text, rect); + + sf::FloatRect sfmlRect = text->This.GetGlobalBounds(); + rect.Left = sfmlRect.Left; + rect.Top = sfmlRect.Top; + rect.Width = sfmlRect.Width; + rect.Height = sfmlRect.Height; + + return rect; +}