views:

96

answers:

1

Assume I load an NSImage of dimensions 2000x2000 and display only a portion of the picture inside an NSScrollView with frame size 500x300. How can I calculate the distance between the images 0,0 origin and the views 0,0 origin (so I can determine the x,y coordinates of the view relative to the whole image)?

Thanks in advance :-)

+1  A: 

Use the documentVisibleRect method:

NSRect rect=[scrollView documentVisibleRect];
CGFloat x=rect.origin.x;
CGFloat y=rect.origin.y;

x and y will be the coordinate on the image that's currently at the top left corner.

grahamparks
Thanks a lot, grahamparks. Works like a charm :-)
Bender