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: Uli Kusterer <email@hidden>
- Date: Fri, 18 May 2007 09:45:58 +0200
On 15.05.2007, at 21:30, Mathieu Coursolle wrote:
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?
Just some guesses:
-> You may be converting a parent-view-relative mouse position, but
treating it as window-relative.
-> You may have placed one of your views one pixel too far up in its
window/parent view
-> I presume you actually looked at the coordinates, and not just the
graphics? Otherwise, you may be drawing "between" pixels, and you
need to add/subtract 0.5 to make your drawings end up on a pixel. You
can see this effect e.g. in Apple's "Sketch" sample app, where
everything looks blurry. I filed a bug on this ages ago, but it seems
nobody cares enough to fix this with the little three-line-fix I
included, so looking at that code makes many people do it wrong.
Cheers,
-- M. Uli Kusterer
http://www.zathras.de
_______________________________________________
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