1 #import "ITImageCell.h"
2 #import "ITCoreGraphicsHacks.h"
3 #import <ApplicationServices/ApplicationServices.h>
5 @implementation ITImageCell
7 - (id)initImageCell:(NSImage *)image {
8 if ((self = [super initImageCell:image])) {
11 shadowElevation = 45.0;
16 shadowSaturation = 1.0;
22 if ((self = [super init])) {
23 _scalesSmoothly = YES;
25 shadowElevation = 45.0;
30 shadowSaturation = 1.0;
35 - (void)drawWithFrame:(NSRect)rect inView:(NSView *)controlView {
36 CGSGenericObj style = nil;
39 if (_scalesSmoothly || castsShadow) {
40 [NSGraphicsContext saveGraphicsState];
43 if (_scalesSmoothly) {
44 // CGContextSetInterpolationQuality([[NSGraphicsContext currentContext] graphicsPort], kCGInterpolationHigh);
45 [[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationHigh];
46 [[NSGraphicsContext currentContext] setShouldAntialias:YES];
50 // Create the shadow style to use for drawing the string
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);
62 [super drawWithFrame:rect inView:controlView];
65 CGStyleRelease(style);
68 if (_scalesSmoothly || castsShadow) {
69 [NSGraphicsContext restoreGraphicsState];
73 - (BOOL)scalesSmoothly {
74 return _scalesSmoothly;
77 - (void)setScalesSmoothly:(BOOL)flag {
78 _scalesSmoothly = flag;
79 [[self controlView] setNeedsDisplay:YES];
86 - (void)setCastsShadow:(BOOL)newSetting {
87 castsShadow = newSetting;
88 [[self controlView] setNeedsDisplay:YES];
91 - (float)shadowElevation {
92 return shadowElevation;
95 - (void)setShadowElevation:(float)newElevation {
96 shadowElevation = newElevation;
97 [[self controlView] setNeedsDisplay:YES];
100 - (float)shadowAzimuth {
101 return shadowAzimuth;
104 - (void)setShadowAzimuth:(float)newAzimuth {
105 shadowAzimuth = newAzimuth;
106 [[self controlView] setNeedsDisplay:YES];
109 - (float)shadowAmbient {
110 return shadowAmbient;
113 - (void)setShadowAmbient:(float)newAmbient {
114 shadowAmbient = newAmbient;
115 [[self controlView] setNeedsDisplay:YES];
118 - (float)shadowHeight {
122 - (void)setShadowHeight:(float)newHeight {
123 shadowHeight = newHeight;
124 [[self controlView] setNeedsDisplay:YES];
127 - (float)shadowRadius {
131 - (void)setShadowRadius:(float)newRadius {
132 shadowRadius = newRadius;
133 [[self controlView] setNeedsDisplay:YES];
136 - (float)shadowSaturation {
137 return shadowSaturation;
140 - (void)setShadowSaturation:(float)newSaturation {
141 shadowSaturation = newSaturation;
142 [[self controlView] setNeedsDisplay:YES];