Another cleanup that doesn't seem to actually help
[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         [[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationHigh];
52         [[NSGraphicsContext currentContext] setShouldAntialias:YES];
53     }
54     
55     if ( castsShadow ) {
56         //      Create the shadow style to use for drawing the string
57         shadow.version    = 0;
58         shadow.elevation  = shadowElevation;
59         shadow.azimuth    = shadowAzimuth;
60         shadow.ambient    = shadowAmbient;
61         shadow.height     = shadowHeight;
62         shadow.radius     = shadowRadius;
63         shadow.saturation = shadowSaturation;
64         style = CGStyleCreateShadow(&shadow);
65         CGContextSetStyle([[NSGraphicsContext currentContext] graphicsPort], style);
66     }
67     
68     [super drawWithFrame:rect inView:controlView];
69
70     if ( _scalesSmoothly || castsShadow ) {
71         [NSGraphicsContext restoreGraphicsState];
72     }
73     
74     if ( castsShadow ) {
75         CGStyleRelease(style);
76     }
77 }
78
79 - (BOOL)scalesSmoothly
80 {
81     return _scalesSmoothly;
82 }
83
84 - (void)setScalesSmoothly:(BOOL)flag
85 {
86     _scalesSmoothly = flag;
87     [[self controlView] setNeedsDisplay:YES];
88 }
89
90 - (BOOL)castsShadow;
91 {
92     return castsShadow;
93 }
94
95 - (void)setCastsShadow:(BOOL)newSetting;
96 {
97     castsShadow = newSetting;
98     [[self controlView] setNeedsDisplay:YES];
99 }
100
101 - (float)shadowElevation;
102 {
103     return shadowElevation;
104 }
105
106 - (void)setShadowElevation:(float)newElevation;
107 {
108     shadowElevation = newElevation;
109     [[self controlView] setNeedsDisplay:YES];
110 }
111
112 - (float)shadowAzimuth;
113 {
114     return shadowAzimuth;
115 }
116
117 - (void)setShadowAzimuth:(float)newAzimuth;
118 {
119     shadowAzimuth = newAzimuth;
120     [[self controlView] setNeedsDisplay:YES];
121 }
122
123 - (float)shadowAmbient;
124 {
125     return shadowAmbient;
126 }
127
128 - (void)setShadowAmbient:(float)newAmbient;
129 {
130     shadowAmbient = newAmbient;
131     [[self controlView] setNeedsDisplay:YES];
132 }
133
134 - (float)shadowHeight;
135 {
136     return shadowHeight;
137 }
138
139 - (void)setShadowHeight:(float)newHeight;
140 {
141     shadowHeight = newHeight;
142     [[self controlView] setNeedsDisplay:YES];
143 }
144
145 - (float)shadowRadius;
146 {
147     return shadowRadius;
148 }
149
150 - (void)setShadowRadius:(float)newRadius;
151 {
152     shadowRadius = newRadius;
153     [[self controlView] setNeedsDisplay:YES];
154 }
155
156 - (float)shadowSaturation;
157 {
158     return shadowSaturation;
159 }
160
161 - (void)setShadowSaturation:(float)newSaturation;
162 {
163     shadowSaturation = newSaturation;
164     [[self controlView] setNeedsDisplay:YES];
165 }
166
167
168 @end