Fixing the effects so they work on multiple monitors where the screen
[ITKit.git] / ITTSWBackgroundView.m
index c978c55..9ee7e7b 100755 (executable)
@@ -1,41 +1,97 @@
-//
-//  ITGrayRoundedView.m
-//  ITKit
-//
-//  Created by Matt L. Judy on Wed Jan 22 2003.
-//  Copyright (c) 2003 NibFile.com. All rights reserved.
-//
+#import "ITTSWBackgroundView.h"
 
 
-#import "ITGrayRoundedView.h"
 
 
+#define RADIUS 24.0
 
 
-@implementation ITGrayRoundedView
 
 
-- (void)drawRect:(NSRect)theRect
+@interface ITTSWBackgroundView (Private)
+@end
+
+
+@implementation ITTSWBackgroundView
+
+
+- (id)initWithFrame:(NSRect)frameRect
 {
 {
-    NSBezierPath *path = [NSBezierPath bezierPath];
-    float vh = NSHeight(theRect);
-    float vw = NSWidth(theRect);
-    [path moveToPoint:NSMakePoint( 0.0, (vh - 24.0) )];          //  first point
-    [path curveToPoint:NSMakePoint( 24.0, vh )
-         controlPoint1:NSMakePoint( 0.0, (vh - 11.0) )
-         controlPoint2:NSMakePoint( 11.0, vh )];                 //  top-left curve
-    [path lineToPoint:NSMakePoint( (vw - 24.0), vh )];    //  top line
-    [path curveToPoint:NSMakePoint( vw, (vh - 24.0) )
-         controlPoint1:NSMakePoint( (vw - 11.0), vh )
-         controlPoint2:NSMakePoint( vw, (vh - 11.0) )];   //  top-right curve
-    [path lineToPoint:NSMakePoint( vw, 24.0 )];           //  right line
-    [path curveToPoint:NSMakePoint( (vw - 24.0), 0.0 )
-         controlPoint1:NSMakePoint( vw, 11.0 )
-         controlPoint2:NSMakePoint( (vw - 11.0), 0.0 )];  //  bottom-right curve
-    [path lineToPoint:NSMakePoint( 24.0, 0.0 )];          //  bottom line
-    [path curveToPoint:NSMakePoint( 0.0, 24.0 )
-         controlPoint1:NSMakePoint( 11.0, 0.0 )
-         controlPoint2:NSMakePoint( 0.0, 11.0 )];         //  bottom-left curve
-    [path closePath];                                                                    //  left line
-
-    [[NSColor colorWithCalibratedWhite:0.0 alpha:0.15] set];
-    [path fill];
+    if ( (self = [super initWithFrame:frameRect]) ) {
+        _path  = [[NSBezierPath bezierPath] retain];
+        _color = [[NSColor blueColor] retain];
+        _mode  = ITTSWBackgroundApple;
+    }
+    
+    return self;
+}
+
+- (void)drawRect:(NSRect)rect
+{
+    float vh     = NSHeight(rect);
+    float vw     = NSWidth(rect);
+    float indent = 0.0;
+    
+    if ( (_mode == ITTSWBackgroundReadable) || (_mode == ITTSWBackgroundColored) ) {
+        indent = 2.0;
+    }
+    
+    NSPoint pointA = NSMakePoint( ((vw - RADIUS) - indent) , (vh - indent)            );
+    NSPoint pointB = NSMakePoint( (RADIUS + indent)        , (vh - indent)            );
+    NSPoint pointD = NSMakePoint( indent                   , (RADIUS + indent)        );
+    NSPoint pointF = NSMakePoint( ((vw - RADIUS) - indent) , indent                   );
+    NSPoint pointH = NSMakePoint( (vw - indent)            , ((vh - RADIUS) - indent) );
+    
+    NSPoint ctrBC  = NSMakePoint( (RADIUS + indent)        , ((vh - RADIUS) - indent) );
+    NSPoint ctrDE  = NSMakePoint( (RADIUS + indent)        , (RADIUS + indent)        );
+    NSPoint ctrFG  = NSMakePoint( ((vw - RADIUS) - indent) , (RADIUS + indent)        );
+    NSPoint ctrHA  = NSMakePoint( ((vw - RADIUS) - indent) , ((vh - RADIUS) - indent) );
+    
+    /*
+     *        D                    E
+     *      +------------------------+
+     *    C | * ctrCD        ctrEF * | F
+     *      |                        |
+     *    B | * ctrAB        ctrGH * | G
+     *      +------------------------+
+     *        A                    H
+     */
+    
+    [_path removeAllPoints];
+    
+    [_path moveToPoint:pointA];                         //  first point
+    [_path lineToPoint:pointB];                         //  top line
+    [_path appendBezierPathWithArcWithCenter:ctrBC      //  top-left curve
+                                      radius:RADIUS
+                                  startAngle:90.0
+                                    endAngle:180.0];
+    [_path lineToPoint:pointD];                         //  left line
+    [_path appendBezierPathWithArcWithCenter:ctrDE      //  bottom-left curve
+                                      radius:RADIUS
+                                  startAngle:180.0
+                                    endAngle:270.0];
+    [_path lineToPoint:pointF];                         //  top line
+    [_path appendBezierPathWithArcWithCenter:ctrFG      //  top-right curve
+                                      radius:RADIUS
+                                  startAngle:270.0
+                                    endAngle:0.0];
+    [_path lineToPoint:pointH];                         //  right line
+    [_path appendBezierPathWithArcWithCenter:ctrHA      //  bottom-right curve
+                                      radius:RADIUS
+                                  startAngle:0.0
+                                    endAngle:90.0];
+                                    
+    if ( _mode == ITTSWBackgroundApple ) {
+        [[NSColor colorWithCalibratedWhite:0.0 alpha:0.15] set];
+    } else if ( _mode == ITTSWBackgroundReadable ) {
+        [[NSColor colorWithCalibratedWhite:0.15 alpha:0.70] set];
+    } else if ( _mode == ITTSWBackgroundColored ) {
+        [_color set];
+    }
+    
+    [_path fill];
+
+    if ( (_mode == ITTSWBackgroundReadable) || (_mode == ITTSWBackgroundColored) ) {
+        [[NSColor colorWithCalibratedWhite:0.90 alpha:1.00] set];
+        [_path setLineWidth:3.0];
+        [_path stroke];
+    }
 }
 
 - (BOOL)isOpaque
 }
 
 - (BOOL)isOpaque
     return NO;
 }
 
     return NO;
 }
 
+- (ITTSWBackgroundMode)backgroundMode
+{
+    return _mode;
+}
+
+- (void)setBackgroundMode:(ITTSWBackgroundMode)newMode
+{
+    _mode = newMode;
+    [self setNeedsDisplay:YES];
+}
+
+- (NSColor *)backgroundColor
+{
+    return _color;
+}
+
+- (void)setBackgroundColor:(NSColor *)newColor
+{
+    [_color autorelease];
+    _color = [newColor copy];
+    [self setNeedsDisplay:YES];
+}
+
+
 @end
 @end