1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-23 10:48:51 -05:00

Mouse input fixes.

This commit is contained in:
Camilla Berglund 2011-10-13 14:07:52 +02:00
parent 30c43d60a5
commit 3ebe9a4358
2 changed files with 15 additions and 20 deletions

View File

@ -122,17 +122,23 @@ void _glfwInputCursorMotion(_GLFWwindow* window, int x, int y)
{ {
if (window->cursorMode == GLFW_CURSOR_CAPTURED) if (window->cursorMode == GLFW_CURSOR_CAPTURED)
{ {
if (!x && !y)
return;
window->mousePosX += x; window->mousePosX += x;
window->mousePosY += y; window->mousePosY += y;
} }
else else
{ {
if (window->mousePosX == x && window->mousePosY == y)
return;
window->mousePosX = x; window->mousePosX = x;
window->mousePosY = y; window->mousePosY = y;
} }
if (_glfwLibrary.mousePosCallback) if (_glfwLibrary.mousePosCallback)
_glfwLibrary.mousePosCallback(window, x, y); _glfwLibrary.mousePosCallback(window, window->mousePosX, window->mousePosY);
} }
@ -296,6 +302,7 @@ GLFWAPI void glfwGetScrollOffset(GLFWwindow handle, int* xoffset, int* yoffset)
GLFWAPI void glfwSetCursorMode(GLFWwindow handle, int mode) GLFWAPI void glfwSetCursorMode(GLFWwindow handle, int mode)
{ {
int centerPosX, centerPosY;
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized) if (!_glfwInitialized)
@ -315,29 +322,17 @@ GLFWAPI void glfwSetCursorMode(GLFWwindow handle, int mode)
if (window->cursorMode == mode) if (window->cursorMode == mode)
return; return;
int centerPosX = window->width / 2; centerPosX = window->width / 2;
int centerPosY = window->height / 2; centerPosY = window->height / 2;
if (mode == GLFW_CURSOR_CAPTURED) if (mode == GLFW_CURSOR_CAPTURED)
{
_glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY); _glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY);
}
else if (window->cursorMode == GLFW_CURSOR_CAPTURED) else if (window->cursorMode == GLFW_CURSOR_CAPTURED)
{ {
if (centerPosX != window->mousePosX || centerPosY != window->mousePosY) _glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY);
{ _glfwInputCursorMotion(window,
_glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY); centerPosX - window->mousePosX,
centerPosY - window->mousePosY);
window->mousePosX = centerPosX;
window->mousePosY = centerPosY;
if (_glfwLibrary.mousePosCallback)
{
_glfwLibrary.mousePosCallback(window,
window->mousePosX,
window->mousePosY);
}
}
} }
_glfwPlatformSetCursorMode(window, mode); _glfwPlatformSetCursorMode(window, mode);

View File

@ -1207,7 +1207,7 @@ static void processSingleEvent(void)
else else
{ {
x = event.xmotion.x; x = event.xmotion.x;
x = event.xmotion.y; y = event.xmotion.y;
} }
window->X11.cursorPosX = event.xmotion.x; window->X11.cursorPosX = event.xmotion.x;