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
|
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/cocoa/toolbar_button_cell.h"
@implementation ToolbarButtonCell
- (NSBackgroundStyle)interiorBackgroundStyle {
return [self isHighlighted] ?
NSBackgroundStyleLowered : NSBackgroundStyleRaised;
}
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView{
NSRect drawFrame = NSInsetRect(cellFrame, 1.5, 1.5);
ButtonType type = [[(NSControl*)controlView cell] tag];
switch (type) {
case kRightButtonType:
drawFrame.origin.x -= 20;
case kLeftButtonType:
case kLeftButtonWithShadowType:
drawFrame.size.width += 20;
default:
break;
}
float radius = 3.5;
BOOL highlighted = [self isHighlighted];
NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:drawFrame
xRadius:radius
yRadius:radius];
NSBezierPath *outerPath =
[NSBezierPath bezierPathWithRoundedRect:NSInsetRect(drawFrame, -1, -1)
xRadius:radius + 1
yRadius:radius + 1];
NSGradient *gradient = nil;
if (highlighted) {
NSColor* start = [NSColor colorWithCalibratedHue:0.6
saturation:1.0
brightness:0.6
alpha:1.0];
NSColor* end = [NSColor colorWithCalibratedHue:0.6
saturation:1.0
brightness:0.8
alpha:1.0];
gradient = [[[NSGradient alloc] initWithStartingColor:start
endingColor:end] autorelease];
} else {
NSColor* start = [NSColor colorWithCalibratedWhite:1.0 alpha:1.0];
NSColor* end = [NSColor colorWithCalibratedWhite:0.90 alpha:1.0];
gradient = [[[NSGradient alloc] initWithStartingColor:start
endingColor:end] autorelease];
}
[[NSColor colorWithCalibratedWhite:1.0 alpha:0.25] set];
[outerPath stroke];
[gradient drawInBezierPath:path angle:90.0];
[[NSColor colorWithCalibratedWhite:0.0 alpha:0.15] set];
[path stroke];
if (type == kLeftButtonWithShadowType) {
NSRect borderRect, contentRect;
NSDivideRect(cellFrame, &borderRect, &contentRect, 1.0, NSMaxXEdge);
[[NSColor colorWithCalibratedWhite:0.0 alpha:0.15] set];
NSRectFillUsingOperation(NSInsetRect(borderRect, 0, 2),
NSCompositeSourceOver);
}
[self drawInteriorWithFrame:NSOffsetRect(cellFrame, 0, 1) inView:controlView];
}
@end
|