mirror of
https://github.com/glfw/glfw.git
synced 2024-11-26 14:24:35 +00:00
Restore cursor position on capture mode exit.
This commit is contained in:
parent
648c8e7371
commit
008376d450
21
src/input.c
21
src/input.c
@ -38,8 +38,7 @@
|
|||||||
//
|
//
|
||||||
static void setCursorMode(_GLFWwindow* window, int newMode)
|
static void setCursorMode(_GLFWwindow* window, int newMode)
|
||||||
{
|
{
|
||||||
int width, height, oldMode;
|
int oldMode;
|
||||||
double centerPosX, centerPosY;
|
|
||||||
|
|
||||||
if (newMode != GLFW_CURSOR_NORMAL &&
|
if (newMode != GLFW_CURSOR_NORMAL &&
|
||||||
newMode != GLFW_CURSOR_HIDDEN &&
|
newMode != GLFW_CURSOR_HIDDEN &&
|
||||||
@ -53,19 +52,21 @@ static void setCursorMode(_GLFWwindow* window, int newMode)
|
|||||||
if (oldMode == newMode)
|
if (oldMode == newMode)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_glfwPlatformGetWindowSize(window, &width, &height);
|
if (oldMode == GLFW_CURSOR_CAPTURED)
|
||||||
|
_glfwPlatformSetCursorPos(window, _glfw.cursorPosX, _glfw.cursorPosY);
|
||||||
|
else if (newMode == GLFW_CURSOR_CAPTURED)
|
||||||
|
{
|
||||||
|
int width, height;
|
||||||
|
|
||||||
centerPosX = width / 2.0;
|
_glfw.cursorPosX = window->cursorPosX;
|
||||||
centerPosY = height / 2.0;
|
_glfw.cursorPosY = window->cursorPosY;
|
||||||
|
|
||||||
if (oldMode == GLFW_CURSOR_CAPTURED || newMode == GLFW_CURSOR_CAPTURED)
|
_glfwPlatformGetWindowSize(window, &width, &height);
|
||||||
_glfwPlatformSetCursorPos(window, centerPosX, centerPosY);
|
_glfwPlatformSetCursorPos(window, width / 2.0, height / 2.0);
|
||||||
|
}
|
||||||
|
|
||||||
_glfwPlatformSetCursorMode(window, newMode);
|
_glfwPlatformSetCursorMode(window, newMode);
|
||||||
window->cursorMode = newMode;
|
window->cursorMode = newMode;
|
||||||
|
|
||||||
if (oldMode == GLFW_CURSOR_CAPTURED)
|
|
||||||
_glfwInputCursorMotion(window, window->cursorPosX, window->cursorPosY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set sticky keys mode for the specified window
|
// Set sticky keys mode for the specified window
|
||||||
|
@ -291,6 +291,8 @@ struct _GLFWlibrary
|
|||||||
{
|
{
|
||||||
_GLFWhints hints;
|
_GLFWhints hints;
|
||||||
|
|
||||||
|
double cursorPosX, cursorPosY;
|
||||||
|
|
||||||
_GLFWwindow* windowListHead;
|
_GLFWwindow* windowListHead;
|
||||||
_GLFWwindow* focusedWindow;
|
_GLFWwindow* focusedWindow;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user