Permalink
Browse files

Round the mouseDownLocation & mouseDraggedLocation points.

This change fixes an issue with the selection rectangle drawing on half pixels.
  • Loading branch information...
1 parent dbf0e3c commit d0faa1e6c0bd02f77e073ce4fcc637274758929d @kgn committed Mar 1, 2012
Showing with 6 additions and 2 deletions.
  1. +2 −2 BCCollectionView+Mouse.m
  2. +4 −0 BCGeometryExtensions.h
View
@@ -18,7 +18,7 @@ - (void)mouseDown:(NSEvent *)theEvent
[[self window] makeFirstResponder:self];
isDragging = YES;
- mouseDownLocation = [self convertPoint:[theEvent locationInWindow] fromView:nil];
+ mouseDownLocation = BCRoundedPoint([self convertPoint:[theEvent locationInWindow] fromView:nil]);
mouseDraggedLocation = mouseDownLocation;
NSUInteger index = [layoutManager indexOfItemContentRectAtPoint:mouseDownLocation];
@@ -62,7 +62,7 @@ - (void)regularMouseDragged:(NSEvent *)anEvent
}
[self setNeedsDisplayInRect:BCRectFromTwoPoints(mouseDownLocation, mouseDraggedLocation)];
- mouseDraggedLocation = [self convertPoint:[anEvent locationInWindow] fromView:nil];
+ mouseDraggedLocation = BCRoundedPoint([self convertPoint:[anEvent locationInWindow] fromView:nil]);
NSIndexSet *suggestedIndexes = [self indexesOfItemContentRectsInRect:BCRectFromTwoPoints(mouseDownLocation, mouseDraggedLocation)];
if (![self shiftOrCommandKeyPressed]) {
View
@@ -3,6 +3,10 @@
#import <Foundation/Foundation.h>
+static NSPoint BCRoundedPoint(NSPoint a){
+ return NSMakePoint(round(a.x), round(a.y));
+}
+
static NSRect BCRectFromTwoPoints(NSPoint a, NSPoint b)
{
NSRect r;

0 comments on commit d0faa1e

Please sign in to comment.