Fixed the conversion of window to layer coordinates. The old way didn't work in HiDPI. Thanks to Quincey Morriss and Nathan Vander Wilt for figuring this out.
1.1 --- a/Source/BoardView.m Tue Mar 11 17:09:50 2008 -0700
1.2 +++ b/Source/BoardView.m Wed Mar 12 15:49:36 2008 -0700
1.3 @@ -104,6 +104,14 @@
1.4 #pragma mark HIT-TESTING:
1.5
1.6
1.7 +/** Converts a point from window coords, to this view's root layer's coords. */
1.8 +- (CGPoint) _convertPointFromWindowToLayer: (NSPoint)locationInWindow
1.9 +{
1.10 + NSPoint where = [self convertPoint: locationInWindow fromView: nil]; // convert to view coords
1.11 + return NSPointToCGPoint( [self convertPointToBase: where] ); // then to layer coords
1.12 +}
1.13 +
1.14 +
1.15 // Hit-testing callbacks (to identify which layers caller is interested in):
1.16 typedef BOOL (*LayerMatchCallback)(CALayer*);
1.17
1.18 @@ -119,8 +127,7 @@
1.19 forLayerMatching: (LayerMatchCallback)match
1.20 offset: (CGPoint*)outOffset
1.21 {
1.22 - CGPoint where = NSPointToCGPoint([self convertPoint: locationInWindow fromView: nil]);
1.23 - where = [_gameboard convertPoint: where fromLayer: self.layer];
1.24 + CGPoint where = [self _convertPointFromWindowToLayer: locationInWindow ];
1.25 CALayer *layer = [_gameboard hitTest: where];
1.26 while( layer ) {
1.27 if( match(layer) ) {
1.28 @@ -158,7 +165,7 @@
1.29 if( _dragBit ) {
1.30 _dragOffset.x = _dragOffset.y = 0;
1.31 if( _dragBit.superlayer==nil )
1.32 - _dragBit.position = NSPointToCGPoint([self convertPoint: _dragStartPos fromView: nil]);
1.33 + _dragBit.position = [self _convertPointFromWindowToLayer: _dragStartPos];
1.34 placing = YES;
1.35 }
1.36 }
1.37 @@ -197,7 +204,7 @@
1.38
1.39 if( placing ) {
1.40 if( _oldSuperlayer )
1.41 - _dragBit.position = NSPointToCGPoint([self convertPoint: _dragStartPos fromView: nil]);
1.42 + _dragBit.position = [self _convertPointFromWindowToLayer: _dragStartPos];
1.43 _dragMoved = YES;
1.44 [self _findDropTarget: _dragStartPos];
1.45 }
1.46 @@ -213,12 +220,11 @@
1.47 _dragMoved = YES;
1.48
1.49 // Move the _dragBit (without animation -- it's unnecessary and slows down responsiveness):
1.50 - NSPoint where = [self convertPoint: pos fromView: nil];
1.51 + CGPoint where = [self _convertPointFromWindowToLayer: pos];
1.52 where.x += _dragOffset.x;
1.53 where.y += _dragOffset.y;
1.54
1.55 - CGPoint newPos = [_dragBit.superlayer convertPoint: NSPointToCGPoint(where)
1.56 - fromLayer: self.layer];
1.57 + CGPoint newPos = [_dragBit.superlayer convertPoint: where fromLayer: self.layer];
1.58
1.59 [CATransaction flush];
1.60 [CATransaction begin];