forked from gnachman/iTerm2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NSBezierPath+iTerm.m
59 lines (54 loc) · 1.67 KB
/
NSBezierPath+iTerm.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// NSBezierPath+iTerm.m
// iTerm
//
// Created by George Nachman on 3/12/13.
//
//
#import "NSBezierPath+iTerm.h"
@implementation NSBezierPath (iTerm)
+ (NSBezierPath *)smoothPathAroundBottomOfFrame:(NSRect)frame {
NSBezierPath* path = [[NSBezierPath alloc] init];
[path setLineWidth:1];
float radius = 4;
float height = frame.size.height - 1;
float width = frame.size.width - 1;
float x = 0.5;
float y = 0;
float nx, ny;
[path moveToPoint:NSMakePoint(x, y)];
nx = x+radius;
ny = y+radius+0.5; // Add an extra 0.5 to get on the pixel grid.
[path curveToPoint:NSMakePoint(nx, ny)
controlPoint1:NSMakePoint((nx+x)/2, y)
controlPoint2:NSMakePoint(nx, (ny+y)/2)];
y = ny;
ny = y + height - 2*radius;
[path lineToPoint:NSMakePoint(nx, ny)];
x = nx; y = ny;
nx = x + radius;
ny = y + radius;
[path curveToPoint:NSMakePoint(nx, ny)
controlPoint1:NSMakePoint(x, (y + ny)/2)
controlPoint2:NSMakePoint((x+nx)/2, ny)];
x = nx;
nx = x + width - 4*radius;
[path lineToPoint:NSMakePoint(nx, ny)];
x = nx; y = ny;
nx = x + radius;
ny = y - radius;
[path curveToPoint:NSMakePoint(nx, ny)
controlPoint1:NSMakePoint((nx+x)/2, y)
controlPoint2:NSMakePoint(nx, (ny+y)/2)];
y = ny;
ny = y - height + 2*radius;
[path lineToPoint:NSMakePoint(nx, ny)];
x = nx; y = ny;
nx = x + radius;
ny = y - radius - 0.5; // Subtract 0.5 to return to the "true" origin of the frame
[path curveToPoint:NSMakePoint(nx, ny)
controlPoint1:NSMakePoint(x, (ny+y)/2)
controlPoint2:NSMakePoint((x+nx)/2, ny)];
return path;
}
@end