diff options
author | Max <post@wickenrode.com> | 2015-02-15 02:59:14 +0100 |
---|---|---|
committer | Max <post@wickenrode.com> | 2015-02-15 02:59:14 +0100 |
commit | baa1593d4bd84b2eebc41821d5ff2b70013371bf (patch) | |
tree | 33b06aed0f180784e5b827c40013af9cbb3744ea /Source/SPFavoriteTextFieldCell.m | |
parent | 085b381858dcd3cda5c0b00527d3b7a77641345a (diff) | |
download | sequelpro-baa1593d4bd84b2eebc41821d5ff2b70013371bf.tar.gz sequelpro-baa1593d4bd84b2eebc41821d5ff2b70013371bf.tar.bz2 sequelpro-baa1593d4bd84b2eebc41821d5ff2b70013371bf.zip |
Add basic color highlighting in favorites list
Diffstat (limited to 'Source/SPFavoriteTextFieldCell.m')
-rw-r--r-- | Source/SPFavoriteTextFieldCell.m | 45 |
1 files changed, 45 insertions, 0 deletions
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 <https://github.com/sequelpro/sequelpro> #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; +} |