-
Notifications
You must be signed in to change notification settings - Fork 2
/
NSBezierPathAdditions.m
32 lines (27 loc) · 1.13 KB
/
NSBezierPathAdditions.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
31
32
//
// NSBezierPathAdditions.m
// ShortcutRecorder
//
// Copyright 2006 Contributors. All rights reserved.
//
// License: BSD
//
// Contributors:
// http://www.cocoadev.com/index.pl?RoundedRectangles
//
// Revisions:
// 2006-03-12 Created.
#import "NSBezierPathAdditions.h"
@implementation NSBezierPath (Additions)
+ (NSBezierPath *)bezierPathWithRoundRectInRect:(NSRect)aRect radius:(float)radius {
NSBezierPath *path = [self bezierPath];
radius = MIN(radius, 0.5f * MIN(NSWidth(aRect), NSHeight(aRect)));
NSRect 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