Skip navigation.
 
mlRe: NSBezierPath geometry question...
FROM : Heinrich Giesen
DATE : Mon Apr 11 20:49:39 2005

On 11.04.2005, at 18:48, Serge Meynard wrote:

> You're right, I guess I misunderstood the doc about how that method
> works... Reading it again it makes more sense now, and is actually
>


Yes, the text is difficult to understand. Therefore I used one of my
old PostScript books which showed a clear description of the arcto
function with a picture and an example. And this is the result in
Objective-C for drawing a rect with rounded corners

- (void) drawRoundedRect:(NSRect)aRect inView:(NSView *)aView
{
   NSBezierPath *path;
   float radius = 9.0;    // looks good
   NSPoint topLeft, topRight, bottomRight, bottomLeft, startPoint;
   
   topLeft = NSMakePoint( aRect.origin.x, aRect.origin.y );
   topRight = NSMakePoint( topLeft.x + aRect.size.width, topLeft.y );
   bottomRight = NSMakePoint( topRight.x, topRight.y + aRect.size.height
);
   bottomLeft = NSMakePoint( topLeft.x, bottomRight.y );
   startPoint = NSMakePoint( topLeft.x, topLeft.y + radius );

   path = [NSBezierPath bezierPath];
   [path moveToPoint:startPoint];
   
   [path appendBezierPathWithArcFromPoint:topLeft
                                    toPoint:topRight radius:radius];
   [path appendBezierPathWithArcFromPoint:topRight
                                    toPoint:bottomRight radius:radius];
   [path appendBezierPathWithArcFromPoint:bottomRight
                                    toPoint:bottomLeft radius:radius];
   [path appendBezierPathWithArcFromPoint:bottomLeft
                                    toPoint:topLeft radius:radius];
   [path closePath];
   [path setLineWidth:1];
   [aView lockFocus];
   [[NSColor redColor] set];    // whatever you want
   [path stroke];
   [aView unlockFocus];
}



--
Heinrich Giesen

email: <email_removed>

Related mailsAuthorDate
mlNSBezierPath geometry question... Keith Blount Apr 10, 23:40
mlRe: NSBezierPath geometry question... Serge Meynard Apr 11, 00:37
mlRe: NSBezierPath geometry question... Robert Clair Apr 11, 13:01
mlRe: NSBezierPath geometry question... Keith Blount Apr 11, 13:17
mlRe: NSBezierPath geometry question... Serge Meynard Apr 11, 16:02
mlRe: NSBezierPath geometry question... Nicko van Someren Apr 11, 17:48
mlRe: NSBezierPath geometry question... Serge Meynard Apr 11, 18:41
mlRe: NSBezierPath geometry question... David Phillip Oste… Apr 11, 18:46
mlRe: NSBezierPath geometry question... Nicko van Someren Apr 11, 19:48
mlRe: NSBezierPath geometry question... Heinrich Giesen Apr 11, 20:49
mlRe: NSBezierPath geometry question... Robert Clair Apr 11, 21:02
mlRe: NSBezierPath geometry question... Keith Blount Apr 11, 21:19
mlRe: NSBezierPath geometry question... Scott Thompson Apr 11, 23:25
mlRe: NSBezierPath geometry question... Robert Clair Apr 11, 23:54
mlRe: NSBezierPath geometry question... Keith Blount Apr 12, 00:24
mlRe: NSBezierPath geometry question... Nicko van Someren Apr 12, 10:04
mlRe: NSBezierPath geometry question... Keith Blount Apr 12, 18:08
mlRe: NSBezierPath geometry question... Jonathon Mah Apr 13, 17:11