• 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: Exact definition of NSView/NSEvent coordinate system origin?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Exact definition of NSView/NSEvent coordinate system origin?


  • Subject: Re: Exact definition of NSView/NSEvent coordinate system origin?
  • From: "Sean McBride" <email@hidden>
  • Date: Fri, 11 Aug 2017 13:58:44 -0400
  • Organization: Rogue Research Inc.

On Fri, 11 Aug 2017 11:53:10 -0500, Ken Thomases said:

>> I know 0,0 is the bottom-left, but is it:
>> - the centre of the bottom-left pixel?
>> - the bottom-left corner of the bottom-left pixel?
>
>It's the bottom-left corner of the bottom-left pixel.

Playing around with NSRectFill() that indeed seems to be the case, thanks.

I assume it's the same for screen, window, and layer coordinates, surely?

>Depending on what you're doing, you should more or less ignore the
>fractional part.  At some point, Apple started supporting high-
>resolution mouse positions.  Since then, the mouse is almost never at an
>integral position.

Ah, found this in the 10.1 (sic) AppKit Release Notes: "-[NSEvent
locationInWindow] may now return NSPoints with non-integral coordinates to
represent sub-pixel precision generated by some input devices..."

Presumably these are also corner-pixel based?

>> Then there's the 'locationInWindow' docs, that say "Note: The y
>coordinate in the returned point starts from a base of 1, not 0."
>That's quite odd.  Why?
>
>I believe for compatibility with what was originally a bug.  When
>converting from the Core Graphics coordinate space, where the origin is
>at the top left, to the Cocoa coordinate space, where it's at the bottom
>left, somebody did pt.y = primaryScreenHeight - pt.y.  That's correct
>for an infinitely-small point.  However, for a pixel, it's not.  On a
>single-screen system and with integral-pixel positions, pt.y can range
>from 0 to primaryScreenHeight - 1, inclusive.  That means that
>(primaryScreenHeight - pt.y) can range from primaryScreenHeight to 1,
>inclusive.  The correct code would have been pt.y = primaryScreenHeight
>- 1 - pt.y, but it's too late to fix it now.

Right, classic off-by-1 error. :)

Doing the following in mouseDown: is idiomatic:

        NSPoint viewPoint = [self convertPoint:[inEvent locationInWindow]
fromView:nil];

but it's not clear to me if convertPoint:fromView: expects the off-by-1 value
from locationInWindow or not.

It seems to work correctly the idiomatic way, that is, if I use Pixie to zoom
and carefully click the corner pixel in my NSView, the 'viewPoint' is always
some fraction between 0 and 1 in both x and y.  I would have expected to be
off-by-1 in y....

Cheers,

Sean


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please 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

References: 
 >Exact definition of NSView/NSEvent coordinate system origin? (From: "Sean McBride" <email@hidden>)
 >Re: Exact definition of NSView/NSEvent coordinate system origin? (From: Ken Thomases <email@hidden>)

  • Prev by Date: Re: Exact definition of NSView/NSEvent coordinate system origin?
  • Next by Date: Question about NSObject based Class & delegates
  • Previous by thread: Re: Exact definition of NSView/NSEvent coordinate system origin?
  • Next by thread: Question about NSObject based Class & delegates
  • Index(es):
    • Date
    • Thread