Commits

Jason Harris committed 3f0dc7c

- Move RadialGradiantBox to its own file since I will reuse it in a few places.
- switch to viewWillDraw method rather than using drawInRect method.
- Start to expose some basic settings of the RadialGradiantBox.

  • Participants
  • Parent commits eb9e195

Comments (0)

Files changed (5)

File Classes/BackingPane/BackingPaneController.h

 
 @end
 
-// This box draws itself with a radial gradiant centered on the centering Object
-@interface RadialGradiantBox : NSBox
-{
-	IBOutlet NSView*	centeringObject;
-}
-
-@end

File Classes/BackingPane/BackingPaneController.m

 @end
 
 
-@implementation RadialGradiantBox : NSBox
-{
-}
 
-// If anyone knows how to implement this better please tell me...
-- (void) drawRect:(NSRect)dirtyRect
-{
-	CIColor* black   = [CIColor colorWithRed:  0.0/255.0 green:  0.0/255.0 blue:  0.0/255.0 alpha:1.0];
-	CIColor* color0  = [CIColor colorWithRed: 77.0/255.0 green: 78.0/255.0 blue: 87.0/255.0 alpha:0.8];
-	CIColor* color1  = [CIColor colorWithRed: 39.0/255.0 green: 40.0/255.0 blue: 52.0/255.0 alpha:0.5];
-	NSRect buttonBoxFrame = [centeringObject bounds];
-	NSRect other = [centeringObject convertRect:buttonBoxFrame toView:self];
-	CIVector* center = [CIVector vectorWithX:NSMidX(other) Y:NSMidY(other)];
-	NSNumber* radius = [NSNumber numberWithFloat:450.0];
-	
-	CIFilter* gradiantFilter = [CIFilter filterWithName:@"CIGaussianGradient"];
-	[gradiantFilter setValue:color0 forKey:@"inputColor0"];
-	[gradiantFilter setValue:color1 forKey:@"inputColor1"];
-	[gradiantFilter setValue:center forKey:@"inputCenter"];
-	[gradiantFilter setValue:radius forKey:@"inputRadius"];
-
-	
-	CIFilter* constantFilter = [CIFilter filterWithName:@"CIConstantColorGenerator"];
-	[constantFilter setValue:black forKey:@"inputColor"];
-
-	NSArray* gradiantAttributes   = [NSArray arrayWithObject:gradiantFilter];
-	NSArray* backgroundAttributes = [NSArray arrayWithObject:constantFilter];
-	[[self layer] setFilters: gradiantAttributes];
-	[[self layer] setBackgroundFilters:backgroundAttributes];
-}
-
-
-@end

File Classes/UtilityClasses/RadialGradiantBox/RadialGradiantBox.h

+//
+//  RadialGradiantBox.h
+//  MacHg
+//
+//  Created by Jason Harris on 6/1/10.
+//  Copyright 2010 Jason F Harris. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+@class CIFilter;
+
+
+// This box draws itself with a radial gradiant centered on the centering Object
+@interface RadialGradiantBox : NSBox
+{
+	IBOutlet NSView*	centeringObject;
+	NSArray*			foregroundFilters_;
+	NSArray*			backgroundFilters_;
+	NSPoint				offsetFromCenter_;
+	CIVector*			lastCenterForGradiant_;
+	NSNumber*			radius_;
+}
+
+- (void) setRadius:(NSNumber*)r;
+- (void) setOffsetFromCenter:(NSPoint)offset;
+@end

File Classes/UtilityClasses/RadialGradiantBox/RadialGradiantBox.m

