window.SetCursorPosition(halfScreenWidth, halfScreenHeight);
Unfortunately that isn't sufficient because the user can still move the mouse outside the window. What's even worse, if the user clicks when the mouse is outside the window, the SFML window loses focus.
Can anybody post a workaround until we get it?
SFML 2* and Windows only:
Get the HWND of the SFML window with
sf::Window::GetSystemHandle.
Get the window area coordinates to a RECT with
GetClientRect.
Translate the window coordinates to screen coordinates with
ClientToScreen.
Supply those coordinates to
ClipCursor. That limits the the mouse movement to the window area.
For sample code (and how to do it on X11 / OSX), you could check
how SDL does it.
To ungrab mouse, just call ClipCursor(NULL).
*SFML 1.x has no sf::Window::GetSystemHandle, so you would need to get the HWND some other way.