mirror of
https://github.com/glfw/glfw.git
synced 2025-06-14 19:52:14 +00:00
Support for getting cursor position after window creation and setting window position, before mouse moves.
This commit is contained in:
parent
bd2d571c31
commit
f03a8bd152
@ -858,6 +858,14 @@ static GLboolean createWindow(_GLFWwindow* window,
|
||||
[window->ns.object disableCursorRects];
|
||||
[window->ns.object center];
|
||||
|
||||
if (window->cursorMode != GLFW_CURSOR_DISABLED)
|
||||
{
|
||||
const NSRect contentRect = [window->ns.view frame];
|
||||
const NSPoint p = [window->ns.object mouseLocationOutsideOfEventStream];
|
||||
window->cursorPosX = p.x;
|
||||
window->cursorPosY = contentRect.size.height - p.y;
|
||||
}
|
||||
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
|
||||
if ([window->ns.object respondsToSelector:@selector(setRestorable:)])
|
||||
[window->ns.object setRestorable:NO];
|
||||
@ -960,6 +968,17 @@ void _glfwPlatformSetWindowPos(_GLFWwindow* window, int x, int y)
|
||||
const NSRect dummyRect = NSMakeRect(x, transformY(y + contentRect.size.height), 0, 0);
|
||||
const NSRect frameRect = [window->ns.object frameRectForContentRect:dummyRect];
|
||||
[window->ns.object setFrameOrigin:frameRect.origin];
|
||||
|
||||
if (window->cursorMode != GLFW_CURSOR_DISABLED)
|
||||
{
|
||||
const NSPoint p = [window->ns.object mouseLocationOutsideOfEventStream];
|
||||
// TODO: This should enqueue an event that will result in cursor position callback being called
|
||||
// during the next glfwPollEvents()
|
||||
// (But can't call _glfwInputCursorMotion directly here because that'd result in callbacks
|
||||
// being called outside of glfwPollEvents() timeframe)
|
||||
window->cursorPosX = p.x;
|
||||
window->cursorPosY = contentRect.size.height - p.y;
|
||||
}
|
||||
}
|
||||
|
||||
void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height)
|
||||
|
Loading…
Reference in New Issue
Block a user