-
-
Notifications
You must be signed in to change notification settings - Fork 134
/
TPBezierPath.m
66 lines (57 loc) · 2.37 KB
/
TPBezierPath.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
60
61
62
63
64
65
66
#import "TPBezierPath.h"
@implementation NSBezierPath (teleportAdditions)
+ (NSBezierPath *)bezierPathWithRoundRectInRect:(NSRect)aRect radius:(float) radius
{
NSBezierPath * path = [NSBezierPath bezierPath];
NSPoint topMid = NSMakePoint(NSMidX(aRect), NSMaxY(aRect));
NSPoint topLeft = NSMakePoint(NSMinX(aRect), NSMaxY(aRect));
NSPoint topRight = NSMakePoint(NSMaxX(aRect), NSMaxY(aRect));
NSPoint bottomRight = NSMakePoint(NSMaxX(aRect), NSMinY(aRect));
[path moveToPoint:topMid];
[path appendBezierPathWithArcFromPoint:topLeft toPoint:aRect.origin radius:radius];
[path appendBezierPathWithArcFromPoint:aRect.origin toPoint:bottomRight radius:radius];
[path appendBezierPathWithArcFromPoint:bottomRight toPoint:topRight radius:radius];
[path appendBezierPathWithArcFromPoint:topRight toPoint:topLeft radius:radius];
[path closePath];
return path;
}
+ (void)fillLeftRoundedRectInRect:(NSRect)aRect radius:(float)radius
{
if(aRect.size.width < 4)
return;
NSBezierPath * path = [NSBezierPath bezierPath];
NSRect fullRect = aRect;
fullRect.size.width += 16;
NSPoint topMid = NSMakePoint(NSMidX(aRect), NSMaxY(aRect));
NSPoint topLeft = NSMakePoint(NSMinX(aRect), NSMaxY(aRect));
NSPoint topRight = NSMakePoint(NSMaxX(aRect), NSMaxY(aRect));
NSPoint bottomRight = NSMakePoint(NSMaxX(aRect), NSMinY(aRect));
[path moveToPoint:topMid];
[path appendBezierPathWithArcFromPoint:topLeft toPoint:aRect.origin radius:radius];
[path appendBezierPathWithArcFromPoint:aRect.origin toPoint:bottomRight radius:radius];
[path appendBezierPathWithArcFromPoint:bottomRight toPoint:topRight radius:0];
[path appendBezierPathWithArcFromPoint:topRight toPoint:topLeft radius:0];
[path closePath];
[path fill];
//NSEraseRect(NSMakeRect(aRect.origin.x+aRect.size.width, aRect.origin.y, 18, aRect.size.height));
}
+ (void)drawRect:(NSRect)rect withGradientFrom:(NSColor*)colorStart to:(NSColor*)colorEnd
{
float fraction = 0;
float height = rect.size.height - 1;
float width = rect.size.width;
float step = 1/height;
int i;
NSRect gradientRect = NSMakeRect(rect.origin.x, rect.origin.y, width, 1.0);
[colorEnd set];
[NSBezierPath fillRect:gradientRect];
for(i = 0; i < height; i++)
{
gradientRect.origin.y++;
NSColor * gradientColor = [colorStart blendedColorWithFraction:fraction ofColor:colorEnd];
[gradientColor set];
[NSBezierPath fillRect:gradientRect];
fraction += step;
}
}
@end