Removing the use of private CoreGraphics APIs to draw shadows, and replacing with...
[ITKit.git] / ITButtonCell.m
1 #import "ITButtonCell.h"
2
3 #define GRAY_EXTRA_PAD_H 60.0
4
5 @interface ITButtonCell (Private)
6 - (void)drawGrayRoundedBezelWithFrame:(NSRect)rect inView:(NSView *)controlView;
7 @end
8
9 @implementation ITButtonCell
10
11 - (id)init {
12         if ((self = [super init])) {
13                 _subStyle = 0;
14         }
15         return self;
16 }
17
18 - (void)setBezelStyle:(NSBezelStyle)bezelStyle {
19         if (bezelStyle == ITGrayRoundedBezelStyle) {
20                 _subStyle = bezelStyle;
21                 bezelStyle = NSRegularSquareBezelStyle;
22         } else {
23                 _subStyle = 0;
24         }
25         [super setBezelStyle:bezelStyle];
26 }
27
28 - (void)drawWithFrame:(NSRect)rect inView:(NSView *)controlView {
29         if (_subStyle == ITGrayRoundedBezelStyle) {
30                 [self drawGrayRoundedBezelWithFrame:rect inView:controlView];
31                 if ([self attributedTitle]) {
32                         NSPoint stringOrigin;
33                         NSSize stringSize;
34                         stringSize = [[self attributedTitle] size];
35                         stringOrigin.x = rect.origin.x + (rect.size.width - stringSize.width) / 2;
36                         stringOrigin.y = (rect.origin.y + (rect.size.height - stringSize.height) / 2) - 2;
37                         [controlView lockFocus];
38                         [[self attributedTitle] drawAtPoint:stringOrigin];
39                         [controlView unlockFocus];
40                 } else {
41                         [super drawInteriorWithFrame:rect inView:controlView];
42                 }
43                 [[controlView superview] setNeedsDisplay:YES];
44         } else {
45                 [super drawWithFrame:rect inView:controlView];
46         }
47 }
48
49 - (void)drawGrayRoundedBezelWithFrame:(NSRect)rect inView:(NSView *)controlView {
50         NSBezierPath *path = [NSBezierPath bezierPath];
51         float ch = rect.size.height;
52         float cw = rect.size.width;
53         float radius = (ch / 2);
54         NSPoint pointA = NSMakePoint((ch / 2), 0.0);
55         NSPoint pointB = NSMakePoint((cw - (ch / 2)), 0.0);
56 //      NSPoint pointC = NSMakePoint((cw - (ch / 2)), ch);
57         NSPoint pointD = NSMakePoint((ch / 2), ch);
58         NSPoint lCtr = NSMakePoint((ch / 2), (ch / 2));
59         NSPoint rCtr = NSMakePoint((cw - (ch / 2)), (ch / 2));
60         float alpha = 0.45;
61         
62         [path moveToPoint:pointA];
63         [path lineToPoint:pointB];
64         [path appendBezierPathWithArcWithCenter:rCtr radius:radius startAngle:270.0 endAngle:90.0];
65         [path lineToPoint:pointD];
66         [path appendBezierPathWithArcWithCenter:lCtr radius:radius startAngle:90.0 endAngle:270.0];
67         
68         if ([self isHighlighted]) {
69                 alpha = 0.60;
70         }
71         
72         [[NSColor colorWithCalibratedWhite:0.15 alpha:alpha] set];
73         [path fill];
74 }
75
76 - (BOOL)isOpaque {
77         return NO;
78 }
79
80 @end