Re: Round Corners With BezierPath
Re: Round Corners With BezierPath
- Subject: Re: Round Corners With BezierPath
- From: Stephen Deken <email@hidden>
- Date: Tue, 22 Aug 2006 21:46:41 -0500
NSRect myBounds = [self bounds];
NSBezierPath *Box;
[NSBezierPath setDefaultLineJoinStyle:NSRoundLineJoinStyle];
Box=[NSBezierPath bezierPathWithRect: myBounds];
[Box stroke];
A few observations:
* If you haven't set the line width, it will default to a width
of 1.0. The rounding wouldn't be evident on such a line, since the
radius of the rounding is equal to half of the width of the line.
* The stroke of a path is centered on the path. If you're
outlining the bounds of an object, half of the line will be clipped
away and you'll always wind up with a rectangle, with a stroke of 1/2
the width of the actual stroke.
There are two ways to go about it: one is to subtract half of the
line width from the rectangle before stroking it:
float lineWidth;
NSRect myBounds = [self bounds];
myBounds.origin.x += lineWidth / 2;
myBounds.origin.y += lineWidth / 2;
myBounds.size.width -= lineWidth;
myBounds.size.height -= lineWidth;
The other way is to construct a path which actually consists of the
lines and arcs corresponding to the rounded rect. I'm not sure what
the most efficient solution is.
--sjd;
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden