Re: Mouse position from NSEvent starts at (0, 1) ?
Re: Mouse position from NSEvent starts at (0, 1) ?
- Subject: Re: Mouse position from NSEvent starts at (0, 1) ?
- From: Dominik Pich <email@hidden>
- Date: Tue, 15 May 2007 21:38:46 +0200
I'd say it is a rounding issue...
the mouse might be at 0.7!?
On May 15, 2007, at 9:30 PM, Mathieu Coursolle wrote:
Hi cocoa developers,
I created a subclass of NSView to draw a 1 pixel thick cross at the
mouse cursor position. However, the cross is offset by one pixel in
the
Y direction.
In the mouseDragged: method, I use the following code to get the view
coordinates:
NSPoint pt = [self convertPoint:[theEvent locationInWindow]
fromView:nil];
Then in drawRect: I draw a cross at that position like so:
- (void)drawRect:(NSRect)rect
{
// Gray background.
[[NSColor colorWithCalibratedRed:0.2 green:0.2 blue:0.2 alpha:
0.2] set];
[NSBezierPath fillRect:[self bounds]];
// Red cross.
[[NSColor colorWithCalibratedRed:1.0 green:0.0 blue:0.0 alpha:
1.0] set];
[NSBezierPath fillRect:NSMakeRect(x, y-100, 1, 200)];
[NSBezierPath fillRect:NSMakeRect(x-100, y, 200, 1)];
}
It seems like the cross is drawn at the position I ask for, but the
mouse cursor position I get is offset.
When I click the bottom left pixel of the view, I get (0, 1)
coordinates
(pt in code above). Shouldn't it be (0, 0)? I have to draw at (0,
0) to
draw that pixel.
I came across an old post describing exactly the same problem:
<http://www.omnigroup.com/mailman/archive/macosx-dev/2000-March/
013028.html>
I can solve the problem by doing something like:
pt.y = pt.y - 1;
but I would like to have an explanation for this. ;)
Anyone can explain this behaviour?
Thank you.
Mathieu
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden