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:
parent
30c43d60a5
commit
3ebe9a4358
31
src/input.c
31
src/input.c
|
@ -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);
|
_glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY);
|
||||||
|
_glfwInputCursorMotion(window,
|
||||||
window->mousePosX = centerPosX;
|
centerPosX - window->mousePosX,
|
||||||
window->mousePosY = centerPosY;
|
centerPosY - window->mousePosY);
|
||||||
|
|
||||||
if (_glfwLibrary.mousePosCallback)
|
|
||||||
{
|
|
||||||
_glfwLibrary.mousePosCallback(window,
|
|
||||||
window->mousePosX,
|
|
||||||
window->mousePosY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_glfwPlatformSetCursorMode(window, mode);
|
_glfwPlatformSetCursorMode(window, mode);
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user