• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: The fieldEditor and a focus ring
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: The fieldEditor and a focus ring
      • From: Eric Gorr <email@hidden>
References: 
 >Re: The fieldEditor and a focus ring (From: Eric Gorr <email@hidden>)

  • Prev by Date: Re: NSTreeController, NSOutlineView and Core Data (again)
  • Next by Date: Re: do i need to create autorelease pool?
  • Previous by thread: Re: The fieldEditor and a focus ring
  • Next by thread: Re: The fieldEditor and a focus ring
  • Index(es):
    • Date
    • Thread