+//
+//  RadialGradiantBox.m
+//  MacHg
+//
+//  Created by Jason Harris on 6/1/10.
+//  Copyright 2010 Jason F Harris. All rights reserved.
+//
+
+#import "RadialGradiantBox.h"
+#import <QuartzCore/CIFilter.h>
+
+@interface RadialGradiantBox (PrivateAPI)
+
+- (void) recomputeFilters;
+@end
+
+
+
+// -----------------------------------------------------------------------------------------------------------------------------------------
+// MARK: -
+// MARK:  RadialGradiantBox
+// -----------------------------------------------------------------------------------------------------------------------------------------
+// MARK: -
+
+@implementation RadialGradiantBox : NSBox
+
+
+
+
+
+// -----------------------------------------------------------------------------------------------------------------------------------------
+// MARK: -
+// MARK:  Initilization
+// -----------------------------------------------------------------------------------------------------------------------------------------
+
+- (id) init
+{
+	self = [super init];
+	if (self)
+	{
+		offsetFromCenter_ = NSMakePoint(0.0, 0.0);
+		radius_ = [NSNumber numberWithFloat:450.0];
+		foregroundFilters_ = nil;
+		backgroundFilters_ = nil;
+		lastCenterForGradiant_ = nil;
+	}
+	return self;
+}
+
+
+
+
+
+// -----------------------------------------------------------------------------------------------------------------------------------------
+// MARK: -
+// MARK:  Filters
+// -----------------------------------------------------------------------------------------------------------------------------------------
+
+- (CIVector*) recomputePosition
+{
+	NSRect buttonBoxFrame = [centeringObject bounds];
+	NSRect other = [centeringObject convertRect:buttonBoxFrame toView:self];
+	CIVector* center = [CIVector vectorWithX:NSMidX(other)+offsetFromCenter_.x Y:NSMidY(other)+offsetFromCenter_.y];
+	return center;
+}
+																				  
+- (void) recomputeFilters
+{
+	CIColor* black   = [CIColor colorWithRed:  0.0/255.0 green:  0.0/255.0 blue:  0.0/255.0 alpha:1.0];
+	CIColor* color0  = [CIColor colorWithRed: 77.0/255.0 green: 78.0/255.0 blue: 87.0/255.0 alpha:0.8];
+	CIColor* color1  = [CIColor colorWithRed: 39.0/255.0 green: 40.0/255.0 blue: 52.0/255.0 alpha:0.5];
+	CIVector* center = [self recomputePosition];
+	NSNumber* radius = radius_ ? radius_ : [NSNumber numberWithFloat:450.0];
+	
+	CIFilter* gradiantFilter = [CIFilter filterWithName:@"CIGaussianGradient"];
+	[gradiantFilter setValue:color0 forKey:@"inputColor0"];
+	[gradiantFilter setValue:color1 forKey:@"inputColor1"];
+	[gradiantFilter setValue:center forKey:@"inputCenter"];
+	[gradiantFilter setValue:radius forKey:@"inputRadius"];
+	
+	CIFilter* constantFilter = [CIFilter filterWithName:@"CIConstantColorGenerator"];
+	[constantFilter setValue:black forKey:@"inputColor"];
+	
+	foregroundFilters_ = [NSArray arrayWithObject:gradiantFilter];
+	backgroundFilters_ = [NSArray arrayWithObject:constantFilter];
+	
+}
+
+- (void) setRadius:(NSNumber*)r					{ radius_ = r;				  foregroundFilters_ = nil; backgroundFilters_ = nil; }
+- (void) setOffsetFromCenter:(NSPoint)offset	{ offsetFromCenter_ = offset; foregroundFilters_ = nil; backgroundFilters_ = nil; }
+
+
+
+
+
+// -----------------------------------------------------------------------------------------------------------------------------------------
+// MARK: -
+// MARK:  Drawing
+// -----------------------------------------------------------------------------------------------------------------------------------------
+
+- (void) viewWillDraw
+{
+	CIVector* newPosition = [self recomputePosition];
+	if (!foregroundFilters_ || !backgroundFilters_ || !lastCenterForGradiant_ || [lastCenterForGradiant_ isNotEqualTo:newPosition])
+		[self recomputeFilters];
+	[[self layer] setFilters: foregroundFilters_];
+	[[self layer] setBackgroundFilters:backgroundFilters_];
+	
+    [super viewWillDraw];
+} 
+
+
+
+@end

