Removing the use of private CoreGraphics APIs to draw shadows, and replacing with...
[ITKit.git] / ITTSWBackgroundView.m
1 #import "ITTSWBackgroundView.h"
2
3
4 #define RADIUS 24.0
5
6
7 @interface ITTSWBackgroundView (Private)
8 @end
9
10
11 @implementation ITTSWBackgroundView
12
13
14 - (id)initWithFrame:(NSRect)frameRect
15 {
16     if ( (self = [super initWithFrame:frameRect]) ) {
17         _path  = [[NSBezierPath bezierPath] retain];
18         _color = [[NSColor blueColor] retain];
19         _mode  = ITTSWBackgroundApple;
20     }
21     
22     return self;
23 }
24
25 - (void)drawRect:(NSRect)rect
26 {
27     float vh     = NSHeight(rect);
28     float vw     = NSWidth(rect);
29     float indent = 0.0;
30     
31     if ( (_mode == ITTSWBackgroundReadable) || (_mode == ITTSWBackgroundColored) ) {
32         indent = 2.0;
33     }
34     
35     NSPoint pointA = NSMakePoint( ((vw - RADIUS) - indent) , (vh - indent)            );
36     NSPoint pointB = NSMakePoint( (RADIUS + indent)        , (vh - indent)            );
37     NSPoint pointD = NSMakePoint( indent                   , (RADIUS + indent)        );
38     NSPoint pointF = NSMakePoint( ((vw - RADIUS) - indent) , indent                   );
39     NSPoint pointH = NSMakePoint( (vw - indent)            , ((vh - RADIUS) - indent) );
40     
41     NSPoint ctrBC  = NSMakePoint( (RADIUS + indent)        , ((vh - RADIUS) - indent) );
42     NSPoint ctrDE  = NSMakePoint( (RADIUS + indent)        , (RADIUS + indent)        );
43     NSPoint ctrFG  = NSMakePoint( ((vw - RADIUS) - indent) , (RADIUS + indent)        );
44     NSPoint ctrHA  = NSMakePoint( ((vw - RADIUS) - indent) , ((vh - RADIUS) - indent) );
45     
46     /*
47      *        D                    E
48      *      +------------------------+
49      *    C | * ctrCD        ctrEF * | F
50      *      |                        |
51      *    B | * ctrAB        ctrGH * | G
52      *      +------------------------+
53      *        A                    H
54      */
55     
56     [_path removeAllPoints];
57     
58     [_path moveToPoint:pointA];                         //  first point
59     [_path lineToPoint:pointB];                         //  top line
60     [_path appendBezierPathWithArcWithCenter:ctrBC      //  top-left curve
61                                       radius:RADIUS
62                                   startAngle:90.0
63                                     endAngle:180.0];
64     [_path lineToPoint:pointD];                         //  left line
65     [_path appendBezierPathWithArcWithCenter:ctrDE      //  bottom-left curve
66                                       radius:RADIUS
67                                   startAngle:180.0
68                                     endAngle:270.0];
69     [_path lineToPoint:pointF];                         //  top line
70     [_path appendBezierPathWithArcWithCenter:ctrFG      //  top-right curve
71                                       radius:RADIUS
72                                   startAngle:270.0
73                                     endAngle:0.0];
74     [_path lineToPoint:pointH];                         //  right line
75     [_path appendBezierPathWithArcWithCenter:ctrHA      //  bottom-right curve
76                                       radius:RADIUS
77                                   startAngle:0.0
78                                     endAngle:90.0];
79                                     
80     if ( _mode == ITTSWBackgroundApple ) {
81         [[NSColor colorWithCalibratedWhite:0.0 alpha:0.15] set];
82     } else if ( _mode == ITTSWBackgroundReadable ) {
83         [[NSColor colorWithCalibratedWhite:0.15 alpha:0.70] set];
84     } else if ( _mode == ITTSWBackgroundColored ) {
85         [_color set];
86     }
87     
88     [_path fill];
89
90     if ( (_mode == ITTSWBackgroundReadable) || (_mode == ITTSWBackgroundColored) ) {
91         [[NSColor colorWithCalibratedWhite:0.90 alpha:1.00] set];
92         [_path setLineWidth:3.0];
93         [_path stroke];
94     }
95 }
96
97 - (BOOL)isOpaque
98 {
99     return NO;
100 }
101
102 - (ITTSWBackgroundMode)backgroundMode
103 {
104     return _mode;
105 }
106
107 - (void)setBackgroundMode:(ITTSWBackgroundMode)newMode
108 {
109     _mode = newMode;
110     [self setNeedsDisplay:YES];
111 }
112
113 - (NSColor *)backgroundColor
114 {
115     return _color;
116 }
117
118 - (void)setBackgroundColor:(NSColor *)newColor
119 {
120     [_color autorelease];
121     _color = [newColor copy];
122     [self setNeedsDisplay:YES];
123 }
124
125
126 @end