mirror of
https://github.com/SFML/SFML.git
synced 2024-11-28 22:31:09 +08:00
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:
parent
3f61214571
commit
46be2159cb
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user