Re: The fieldEditor and a focus ring
Re: The fieldEditor and a focus ring
- Subject: Re: The fieldEditor and a focus ring
- From: Graham Cox <email@hidden>
- Date: Tue, 3 Mar 2009 10:19:12 +1100
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];
--Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden