On 27 Mar 2012, at 12:19, Nick wrote:

> I would like to place a PDFAnnotation onto a PDF page in a place where
> the user clicked with the mouse.
[...]
> NSPoint locationInView = [self convertPoint:[theEvent
> locationInWindow] fromView:[[self window] contentView]];

You are receiving the event location in the window, but you are converting 
based on the content view. Pass NULL in fromView: to translate from window 
coordinates to local coordinates. Then let PDFView do the heave lifting for you 
to translate that point to a point on a page.


To convert the point to page coordinates use something to the effect of:

-(void)mouseDown:(NSEvent *)event
{
        NSPoint         mouseDownPoint = [self convertPoint:[event 
locationInWindow] fromView:NULL];
        PDFPage         *mouseDownPage = [self pageForPoint:mouseDownPoint 
nearest:NO];
        NSPoint         pagePoint = [self convertPoint: mouseDownPoint 
toPage:mouseDownPage];
        ...
}

The above should work at any scale factor.

-António

-----------------------------------------------------------
And you would accept the seasons of your
heart, even as you have always accepted
the seasons that pass over your field.

--Kahlil Gibran
-----------------------------------------------------------




_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to