// Sets the cursor mode for the specified window // static void setCursorMode(_GLFWwindow* window, int newMode) { const int oldMode = window->cursorMode; if (newMode != GLFW_CURSOR_NORMAL && newMode != GLFW_CURSOR_HIDDEN && newMode != GLFW_CURSOR_DISABLED) { _glfwInputError(GLFW_INVALID_ENUM, NULL); return; } if (oldMode == newMode) return; window->cursorMode = newMode; if (_glfw.focusedWindow == window) { if (oldMode == GLFW_CURSOR_DISABLED) { _glfwPlatformSetCursorPos(window, _glfw.cursorPosX, _glfw.cursorPosY); } else if (newMode == GLFW_CURSOR_DISABLED) { int width, height; _glfwPlatformGetCursorPos(window, &_glfw.cursorPosX, &_glfw.cursorPosY); window->cursorPosX = _glfw.cursorPosX; window->cursorPosY = _glfw.cursorPosY; _glfwPlatformGetWindowSize(window, &width, &height); _glfwPlatformSetCursorPos(window, width / 2, height / 2); } _glfwPlatformApplyCursorMode(window); } }
GLFWAPI void glfwGetCursorPos(GLFWwindow* handle, double* xpos, double* ypos) { _GLFWwindow* window = (_GLFWwindow*) handle; if (xpos) *xpos = 0; if (ypos) *ypos = 0; _GLFW_REQUIRE_INIT(); if (window->cursorMode == GLFW_CURSOR_DISABLED) { if (xpos) *xpos = window->cursorPosX; if (ypos) *ypos = window->cursorPosY; } else _glfwPlatformGetCursorPos(window, xpos, ypos); }
void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode) { if (mode == GLFW_CURSOR_DISABLED) { _glfw.win32.disabledCursorWindow = window; _glfwPlatformGetCursorPos(window, &_glfw.win32.restoreCursorPosX, &_glfw.win32.restoreCursorPosY); centerCursor(window); updateClipRect(window); } else if (_glfw.win32.disabledCursorWindow == window) { _glfw.win32.disabledCursorWindow = NULL; updateClipRect(NULL); _glfwPlatformSetCursorPos(window, _glfw.win32.restoreCursorPosX, _glfw.win32.restoreCursorPosY); } if (cursorInClientArea(window)) updateCursorImage(window); }
GLFWAPI void glfwSetInputMode(GLFWwindow* handle, int mode, int value) { _GLFWwindow* window = (_GLFWwindow*) handle; assert(window != NULL); _GLFW_REQUIRE_INIT(); switch (mode) { case GLFW_CURSOR: { if (value != GLFW_CURSOR_NORMAL && value != GLFW_CURSOR_HIDDEN && value != GLFW_CURSOR_DISABLED) { _glfwInputError(GLFW_INVALID_ENUM, "Invalid cursor mode %i", value); return; } if (window->cursorMode == value) return; window->cursorMode = value; _glfwPlatformGetCursorPos(window, &window->virtualCursorPosX, &window->virtualCursorPosY); if (_glfwPlatformWindowFocused(window)) _glfwPlatformSetCursorMode(window, value); return; } case GLFW_STICKY_KEYS: { if (window->stickyKeys == value) return; if (!value) { int i; // Release all sticky keys for (i = 0; i <= GLFW_KEY_LAST; i++) { if (window->keys[i] == _GLFW_STICK) window->keys[i] = GLFW_RELEASE; } } window->stickyKeys = value ? GLFW_TRUE : GLFW_FALSE; return; } case GLFW_STICKY_MOUSE_BUTTONS: { if (window->stickyMouseButtons == value) return; if (!value) { int i; // Release all sticky mouse buttons for (i = 0; i <= GLFW_MOUSE_BUTTON_LAST; i++) { if (window->mouseButtons[i] == _GLFW_STICK) window->mouseButtons[i] = GLFW_RELEASE; } } window->stickyMouseButtons = value ? GLFW_TRUE : GLFW_FALSE; return; } } _glfwInputError(GLFW_INVALID_ENUM, "Invalid input mode %i", mode); }