views:

48

answers:

1

Hi,

I want to get the screen location (NSPoint) of a point in an NSTextView, this should be simple, but by results are always a bit off, the X is perfect, but the Y seems to vary.

I've tried a few variations of the code below, but can't get the result I'm after, is the NSClipView screwing it up?

NSPoint p = [[self layoutManager] locationForGlyphAtIndex:r.location];
//NSPoint b= [self convertPoint:p toView:nil];
NSPoint screenlocation = [self convertPointToBase:p];

Any ideas?

Cheers!

MT

A: 

According to the documentation, the location for a glyph is relative to its enclosing line fragment. You should adjust the point by using the rectangle of the line fragment. That should fix the variation you see.

Laurent Etiemble
Perfect! Thanks a lot!
MT