X-Git-Url: http://git.ithinksw.org/ITKit.git/blobdiff_plain/55f9d57f56bbbbb2c589201246a29858c6cf4e56..3269e9dfcbe058cef9e1da01ab45a93f07ee2be1:/ITImageCell.m diff --git a/ITImageCell.m b/ITImageCell.m index cefbcff..d8f38b9 100755 --- a/ITImageCell.m +++ b/ITImageCell.m @@ -1,4 +1,6 @@ #import "ITImageCell.h" +#import +#import "ITCoreGraphicsHacks.h" @implementation ITImageCell @@ -7,27 +9,68 @@ - (id)initImageCell:(NSImage *)image { if ( (self = [super initImageCell:image]) ) { - _scalesSmoothly = YES; + _scalesSmoothly = YES; + castsShadow = NO; + shadowElevation = 45.0; + shadowAzimuth = 90.0; + shadowAmbient = 0.15; + shadowHeight = 1.00; + shadowRadius = 4.00; + shadowSaturation = 1.0; } NSLog(@"foo"); return self; } - +- (id)init +{ + if ( (self = [super init]) ) { + _scalesSmoothly = YES; + castsShadow = NO; + shadowElevation = 45.0; + shadowAzimuth = 90.0; + shadowAmbient = 0.15; + shadowHeight = 1.00; + shadowRadius = 4.00; + shadowSaturation = 1.0; + } + return self; +} - (void)drawWithFrame:(NSRect)rect inView:(NSView *)controlView { - NSImageInterpolation interpolation; - + CGSGenericObj style = nil; + CGShadowStyle shadow; + + if ( _scalesSmoothly || castsShadow ) { + [NSGraphicsContext saveGraphicsState]; + } + if ( _scalesSmoothly ) { - interpolation = [[NSGraphicsContext currentContext] imageInterpolation]; - [[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationHigh]; + CGContextSetInterpolationQuality([[NSGraphicsContext currentContext] graphicsPort], kCGInterpolationHigh); + } + + if ( castsShadow ) { + // Create the shadow style to use for drawing the string + shadow.version = 0; + shadow.elevation = shadowElevation; + shadow.azimuth = shadowAzimuth; + shadow.ambient = shadowAmbient; + shadow.height = shadowHeight; + shadow.radius = shadowRadius; + shadow.saturation = shadowSaturation; + style = CGStyleCreateShadow(&shadow); + CGContextSetStyle([[NSGraphicsContext currentContext] graphicsPort], style); } [super drawWithFrame:rect inView:controlView]; - if ( _scalesSmoothly ) { - [[NSGraphicsContext currentContext] setImageInterpolation:interpolation]; + if ( _scalesSmoothly || castsShadow ) { + [NSGraphicsContext restoreGraphicsState]; + } + + if ( castsShadow ) { + CGStyleRelease(style); } } @@ -42,5 +85,82 @@ [[self controlView] setNeedsDisplay:YES]; } +- (BOOL)castsShadow; +{ + return castsShadow; +} + +- (void)setCastsShadow:(BOOL)newSetting; +{ + castsShadow = newSetting; + [[self controlView] setNeedsDisplay:YES]; +} + +- (float)shadowElevation; +{ + return shadowElevation; +} + +- (void)setShadowElevation:(float)newElevation; +{ + shadowElevation = newElevation; + [[self controlView] setNeedsDisplay:YES]; +} + +- (float)shadowAzimuth; +{ + return shadowAzimuth; +} + +- (void)setShadowAzimuth:(float)newAzimuth; +{ + shadowAzimuth = newAzimuth; + [[self controlView] setNeedsDisplay:YES]; +} + +- (float)shadowAmbient; +{ + return shadowAmbient; +} + +- (void)setShadowAmbient:(float)newAmbient; +{ + shadowAmbient = newAmbient; + [[self controlView] setNeedsDisplay:YES]; +} + +- (float)shadowHeight; +{ + return shadowHeight; +} + +- (void)setShadowHeight:(float)newHeight; +{ + shadowHeight = newHeight; + [[self controlView] setNeedsDisplay:YES]; +} + +- (float)shadowRadius; +{ + return shadowRadius; +} + +- (void)setShadowRadius:(float)newRadius; +{ + shadowRadius = newRadius; + [[self controlView] setNeedsDisplay:YES]; +} + +- (float)shadowSaturation; +{ + return shadowSaturation; +} + +- (void)setShadowSaturation:(float)newSaturation; +{ + shadowSaturation = newSaturation; + [[self controlView] setNeedsDisplay:YES]; +} + @end