From 67d87d36d52baf5237f24c4bf5d83426362f25b0 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 28 Sep 2013 10:09:57 +0200 Subject: cocoa_common: report pixels instead of points during mouse movement This fixes the position reporting on retina displays. Doesn't make any difference on normal displays where 1px = 1pt. Fixes: #260 --- video/out/cocoa/view.m | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'video') diff --git a/video/out/cocoa/view.m b/video/out/cocoa/view.m index bac485b225..2ae81abda9 100644 --- a/video/out/cocoa/view.m +++ b/video/out/cocoa/view.m @@ -94,8 +94,7 @@ - (NSPoint)mouseLocation { - NSPoint wLoc = [self.window mouseLocationOutsideOfEventStream]; - return [self convertPoint:wLoc fromView:nil]; + return [self.window mouseLocationOutsideOfEventStream]; } - (BOOL)containsMouseLocation @@ -103,10 +102,11 @@ NSRect vF = [[self.window screen] visibleFrame]; NSRect vFW = [self.window convertRectFromScreen:vF]; NSRect vFV = [self convertRect:vFW fromView:nil]; + NSPoint pt = [self convertPoint:[self mouseLocation] fromView:nil]; // clip bounds to current visibleFrame NSRect clippedBounds = CGRectIntersection([self bounds], vFV); - return CGRectContainsPoint(clippedBounds, [self mouseLocation]); + return CGRectContainsPoint(clippedBounds, pt); } - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent { return YES; } @@ -140,15 +140,25 @@ [self signalMousePosition]; } +- (NSPoint)convertPointToPixels:(NSPoint)point +{ + point = [self convertPoint:point fromView:nil]; + point = [self convertPointToBacking:point]; + // flip y since isFlipped returning YES doesn't affect the backing + // coordinate system + point.y = -point.y; + return point; +} + - (void)signalMousePosition { - NSPoint p = [self convertPoint:[self mouseLocation] fromView:nil]; + NSPoint p = [self convertPointToPixels:[self mouseLocation]]; [self.adapter signalMouseMovement:p]; } - (void)signalMouseMovement:(NSEvent *)event { - NSPoint p = [self convertPoint:[event locationInWindow] fromView:nil]; + NSPoint p = [self convertPointToPixels:[event locationInWindow]]; [self.adapter signalMouseMovement:p]; } -- cgit v1.2.3