1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-23 10:48:51 -05:00

Unified Win32 cursor clip rect setting.

This commit is contained in:
Camilla Berglund 2013-02-20 17:29:06 +01:00
parent 7b3783abe2
commit e666835ca6

View File

@ -34,6 +34,18 @@
#include <malloc.h> #include <malloc.h>
#include <windowsx.h> #include <windowsx.h>
// Updates the cursor clip rect
//
static void updateClipRect(_GLFWwindow* window)
{
RECT clipRect;
GetClientRect(window->win32.handle, &clipRect);
ClientToScreen(window->win32.handle, (POINT*) &clipRect.left);
ClientToScreen(window->win32.handle, (POINT*) &clipRect.right);
ClipCursor(&clipRect);
}
// Hide mouse cursor // Hide mouse cursor
// //
static void hideCursor(_GLFWwindow* window) static void hideCursor(_GLFWwindow* window)
@ -45,15 +57,8 @@ static void hideCursor(_GLFWwindow* window)
// //
static void captureCursor(_GLFWwindow* window) static void captureCursor(_GLFWwindow* window)
{ {
RECT ClipWindowRect;
ShowCursor(FALSE); ShowCursor(FALSE);
updateClipRect(window);
// Clip cursor to the window
if (GetWindowRect(window->win32.handle, &ClipWindowRect))
ClipCursor(&ClipWindowRect);
// Capture cursor to user window
SetCapture(window->win32.handle); SetCapture(window->win32.handle);
} }
@ -571,13 +576,8 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
case WM_SIZE: case WM_SIZE:
{ {
// If window is in cursor capture mode, update clipping rect
if (window->cursorMode == GLFW_CURSOR_CAPTURED) if (window->cursorMode == GLFW_CURSOR_CAPTURED)
{ updateClipRect(window);
RECT ClipWindowRect;
if (GetWindowRect(window->win32.handle, &ClipWindowRect))
ClipCursor(&ClipWindowRect);
}
_glfwInputWindowSize(window, LOWORD(lParam), HIWORD(lParam)); _glfwInputWindowSize(window, LOWORD(lParam), HIWORD(lParam));
return 0; return 0;
@ -585,13 +585,8 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
case WM_MOVE: case WM_MOVE:
{ {
// If window is in cursor capture mode, update clipping rect
if (window->cursorMode == GLFW_CURSOR_CAPTURED) if (window->cursorMode == GLFW_CURSOR_CAPTURED)
{ updateClipRect(window);
RECT ClipWindowRect;
if (GetWindowRect(window->win32.handle, &ClipWindowRect))
ClipCursor(&ClipWindowRect);
}
_glfwInputWindowPos(window, LOWORD(lParam), HIWORD(lParam)); _glfwInputWindowPos(window, LOWORD(lParam), HIWORD(lParam));
return 0; return 0;