1 #import "ITImageCell.h"
2 #import <ApplicationServices/ApplicationServices.h>
3 #import "ITCoreGraphicsHacks.h"
6 @implementation ITImageCell
9 - (id)initImageCell:(NSImage *)image
11 if ( (self = [super initImageCell:image]) ) {
12 _scalesSmoothly = YES;
14 shadowElevation = 45.0;
19 shadowSaturation = 1.0;
27 if ( (self = [super init]) ) {
28 _scalesSmoothly = YES;
30 shadowElevation = 45.0;
35 shadowSaturation = 1.0;
40 - (void)drawWithFrame:(NSRect)rect inView:(NSView *)controlView
42 CGSGenericObj style = nil;
45 if ( _scalesSmoothly || castsShadow ) {
46 [NSGraphicsContext saveGraphicsState];
49 if ( _scalesSmoothly ) {
50 // CGContextSetInterpolationQuality([[NSGraphicsContext currentContext] graphicsPort], kCGInterpolationHigh);
51 [[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationHigh];
52 [[NSGraphicsContext currentContext] setShouldAntialias:YES];
56 // Create the shadow style to use for drawing the string
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);
68 [super drawWithFrame:rect inView:controlView];
70 if ( _scalesSmoothly || castsShadow ) {
71 [NSGraphicsContext restoreGraphicsState];
75 CGStyleRelease(style);
79 - (BOOL)scalesSmoothly
81 return _scalesSmoothly;
84 - (void)setScalesSmoothly:(BOOL)flag
86 _scalesSmoothly = flag;
87 [[self controlView] setNeedsDisplay:YES];
95 - (void)setCastsShadow:(BOOL)newSetting;
97 castsShadow = newSetting;
98 [[self controlView] setNeedsDisplay:YES];
101 - (float)shadowElevation;
103 return shadowElevation;
106 - (void)setShadowElevation:(float)newElevation;
108 shadowElevation = newElevation;
109 [[self controlView] setNeedsDisplay:YES];
112 - (float)shadowAzimuth;
114 return shadowAzimuth;
117 - (void)setShadowAzimuth:(float)newAzimuth;
119 shadowAzimuth = newAzimuth;
120 [[self controlView] setNeedsDisplay:YES];
123 - (float)shadowAmbient;
125 return shadowAmbient;
128 - (void)setShadowAmbient:(float)newAmbient;
130 shadowAmbient = newAmbient;
131 [[self controlView] setNeedsDisplay:YES];
134 - (float)shadowHeight;
139 - (void)setShadowHeight:(float)newHeight;
141 shadowHeight = newHeight;
142 [[self controlView] setNeedsDisplay:YES];
145 - (float)shadowRadius;
150 - (void)setShadowRadius:(float)newRadius;
152 shadowRadius = newRadius;
153 [[self controlView] setNeedsDisplay:YES];
156 - (float)shadowSaturation;
158 return shadowSaturation;
161 - (void)setShadowSaturation:(float)newSaturation;
163 shadowSaturation = newSaturation;
164 [[self controlView] setNeedsDisplay:YES];