From 56df80a7d365f2200fad324ecd4b623015dc9d6b Mon Sep 17 00:00:00 2001 From: Laurent Gomila Date: Fri, 8 Jul 2011 08:34:43 +0200 Subject: [PATCH] Updated to the new Mouse functions --- include/SFML/Graphics/RenderWindow.h | 10 ---------- include/SFML/Window/Mouse.h | 25 +++++++++++++++++++------ include/SFML/Window/Window.h | 20 -------------------- src/SFML/Graphics/RenderWindow.cpp | 9 --------- src/SFML/Window/Mouse.cpp | 21 +++++++++++++++++++-- src/SFML/Window/Window.cpp | 24 ------------------------ 6 files changed, 38 insertions(+), 71 deletions(-) diff --git a/include/SFML/Graphics/RenderWindow.h b/include/SFML/Graphics/RenderWindow.h index 2579303..7940bb7 100644 --- a/include/SFML/Graphics/RenderWindow.h +++ b/include/SFML/Graphics/RenderWindow.h @@ -152,16 +152,6 @@ CSFML_API void sfRenderWindow_EnableVerticalSync(sfRenderWindow* renderWindow, s //////////////////////////////////////////////////////////// CSFML_API void sfRenderWindow_ShowMouseCursor(sfRenderWindow* renderWindow, sfBool show); -//////////////////////////////////////////////////////////// -/// Change the position of the mouse cursor on a window -/// -/// \param renderWindow : Renderwindow object -/// \param left : Left coordinate of the cursor, relative to the window -/// \param top : Top coordinate of the cursor, relative to the window -/// -//////////////////////////////////////////////////////////// -CSFML_API void sfRenderWindow_SetCursorPosition(sfRenderWindow* renderWindow, unsigned int left, unsigned int top); - //////////////////////////////////////////////////////////// /// Change the position of a window on screen. /// Only works for top-level windows diff --git a/include/SFML/Window/Mouse.h b/include/SFML/Window/Mouse.h index 3fb895e..ff327af 100644 --- a/include/SFML/Window/Mouse.h +++ b/include/SFML/Window/Mouse.h @@ -28,6 +28,7 @@ // Headers //////////////////////////////////////////////////////////// #include +#include //////////////////////////////////////////////////////////// @@ -60,15 +61,27 @@ CSFML_API sfBool sfMouse_IsButtonPressed(sfMouseButton button); /// \brief Get the current position of the mouse /// /// This function returns the current position of the mouse -/// cursor. -/// If the cursor is over a SFML window, the returned position -/// is relative to this window. Otherwise, the returned position -/// is in desktop coordinates. +/// cursor relative to the given window, or desktop if NULL is passed. /// -/// \return Current position of the mouse +/// \param x Variable to fill with the current X position of the mouse +/// \param y Variable to fill with the current Y position of the mouse +/// \param relativeTo Reference window /// //////////////////////////////////////////////////////////// -CSFML_API void sfMouse_GetPosition(int* x, int* y); +CSFML_API void sfMouse_GetPosition(int* x, int* y, const sfWindow* relativeTo); + +//////////////////////////////////////////////////////////// +/// \brief Set the current position of the mouse +/// +/// This function sets the current position of the mouse +/// cursor relative to the given window, or desktop if NULL is passed. +/// +/// \param x New X position of the mouse +/// \param y New Y position of the mouse +/// \param relativeTo Reference window +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfMouse_SetPosition(int x, int y, const sfWindow* relativeTo); #endif // SFML_MOUSE_H diff --git a/include/SFML/Window/Window.h b/include/SFML/Window/Window.h index f25990c..9bc6d98 100644 --- a/include/SFML/Window/Window.h +++ b/include/SFML/Window/Window.h @@ -177,26 +177,6 @@ CSFML_API void sfWindow_EnableVerticalSync(sfWindow* window, sfBool enabled); //////////////////////////////////////////////////////////// CSFML_API void sfWindow_ShowMouseCursor(sfWindow* window, sfBool show); -//////////////////////////////////////////////////////////// -/// Change the position of the mouse cursor on a window -/// -/// \param window : Window object -/// \param left : Left coordinate of the cursor, relative to the window -/// \param top : Top coordinate of the cursor, relative to the window -/// -//////////////////////////////////////////////////////////// -CSFML_API void sfWindow_SetCursorPosition(sfWindow* window, unsigned int left, unsigned int top); - -//////////////////////////////////////////////////////////// -/// Get the position of the mouse cursor on a window -/// -/// \param window : Window object -/// \param left : Left coordinate of the cursor, relative to the window -/// \param top : Top coordinate of the cursor, relative to the window -/// -//////////////////////////////////////////////////////////// -CSFML_API void sfWindow_GetCursorPosition(sfWindow* window, int* left, int* top); - //////////////////////////////////////////////////////////// /// Change the position of a window on screen. /// Only works for top-level windows diff --git a/src/SFML/Graphics/RenderWindow.cpp b/src/SFML/Graphics/RenderWindow.cpp index 304e23b..e00bb3e 100644 --- a/src/SFML/Graphics/RenderWindow.cpp +++ b/src/SFML/Graphics/RenderWindow.cpp @@ -217,15 +217,6 @@ void sfRenderWindow_ShowMouseCursor(sfRenderWindow* renderWindow, sfBool show) } -//////////////////////////////////////////////////////////// -/// Change the position of the mouse cursor on a window -//////////////////////////////////////////////////////////// -void sfRenderWindow_SetCursorPosition(sfRenderWindow* renderWindow, unsigned int left, unsigned int top) -{ - CSFML_CALL(renderWindow, SetCursorPosition(left, top)); -} - - //////////////////////////////////////////////////////////// /// Change the position of a window on screen. /// Only works for top-level windows diff --git a/src/SFML/Window/Mouse.cpp b/src/SFML/Window/Mouse.cpp index ac0a266..c972796 100644 --- a/src/SFML/Window/Mouse.cpp +++ b/src/SFML/Window/Mouse.cpp @@ -26,6 +26,7 @@ // Headers //////////////////////////////////////////////////////////// #include +#include #include #include @@ -42,12 +43,28 @@ sfBool sfMouse_IsButtonPressed(sfMouseButton button) //////////////////////////////////////////////////////////// /// Get the current position of the mouse //////////////////////////////////////////////////////////// -void sfMouse_GetPosition(int* x, int* y) +void sfMouse_GetPosition(int* x, int* y, const sfWindow* relativeTo) { - sf::Vector2i position = sf::Mouse::GetPosition(); + sf::Vector2i position; + if (relativeTo) + position = sf::Mouse::GetPosition(relativeTo->This); + else + position = sf::Mouse::GetPosition(); if (x) *x = position.x; if (y) *y = position.y; } + + +//////////////////////////////////////////////////////////// +/// Get the current position of the mouse +//////////////////////////////////////////////////////////// +void sfMouse_SetPosition(int x, int y, const sfWindow* relativeTo) +{ + if (relativeTo) + sf::Mouse::SetPosition(sf::Vector2i(x, y), relativeTo->This); + else + sf::Mouse::SetPosition(sf::Vector2i(x, y)); +} diff --git a/src/SFML/Window/Window.cpp b/src/SFML/Window/Window.cpp index 1226982..0a1206e 100644 --- a/src/SFML/Window/Window.cpp +++ b/src/SFML/Window/Window.cpp @@ -209,30 +209,6 @@ void sfWindow_ShowMouseCursor(sfWindow* window, sfBool show) } -//////////////////////////////////////////////////////////// -/// Change the position of the mouse cursor on a window -//////////////////////////////////////////////////////////// -void sfWindow_SetCursorPosition(sfWindow* window, unsigned int left, unsigned int top) -{ - CSFML_CALL(window, SetCursorPosition(left, top)) -} - - -//////////////////////////////////////////////////////////// -/// Get the position of the mouse cursor on a window -//////////////////////////////////////////////////////////// -void sfWindow_GetCursorPosition(sfWindow* window, int* left, int* top) -{ - CSFML_CHECK(window); - sf::Vector2i position = window->This.GetCursorPosition(); - - if (left) - *left = position.x; - if (top) - *top = position.y; -} - - //////////////////////////////////////////////////////////// /// Change the position of a window on screen. /// Only works for top-level windows