Flycut/UI/RoundRecBezierPath.m

31 lines
1.3 KiB
Mathematica
Raw Normal View History

2011-03-20 15:16:13 +08:00
//
// RoundRecBezierPath.m
// Flycut
2011-03-20 15:16:13 +08:00
//
// Flycut by Gennadiy Potapov and contributors. Based on Jumpcut by Steve Cook.
// Copyright 2011 General Arcade. All rights reserved.
2011-03-20 15:16:13 +08:00
//
// This code is open-source software subject to the MIT License; see the homepage
// at <https://github.com/TermiT/Flycut> for details.
//
2011-03-20 15:16:13 +08:00
#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