On Aug 11, 2017, at 11:38 AM, Sean McBride <s...@rogue-research.com> wrote: > > I'm tying to understand the exact definition of the Cocoa drawing and event > coordinate system on macOS. In particular the exact location of 0,0 and > subpixel accuracy. > > 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. > I made a custom NSView and implemented mouseDown: > > - (void)mouseDown:(NSEvent*)inEvent { > NSPoint viewPoint = [self convertPoint:[inEvent locationInWindow] > fromView:nil]; > > I then use Pixie.app at max magnification and click the bottom-left pixel, > yielding results like: > > (lldb) p viewPoint > (NSPoint) $3 = (x = 0.15234375, y = 0.90625) > > So it's giving fractional values, but they are hard to interpret without > knowing where 0,0 is exactly. 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. > 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. Regards, Ken _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com