Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert NSPoint in screen coordinates to window coordinates

I am implementing drag and drop in a cocoa application and I am using the following method from the NSDraggingSource Protocol:

- (void)draggedImage:(NSImage *)draggedImage movedTo:(NSPoint)screenPoint{

The NSPoint is given in screen coordinates and I need it in window or view coordinates. If the method was called with an NSEvent I could do the following:

    -(void)mouseDown:(NSEvent *)pTheEvent {

 NSPoint tvarMouseInWindow = [pTheEvent locationInWindow];
 NSPoint tvarMouseInView   = [self convertPoint:tvarMouseInWindow fromView:nil]; }

But I cannot figure out how to do it with just an NSPoint. Thanks in advance!

like image 791
Dillon Avatar asked Oct 25 '10 09:10

Dillon


1 Answers

Have a look at the NSWindow documentation, there is a

- (NSPoint)convertScreenToBase:(NSPoint)aPoint

which will let you convert the point to window coordinates.

like image 126
w-m Avatar answered Oct 23 '22 14:10

w-m