Re: NS <-> CG Rect Conversion and screen coordinates
Re: NS <-> CG Rect Conversion and screen coordinates
- Subject: Re: NS <-> CG Rect Conversion and screen coordinates
- From: Chris Suter <email@hidden>
- Date: Wed, 1 Apr 2009 16:38:09 +1100
Hi Trygve,
2009/4/1 Trygve Inda <email@hidden>:
> Using these two calls:
>
> NSRect nsRect = [screen frame];
> CGRect cgRect = CGDisplayBounds (displayID);
>
> I get for my two screens:
>
> NS x=0 y=0 w=2560 h=1600 // screen A
> CG x=0 y=0 w=2560 h=1600
>
> NS x=-1920 y=184 w=1920 h=1200 // screen B
> CG x=-1920 y=216 w=1920 h=1200
>
>
> It seems CG origin is Top, Left with y growing down, while NS is origin
> Bottom, Left, y growing up. So I convert CG to NS with:
>
> // Convert CG coordinates from (TL, y down) to (BL, y up)
>
> CGRect mainScreenRect = CGDisplayBounds (CGMainDisplayID ());
>
> cgRect.origin.y = (cgRect.origin.y + cgRect.size.height -
> mainScreenRect.size.height) * -1;
>
> (216 + 1200 - 1600) * -1 = 184
>
> Is there a system function that does this? NSRectFromCGRect does not do the
> coordinate conversion.
Why do you want to convert?
Most of the Quartz drawing functions use the same coordinate system as
the Cocoa functions. It's only a few (mainly the display ones I think)
that are different. You certainly wouldn't want NSRectFromCGRect to do
the transformation for you since you don't want it most of the time.
As far as I know, there isn't any built in function to convert between
the two. I was looking for one recently so I'd be interested if you
come across one.
Regards,
Chris
_______________________________________________
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