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: "Mathieu Coursolle" <email@hidden>
- Date: Fri, 18 May 2007 11:03:42 -0400
- Organization: Rogue Research
Thanks for the answer,
However, I am not quite sure I can apply those to my application.
I use the crosshairs cursor and use mouseDragged: NSEvent parameter
to get the mouse position:
NSPoint pt = [self convertPoint:[theEvent locationInWindow] fromView:nil];
And then draw a cross at pt position in drawRect:.
The crosshair's hot point is defined as the intersection of the cross,
but my drawing
is offset by one pixel in the Y direction.
My application is available at:
www.rogue-research.com/vtk/TestCursor.zip
if you ever want to take a look... It is approximatively 10 lines of code.
Thanks!
Mathieu
--
____________________________________________________________
Mathieu Coursolle email@hidden
Rogue Research www.rogue-research.com
Montréal, Québec, Canada
>
>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