mirror of
https://github.com/glfw/glfw.git
synced 2024-11-22 21:14:35 +00:00
Clarify cursor position variable names
This commit is contained in:
parent
72b3a7a59f
commit
0e846883bf
@ -78,7 +78,7 @@ typedef struct _GLFWwindowNS
|
|||||||
// The total sum of the distances the cursor has been warped
|
// The total sum of the distances the cursor has been warped
|
||||||
// since the last cursor motion event was processed
|
// since the last cursor motion event was processed
|
||||||
// This is kept to counteract Cocoa doing the same internally
|
// This is kept to counteract Cocoa doing the same internally
|
||||||
double warpDeltaX, warpDeltaY;
|
double cursorWarpDeltaX, cursorWarpDeltaY;
|
||||||
|
|
||||||
} _GLFWwindowNS;
|
} _GLFWwindowNS;
|
||||||
|
|
||||||
|
@ -423,8 +423,8 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
|
|||||||
if (window->cursorMode == GLFW_CURSOR_DISABLED)
|
if (window->cursorMode == GLFW_CURSOR_DISABLED)
|
||||||
{
|
{
|
||||||
_glfwInputCursorMotion(window,
|
_glfwInputCursorMotion(window,
|
||||||
[event deltaX] - window->ns.warpDeltaX,
|
[event deltaX] - window->ns.cursorWarpDeltaX,
|
||||||
[event deltaY] - window->ns.warpDeltaY);
|
[event deltaY] - window->ns.cursorWarpDeltaY);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -434,8 +434,8 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
|
|||||||
_glfwInputCursorMotion(window, pos.x, contentRect.size.height - pos.y);
|
_glfwInputCursorMotion(window, pos.x, contentRect.size.height - pos.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
window->ns.warpDeltaX = 0;
|
window->ns.cursorWarpDeltaX = 0;
|
||||||
window->ns.warpDeltaY = 0;
|
window->ns.cursorWarpDeltaY = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)rightMouseDown:(NSEvent *)event
|
- (void)rightMouseDown:(NSEvent *)event
|
||||||
@ -1402,8 +1402,8 @@ void _glfwPlatformSetCursorPos(_GLFWwindow* window, double x, double y)
|
|||||||
const NSRect contentRect = [window->ns.view frame];
|
const NSRect contentRect = [window->ns.view frame];
|
||||||
const NSPoint pos = [window->ns.object mouseLocationOutsideOfEventStream];
|
const NSPoint pos = [window->ns.object mouseLocationOutsideOfEventStream];
|
||||||
|
|
||||||
window->ns.warpDeltaX += x - pos.x;
|
window->ns.cursorWarpDeltaX += x - pos.x;
|
||||||
window->ns.warpDeltaY += y - contentRect.size.height + pos.y;
|
window->ns.cursorWarpDeltaY += y - contentRect.size.height + pos.y;
|
||||||
|
|
||||||
if (window->monitor)
|
if (window->monitor)
|
||||||
{
|
{
|
||||||
|
28
src/input.c
28
src/input.c
@ -59,19 +59,19 @@ static void setCursorMode(_GLFWwindow* window, int newMode)
|
|||||||
if (oldMode == GLFW_CURSOR_DISABLED)
|
if (oldMode == GLFW_CURSOR_DISABLED)
|
||||||
{
|
{
|
||||||
_glfwPlatformSetCursorPos(window,
|
_glfwPlatformSetCursorPos(window,
|
||||||
_glfw.cursorPosX,
|
_glfw.restoreCursorPosX,
|
||||||
_glfw.cursorPosY);
|
_glfw.restoreCursorPosY);
|
||||||
}
|
}
|
||||||
else if (newMode == GLFW_CURSOR_DISABLED)
|
else if (newMode == GLFW_CURSOR_DISABLED)
|
||||||
{
|
{
|
||||||
int width, height;
|
int width, height;
|
||||||
|
|
||||||
_glfwPlatformGetCursorPos(window,
|
_glfwPlatformGetCursorPos(window,
|
||||||
&_glfw.cursorPosX,
|
&_glfw.restoreCursorPosX,
|
||||||
&_glfw.cursorPosY);
|
&_glfw.restoreCursorPosY);
|
||||||
|
|
||||||
window->cursorPosX = _glfw.cursorPosX;
|
window->virtualCursorPosX = _glfw.restoreCursorPosX;
|
||||||
window->cursorPosY = _glfw.cursorPosY;
|
window->virtualCursorPosY = _glfw.restoreCursorPosY;
|
||||||
|
|
||||||
_glfwPlatformGetWindowSize(window, &width, &height);
|
_glfwPlatformGetWindowSize(window, &width, &height);
|
||||||
_glfwPlatformSetCursorPos(window, width / 2, height / 2);
|
_glfwPlatformSetCursorPos(window, width / 2, height / 2);
|
||||||
@ -198,11 +198,11 @@ void _glfwInputCursorMotion(_GLFWwindow* window, double x, double y)
|
|||||||
if (x == 0.0 && y == 0.0)
|
if (x == 0.0 && y == 0.0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
window->cursorPosX += x;
|
window->virtualCursorPosX += x;
|
||||||
window->cursorPosY += y;
|
window->virtualCursorPosY += y;
|
||||||
|
|
||||||
x = window->cursorPosX;
|
x = window->virtualCursorPosX;
|
||||||
y = window->cursorPosY;
|
y = window->virtualCursorPosY;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (window->callbacks.cursorPos)
|
if (window->callbacks.cursorPos)
|
||||||
@ -356,9 +356,9 @@ GLFWAPI void glfwGetCursorPos(GLFWwindow* handle, double* xpos, double* ypos)
|
|||||||
if (window->cursorMode == GLFW_CURSOR_DISABLED)
|
if (window->cursorMode == GLFW_CURSOR_DISABLED)
|
||||||
{
|
{
|
||||||
if (xpos)
|
if (xpos)
|
||||||
*xpos = window->cursorPosX;
|
*xpos = window->virtualCursorPosX;
|
||||||
if (ypos)
|
if (ypos)
|
||||||
*ypos = window->cursorPosY;
|
*ypos = window->virtualCursorPosY;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
_glfwPlatformGetCursorPos(window, xpos, ypos);
|
_glfwPlatformGetCursorPos(window, xpos, ypos);
|
||||||
@ -386,8 +386,8 @@ GLFWAPI void glfwSetCursorPos(GLFWwindow* handle, double xpos, double ypos)
|
|||||||
if (window->cursorMode == GLFW_CURSOR_DISABLED)
|
if (window->cursorMode == GLFW_CURSOR_DISABLED)
|
||||||
{
|
{
|
||||||
// Only update the accumulated position if the cursor is disabled
|
// Only update the accumulated position if the cursor is disabled
|
||||||
window->cursorPosX = xpos;
|
window->virtualCursorPosX = xpos;
|
||||||
window->cursorPosY = ypos;
|
window->virtualCursorPosY = ypos;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -359,13 +359,13 @@ struct _GLFWwindow
|
|||||||
int maxwidth, maxheight;
|
int maxwidth, maxheight;
|
||||||
int numer, denom;
|
int numer, denom;
|
||||||
|
|
||||||
// Window input state
|
|
||||||
GLFWbool stickyKeys;
|
GLFWbool stickyKeys;
|
||||||
GLFWbool stickyMouseButtons;
|
GLFWbool stickyMouseButtons;
|
||||||
double cursorPosX, cursorPosY;
|
|
||||||
int cursorMode;
|
int cursorMode;
|
||||||
char mouseButtons[GLFW_MOUSE_BUTTON_LAST + 1];
|
char mouseButtons[GLFW_MOUSE_BUTTON_LAST + 1];
|
||||||
char keys[GLFW_KEY_LAST + 1];
|
char keys[GLFW_KEY_LAST + 1];
|
||||||
|
// Virtual cursor position when cursor is disabled
|
||||||
|
double virtualCursorPosX, virtualCursorPosY;
|
||||||
|
|
||||||
_GLFWcontext context;
|
_GLFWcontext context;
|
||||||
|
|
||||||
@ -437,7 +437,8 @@ struct _GLFWlibrary
|
|||||||
int refreshRate;
|
int refreshRate;
|
||||||
} hints;
|
} hints;
|
||||||
|
|
||||||
double cursorPosX, cursorPosY;
|
// Where to place the cursor when re-enabled
|
||||||
|
double restoreCursorPosX, restoreCursorPosY;
|
||||||
|
|
||||||
_GLFWcursor* cursorListHead;
|
_GLFWcursor* cursorListHead;
|
||||||
|
|
||||||
|
@ -201,8 +201,8 @@ static void handlePointerButton(_GLFWwindow* window,
|
|||||||
static void handlePointerMotion(_GLFWwindow* window,
|
static void handlePointerMotion(_GLFWwindow* window,
|
||||||
const MirPointerEvent* pointer_event)
|
const MirPointerEvent* pointer_event)
|
||||||
{
|
{
|
||||||
int current_x = window->cursorPosX;
|
int current_x = window->virtualCursorPosX;
|
||||||
int current_y = window->cursorPosY;
|
int current_y = window->virtualCursorPosY;
|
||||||
int x = mir_pointer_event_axis_value(pointer_event, mir_pointer_axis_x);
|
int x = mir_pointer_event_axis_value(pointer_event, mir_pointer_axis_x);
|
||||||
int y = mir_pointer_event_axis_value(pointer_event, mir_pointer_axis_y);
|
int y = mir_pointer_event_axis_value(pointer_event, mir_pointer_axis_y);
|
||||||
int dx = mir_pointer_event_axis_value(pointer_event, mir_pointer_axis_hscroll);
|
int dx = mir_pointer_event_axis_value(pointer_event, mir_pointer_axis_hscroll);
|
||||||
|
@ -237,7 +237,7 @@ typedef struct _GLFWwindowWin32
|
|||||||
GLFWbool iconified;
|
GLFWbool iconified;
|
||||||
|
|
||||||
// The last received cursor position, regardless of source
|
// The last received cursor position, regardless of source
|
||||||
int cursorPosX, cursorPosY;
|
int lastCursorPosX, lastCursorPosY;
|
||||||
|
|
||||||
} _GLFWwindowWin32;
|
} _GLFWwindowWin32;
|
||||||
|
|
||||||
|
@ -572,14 +572,14 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
_glfwInputCursorMotion(window,
|
_glfwInputCursorMotion(window,
|
||||||
x - window->win32.cursorPosX,
|
x - window->win32.lastCursorPosX,
|
||||||
y - window->win32.cursorPosY);
|
y - window->win32.lastCursorPosY);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
_glfwInputCursorMotion(window, x, y);
|
_glfwInputCursorMotion(window, x, y);
|
||||||
|
|
||||||
window->win32.cursorPosX = x;
|
window->win32.lastCursorPosX = x;
|
||||||
window->win32.cursorPosY = y;
|
window->win32.lastCursorPosY = y;
|
||||||
|
|
||||||
if (!window->win32.cursorTracked)
|
if (!window->win32.cursorTracked)
|
||||||
{
|
{
|
||||||
@ -1386,8 +1386,8 @@ void _glfwPlatformPollEvents(void)
|
|||||||
|
|
||||||
// NOTE: Re-center the cursor only if it has moved since the last
|
// NOTE: Re-center the cursor only if it has moved since the last
|
||||||
// call, to avoid breaking glfwWaitEvents with WM_MOUSEMOVE
|
// call, to avoid breaking glfwWaitEvents with WM_MOUSEMOVE
|
||||||
if (window->win32.cursorPosX != width / 2 ||
|
if (window->win32.lastCursorPosX != width / 2 ||
|
||||||
window->win32.cursorPosY != height / 2)
|
window->win32.lastCursorPosY != height / 2)
|
||||||
{
|
{
|
||||||
_glfwPlatformSetCursorPos(window, width / 2, height / 2);
|
_glfwPlatformSetCursorPos(window, width / 2, height / 2);
|
||||||
}
|
}
|
||||||
@ -1435,8 +1435,8 @@ void _glfwPlatformSetCursorPos(_GLFWwindow* window, double xpos, double ypos)
|
|||||||
POINT pos = { (int) xpos, (int) ypos };
|
POINT pos = { (int) xpos, (int) ypos };
|
||||||
|
|
||||||
// Store the new position so it can be recognized later
|
// Store the new position so it can be recognized later
|
||||||
window->win32.cursorPosX = pos.x;
|
window->win32.lastCursorPosX = pos.x;
|
||||||
window->win32.cursorPosY = pos.y;
|
window->win32.lastCursorPosY = pos.y;
|
||||||
|
|
||||||
ClientToScreen(window->win32.handle, &pos);
|
ClientToScreen(window->win32.handle, &pos);
|
||||||
SetCursorPos(pos.x, pos.y);
|
SetCursorPos(pos.x, pos.y);
|
||||||
|
@ -224,10 +224,12 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height,
|
|||||||
int width, height;
|
int width, height;
|
||||||
_glfwPlatformGetWindowSize(window, &width, &height);
|
_glfwPlatformGetWindowSize(window, &width, &height);
|
||||||
|
|
||||||
window->cursorPosX = width / 2;
|
window->virtualCursorPosX = width / 2;
|
||||||
window->cursorPosY = height / 2;
|
window->virtualCursorPosY = height / 2;
|
||||||
|
|
||||||
_glfwPlatformSetCursorPos(window, window->cursorPosX, window->cursorPosY);
|
_glfwPlatformSetCursorPos(window,
|
||||||
|
window->virtualCursorPosX,
|
||||||
|
window->virtualCursorPosY);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -118,9 +118,9 @@ typedef struct _GLFWwindowX11
|
|||||||
int xpos, ypos;
|
int xpos, ypos;
|
||||||
|
|
||||||
// The last received cursor position, regardless of source
|
// The last received cursor position, regardless of source
|
||||||
double cursorPosX, cursorPosY;
|
double lastCursorPosX, lastCursorPosY;
|
||||||
// The last position the cursor was warped to by GLFW
|
// The last position the cursor was warped to by GLFW
|
||||||
int warpPosX, warpPosY;
|
int warpCursorPosX, warpCursorPosY;
|
||||||
|
|
||||||
// The information from the last KeyPress event
|
// The information from the last KeyPress event
|
||||||
struct {
|
struct {
|
||||||
|
@ -1149,7 +1149,7 @@ static void processEvent(XEvent *event)
|
|||||||
const int x = event->xmotion.x;
|
const int x = event->xmotion.x;
|
||||||
const int y = event->xmotion.y;
|
const int y = event->xmotion.y;
|
||||||
|
|
||||||
if (x != window->x11.warpPosX || y != window->x11.warpPosY)
|
if (x != window->x11.warpCursorPosX || y != window->x11.warpCursorPosY)
|
||||||
{
|
{
|
||||||
// The cursor was moved by something other than GLFW
|
// The cursor was moved by something other than GLFW
|
||||||
|
|
||||||
@ -1159,15 +1159,15 @@ static void processEvent(XEvent *event)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
_glfwInputCursorMotion(window,
|
_glfwInputCursorMotion(window,
|
||||||
x - window->x11.cursorPosX,
|
x - window->x11.lastCursorPosX,
|
||||||
y - window->x11.cursorPosY);
|
y - window->x11.lastCursorPosY);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
_glfwInputCursorMotion(window, x, y);
|
_glfwInputCursorMotion(window, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
window->x11.cursorPosX = x;
|
window->x11.lastCursorPosX = x;
|
||||||
window->x11.cursorPosY = y;
|
window->x11.lastCursorPosY = y;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2071,8 +2071,8 @@ void _glfwPlatformGetCursorPos(_GLFWwindow* window, double* xpos, double* ypos)
|
|||||||
void _glfwPlatformSetCursorPos(_GLFWwindow* window, double x, double y)
|
void _glfwPlatformSetCursorPos(_GLFWwindow* window, double x, double y)
|
||||||
{
|
{
|
||||||
// Store the new position so it can be recognized later
|
// Store the new position so it can be recognized later
|
||||||
window->x11.warpPosX = (int) x;
|
window->x11.warpCursorPosX = (int) x;
|
||||||
window->x11.warpPosY = (int) y;
|
window->x11.warpCursorPosY = (int) y;
|
||||||
|
|
||||||
XWarpPointer(_glfw.x11.display, None, window->x11.handle,
|
XWarpPointer(_glfw.x11.display, None, window->x11.handle,
|
||||||
0,0,0,0, (int) x, (int) y);
|
0,0,0,0, (int) x, (int) y);
|
||||||
|
Loading…
Reference in New Issue
Block a user