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 (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

Reply via email to