Adding quick fix get-the-fuck-out-of-the-way positioning
[ITKit.git] / ITButtonCell.m
1 #import "ITButtonCell.h"
2 #import "ITTextFieldCell.h"
3
4
5 #define GRAY_EXTRA_PAD_H 60.0
6
7
8 @interface ITButtonCell (Private)
9 - (void)drawGrayRoundedBezelWithFrame:(NSRect)rect inView:(NSView *)controlView;
10 @end
11
12
13 @implementation ITButtonCell
14
15 - (id)init
16 {
17     if ( ( self = [super init] ) ) {
18         _subStyle = 0;
19     }
20     
21     return self;
22 }
23
24
25
26 /*************************************************************************/
27 #pragma mark -
28 #pragma mark INSTANCE METHODS
29 /*************************************************************************/
30
31 - (void)setBezelStyle:(NSBezelStyle)bezelStyle
32 {
33     if ( bezelStyle == ITGrayRoundedBezelStyle ) {
34         _subStyle  = bezelStyle;
35         bezelStyle = NSRegularSquareBezelStyle;
36     } else {
37         _subStyle = 0;
38     }
39
40     [super setBezelStyle:bezelStyle];
41 }
42
43
44 /*************************************************************************/
45 #pragma mark -
46 #pragma mark DRAWING METHODS
47 /*************************************************************************/
48
49 - (void)drawWithFrame:(NSRect)rect inView:(NSView *)controlView
50 {
51     if ( _subStyle == ITGrayRoundedBezelStyle ) {
52         [self drawGrayRoundedBezelWithFrame:rect inView:controlView];
53         [super drawInteriorWithFrame:rect inView:controlView];
54         [[controlView superview] setNeedsDisplay:YES];
55     } else {
56         [super drawWithFrame:rect inView:controlView];
57     }
58 }
59
60 - (void)drawGrayRoundedBezelWithFrame:(NSRect)rect inView:(NSView *)controlView
61 {
62     NSBezierPath *path   = [NSBezierPath bezierPath];
63     float         ch     = rect.size.height;
64     float         cw     = rect.size.width;
65     float         radius = ( ch / 2 );
66     NSPoint       pointA = NSMakePoint( (ch / 2)        , 0.0      );
67     NSPoint       pointB = NSMakePoint( (cw - (ch / 2)) , 0.0      );
68 //  NSPoint       pointC = NSMakePoint( (cw - (ch / 2)) , ch       );
69     NSPoint       pointD = NSMakePoint( (ch / 2)        , ch       );
70     NSPoint       lCtr   = NSMakePoint( (ch / 2)        , (ch / 2) );
71     NSPoint       rCtr   = NSMakePoint( (cw - (ch / 2)) , (ch / 2) );
72     float         alpha  = 0.45;
73     
74     [path moveToPoint:pointA];
75     [path lineToPoint:pointB];
76     [path appendBezierPathWithArcWithCenter:rCtr
77                                      radius:radius
78                                  startAngle:270.0
79                                    endAngle:90.0];
80     [path lineToPoint:pointD];
81     [path appendBezierPathWithArcWithCenter:lCtr
82                                      radius:radius
83                                  startAngle:90.0
84                                    endAngle:270.0];
85
86     if ( [self isHighlighted] ) {
87         alpha = 0.60;
88     }
89     
90     [[NSColor colorWithCalibratedWhite:0.15 alpha:alpha] set];
91     [path fill];
92 }
93
94 - (BOOL)isOpaque
95 {
96     return NO;
97 }
98
99 @end