aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPFavoriteTextFieldCell.m
diff options
context:
space:
mode:
authorAbhi Beckert <abhi@Twist-of-Lemon-2.local>2015-05-16 08:06:06 +1000
committerAbhi Beckert <abhi@Twist-of-Lemon-2.local>2015-05-16 08:06:06 +1000
commit57a6f6c73bdaa202164645370d37fcbe5d14a092 (patch)
treedd30aa6156064f1d4c0e10ea87059625470fc2f9 /Source/SPFavoriteTextFieldCell.m
parentb5e972f4504043dfb9c358e272e93fb59ae2127f (diff)
parent0f0c43eb74408b6a65a42e2c6fd46f4142ef8e3f (diff)
downloadsequelpro-57a6f6c73bdaa202164645370d37fcbe5d14a092.tar.gz
sequelpro-57a6f6c73bdaa202164645370d37fcbe5d14a092.tar.bz2
sequelpro-57a6f6c73bdaa202164645370d37fcbe5d14a092.zip
Merge remote-tracking branch 'sequelpro/master'
Diffstat (limited to 'Source/SPFavoriteTextFieldCell.m')
-rw-r--r--Source/SPFavoriteTextFieldCell.m87
1 files changed, 87 insertions, 0 deletions
diff --git a/Source/SPFavoriteTextFieldCell.m b/Source/SPFavoriteTextFieldCell.m
index 41511c8c..5eb6c103 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 = [labelColor copyWithZone:zone];
return cell;
}
@@ -68,8 +72,79 @@
drawsDividerUnderCell = drawsDivider;
}
+@synthesize labelColor;
+
#pragma mark -
+- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
+{
+ 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;
+ [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 {
+ // 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];
+ }
+ }
+
+ [super drawWithFrame:cellFrame inView:controlView];
+}
+
+
/**
* Draws the actual cell, with a divider if appropriate.
*/
@@ -110,4 +185,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;
+}