From baa1593d4bd84b2eebc41821d5ff2b70013371bf Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 15 Feb 2015 02:59:14 +0100 Subject: Add basic color highlighting in favorites list --- Source/SPFavoriteTextFieldCell.m | 45 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'Source/SPFavoriteTextFieldCell.m') diff --git a/Source/SPFavoriteTextFieldCell.m b/Source/SPFavoriteTextFieldCell.m index 41511c8c..c5ec9150 100644 --- a/Source/SPFavoriteTextFieldCell.m +++ b/Source/SPFavoriteTextFieldCell.m @@ -29,6 +29,9 @@ // More info at #import "SPFavoriteTextFieldCell.h" +#import "SPOSInfo.h" + +extern BOOL isOSAtLeast10_10_0(void); @implementation SPFavoriteTextFieldCell @@ -46,6 +49,7 @@ SPFavoriteTextFieldCell *cell = (SPFavoriteTextFieldCell *)[super copyWithZone:zone]; cell->drawsDividerUnderCell = drawsDividerUnderCell; + cell->labelColor = nil; //TODO copying the color sometimes causes a drawing bug return cell; } @@ -68,8 +72,37 @@ drawsDividerUnderCell = drawsDivider; } +@synthesize labelColor; + #pragma mark - +- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView +{ + if([self labelColor]) { + CGFloat round = (cellFrame.size.height/2); + NSBezierPath *bg = [NSBezierPath bezierPathWithRoundedRect:cellFrame xRadius:round yRadius:round]; + + if(isOSAtLeast10_10_0()) { + CGFloat h,s,b,a; + [[self labelColor] getHue:&h saturation:&s brightness:&b alpha:&a]; + + [[NSColor colorWithCalibratedHue:h saturation:s*1.21 brightness:b*1.1 alpha:a] set]; + [bg fill]; + } + else { + NSGradient * gradient = [[NSGradient alloc] initWithColorsAndLocations: + [[self labelColor] highlightWithLevel:0.33], 0.0, + [self labelColor], 0.5, + [[self labelColor] shadowWithLevel:0.15], 1.0, nil]; + [gradient drawInBezierPath:bg angle:90.0]; + [gradient release]; + } + } + + [super drawWithFrame:cellFrame inView:controlView]; +} + + /** * Draws the actual cell, with a divider if appropriate. */ @@ -110,4 +143,16 @@ } } +- (void)dealloc +{ + [self setLabelColor:nil]; + + [super dealloc]; +} + @end + +BOOL isOSAtLeast10_10_0() { + const BOOL value = [SPOSInfo isOSVersionAtLeastMajor:10 minor:10 patch:0]; + return value; +} -- cgit v1.2.3 From 3d18994b788dc9563bba804e2eec56cd035bae09 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 15 Feb 2015 03:15:28 +0100 Subject: Fix compiler compatibility issue with older Xcode versions --- Source/SPFavoriteTextFieldCell.m | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'Source/SPFavoriteTextFieldCell.m') diff --git a/Source/SPFavoriteTextFieldCell.m b/Source/SPFavoriteTextFieldCell.m index c5ec9150..00c05da1 100644 --- a/Source/SPFavoriteTextFieldCell.m +++ b/Source/SPFavoriteTextFieldCell.m @@ -78,22 +78,22 @@ extern BOOL isOSAtLeast10_10_0(void); - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView { - if([self labelColor]) { + if(labelColor) { CGFloat round = (cellFrame.size.height/2); NSBezierPath *bg = [NSBezierPath bezierPathWithRoundedRect:cellFrame xRadius:round yRadius:round]; if(isOSAtLeast10_10_0()) { CGFloat h,s,b,a; - [[self labelColor] getHue:&h saturation:&s brightness:&b alpha:&a]; + [labelColor getHue:&h saturation:&s brightness:&b alpha:&a]; [[NSColor colorWithCalibratedHue:h saturation:s*1.21 brightness:b*1.1 alpha:a] set]; [bg fill]; } else { NSGradient * gradient = [[NSGradient alloc] initWithColorsAndLocations: - [[self labelColor] highlightWithLevel:0.33], 0.0, - [self labelColor], 0.5, - [[self labelColor] shadowWithLevel:0.15], 1.0, nil]; + [labelColor highlightWithLevel:0.33], 0.0, + labelColor, 0.5, + [labelColor shadowWithLevel:0.15], 1.0, nil]; [gradient drawInBezierPath:bg angle:90.0]; [gradient release]; } -- cgit v1.2.3 From 2fda43e6a54c0c7532d80b9f3f86987ceb772342 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 15 Feb 2015 22:05:37 +0100 Subject: Refined the look of $(see last commit) on systems < 10.10 a bit --- Source/SPFavoriteTextFieldCell.m | 42 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'Source/SPFavoriteTextFieldCell.m') diff --git a/Source/SPFavoriteTextFieldCell.m b/Source/SPFavoriteTextFieldCell.m index 00c05da1..cf9f6a05 100644 --- a/Source/SPFavoriteTextFieldCell.m +++ b/Source/SPFavoriteTextFieldCell.m @@ -90,12 +90,54 @@ extern BOOL isOSAtLeast10_10_0(void); [bg fill]; } else { + // Draw main background gradient NSGradient * gradient = [[NSGradient alloc] initWithColorsAndLocations: [labelColor highlightWithLevel:0.33], 0.0, labelColor, 0.5, [labelColor shadowWithLevel:0.15], 1.0, nil]; [gradient drawInBezierPath:bg angle:90.0]; [gradient release]; + + //replace the shadow color of the highlighted item (the default is dark blue) + if([self isHighlighted]) { + NSMutableAttributedString *mas = [[self attributedStringValue] mutableCopy]; + NSShadow *strShadow = [mas attribute:NSShadowAttributeName atIndex:0 effectiveRange:NULL]; + if(strShadow) { + [strShadow setShadowColor:[labelColor shadowWithLevel:0.4]]; + [self setAttributedStringValue:mas]; + } + [mas release]; + } + + // Add a little border at the top half (technically this is an inner shadow) + CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort]; + + NSShadow* shadow = [[NSShadow alloc] init]; + [shadow setShadowColor:labelColor]; + [shadow setShadowOffset: NSMakeSize(0.1, -1.2)]; + [shadow setShadowBlurRadius: 1]; + + [NSGraphicsContext saveGraphicsState]; + NSRectClip([bg bounds]); + CGContextSetShadowWithColor(context, CGSizeZero, 0, NULL); + + CGContextSetAlpha(context, [[shadow shadowColor] alphaComponent]); + CGContextBeginTransparencyLayer(context, NULL); + { + [shadow set]; + + CGContextSetBlendMode(context, kCGBlendModeSourceOut); + CGContextBeginTransparencyLayer(context, NULL); + + [[shadow shadowColor] setFill]; + [bg fill]; + + CGContextEndTransparencyLayer(context); + } + CGContextEndTransparencyLayer(context); + [NSGraphicsContext restoreGraphicsState]; + + [shadow release]; } } -- cgit v1.2.3 From 5f3c003919903c597b2d6aeb7fcc064b0d6d9ef3 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 19 Feb 2015 18:11:59 +0100 Subject: Fix a bug that could cause items in the favorite list to be color-labeled when they don't have a label assigned --- Source/SPFavoriteTextFieldCell.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/SPFavoriteTextFieldCell.m') diff --git a/Source/SPFavoriteTextFieldCell.m b/Source/SPFavoriteTextFieldCell.m index cf9f6a05..5eb6c103 100644 --- a/Source/SPFavoriteTextFieldCell.m +++ b/Source/SPFavoriteTextFieldCell.m @@ -49,7 +49,7 @@ extern BOOL isOSAtLeast10_10_0(void); SPFavoriteTextFieldCell *cell = (SPFavoriteTextFieldCell *)[super copyWithZone:zone]; cell->drawsDividerUnderCell = drawsDividerUnderCell; - cell->labelColor = nil; //TODO copying the color sometimes causes a drawing bug + cell->labelColor = [labelColor copyWithZone:zone]; return cell; } -- cgit v1.2.3