-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoundRecBezierPath.m
30 lines (25 loc) · 1.23 KB
/
RoundRecBezierPath.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//
// RoundRecBezierPath.m
// Jumpcut
//
// Created by steve on Tue Dec 16 2003.
// Copyright (c) 2003 Steve Cook. All rights reserved.
//
// This code is open-source software subject to the MIT License; see the homepage
// at <http://jumpcut.sourceforge.net/> for details.
#import "RoundRecBezierPath.h"
@implementation NSBezierPath (RoundRecBezierPath)
+(NSBezierPath*)bezierPathWithRoundRectInRect:(NSRect)aRect radius:(float)radius {
// A beautiful means of doing this found on cocoadev.com.
NSBezierPath *path = [NSBezierPath bezierPath];
NSRect rect;
radius = MIN(radius, 0.5f * MIN(NSWidth(aRect), NSHeight(aRect)));
rect = NSInsetRect(aRect, radius, radius);
[path appendBezierPathWithArcWithCenter:NSMakePoint(NSMinX(rect), NSMinY(rect)) radius:radius startAngle:180.0 endAngle:270.0];
[path appendBezierPathWithArcWithCenter:NSMakePoint(NSMaxX(rect), NSMinY(rect)) radius:radius startAngle:270.0 endAngle:360.0];
[path appendBezierPathWithArcWithCenter:NSMakePoint(NSMaxX(rect), NSMaxY(rect)) radius:radius startAngle: 0.0 endAngle: 90.0];
[path appendBezierPathWithArcWithCenter:NSMakePoint(NSMinX(rect), NSMaxY(rect)) radius:radius startAngle: 90.0 endAngle:180.0];
[path closePath];
return path;
}
@end