Fixed OS X implementation of sf::Mouse::(get|set)Position

The code was not updated at all when support for retina display was introduced.
This commit is contained in:
Marco Antognini 2014-06-01 20:07:24 +02:00
parent 3f61214571
commit 46be2159cb

View File

@ -133,7 +133,8 @@ Vector2i InputImpl::getMousePosition()
NSPoint pos = [NSEvent mouseLocation]; NSPoint pos = [NSEvent mouseLocation];
pos.y = sf::VideoMode::getDesktopMode().height - pos.y; 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. // Use -cursorPositionFromEvent: with nil.
NSPoint pos = [view cursorPositionFromEvent: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) void InputImpl::setMousePosition(const Vector2i& position)
{ {
// Here we don't need to reverse the coordinates. // 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. // Place the cursor.
CGEventRef event = CGEventCreateMouseEvent(NULL, CGEventRef event = CGEventCreateMouseEvent(NULL,
@ -180,9 +183,10 @@ void InputImpl::setMousePosition(const Vector2i& position, const Window& relativ
return; return;
// Let SFOpenGLView compute the position in global coordinate // 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]; p = [view computeGlobalPositionOfRelativePoint:p];
setMousePosition(sf::Vector2i(p.x, p.y)); setMousePosition(sf::Vector2i(p.x, p.y) * scale);
} }