Fixed captured cursor mode on OS X.

This commit is contained in:
Camilla Berglund 2013-04-22 00:38:51 +02:00
parent 7423cfa5bf
commit 3ec843a1da
2 changed files with 29 additions and 17 deletions

View File

@ -109,6 +109,8 @@ typedef struct _GLFWlibraryNS
id autoreleasePool; id autoreleasePool;
id cursor; id cursor;
GLboolean cursorHidden;
char* clipboardString; char* clipboardString;
_GLFWjoy joysticks[GLFW_JOYSTICK_LAST + 1]; _GLFWjoy joysticks[GLFW_JOYSTICK_LAST + 1];

View File

@ -942,26 +942,36 @@ void _glfwPlatformSetCursorPos(_GLFWwindow* window, double x, double y)
void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode) void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
{ {
// Unhide the cursor if the last mode was CAPTURED. if (mode == GLFW_CURSOR_HIDDEN)
if (window->cursorMode == GLFW_CURSOR_CAPTURED) { {
CGAssociateMouseAndMouseCursorPosition(true); [window->ns.object enableCursorRects];
[window->ns.object invalidateCursorRectsForView:window->ns.view];
}
else
{
[window->ns.object disableCursorRects];
[window->ns.object invalidateCursorRectsForView:window->ns.view];
} }
switch (mode) if (mode == GLFW_CURSOR_CAPTURED)
{ {
case GLFW_CURSOR_NORMAL: CGAssociateMouseAndMouseCursorPosition(false);
[window->ns.object disableCursorRects];
[window->ns.object invalidateCursorRectsForView:window->ns.view]; if (!_glfw.ns.cursorHidden)
break; {
case GLFW_CURSOR_HIDDEN: [NSCursor hide];
[window->ns.object enableCursorRects]; _glfw.ns.cursorHidden = GL_TRUE;
[window->ns.object invalidateCursorRectsForView:window->ns.view]; }
break; }
case GLFW_CURSOR_CAPTURED: else
[window->ns.object enableCursorRects]; {
[window->ns.object invalidateCursorRectsForView:window->ns.view]; CGAssociateMouseAndMouseCursorPosition(true);
CGAssociateMouseAndMouseCursorPosition(false);
break; if (_glfw.ns.cursorHidden)
{
[NSCursor unhide];
_glfw.ns.cursorHidden = GL_FALSE;
}
} }
} }