Flycut/UI/RoundRecBezierPath.m
2016-04-09 23:18:45 +08:00

31 lines
No EOL
1.3 KiB
Objective-C
Executable file

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