File MacHg.xcodeproj/project.pbxproj

 		96DCD03C10CD430600C843C9 /* LocalMercurial in Copy Files (Mercurial) */ = {isa = PBXBuildFile; fileRef = 96DCCE2710CD430000C843C9 /* LocalMercurial */; };
 		96DD29CA112AE56200A57BD3 /* CollapseSheetController.m in Sources */ = {isa = PBXBuildFile; fileRef = 96DD29C9112AE56200A57BD3 /* CollapseSheetController.m */; };
 		96DD29CD112AE56D00A57BD3 /* CollapseSheet.xib in Resources */ = {isa = PBXBuildFile; fileRef = 96DD29CB112AE56D00A57BD3 /* CollapseSheet.xib */; };
+		96DF426511B48DC700D986FF /* RadialGradiantBox.m in Sources */ = {isa = PBXBuildFile; fileRef = 96DF426411B48DC700D986FF /* RadialGradiantBox.m */; };
 		96F5A4DE11A8185800707404 /* TextButtonCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 96F5A4DD11A8185800707404 /* TextButtonCell.m */; };
 		96F5A4FA11A81B5B00707404 /* DiffTextButtonCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 96F5A4F911A81B5B00707404 /* DiffTextButtonCell.m */; };
 		96F5A70D11A879F100707404 /* LabelTextButtonCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 96F5A70C11A879F100707404 /* LabelTextButtonCell.m */; };
 		96DD29C8112AE56200A57BD3 /* CollapseSheetController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CollapseSheetController.h; sourceTree = "<group>"; };
 		96DD29C9112AE56200A57BD3 /* CollapseSheetController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CollapseSheetController.m; sourceTree = "<group>"; };
 		96DD29CC112AE56D00A57BD3 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/CollapseSheet.xib; sourceTree = SOURCE_ROOT; };
+		96DF426311B48DC700D986FF /* RadialGradiantBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RadialGradiantBox.h; sourceTree = "<group>"; };
+		96DF426411B48DC700D986FF /* RadialGradiantBox.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RadialGradiantBox.m; sourceTree = "<group>"; };
 		96F5A4DC11A8185800707404 /* TextButtonCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextButtonCell.h; sourceTree = "<group>"; };
 		96F5A4DD11A8185800707404 /* TextButtonCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TextButtonCell.m; sourceTree = "<group>"; };
 		96F5A4F811A81B5B00707404 /* DiffTextButtonCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DiffTextButtonCell.h; sourceTree = "<group>"; };
 		9672AC50114B796A00312CE2 /* UtilityClasses */ = {
 			isa = PBXGroup;
 			children = (
+				96DF426211B48DC700D986FF /* RadialGradiantBox */,
 				9606EE15115670FD00968DE8 /* Help Button */,
 				9672ADCA114BD22A00312CE2 /* CommandKeyTextField */,
 				9672AC51114B796A00312CE2 /* ConnectionValidation */,
 			path = CollapseSheet;
 			sourceTree = "<group>";
 		};
+		96DF426211B48DC700D986FF /* RadialGradiantBox */ = {
+			isa = PBXGroup;
+			children = (
+				96DF426311B48DC700D986FF /* RadialGradiantBox.h */,
+				96DF426411B48DC700D986FF /* RadialGradiantBox.m */,
+			);
+			path = RadialGradiantBox;
+			sourceTree = "<group>";
+		};
 		96F5A4DB11A8185800707404 /* TextButtonCell */ = {
 			isa = PBXGroup;
 			children = (
 				96F5A4DE11A8185800707404 /* TextButtonCell.m in Sources */,
 				96F5A4FA11A81B5B00707404 /* DiffTextButtonCell.m in Sources */,
 				96F5A70D11A879F100707404 /* LabelTextButtonCell.m in Sources */,
+				96DF426511B48DC700D986FF /* RadialGradiantBox.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};