Removed Window::GetCursorPosition/SetCursorPosition, added Mouse::GetPosition/SetPosition (two versions: one that handles desktop coordinates, one that handles window coordinates)
This commit is contained in:
parent
e95323e2ea
commit
6fd80e2598
19 changed files with 287 additions and 199 deletions
|
@ -213,16 +213,48 @@ Vector2i InputImpl::GetMousePosition()
|
|||
{
|
||||
// we don't care about these but they are required
|
||||
::Window root, child;
|
||||
int wx, wy;
|
||||
int x, y;
|
||||
unsigned int buttons;
|
||||
|
||||
int gx = 0;
|
||||
int gy = 0;
|
||||
XQueryPointer(global.display, global.window, &root, &child, &gx, &gy, &x, &y, &buttons);
|
||||
|
||||
return Vector2i(gx, gy);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2i InputImpl::GetMousePosition(const Window& relativeTo)
|
||||
{
|
||||
// we don't care about these but they are required
|
||||
::Window root, child;
|
||||
int gx, gy;
|
||||
unsigned int buttons;
|
||||
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
XQueryPointer(global.display, global.window, &root, &child, &x, &y, &wx, &wy, &buttons);
|
||||
XQueryPointer(global.display, relativeTo.GetSystemHandle(), &root, &child, &gx, &gy, &x, &y, &buttons);
|
||||
|
||||
return Vector2i(x, y);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void InputImpl::SetMousePosition(const Vector2i& position)
|
||||
{
|
||||
XWarpPointer(global.display, None, global.window, 0, 0, 0, 0, position.x, position.y);
|
||||
XFlush(global.display);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void InputImpl::SetMousePosition(const Vector2i& position, const Window& relativeTo)
|
||||
{
|
||||
XWarpPointer(global.display, None, relativeTo.GetSystemHandle(), 0, 0, 0, 0, position.x, position.y);
|
||||
XFlush(global.display);
|
||||
}
|
||||
|
||||
} // namespace priv
|
||||
|
||||
} // namespace sf
|
|
@ -65,14 +65,54 @@ public :
|
|||
static bool IsMouseButtonPressed(Mouse::Button button);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the current position of the mouse
|
||||
/// \brief Get the current position of the mouse in desktop coordinates
|
||||
///
|
||||
/// This function returns the mouse position in desktop coordinates.
|
||||
/// This function returns the current position of the mouse
|
||||
/// cursor, in global (desktop) coordinates.
|
||||
///
|
||||
/// \return Current position of the mouse
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static Vector2i GetMousePosition();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the current position of the mouse in window coordinates
|
||||
///
|
||||
/// This function returns the current position of the mouse
|
||||
/// cursor, relative to the given window.
|
||||
/// If no window is used, it returns desktop coordinates.
|
||||
///
|
||||
/// \param relativeTo Reference window
|
||||
///
|
||||
/// \return Current position of the mouse
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static Vector2i GetMousePosition(const Window& relativeTo);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the current position of the mouse in desktop coordinates
|
||||
///
|
||||
/// This function sets the current position of the mouse
|
||||
/// cursor in global (desktop) coordinates.
|
||||
/// If no window is used, it sets the position in desktop coordinates.
|
||||
///
|
||||
/// \param position New position of the mouse
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static void SetMousePosition(const Vector2i& position);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the current position of the mouse in window coordinates
|
||||
///
|
||||
/// This function sets the current position of the mouse
|
||||
/// cursor, relative to the given window.
|
||||
/// If no window is used, it sets the position in desktop coordinates.
|
||||
///
|
||||
/// \param position New position of the mouse
|
||||
/// \param relativeTo Reference window
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static void SetMousePosition(const Vector2i& position, const Window& relativeTo);
|
||||
};
|
||||
|
||||
} // namespace priv
|
||||
|
|
|
@ -302,30 +302,6 @@ void WindowImplX11::ShowMouseCursor(bool show)
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowImplX11::SetCursorPosition(unsigned int x, unsigned int y)
|
||||
{
|
||||
XWarpPointer(myDisplay, None, myWindow, 0, 0, 0, 0, x, y);
|
||||
XFlush(myDisplay);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2i WindowImplX11::GetCursorPosition() const
|
||||
{
|
||||
// we don't care about these but they are required
|
||||
::Window root, child;
|
||||
int gx, gy;
|
||||
unsigned int buttons;
|
||||
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
XQueryPointer(myDisplay, myWindow, &root, &child, &gx, &gy, &x, &y, &buttons);
|
||||
|
||||
return Vector2i(x, y);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowImplX11::SetPosition(int x, int y)
|
||||
{
|
||||
|
|
|
@ -105,23 +105,6 @@ private :
|
|||
////////////////////////////////////////////////////////////
|
||||
virtual void ShowMouseCursor(bool show);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change the position of the mouse cursor
|
||||
///
|
||||
/// \param x Left coordinate of the cursor, relative to the window
|
||||
/// \param y Top coordinate of the cursor, relative to the window
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void SetCursorPosition(unsigned int x, unsigned int y);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the position of the mouse cursor
|
||||
///
|
||||
/// \return Current mouse cursor position, relative to the window
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual Vector2i GetCursorPosition() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change the position of the window on screen
|
||||
///
|
||||
|
|
|
@ -42,17 +42,28 @@ bool Mouse::IsButtonPressed(Button button)
|
|||
////////////////////////////////////////////////////////////
|
||||
Vector2i Mouse::GetPosition()
|
||||
{
|
||||
const Window* focusWindow = Window::GetMouseFocusWindow();
|
||||
if (focusWindow)
|
||||
{
|
||||
// Position relative to the focus window
|
||||
return focusWindow->GetCursorPosition();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Desktop position
|
||||
return priv::InputImpl::GetMousePosition();
|
||||
}
|
||||
return priv::InputImpl::GetMousePosition();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2i Mouse::GetPosition(const Window& relativeTo)
|
||||
{
|
||||
return priv::InputImpl::GetMousePosition(relativeTo);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Mouse::SetPosition(const Vector2i& position)
|
||||
{
|
||||
priv::InputImpl::SetMousePosition(position);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Mouse::SetPosition(const Vector2i& position, const Window& relativeTo)
|
||||
{
|
||||
priv::InputImpl::SetMousePosition(position, relativeTo);
|
||||
}
|
||||
|
||||
} // namespace sf
|
||||
|
|
|
@ -66,14 +66,54 @@ public :
|
|||
static bool IsMouseButtonPressed(Mouse::Button button);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the current position of the mouse
|
||||
/// \brief Get the current position of the mouse in desktop coordinates
|
||||
///
|
||||
/// This function returns the mouse position in desktop coordinates.
|
||||
/// This function returns the current position of the mouse
|
||||
/// cursor, in global (desktop) coordinates.
|
||||
///
|
||||
/// \return Current position of the mouse
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static Vector2i GetMousePosition();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the current position of the mouse in window coordinates
|
||||
///
|
||||
/// This function returns the current position of the mouse
|
||||
/// cursor, relative to the given window.
|
||||
/// If no window is used, it returns desktop coordinates.
|
||||
///
|
||||
/// \param relativeTo Reference window
|
||||
///
|
||||
/// \return Current position of the mouse
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static Vector2i GetMousePosition(const Window& relativeTo);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the current position of the mouse in desktop coordinates
|
||||
///
|
||||
/// This function sets the current position of the mouse
|
||||
/// cursor in global (desktop) coordinates.
|
||||
/// If no window is used, it sets the position in desktop coordinates.
|
||||
///
|
||||
/// \param position New position of the mouse
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static void SetMousePosition(const Vector2i& position);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the current position of the mouse in window coordinates
|
||||
///
|
||||
/// This function sets the current position of the mouse
|
||||
/// cursor, relative to the given window.
|
||||
/// If no window is used, it sets the position in desktop coordinates.
|
||||
///
|
||||
/// \param position New position of the mouse
|
||||
/// \param relativeTo Reference window
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static void SetMousePosition(const Vector2i& position, const Window& relativeTo);
|
||||
};
|
||||
|
||||
} // namespace priv
|
||||
|
|
|
@ -60,6 +60,28 @@ Vector2i InputImpl::GetMousePosition()
|
|||
return Vector2i(pos.x, pos.y);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2i InputImpl::GetMousePosition(const Window& relativeTo)
|
||||
{
|
||||
// @to be implemented
|
||||
return Vector2i();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void InputImpl::SetMousePosition(const Vector2i& position)
|
||||
{
|
||||
// @to be implemented
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void InputImpl::SetMousePosition(const Vector2i& position, const Window& relativeTo)
|
||||
{
|
||||
// @to be implemented
|
||||
}
|
||||
|
||||
} // namespace priv
|
||||
|
||||
} // namespace sf
|
||||
|
|
|
@ -255,23 +255,6 @@ private:
|
|||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void ShowMouseCursor(bool show);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change the position of the mouse cursor
|
||||
///
|
||||
/// \param x Left coordinate of the cursor, relative to the window
|
||||
/// \param y Top coordinate of the cursor, relative to the window
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void SetCursorPosition(unsigned int x, unsigned int y);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the position of the mouse cursor
|
||||
///
|
||||
/// \return Current mouse cursor position, relative to the window
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual Vector2i GetCursorPosition() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change the position of the window on screen
|
||||
|
|
|
@ -338,21 +338,6 @@ void WindowImplCocoa::ShowMouseCursor(bool show)
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowImplCocoa::SetCursorPosition(unsigned int x, unsigned int y)
|
||||
{
|
||||
[myDelegate setCursorPositionToX:x Y:y];
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2i WindowImplCocoa::GetCursorPosition() const
|
||||
{
|
||||
NSPoint pos = [myDelegate cursorPosition];
|
||||
return Vector2i(pos.x, pos.y);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowImplCocoa::SetPosition(int x, int y)
|
||||
{
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
#define _WIN32_WINDOWS 0x0501
|
||||
#define _WIN32_WINNT 0x0501
|
||||
#include <SFML/Window/Window.hpp>
|
||||
#include <SFML/Window/Win32/InputImpl.hpp>
|
||||
#include <windows.h>
|
||||
|
||||
|
@ -168,10 +169,35 @@ bool InputImpl::IsMouseButtonPressed(Mouse::Button button)
|
|||
////////////////////////////////////////////////////////////
|
||||
Vector2i InputImpl::GetMousePosition()
|
||||
{
|
||||
POINT position;
|
||||
GetCursorPos(&position);
|
||||
POINT point;
|
||||
GetCursorPos(&point);
|
||||
return Vector2i(point.x, point.y);
|
||||
}
|
||||
|
||||
return Vector2i(position.x, position.y);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2i InputImpl::GetMousePosition(const Window& relativeTo)
|
||||
{
|
||||
POINT point;
|
||||
GetCursorPos(&point);
|
||||
ScreenToClient(relativeTo.GetSystemHandle(), &point);
|
||||
return Vector2i(point.x, point.y);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void InputImpl::SetMousePosition(const Vector2i& position)
|
||||
{
|
||||
SetCursorPos(position.x, position.y);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void InputImpl::SetMousePosition(const Vector2i& position, const Window& relativeTo)
|
||||
{
|
||||
POINT point = {position.x, position.y};
|
||||
ClientToScreen(relativeTo.GetSystemHandle(), &point);
|
||||
SetCursorPos(point.x, point.y);
|
||||
}
|
||||
|
||||
} // namespace priv
|
||||
|
|
|
@ -65,14 +65,54 @@ public :
|
|||
static bool IsMouseButtonPressed(Mouse::Button button);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the current position of the mouse
|
||||
/// \brief Get the current position of the mouse in desktop coordinates
|
||||
///
|
||||
/// This function returns the mouse position in desktop coordinates.
|
||||
/// This function returns the current position of the mouse
|
||||
/// cursor, in global (desktop) coordinates.
|
||||
///
|
||||
/// \return Current position of the mouse
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static Vector2i GetMousePosition();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the current position of the mouse in window coordinates
|
||||
///
|
||||
/// This function returns the current position of the mouse
|
||||
/// cursor, relative to the given window.
|
||||
/// If no window is used, it returns desktop coordinates.
|
||||
///
|
||||
/// \param relativeTo Reference window
|
||||
///
|
||||
/// \return Current position of the mouse
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static Vector2i GetMousePosition(const Window& relativeTo);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the current position of the mouse in desktop coordinates
|
||||
///
|
||||
/// This function sets the current position of the mouse
|
||||
/// cursor in global (desktop) coordinates.
|
||||
/// If no window is used, it sets the position in desktop coordinates.
|
||||
///
|
||||
/// \param position New position of the mouse
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static void SetMousePosition(const Vector2i& position);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the current position of the mouse in window coordinates
|
||||
///
|
||||
/// This function sets the current position of the mouse
|
||||
/// cursor, relative to the given window.
|
||||
/// If no window is used, it sets the position in desktop coordinates.
|
||||
///
|
||||
/// \param position New position of the mouse
|
||||
/// \param relativeTo Reference window
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static void SetMousePosition(const Vector2i& position, const Window& relativeTo);
|
||||
};
|
||||
|
||||
} // namespace priv
|
||||
|
|
|
@ -231,26 +231,6 @@ void WindowImplWin32::ShowMouseCursor(bool show)
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowImplWin32::SetCursorPosition(unsigned int x, unsigned int y)
|
||||
{
|
||||
POINT position = {x, y};
|
||||
ClientToScreen(myHandle, &position);
|
||||
SetCursorPos(position.x, position.y);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2i WindowImplWin32::GetCursorPosition() const
|
||||
{
|
||||
POINT position;
|
||||
GetCursorPos(&position);
|
||||
ScreenToClient(myHandle, &position);
|
||||
|
||||
return Vector2i(position.x, position.y);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowImplWin32::SetPosition(int x, int y)
|
||||
{
|
||||
|
|
|
@ -94,23 +94,6 @@ private :
|
|||
////////////////////////////////////////////////////////////
|
||||
virtual void ShowMouseCursor(bool show);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change the position of the mouse cursor
|
||||
///
|
||||
/// \param x Left coordinate of the cursor, relative to the window
|
||||
/// \param y Top coordinate of the cursor, relative to the window
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void SetCursorPosition(unsigned int x, unsigned int y);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the position of the mouse cursor
|
||||
///
|
||||
/// \return Current mouse cursor position, relative to the window
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual Vector2i GetCursorPosition() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change the position of the window on screen
|
||||
///
|
||||
|
|
|
@ -242,21 +242,6 @@ void Window::ShowMouseCursor(bool show)
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Window::SetCursorPosition(unsigned int x, unsigned int y)
|
||||
{
|
||||
if (myWindow)
|
||||
myWindow->SetCursorPosition(x, y);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2i Window::GetCursorPosition() const
|
||||
{
|
||||
return myWindow ? myWindow->GetCursorPosition() : Vector2i(0, 0);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Window::SetPosition(int x, int y)
|
||||
{
|
||||
|
|
|
@ -141,23 +141,6 @@ public :
|
|||
////////////////////////////////////////////////////////////
|
||||
virtual void ShowMouseCursor(bool show) = 0;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change the position of the mouse cursor
|
||||
///
|
||||
/// \param x Left coordinate of the cursor, relative to the window
|
||||
/// \param y Top coordinate of the cursor, relative to the window
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void SetCursorPosition(unsigned int x, unsigned int y) = 0;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the position of the mouse cursor
|
||||
///
|
||||
/// \return Current mouse cursor position, relative to the window
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual Vector2i GetCursorPosition() const = 0;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change the position of the window on screen
|
||||
///
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue