From 228a06ba641d82ca0e67d7e8cbc4da2ab69c846a Mon Sep 17 00:00:00 2001 From: Laurent Gomila Date: Tue, 27 Mar 2012 17:26:18 +0200 Subject: [PATCH] Updated RenderTarget::convertCoords --- include/SFML/Graphics/RenderTexture.h | 9 ++++----- include/SFML/Graphics/RenderWindow.h | 9 ++++----- src/SFML/Graphics/RenderTexture.cpp | 17 ++++++++++------- src/SFML/Graphics/RenderWindow.cpp | 17 ++++++++++------- 4 files changed, 28 insertions(+), 24 deletions(-) diff --git a/include/SFML/Graphics/RenderTexture.h b/include/SFML/Graphics/RenderTexture.h index c21ed40..30b6dcd 100644 --- a/include/SFML/Graphics/RenderTexture.h +++ b/include/SFML/Graphics/RenderTexture.h @@ -140,14 +140,13 @@ CSFML_GRAPHICS_API sfIntRect sfRenderTexture_getViewport(const sfRenderTexture* /// \brief Convert a point in texture coordinates into view coordinates /// /// \param renderTexture Render texture object -/// \param windowX X coordinate of the point to convert, relative to the texture -/// \param windowY Y coordinate of the point to convert, relative to the texture -/// \param viewX Pointer to fill with the X coordinate of the converted point -/// \param viewY Pointer to fill with the Y coordinate of the converted point +/// \param point Point to convert, relative to the texture /// \param targetView Target view to convert the point to (pass NULL to use the current view) /// +/// \return The converted point, in "world" units +/// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API void sfRenderTexture_convertCoords(const sfRenderTexture* renderTexture, unsigned int windowX, unsigned int windowY, float* viewX, float* viewY, const sfView* targetView); +CSFML_GRAPHICS_API sfVector2f sfRenderTexture_convertCoords(const sfRenderTexture* renderTexture, sfVector2i point, const sfView* targetView); //////////////////////////////////////////////////////////// /// \brief Draw a drawable object to the render-target diff --git a/include/SFML/Graphics/RenderWindow.h b/include/SFML/Graphics/RenderWindow.h index f791047..911e1c7 100644 --- a/include/SFML/Graphics/RenderWindow.h +++ b/include/SFML/Graphics/RenderWindow.h @@ -316,14 +316,13 @@ CSFML_GRAPHICS_API sfIntRect sfRenderWindow_getViewport(const sfRenderWindow* re /// \brief Convert a point in window coordinates into view coordinates /// /// \param renderWindow Render window object -/// \param windowX X coordinate of the point to convert, relative to the window -/// \param windowY Y coordinate of the point to convert, relative to the window -/// \param viewX Pointer to fill with the X coordinate of the converted point -/// \param viewY Pointer to fill with the Y coordinate of the converted point +/// \param point Point to convert, relative to the window /// \param targetView Target view to convert the point to (pass NULL to use the current view) /// +/// \return The converted point, in "world" units +/// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API void sfRenderWindow_convertCoords(const sfRenderWindow* renderWindow, unsigned int windowX, unsigned int windowY, float* viewX, float* viewY, const sfView* targetView); +CSFML_GRAPHICS_API sfVector2f sfRenderWindow_convertCoords(const sfRenderWindow* renderWindow, sfVector2i point, const sfView* targetView); //////////////////////////////////////////////////////////// /// \brief Draw a drawable object to the render-target diff --git a/src/SFML/Graphics/RenderTexture.cpp b/src/SFML/Graphics/RenderTexture.cpp index 1787351..a561da3 100644 --- a/src/SFML/Graphics/RenderTexture.cpp +++ b/src/SFML/Graphics/RenderTexture.cpp @@ -141,18 +141,21 @@ sfIntRect sfRenderTexture_getViewport(const sfRenderTexture* renderTexture, cons //////////////////////////////////////////////////////////// -void sfRenderTexture_convertCoords(const sfRenderTexture* renderTexture, unsigned int textureX, unsigned int textureY, float* viewX, float* viewY, const sfView* targetView) +sfVector2f sfRenderTexture_convertCoords(const sfRenderTexture* renderTexture, sfVector2i point, const sfView* targetView) { - CSFML_CHECK(renderTexture); + sfVector2f result = {0, 0}; + CSFML_CHECK_RETURN(renderWindow, result); - sf::Vector2f point; + sf::Vector2f sfmlPoint; if (targetView) - point = renderTexture->This.convertCoords(textureX, textureY, targetView->This); + sfmlPoint = renderTexture->This.convertCoords(sf::Vector2i(point.x, point.y), targetView->This); else - point = renderTexture->This.convertCoords(textureX, textureY); + sfmlPoint = renderTexture->This.convertCoords(sf::Vector2i(point.x, point.y)); - if (viewX) *viewX = point.x; - if (viewY) *viewY = point.y; + result.x = sfmlPoint.x; + result.y = sfmlPoint.y; + + return result; } diff --git a/src/SFML/Graphics/RenderWindow.cpp b/src/SFML/Graphics/RenderWindow.cpp index 64a1850..23c46ba 100644 --- a/src/SFML/Graphics/RenderWindow.cpp +++ b/src/SFML/Graphics/RenderWindow.cpp @@ -346,18 +346,21 @@ sfIntRect sfRenderWindow_getViewport(const sfRenderWindow* renderWindow, const s //////////////////////////////////////////////////////////// -void sfRenderWindow_convertCoords(const sfRenderWindow* renderWindow, unsigned int windowX, unsigned int windowY, float* viewX, float* viewY, const sfView* targetView) +sfVector2f sfRenderWindow_convertCoords(const sfRenderWindow* renderWindow, sfVector2i point, const sfView* targetView) { - CSFML_CHECK(renderWindow); + sfVector2f result = {0, 0}; + CSFML_CHECK_RETURN(renderWindow, result); - sf::Vector2f point; + sf::Vector2f sfmlPoint; if (targetView) - point = renderWindow->This.convertCoords(windowX, windowY, targetView->This); + sfmlPoint = renderWindow->This.convertCoords(sf::Vector2i(point.x, point.y), targetView->This); else - point = renderWindow->This.convertCoords(windowX, windowY); + sfmlPoint = renderWindow->This.convertCoords(sf::Vector2i(point.x, point.y)); - if (viewX) *viewX = point.x; - if (viewY) *viewY = point.y; + result.x = sfmlPoint.x; + result.y = sfmlPoint.y; + + return result; }