Adding ITTextFieldCell to the kit, for use in matrices, etc.
authorMatthew Judy <mjudy@ithinksw.com>
Sun, 14 Sep 2003 06:59:39 +0000 (06:59 +0000)
committerMatthew Judy <mjudy@ithinksw.com>
Sun, 14 Sep 2003 06:59:39 +0000 (06:59 +0000)
ITTextFieldCell.h [new file with mode: 0755]
ITTextFieldCell.m [new file with mode: 0755]

diff --git a/ITTextFieldCell.h b/ITTextFieldCell.h
new file mode 100755 (executable)
index 0000000..50d8cf0
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ *     ITKit
+ *  ITTextFieldCell
+ *    Allows shadows to be drawn under text in cells.
+ *
+ *  Original Author : Matt Judy <mjudy@ithinksw.com>
+ *   Responsibility : Matt Judy <mjudy@ithinksw.com>
+ *   Responsibility : Joseph Spiros <joseph.spiros@ithinksw.com>
+ *
+ *  Copyright (c) 2003 iThink Software.
+ *  All Rights Reserved
+ *
+ */
+
+#import <Cocoa/Cocoa.h>
+
+
+@interface ITTextFieldCell : NSTextFieldCell {
+
+    BOOL  castsShadow;
+    
+    float shadowElevation;
+    float shadowAzimuth;
+    float shadowAmbient;
+    float shadowHeight;
+    float shadowRadius;
+    float shadowSaturation;
+
+}
+
+- (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
diff --git a/ITTextFieldCell.m b/ITTextFieldCell.m
new file mode 100755 (executable)
index 0000000..6d2b86a
--- /dev/null
@@ -0,0 +1,171 @@
+#import "ITTextFieldCell.h"
+#import <CoreGraphics/CoreGraphics.h>
+#import "ITCoreGraphicsHacks.h"
+
+
+/*************************************************************************/
+#pragma mark -
+#pragma mark IMPLEMENTATION
+/*************************************************************************/
+
+@implementation ITTextFieldCell
+
+/*************************************************************************/
+#pragma mark -
+#pragma mark INITIALIZATION METHODS
+/*************************************************************************/
+
+- (id)init
+{
+    if ( ( self = [super init] ) ) {
+        castsShadow      = NO;
+        shadowElevation  = 45.0;
+        shadowAzimuth    = 90.0;
+        shadowAmbient    = 0.15;
+        shadowHeight     = 1.00;
+        shadowRadius     = 4.00;
+        shadowSaturation = 1.0;
+    }
+
+    return self;
+}
+
+- (id)initWithCoder:(NSCoder *)coder
+{
+    if ( ( self = [super initWithCoder:coder] ) ) {
+        castsShadow      = NO;
+        shadowElevation  = 45.0;
+        shadowAzimuth    = 90.0;
+        shadowAmbient    = 0.15;
+        shadowHeight     = 1.00;
+        shadowRadius     = 4.00;
+        shadowSaturation = 1.0;
+    }
+    
+    return self;
+}
+
+
+/*************************************************************************/
+#pragma mark -
+#pragma mark DRAWING METHODS
+/*************************************************************************/
+
+- (void)drawInteriorWithFrame:(NSRect)rect inView:(NSView *)controlView
+{
+    CGSGenericObj        style = nil;
+    CGShadowStyle        shadow;
+
+    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);
+        
+        // Set the context for drawing the string
+        [NSGraphicsContext saveGraphicsState];
+        CGContextSetStyle([[NSGraphicsContext currentContext] graphicsPort], style);
+    }
+    
+    // Draw the string
+    [super drawInteriorWithFrame:rect inView:controlView];
+    
+
+    if ( castsShadow ) { 
+        // Restore the old context
+        [NSGraphicsContext restoreGraphicsState];
+        CGStyleRelease(style);
+    }
+}
+
+
+
+/*************************************************************************/
+#pragma mark -
+#pragma mark ACCESSOR METHODS
+/*************************************************************************/
+
+- (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