On Mar 2, 2009, at 6:19 PM, Graham Cox wrote:


On 03/03/2009, at 2:30 AM, Eric Gorr wrote:

[self lockFocus];
[NSGraphicsContext saveGraphicsState];
NSRect focusRingBounds = [self bounds];
NSSetFocusRingStyle( NSFocusRingOnly );
NSBezierPath *path = [NSBezierPath bezierPathWithRect:focusRingBounds];
[path setClip];
[path fill];
[NSGraphicsContext restoreGraphicsState];
[self unlockFocus];


Couple of things:

First, the focus ring is typically drawn around the control which means it's outside the view's bounds. You have to focus on the superview (parent). convert the coordinates and draw it in that view. It can still be drawn by 'this' view, but you need to lockFocus on the parent.

Second, the focus ring is drawn as a stroke along the path, so if you clip to that same path, you'll only see half of the ring - the part that falls inside. So don't bother clipping.

I just had a look at a control I wrote a while back that handles a focus ring, here's the code that draws it:

        [[self superview] lockFocus];
        NSRect fr = [self frame];
        NSSetFocusRingStyle(NSFocusRingOnly);
        [[NSBezierPath bezierPathWithRect:fr] fill];
        [[self superview] unlockFocus];

duh. Yep, this makes sense...since I am drawing in the superview, I naturally needed to lock focus on it...

Thanks.

_______________________________________________

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

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

Reply via email to