Made glfwGetCursorPos query system directly.

Fixes #103.
Fixes #153.
Fixes #193.
Fixes #355.
Fixes #381.
This commit is contained in:
Camilla Berglund
2014-02-11 18:24:01 +01:00
parent 641761ddb0
commit d459145d28
11 changed files with 177 additions and 131 deletions
+32 -36
View File
@@ -59,20 +59,23 @@ static void setCursorMode(_GLFWwindow* window, int newMode)
{
if (oldMode == GLFW_CURSOR_DISABLED)
{
window->cursorPosX = _glfw.cursorPosX;
window->cursorPosY = _glfw.cursorPosY;
_glfwPlatformSetCursorPos(window, _glfw.cursorPosX, _glfw.cursorPosY);
_glfwPlatformSetCursorPos(window,
_glfw.cursorPosX,
_glfw.cursorPosY);
}
else if (newMode == GLFW_CURSOR_DISABLED)
{
int width, height;
_glfw.cursorPosX = window->cursorPosX;
_glfw.cursorPosY = window->cursorPosY;
_glfwPlatformGetCursorPos(window,
&_glfw.cursorPosX,
&_glfw.cursorPosY);
window->cursorPosX = _glfw.cursorPosX;
window->cursorPosY = _glfw.cursorPosY;
_glfwPlatformGetWindowSize(window, &width, &height);
_glfwPlatformSetCursorPos(window, width / 2.0, height / 2.0);
_glfwPlatformSetCursorPos(window, width / 2, height / 2);
}
_glfwPlatformApplyCursorMode(window);
@@ -198,22 +201,13 @@ void _glfwInputCursorMotion(_GLFWwindow* window, double x, double y)
window->cursorPosX += x;
window->cursorPosY += y;
}
else
{
if (window->cursorPosX == x && window->cursorPosY == y)
return;
window->cursorPosX = x;
window->cursorPosY = y;
x = window->cursorPosX;
y = window->cursorPosY;
}
if (window->callbacks.cursorPos)
{
window->callbacks.cursorPos((GLFWwindow*) window,
window->cursorPosX,
window->cursorPosY);
}
window->callbacks.cursorPos((GLFWwindow*) window, x, y);
}
void _glfwInputCursorEnter(_GLFWwindow* window, int entered)
@@ -332,10 +326,15 @@ GLFWAPI void glfwGetCursorPos(GLFWwindow* handle, double* xpos, double* ypos)
_GLFW_REQUIRE_INIT();
if (xpos)
*xpos = window->cursorPosX;
if (ypos)
*ypos = window->cursorPosY;
if (window->cursorMode == GLFW_CURSOR_DISABLED)
{
if (xpos)
*xpos = window->cursorPosX;
if (ypos)
*ypos = window->cursorPosY;
}
else
_glfwPlatformGetCursorPos(window, xpos, ypos);
}
GLFWAPI void glfwSetCursorPos(GLFWwindow* handle, double xpos, double ypos)
@@ -347,20 +346,17 @@ GLFWAPI void glfwSetCursorPos(GLFWwindow* handle, double xpos, double ypos)
if (_glfw.focusedWindow != window)
return;
// Don't do anything if the cursor position did not change
if (xpos == window->cursorPosX && ypos == window->cursorPosY)
return;
// Set GLFW cursor position
window->cursorPosX = xpos;
window->cursorPosY = ypos;
// Do not move physical cursor if it is disabled
if (window->cursorMode == GLFW_CURSOR_DISABLED)
return;
// Update physical cursor position
_glfwPlatformSetCursorPos(window, xpos, ypos);
{
// Only update the accumulated position if the cursor is disabled
window->cursorPosX = xpos;
window->cursorPosY = ypos;
}
else
{
// Update system cursor position
_glfwPlatformSetCursorPos(window, xpos, ypos);
}
}
GLFWAPI GLFWcursor* glfwCreateCursor(const GLFWimage* image, int xhot, int yhot)