lonesock wrote on Tuesday, May 01, 2007:
OK, here is my "patch" (sorry, not in any standard diff format)
All of this applies to the CVS HEAD version of win32_window.c
the simple functions here are shown in their entirety, just
Copy-N-Paste over the old versions.
void _glfwPlatformHideMouseCursor( void )
{
// Hide cursor
ShowCursor( FALSE );
// clip cursor to the window
RECT ClipWindowRect;
if\( GetWindowRect\( \_glfwWin.Wnd, &ClipWindowRect \) \)
\{
ClipCursor\( &ClipWindowRect \);
\}
// Capture cursor to user window
SetCapture\( \_glfwWin.Wnd \);
}
void _glfwPlatformShowMouseCursor( void )
{
// Un-capture cursor
ReleaseCapture();
// unclip cursor from the window
ClipCursor\( NULL \);
// Show cursor
ShowCursor\( TRUE \);
}
These two work great for clipping the mouse cursor to the _exsting_
window, however you need to update the clip rectangle any time the
coordinates of the window change, so in the
_glfwWindowCallback
function, I needed to modify the
case WM_SIZE:
and I needed to add the
case WM_MOVE:
Here are the relevant snippets:
// Resize the window?
case WM_SIZE:
// get the new size
_glfwWin.Width = LOWORD(lParam);
_glfwWin.Height = HIWORD(lParam);
// if the mouse is locked, I need to update the locking coordinates
if( _glfwWin.MouseLock )
{
RECT ClipWindowRect;
if( GetWindowRect( _glfwWin.Wnd, &ClipWindowRect ) )
{
ClipCursor( &ClipWindowRect );
}
}
// and call the user-supplied function, if it exists
if( _glfwWin.WindowSizeCallback )
{
_glfwWin.WindowSizeCallback( LOWORD(lParam),
HIWORD(lParam) );
}
return 0;
// Move the window?
case WM\_MOVE:
// if the mouse is locked, I need to update the locking coordinates
if\( \_glfwWin.MouseLock \)
\{
RECT ClipWindowRect;
if\( GetWindowRect\( \_glfwWin.Wnd, &ClipWindowRect \) \)
\{
ClipCursor\( &ClipWindowRect \);
\}
\}
// do I return something? or just break?
return 0;
Please Note that I did not know how to finish the WM_MOVE case…sometimes there was a return 0 or 1, and sometimes a break. I defaulted to the same behavior as the WM_SIZE case, which was to return 0, though that may be wrong…please help, somebody?
Oh, and while I’m here, one more plug for my custom ICON patch [8^)
inside _glfwPlatformOpenWindow()
// modifying this to load a user-specified Icon, if available
wc.hIcon = LoadIcon( wc.hInstance, "GLFW_ICON" ); // Load default icon
if( !wc.hIcon )
wc.hIcon = LoadIcon( NULL, IDI_WINLOGO ); // Load default icon