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
This commit is contained in:
Stefano Pigozzi 2013-09-28 10:09:57 +02:00
parent 0ab9634eb3
commit 67d87d36d5
1 changed files with 15 additions and 5 deletions

View File

@ -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];
}