mirror of
https://github.com/glfw/glfw.git
synced 2024-11-30 05:47:10 +00:00
Unified Win32 cursor clip rect setting.
This commit is contained in:
parent
7b3783abe2
commit
e666835ca6
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user