mirror of
https://github.com/glfw/glfw.git
synced 2026-09-22 00:49:48 +00:00
Refactor cursor mode paths
This is the refactoring part of adding GLFW_CURSOR_CAPTURED, separated out to help keep 3.3-stable similar to the main branch. Related to #58.
This commit is contained in:
committed by
Camilla Löwy
parent
03af6b3d4c
commit
a46f829de8
+58
-25
@@ -249,20 +249,24 @@ static void updateCursorImage(_GLFWwindow* window)
|
||||
SetCursor(NULL);
|
||||
}
|
||||
|
||||
// Updates the cursor clip rect
|
||||
// Sets the cursor clip rect to the window content area
|
||||
//
|
||||
static void updateClipRect(_GLFWwindow* window)
|
||||
static void captureCursor(_GLFWwindow* window)
|
||||
{
|
||||
if (window)
|
||||
{
|
||||
RECT clipRect;
|
||||
GetClientRect(window->win32.handle, &clipRect);
|
||||
ClientToScreen(window->win32.handle, (POINT*) &clipRect.left);
|
||||
ClientToScreen(window->win32.handle, (POINT*) &clipRect.right);
|
||||
ClipCursor(&clipRect);
|
||||
}
|
||||
else
|
||||
ClipCursor(NULL);
|
||||
RECT clipRect;
|
||||
GetClientRect(window->win32.handle, &clipRect);
|
||||
ClientToScreen(window->win32.handle, (POINT*) &clipRect.left);
|
||||
ClientToScreen(window->win32.handle, (POINT*) &clipRect.right);
|
||||
ClipCursor(&clipRect);
|
||||
_glfw.win32.capturedCursorWindow = window;
|
||||
}
|
||||
|
||||
// Disabled clip cursor
|
||||
//
|
||||
static void releaseCursor(void)
|
||||
{
|
||||
ClipCursor(NULL);
|
||||
_glfw.win32.capturedCursorWindow = NULL;
|
||||
}
|
||||
|
||||
// Enables WM_INPUT messages for the mouse for the specified window
|
||||
@@ -301,7 +305,7 @@ static void disableCursor(_GLFWwindow* window)
|
||||
&_glfw.win32.restoreCursorPosY);
|
||||
updateCursorImage(window);
|
||||
_glfwCenterCursorInContentArea(window);
|
||||
updateClipRect(window);
|
||||
captureCursor(window);
|
||||
|
||||
if (window->rawMouseMotion)
|
||||
enableRawMouseMotion(window);
|
||||
@@ -315,7 +319,7 @@ static void enableCursor(_GLFWwindow* window)
|
||||
disableRawMouseMotion(window);
|
||||
|
||||
_glfw.win32.disabledCursorWindow = NULL;
|
||||
updateClipRect(NULL);
|
||||
releaseCursor();
|
||||
_glfwSetCursorPosWin32(window,
|
||||
_glfw.win32.restoreCursorPosX,
|
||||
_glfw.win32.restoreCursorPosY);
|
||||
@@ -1004,8 +1008,8 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l
|
||||
(window->win32.maximized &&
|
||||
wParam != SIZE_RESTORED);
|
||||
|
||||
if (_glfw.win32.disabledCursorWindow == window)
|
||||
updateClipRect(window);
|
||||
if (_glfw.win32.capturedCursorWindow == window)
|
||||
captureCursor(window);
|
||||
|
||||
if (window->win32.iconified != iconified)
|
||||
_glfwInputWindowIconify(window, iconified);
|
||||
@@ -1040,8 +1044,8 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l
|
||||
|
||||
case WM_MOVE:
|
||||
{
|
||||
if (_glfw.win32.disabledCursorWindow == window)
|
||||
updateClipRect(window);
|
||||
if (_glfw.win32.capturedCursorWindow == window)
|
||||
captureCursor(window);
|
||||
|
||||
// NOTE: This cannot use LOWORD/HIWORD recommended by MSDN, as
|
||||
// those macros do not handle negative window positions correctly
|
||||
@@ -1495,7 +1499,10 @@ void _glfwDestroyWindowWin32(_GLFWwindow* window)
|
||||
window->context.destroy(window);
|
||||
|
||||
if (_glfw.win32.disabledCursorWindow == window)
|
||||
_glfw.win32.disabledCursorWindow = NULL;
|
||||
enableCursor(window);
|
||||
|
||||
if (_glfw.win32.capturedCursorWindow == window)
|
||||
releaseCursor();
|
||||
|
||||
if (window->win32.handle)
|
||||
{
|
||||
@@ -2142,14 +2149,40 @@ void _glfwSetCursorPosWin32(_GLFWwindow* window, double xpos, double ypos)
|
||||
|
||||
void _glfwSetCursorModeWin32(_GLFWwindow* window, int mode)
|
||||
{
|
||||
if (mode == GLFW_CURSOR_DISABLED)
|
||||
if (_glfwWindowFocusedWin32(window))
|
||||
{
|
||||
if (_glfwWindowFocusedWin32(window))
|
||||
disableCursor(window);
|
||||
if (mode == GLFW_CURSOR_DISABLED)
|
||||
{
|
||||
_glfwGetCursorPosWin32(window,
|
||||
&_glfw.win32.restoreCursorPosX,
|
||||
&_glfw.win32.restoreCursorPosY);
|
||||
_glfwCenterCursorInContentArea(window);
|
||||
if (window->rawMouseMotion)
|
||||
enableRawMouseMotion(window);
|
||||
}
|
||||
else if (_glfw.win32.disabledCursorWindow == window)
|
||||
{
|
||||
if (window->rawMouseMotion)
|
||||
disableRawMouseMotion(window);
|
||||
}
|
||||
|
||||
if (mode == GLFW_CURSOR_DISABLED)
|
||||
captureCursor(window);
|
||||
else
|
||||
releaseCursor();
|
||||
|
||||
if (mode == GLFW_CURSOR_DISABLED)
|
||||
_glfw.win32.disabledCursorWindow = window;
|
||||
else if (_glfw.win32.disabledCursorWindow == window)
|
||||
{
|
||||
_glfw.win32.disabledCursorWindow = NULL;
|
||||
_glfwSetCursorPosWin32(window,
|
||||
_glfw.win32.restoreCursorPosX,
|
||||
_glfw.win32.restoreCursorPosY);
|
||||
}
|
||||
}
|
||||
else if (_glfw.win32.disabledCursorWindow == window)
|
||||
enableCursor(window);
|
||||
else if (cursorInContentArea(window))
|
||||
|
||||
if (cursorInContentArea(window))
|
||||
updateCursorImage(window);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user