From c7a316e445d74b214461f26e1310f18d94a0c72d Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sat, 30 Jun 2007 16:19:56 +0000 Subject: [PATCH] From Mike Connell, "This is a tiny fix for win32. The current code takes the mouse cursor position and adds it to the window (left,top) position, and sends the mouse cursor there. But this doesn't take into account the window decoration. The new code converts the given (x,y) coordinates from the client area coordinate system to the screen instead using ClientToScreen. I think this is the natural windows way to do it. Tested on XP with osgviewer " Note from Robet Osfield, made a few changes to layout to make it more consistent with the rest of the OSG and used #if 0 instead if (0) blocks. --- src/osgViewer/GraphicsWindowWin32.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/osgViewer/GraphicsWindowWin32.cpp b/src/osgViewer/GraphicsWindowWin32.cpp index 10e0bc145..ec047d0e7 100644 --- a/src/osgViewer/GraphicsWindowWin32.cpp +++ b/src/osgViewer/GraphicsWindowWin32.cpp @@ -1724,6 +1724,7 @@ void GraphicsWindowWin32::requestWarpPointer( float x, float y ) RECT windowRect; +#if 0 if (!::GetWindowRect(_hwnd, &windowRect)) { reportErrorForScreen("GraphicsWindowWin32::requestWarpPointer() - Unable to get window rectangle", _traits->screenNum, ::GetLastError()); @@ -1734,8 +1735,24 @@ void GraphicsWindowWin32::requestWarpPointer( float x, float y ) { reportErrorForScreen("GraphicsWindowWin32::requestWarpPointer() - Unable to set cursor position", _traits->screenNum, ::GetLastError()); return; + } +#else + // MIKEC: NEW CODE + POINT pt; + pt.x=x; + pt.y=y; + // convert point in client area coordinates to screen coordinates + if (!::ClientToScreen(_hwnd,&pt)) + { + reportErrorForScreen("GraphicsWindowWin32::requestWarpPointer() - Unable to convert cursor position to screen coordinates", _traits->screenNum, ::GetLastError()); } - + if (!::SetCursorPos(pt.x,pt.y)) + { + reportErrorForScreen("GraphicsWindowWin32::requestWarpPointer() - Unable to set cursor position", _traits->screenNum, ::GetLastError()); + return; + } +#endif + getEventQueue()->mouseWarped(x,y); }