-
Notifications
You must be signed in to change notification settings - Fork 0
/
ITButtonCell.m
80 lines (68 loc) · 2.21 KB
/
ITButtonCell.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#import "ITButtonCell.h"
#define GRAY_EXTRA_PAD_H 60.0
@interface ITButtonCell (Private)
- (void)drawGrayRoundedBezelWithFrame:(NSRect)rect inView:(NSView *)controlView;
@end
@implementation ITButtonCell
- (id)init {
if ((self = [super init])) {
_subStyle = 0;
}
return self;
}
- (void)setBezelStyle:(NSBezelStyle)bezelStyle {
if (bezelStyle == ITGrayRoundedBezelStyle) {
_subStyle = bezelStyle;
bezelStyle = NSRegularSquareBezelStyle;
} else {
_subStyle = 0;
}
[super setBezelStyle:bezelStyle];
}
- (void)drawWithFrame:(NSRect)rect inView:(NSView *)controlView {
if (_subStyle == ITGrayRoundedBezelStyle) {
[self drawGrayRoundedBezelWithFrame:rect inView:controlView];
if ([self attributedTitle]) {
NSPoint stringOrigin;
NSSize stringSize;
stringSize = [[self attributedTitle] size];
stringOrigin.x = rect.origin.x + (rect.size.width - stringSize.width) / 2;
stringOrigin.y = (rect.origin.y + (rect.size.height - stringSize.height) / 2) - 2;
[controlView lockFocus];
[[self attributedTitle] drawAtPoint:stringOrigin];
[controlView unlockFocus];
} else {
[super drawInteriorWithFrame:rect inView:controlView];
}
[[controlView superview] setNeedsDisplay:YES];
} else {
[super drawWithFrame:rect inView:controlView];
}
}
- (void)drawGrayRoundedBezelWithFrame:(NSRect)rect inView:(NSView *)controlView {
NSBezierPath *path = [NSBezierPath bezierPath];
float ch = rect.size.height;
float cw = rect.size.width;
float radius = (ch / 2);
NSPoint pointA = NSMakePoint((ch / 2), 0.0);
NSPoint pointB = NSMakePoint((cw - (ch / 2)), 0.0);
// NSPoint pointC = NSMakePoint((cw - (ch / 2)), ch);
NSPoint pointD = NSMakePoint((ch / 2), ch);
NSPoint lCtr = NSMakePoint((ch / 2), (ch / 2));
NSPoint rCtr = NSMakePoint((cw - (ch / 2)), (ch / 2));
float alpha = 0.45;
[path moveToPoint:pointA];
[path lineToPoint:pointB];
[path appendBezierPathWithArcWithCenter:rCtr radius:radius startAngle:270.0 endAngle:90.0];
[path lineToPoint:pointD];
[path appendBezierPathWithArcWithCenter:lCtr radius:radius startAngle:90.0 endAngle:270.0];
if ([self isHighlighted]) {
alpha = 0.60;
}
[[NSColor colorWithCalibratedWhite:0.15 alpha:alpha] set];
[path fill];
}
- (BOOL)isOpaque {
return NO;
}
@end