Converting from NSPoint to CGPoint? (and rects)
Does anyone know how to convert between these types?
i.e.
i.e.
Code:
CGPoint myPoint = myNSPointHere;
Third link from a Google search of Converting from NSPoint to CGPoint
http://developer.apple.com/documentation...ion_2.html
http://developer.apple.com/documentation...ion_2.html
I've read that, but when i try this
But switch it around like this
I get errors
Code:
NSRect cocoaRect = *(NSRect*)&myCGRect;Code:
CGPoint cocoaPoint = *(CGPont*)&myNSPoint;
IIRC, all of the Cocoa datatypes that have a Carbon equivalent can simply be typecasted across.
bronxbomber92 Wrote:I've read that, but when i try thisBut switch it around like thisCode:
NSRect cocoaRect = *(NSRect*)&myCGRect;I get errorsCode:
CGPoint cocoaPoint = *(CGPont*)&myNSPoint;
Try CGPoint instead.

This works just fine for me:
Code:
NSPoint myNSPoint;
CGPoint cocoaPoint = *(CGPoint*)&myNSPoint;akb825 Wrote:IIRC, all of the Cocoa datatypes that have a Carbon equivalent can simply be typecasted across.
that's what i was thinking, too. try searching the apple docs for info about 'toll-free bridging'. you're probably making it harder than it needs to be :]
MacGoober Wrote:that's what i was thinking, too. try searching the apple docs for info about 'toll-free bridging'. you're probably making it harder than it needs to be :]
Nope, not making it harder at all, the cast is actually what the docs say:
Quote:Although in each case the structure layout is the same, you cannot pass the Quartz data type directly to a method expecting the Cocoa type. To convert, you must cast from one type to another, as shown in the following example:
NSRect cocoaRect = *(NSRect*)&myCGRect;
Anyway, the only reason bronxbomber92's code didn't work was because he misspelled CGPoint in the cast
PowerMacX Wrote:Third link from a Google search of Converting from NSPoint to CGPoint
... Just thought you might get a kick out of the fact that ATM this thread happens to be the top search result for cgpoint nspointAnd even better yet, your original search for "Converting from NSPoint to CGPoint" now points to this thread as the top result. Man, that is funny!
I had forgotten the crazy casting for it, so I had to do a quick search.
Of course, now you can just do
&
But you knew that
-LG
Quote:NSPoint point = NSPointFromCGPoint(myCGPoint);
&
Quote:CGPoint point = NSPointToCGPoint(myNSPoint);
But you knew that

-LG
Actually, no, I was not aware of that (or I forgot) -- good catch HairBall!
It looks important too because the docs mention that in 32 bit code NSRects and CGRects are distinct types, which I did not know.
It looks important too because the docs mention that in 32 bit code NSRects and CGRects are distinct types, which I did not know.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| converting quartz to openGL ES | aerospaceman | 2 | 3,337 |
Apr 12, 2010 10:57 AM Last Post: ThemsAllTook |
|

