Shadowless StatusWindow graphics, as well as an ITImageView which casts a shadow.
[ITKit.git] / ITImageCell.m
1 #import "ITImageCell.h"
2 #import <ApplicationServices/ApplicationServices.h>
3 #import "ITCoreGraphicsHacks.h"
4
5
6 @implementation ITImageCell
7
8
9 - (id)initImageCell:(NSImage *)image
10 {
11     if ( (self = [super initImageCell:image]) ) {
12         _scalesSmoothly  = YES;
13         castsShadow      = NO;
14         shadowElevation  = 45.0;
15         shadowAzimuth    = 90.0;
16         shadowAmbient    = 0.15;
17         shadowHeight     = 1.00;
18         shadowRadius     = 4.00;
19         shadowSaturation = 1.0;
20     }
21     NSLog(@"foo");
22     return self;
23 }
24
25 - (id)init
26 {
27     if ( (self = [super init]) ) {
28         _scalesSmoothly  = YES;
29         castsShadow      = NO;
30         shadowElevation  = 45.0;
31         shadowAzimuth    = 90.0;
32         shadowAmbient    = 0.15;
33         shadowHeight     = 1.00;
34         shadowRadius     = 4.00;
35         shadowSaturation = 1.0;
36     }
37     return self;
38 }
39
40 - (void)drawWithFrame:(NSRect)rect inView:(NSView *)controlView
41 {
42     CGSGenericObj        style = nil;
43     CGShadowStyle        shadow;
44     
45     if ( _scalesSmoothly || castsShadow ) {
46         [NSGraphicsContext saveGraphicsState];
47     }
48     
49     if ( _scalesSmoothly ) {
50         CGContextSetInterpolationQuality([[NSGraphicsContext currentContext] graphicsPort], kCGInterpolationHigh);
51     }
52     
53     if ( castsShadow ) {
54         //      Create the shadow style to use for drawing the string
55         shadow.version    = 0;
56         shadow.elevation  = shadowElevation;
57         shadow.azimuth    = shadowAzimuth;
58         shadow.ambient    = shadowAmbient;
59         shadow.height     = shadowHeight;
60         shadow.radius     = shadowRadius;
61         shadow.saturation = shadowSaturation;
62         style = CGStyleCreateShadow(&shadow);
63         CGContextSetStyle([[NSGraphicsContext currentContext] graphicsPort], style);
64     }
65     
66     [super drawWithFrame:rect inView:controlView];
67
68     if ( _scalesSmoothly || castsShadow ) {
69         [NSGraphicsContext restoreGraphicsState];
70     }
71     
72     if ( castsShadow ) {
73         CGStyleRelease(style);
74     }
75 }
76
77 - (BOOL)scalesSmoothly
78 {
79     return _scalesSmoothly;
80 }
81
82 - (void)setScalesSmoothly:(BOOL)flag
83 {
84     _scalesSmoothly = flag;
85     [[self controlView] setNeedsDisplay:YES];
86 }
87
88 - (BOOL)castsShadow;
89 {
90     return castsShadow;
91 }
92
93 - (void)setCastsShadow:(BOOL)newSetting;
94 {
95     castsShadow = newSetting;
96     [[self controlView] setNeedsDisplay:YES];
97 }
98
99 - (float)shadowElevation;
100 {
101     return shadowElevation;
102 }
103
104 - (void)setShadowElevation:(float)newElevation;
105 {
106     shadowElevation = newElevation;
107     [[self controlView] setNeedsDisplay:YES];
108 }
109
110 - (float)shadowAzimuth;
111 {
112     return shadowAzimuth;
113 }
114
115 - (void)setShadowAzimuth:(float)newAzimuth;
116 {
117     shadowAzimuth = newAzimuth;
118     [[self controlView] setNeedsDisplay:YES];
119 }
120
121 - (float)shadowAmbient;
122 {
123     return shadowAmbient;
124 }
125
126 - (void)setShadowAmbient:(float)newAmbient;
127 {
128     shadowAmbient = newAmbient;
129     [[self controlView] setNeedsDisplay:YES];
130 }
131
132 - (float)shadowHeight;
133 {
134     return shadowHeight;
135 }
136
137 - (void)setShadowHeight:(float)newHeight;
138 {
139     shadowHeight = newHeight;
140     [[self controlView] setNeedsDisplay:YES];
141 }
142
143 - (float)shadowRadius;
144 {
145     return shadowRadius;
146 }
147
148 - (void)setShadowRadius:(float)newRadius;
149 {
150     shadowRadius = newRadius;
151     [[self controlView] setNeedsDisplay:YES];
152 }
153
154 - (float)shadowSaturation;
155 {
156     return shadowSaturation;
157 }
158
159 - (void)setShadowSaturation:(float)newSaturation;
160 {
161     shadowSaturation = newSaturation;
162     [[self controlView] setNeedsDisplay:YES];
163 }
164
165
166 @end