-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPDCircleButtonCell.m
129 lines (78 loc) · 3.11 KB
/
PDCircleButtonCell.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//
// PDCircleButtonCell.m
// SproutedInterface
//
// Created by Philip Dow on 12/10/05.
// Copyright Sprouted. All rights reserved.
// Inquiries should be directed to [email protected]
//
#import <SproutedInterface/PDCircleButtonCell.h>
#import <SproutedUtilities/NSBezierPath_AMShading.h>
#import <SproutedUtilities/NSBezierPath_AMAdditons.h>
#define PDButtonCellFillLeft 0
#define PDButtonCellFillCenter 1
#define PDButtonCellFillRight 2
#define PDButtonCellDarkLeft 3
#define PDButtonCellDarkCenter 4
#define PDButtonCellDarkRight 5
@implementation PDCircleButtonCell
- (id)initWithCoder:(NSCoder *)decoder {
if ( self = [super initWithCoder:decoder] ) {
[self setBordered:NO];
}
return self;
}
- (id)initTextCell:(NSString *)aString {
if ( self = [super initTextCell:aString] ) {
[self setBordered:NO];
}
return self;
}
- (void) dealloc {
[super dealloc];
}
#pragma mark -
- (NSRect)drawingRectForBounds:(NSRect)theRect {
return theRect;
}
- (NSRect)titleRectForBounds:(NSRect)theRect {
return theRect;
}
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
//
// bypass the frame
//
[self drawInteriorWithFrame:cellFrame inView:controlView];
}
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
float alpha = ( [self isEnabled] ? 1.0 : 0.70 );
NSColor *gradientStart, *gradientEnd, *borderColor;
if ( [self isHighlighted] ) {
borderColor = [NSColor colorWithCalibratedRed:149.0/255.0 green:149.0/255.0 blue:149.0/255.0 alpha:alpha];
gradientStart = [NSColor colorWithCalibratedRed:186.0/255.0 green:186.0/255.0 blue:186.0/255.0 alpha:alpha];
gradientEnd = [NSColor colorWithCalibratedRed:218.0/255.0 green:218.0/255.0 blue:218.0/255.0 alpha:alpha];
}
else {
borderColor = [NSColor colorWithCalibratedRed:173.0/255.0 green:173.0/255.0 blue:173.0/255.0 alpha:alpha];
gradientEnd = [NSColor colorWithCalibratedRed:224.0/255.0 green:224.0/255.0 blue:224.0/255.0 alpha:alpha];
gradientStart = [NSColor colorWithCalibratedRed:253.0/255.0 green:253.0/255.0 blue:253.0/255.0 alpha:alpha];
}
static float fontSize = 12.0;
int height = cellFrame.size.height;
int width = cellFrame.size.width;
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
[NSFont boldSystemFontOfSize:fontSize], NSFontAttributeName,
( [self isEnabled] ? [NSColor blackColor] : [NSColor lightGrayColor] ), NSForegroundColorAttributeName, nil];
NSSize stringSize = [[self title] sizeWithAttributes:attributes];
NSRect stringRect = NSMakeRect(width/2.0-stringSize.width/2.0, height/2.0-stringSize.height/2.0,
stringSize.width, stringSize.height);
float offset = fontSize * 1.5;
NSRect targetRect = NSMakeRect( width/2.0 - offset/2, height/2.0 - offset/2, offset, offset );
targetRect = NSInsetRect(targetRect,0.5,0.5);
[[NSBezierPath bezierPathWithOvalInRect:targetRect]
linearGradientFillWithStartColor:gradientStart endColor:gradientEnd];
[borderColor set];
[[NSBezierPath bezierPathWithOvalInRect:targetRect] stroke];
[[self title] drawInRect:stringRect withAttributes:attributes];
}
@end