diff --git a/src/SFML/Window/OSX/InputImpl.mm b/src/SFML/Window/OSX/InputImpl.mm index eb24fd080..f0fac7503 100644 --- a/src/SFML/Window/OSX/InputImpl.mm +++ b/src/SFML/Window/OSX/InputImpl.mm @@ -133,7 +133,8 @@ Vector2i InputImpl::getMousePosition() NSPoint pos = [NSEvent mouseLocation]; pos.y = sf::VideoMode::getDesktopMode().height - pos.y; - return Vector2i(pos.x, pos.y); + int scale = [[NSScreen mainScreen] backingScaleFactor]; + return Vector2i(pos.x, pos.y) * scale; } @@ -149,7 +150,8 @@ Vector2i InputImpl::getMousePosition(const Window& relativeTo) // Use -cursorPositionFromEvent: with nil. NSPoint pos = [view cursorPositionFromEvent:nil]; - return Vector2i(pos.x, pos.y); + int scale = [view displayScaleFactor]; + return Vector2i(pos.x, pos.y) * scale; } @@ -157,7 +159,8 @@ Vector2i InputImpl::getMousePosition(const Window& relativeTo) void InputImpl::setMousePosition(const Vector2i& position) { // Here we don't need to reverse the coordinates. - CGPoint pos = CGPointMake(position.x, position.y); + int scale = [[NSScreen mainScreen] backingScaleFactor]; + CGPoint pos = CGPointMake(position.x / scale, position.y / scale); // Place the cursor. CGEventRef event = CGEventCreateMouseEvent(NULL, @@ -180,9 +183,10 @@ void InputImpl::setMousePosition(const Vector2i& position, const Window& relativ return; // Let SFOpenGLView compute the position in global coordinate - NSPoint p = NSMakePoint(position.x, position.y); + int scale = [view displayScaleFactor]; + NSPoint p = NSMakePoint(position.x / scale, position.y / scale); p = [view computeGlobalPositionOfRelativePoint:p]; - setMousePosition(sf::Vector2i(p.x, p.y)); + setMousePosition(sf::Vector2i(p.x, p.y) * scale); }