Converting from Window to View Coordinates
Converting from Window to View Coordinates
- Subject: Converting from Window to View Coordinates
- From: Richard Somers <email@hidden>
- Date: Mon, 25 Feb 2008 08:49:49 -0700
With the user interface resolution at a value other than 1.0, I
noticed a small inconstancy in the converted y coordinate of a mouse
event in my application. I had subtracted 1.0 from the y coordinate
but something was still slightly off.
I did some testing and observed that the larger the user interface
resolution scale factor got the more noticeable the inconstancy
became. When I use the following code to convert a mouse event to view
coordinates the inconstancy completely disappears.
NSPoint loc = [aView convertPointFromBase:[event locationInWindow]];
loc.y -= (1.0 / [[aView window] userSpaceScaleFactor]);
Apple's Cocoa Drawing Guide 2007-10-31 page 52 states " Cocoa event
objects return y coordinate values that are 1-based instead of 0-
based. Thus, a mouse click on the bottom left corner of a window or
view would yield the point (0, 1) in Cocoa and not (0, 0). Only y-
coordinates are 1-based."
So it would appear that the above statement is not exactly correct.
The "1" value in the 1-based y coordinate apparently needs to be
modified by the userSpaceScaleFactor.
Can anyone confirm this?
Regards,
Richard Somers
_______________________________________________
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