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: Manfred Schwind <email@hidden>
- Date: Mon, 21 May 2007 12:15:52 +0200
After thinking a little bit about the problem, I am no longer sure if
this is really a bug in Cocoa. I think it's correct.
Because:
Coordinates in Cocoa (and Core Graphics) always define the positions
relative to the "grid". So coordinates with integer values lie
exactly between pixels.
The mouse is usually positioned on a pixel, so to be exact, [NSEvent
locationInWindow] had to return coordinates e.g. like {42.5, 123.5}
etc. But - I think for historical reasons - the mouse location is (in
most cases) rounded to integer values. So the mouse location is
rounded from the center of the pixel to a grid crossing. Now it has
to be defined, in which direction the mouse location is rounded. And
it seems the location is always rounded to the top left grid
crossing. And that's the reason why [self convertPoint:p
fromView:nil] always starts at (0.0, 1.0) for not flipped NSViews.
If the mouse points at the "lowest leftest" pixel, the top left grid
crossing is really {0.0, 1.0}.
If you draw images of big pixels and think about it, it all makes
sense! ;-)
So you really have to draw that way:
[NSBezierPath fillRect:NSMakeRect(x-100, y-1, 200, 1)];
Or, just flip the coordinates of your RRView (so the coordinates
start at the top left corner):
- (BOOL)isFlipped
{
return YES;
}
In this case, you really get {0.0, 0.0} as coordinate if the mouse is
located at the top left corner pixel.
Regards,
Mani
--
http://www.mani.de
iVolume - Loudness adjustment for iTunes.
LittleSecrets - The encrypted notepad.
_______________________________________________
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