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