Shadowless StatusWindow graphics, as well as an ITImageView which casts a shadow.
authorMatthew Judy <mjudy@ithinksw.com>
Wed, 3 Dec 2003 13:45:00 +0000 (13:45 +0000)
committerMatthew Judy <mjudy@ithinksw.com>
Wed, 3 Dec 2003 13:45:00 +0000 (13:45 +0000)
ITImageCell.h
ITImageCell.m
ITImageView.h
ITImageView.m

index 4da918b..d3a9424 100755 (executable)
 
     BOOL _scalesSmoothly;
 
 
     BOOL _scalesSmoothly;
 
+    BOOL  castsShadow;
+    
+    float shadowElevation;
+    float shadowAzimuth;
+    float shadowAmbient;
+    float shadowHeight;
+    float shadowRadius;
+    float shadowSaturation;
 }
 
 - (BOOL)scalesSmoothly;
 - (void)setScalesSmoothly:(BOOL)flag;
 
 }
 
 - (BOOL)scalesSmoothly;
 - (void)setScalesSmoothly:(BOOL)flag;
 
+- (BOOL)castsShadow;
+- (void)setCastsShadow:(BOOL)newSetting;
+
+- (float)shadowElevation;              /* Light source elevation in degrees.  Defaults to 45.0 */
+- (void)setShadowElevation:(float)newElevation;
+
+- (float)shadowAzimuth;                        /* Light source azimuth in degrees.  Defaults to 90.0 */
+- (void)setShadowAzimuth:(float)newAzimuth;
+
+- (float)shadowAmbient;                        /* Amount of ambient light.  Defaults to 0.15 */
+- (void)setShadowAmbient:(float)newAmbient;
+
+- (float)shadowHeight;                 /* Height above the canvas.  Defaults to 1.0 */
+- (void)setShadowHeight:(float)newHeight;
+
+- (float)shadowRadius;                 /* Blur radius.  Defaults to 4.0 */
+- (void)setShadowRadius:(float)newRadius;
+
+- (float)shadowSaturation;             /* Maximum saturation.  Defaults to 1.0 */
+- (void)setShadowSaturation:(float)newSaturation;
 
 @end
 
 @end
index cefbcff..d8f38b9 100755 (executable)
@@ -1,4 +1,6 @@
 #import "ITImageCell.h"
 #import "ITImageCell.h"
+#import <ApplicationServices/ApplicationServices.h>
+#import "ITCoreGraphicsHacks.h"
 
 
 @implementation ITImageCell
 
 
 @implementation ITImageCell
@@ -7,27 +9,68 @@
 - (id)initImageCell:(NSImage *)image
 {
     if ( (self = [super initImageCell:image]) ) {
 - (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;
 }
 
     }
     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
 {
 
 - (void)drawWithFrame:(NSRect)rect inView:(NSView *)controlView
 {
-    NSImageInterpolation interpolation;
-
+    CGSGenericObj        style = nil;
+    CGShadowStyle        shadow;
+    
+    if ( _scalesSmoothly || castsShadow ) {
+        [NSGraphicsContext saveGraphicsState];
+    }
+    
     if ( _scalesSmoothly ) {
     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];
 
     }
     
     [super drawWithFrame:rect inView:controlView];
 
-    if ( _scalesSmoothly ) {
-        [[NSGraphicsContext currentContext] setImageInterpolation:interpolation];
+    if ( _scalesSmoothly || castsShadow ) {
+        [NSGraphicsContext restoreGraphicsState];
+    }
+    
+    if ( castsShadow ) {
+        CGStyleRelease(style);
     }
 }
 
     }
 }
 
     [[self controlView] setNeedsDisplay:YES];
 }
 
     [[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
 
 @end
index aafb576..72b768d 100755 (executable)
 - (BOOL)scalesSmoothly;
 - (void)setScalesSmoothly:(BOOL)flag;
 
 - (BOOL)scalesSmoothly;
 - (void)setScalesSmoothly:(BOOL)flag;
 
+- (BOOL)castsShadow;
+- (void)setCastsShadow:(BOOL)newSetting;
+
+- (float)shadowElevation;              /* Light source elevation in degrees.  Defaults to 45.0 */
+- (void)setShadowElevation:(float)newElevation;
+
+- (float)shadowAzimuth;                        /* Light source azimuth in degrees.  Defaults to 90.0 */
+- (void)setShadowAzimuth:(float)newAzimuth;
+
+- (float)shadowAmbient;                        /* Amount of ambient light.  Defaults to 0.15 */
+- (void)setShadowAmbient:(float)newAmbient;
+
+- (float)shadowHeight;                 /* Height above the canvas.  Defaults to 1.0 */
+- (void)setShadowHeight:(float)newHeight;
+
+- (float)shadowRadius;                 /* Blur radius.  Defaults to 4.0 */
+- (void)setShadowRadius:(float)newRadius;
+
+- (float)shadowSaturation;             /* Maximum saturation.  Defaults to 1.0 */
+- (void)setShadowSaturation:(float)newSaturation;
+
+
 @end
 @end
index 899cae6..228e2f4 100755 (executable)
     [[self cell] setScalesSmoothly:flag];
 }
 
     [[self cell] setScalesSmoothly:flag];
 }
 
+- (BOOL)castsShadow;
+{
+    return [[self cell] castsShadow];
+}
+
+- (void)setCastsShadow:(BOOL)newSetting;
+{
+    [[self cell] setCastsShadow:newSetting];
+}
+
+- (float)shadowElevation;
+{
+    return [[self cell] shadowElevation];
+}
+
+- (void)setShadowElevation:(float)newElevation;
+{
+    [[self cell] setShadowElevation:newElevation];
+}
+
+- (float)shadowAzimuth;
+{
+    return [[self cell] shadowAzimuth];
+}
+
+- (void)setShadowAzimuth:(float)newAzimuth;
+{
+    [[self cell] setShadowAzimuth:newAzimuth];
+}
+
+- (float)shadowAmbient;
+{
+    return [[self cell] shadowAmbient];
+}
+
+- (void)setShadowAmbient:(float)newAmbient;
+{
+    [[self cell] setShadowAmbient:newAmbient];
+}
+
+- (float)shadowHeight;
+{
+    return [[self cell] shadowHeight];
+}
+
+- (void)setShadowHeight:(float)newHeight;
+{
+    [[self cell] setShadowHeight:newHeight];
+}
+
+- (float)shadowRadius;
+{
+    return [[self cell] shadowRadius];
+}
+
+- (void)setShadowRadius:(float)newRadius;
+{
+    [[self cell] setShadowRadius:newRadius];
+}
+
+- (float)shadowSaturation;
+{
+    return [[self cell] shadowSaturation];
+}
+
+- (void)setShadowSaturation:(float)newSaturation;
+{
+    [[self cell] setShadowSaturation:newSaturation];
+}
+
 
 @end
 
 @end