-
Notifications
You must be signed in to change notification settings - Fork 1
/
PDButtonColorWellCell.m
196 lines (139 loc) · 5.5 KB
/
PDButtonColorWellCell.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
//
// PDButtonColorWellCell.m
// SproutedInterface
//
// Created by Philip Dow on 1/7/06.
// Copyright Sprouted. All rights reserved.
// Inquiries should be directed to [email protected]
//
#import <SproutedInterface/PDButtonColorWellCell.h>
#import <SproutedUtilities/NSBezierPath_AMShading.h>
#import <SproutedUtilities/NSBezierPath_AMAdditons.h>
#define kLabelOffset 20
@implementation PDButtonColorWellCell
- (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 {
[_color release];
[super dealloc];
}
#pragma mark -
- (NSColor*) color
{
return _color;
}
- (void) setColor:(NSColor*)color
{
if ( _color != color )
{
[self willChangeValueForKey:@"color"];
[_color release];
_color = [color copyWithZone:[self zone]];
[self didChangeValueForKey:@"color"];
}
}
#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] /*|| [self state] == NSOnState*/ ) {
borderColor = [NSColor colorWithCalibratedRed:119.0/255.0 green:119.0/255.0 blue:119.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:143.0/255.0 green:143.0/255.0 blue:143.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];
}
NSRect targetRect = cellFrame;
targetRect = NSInsetRect(targetRect,0.5,0.5);
//targetRect.origin.x += 0.5; targetRect.origin.y += 0.5; targetRect.size.width = 21; targetRect.size.height -= 1;
NSBezierPath *thePath = [NSBezierPath bezierPathWithRoundedRect:targetRect cornerRadius:2.0];
[thePath linearGradientFillWithStartColor:gradientStart endColor:gradientEnd];
[borderColor set];
[thePath stroke];
//
// draw the color inside the cell image
NSColor *cellColor = [self color];
if ( !cellColor ) cellColor = [NSColor blackColor];
[cellColor set];
//NSRect colorRect = NSInsetRect(targetRect, 5.0, 4.0);
NSRect colorRect = targetRect;
colorRect.origin.x += 5; colorRect.origin.y += 4; colorRect.size.width = 10; colorRect.size.height -= 8;
NSBezierPath *insetPath = [NSBezierPath bezierPathWithRoundedRect:colorRect cornerRadius:2.0];
[insetPath fill];
[[borderColor colorWithAlphaComponent:0.7] set];
//[borderColor set];
[insetPath stroke];
if ( [[self title] length] != 0 )
{
cellFrame.origin.x += kLabelOffset;
cellFrame.size.width -= kLabelOffset;
[super 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];
}
NSRect targetRect = cellFrame;
targetRect = NSInsetRect(targetRect,0.5,0.5);
[[NSBezierPath bezierPathWithRoundedRect:targetRect cornerRadius:2.0]
linearGradientFillWithStartColor:gradientStart endColor:gradientEnd];
[borderColor set];
[[NSBezierPath bezierPathWithRoundedRect:targetRect cornerRadius:2.0] stroke];
// draw the color inside the cell image
NSColor *cellColor = [self color];
if ( !cellColor ) cellColor = [NSColor blackColor];
[cellColor set];
NSRect colorRect = NSInsetRect(targetRect, 6.0, 4.0);
[[NSBezierPath bezierPathWithRoundedRect:colorRect cornerRadius:2.0] fill];
// draw the label if there is one
NSString *title = [self title];
if ( title != nil && [title length] > 0 )
{
// really basic stuff happening here - no alignment, no elision, etc
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
[self font], NSFontAttributeName, nil];
NSSize stringSize = [title sizeWithAttributes:attributes];
NSRect titleRect = NSMakeRect( cellFrame.origin.x + cellFrame.size.width - stringSize.width,
cellFrame.origin.y + cellFrame.size.height - stringSize.height,
stringSize.width, stringSize.height );
[title drawInRect:titleRect withAttributes:attributes];
}
}
*/
@end