diff -r 40d225cf9c43 -r af9b2b929b03 Source/BoardView.m --- a/Source/BoardView.m Tue Mar 11 09:21:53 2008 -0700 +++ b/Source/BoardView.m Wed Mar 12 15:51:32 2008 -0700 @@ -104,6 +104,14 @@ #pragma mark HIT-TESTING: +/** Converts a point from window coords, to this view's root layer's coords. */ +- (CGPoint) _convertPointFromWindowToLayer: (NSPoint)locationInWindow +{ + NSPoint where = [self convertPoint: locationInWindow fromView: nil]; // convert to view coords + return NSPointToCGPoint( [self convertPointToBase: where] ); // then to layer coords +} + + // Hit-testing callbacks (to identify which layers caller is interested in): typedef BOOL (*LayerMatchCallback)(CALayer*); @@ -119,8 +127,7 @@ forLayerMatching: (LayerMatchCallback)match offset: (CGPoint*)outOffset { - CGPoint where = NSPointToCGPoint([self convertPoint: locationInWindow fromView: nil]); - where = [_gameboard convertPoint: where fromLayer: self.layer]; + CGPoint where = [self _convertPointFromWindowToLayer: locationInWindow ]; CALayer *layer = [_gameboard hitTest: where]; while( layer ) { if( match(layer) ) { @@ -158,7 +165,7 @@ if( _dragBit ) { _dragOffset.x = _dragOffset.y = 0; if( _dragBit.superlayer==nil ) - _dragBit.position = NSPointToCGPoint([self convertPoint: _dragStartPos fromView: nil]); + _dragBit.position = [self _convertPointFromWindowToLayer: _dragStartPos]; placing = YES; } } @@ -197,7 +204,7 @@ if( placing ) { if( _oldSuperlayer ) - _dragBit.position = NSPointToCGPoint([self convertPoint: _dragStartPos fromView: nil]); + _dragBit.position = [self _convertPointFromWindowToLayer: _dragStartPos]; _dragMoved = YES; [self _findDropTarget: _dragStartPos]; } @@ -213,12 +220,11 @@ _dragMoved = YES; // Move the _dragBit (without animation -- it's unnecessary and slows down responsiveness): - NSPoint where = [self convertPoint: pos fromView: nil]; + CGPoint where = [self _convertPointFromWindowToLayer: pos]; where.x += _dragOffset.x; where.y += _dragOffset.y; - CGPoint newPos = [_dragBit.superlayer convertPoint: NSPointToCGPoint(where) - fromLayer: self.layer]; + CGPoint newPos = [_dragBit.superlayer convertPoint: where fromLayer: self.layer]; [CATransaction flush]; [CATransaction begin];