• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Mouse position from NSEvent starts at (0, 1) ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Mouse position from NSEvent starts at (0, 1) ?


  • Subject: Re: Mouse position from NSEvent starts at (0, 1) ?
  • From: Steve Weller <email@hidden>
  • Date: Mon, 21 May 2007 07:47:02 -0700


But mouse coordinates are floats, so they are not always on a pixel. Some applications do weird things with their interfaces if I use my graphics tablet (Garageband and Aperture spring to mind) because -- I assume -- the coordinates are not as expected and are not being correctly massaged before processing. The difference is that tablets are absolute devices and may return position fractions that mice may not.


On May 21, 2007, at 3:15 AM, Manfred Schwind wrote:

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

-- Bagelturf Blog http://www.bagelturf.com/



_______________________________________________

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


  • Follow-Ups:
    • Re: Mouse position from NSEvent starts at (0, 1) ?
      • From: Manfred Schwind <email@hidden>
References: 
 >Mouse position from NSEvent starts at (0, 1) ? (From: "Mathieu Coursolle" <email@hidden>)
 >Re: Mouse position from NSEvent starts at (0, 1) ? (From: Uli Kusterer <email@hidden>)
 >Re: Mouse position from NSEvent starts at (0, 1) ? (From: "Mathieu Coursolle" <email@hidden>)
 >Re: Mouse position from NSEvent starts at (0, 1) ? (From: "Joshua Pennington" <email@hidden>)
 >Re: Mouse position from NSEvent starts at (0, 1) ? (From: "Mathieu Coursolle" <email@hidden>)
 >Re: Mouse position from NSEvent starts at (0, 1) ? (From: Manfred Schwind <email@hidden>)
 >Re: Mouse position from NSEvent starts at (0, 1) ? (From: Manfred Schwind <email@hidden>)

  • Prev by Date: notifications
  • Next by Date: Re: Encoding infinite loops
  • Previous by thread: Re: Mouse position from NSEvent starts at (0, 1) ?
  • Next by thread: Re: Mouse position from NSEvent starts at (0, 1) ?
  • Index(es):
    • Date
    • Thread