Skip to content
Snippets Groups Projects
Commit e497fd30 authored by George Nachman's avatar George Nachman
Browse files

Get rid of the ugly gradients used with colored tabs. Draw a light outline...

Get rid of the ugly gradients used with colored tabs. Draw a light outline around the selected tab if any tab has a color. Issue 5799.
parent 4eefc2a3
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -66,6 +66,7 @@
 
// drawing
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView;
- (void)drawPostHocDecorationsOnSelectedCell;
 
// drag support
- (NSImage *)dragImage;
Loading
Loading
Loading
Loading
@@ -379,6 +379,10 @@ static NSRect PSMConvertAccessibilityFrameToScreen(NSView *view, NSRect frame) {
[[[self psmTabControlView] style] drawTabCell:self highlightAmount:[self highlightAmount]];
}
 
- (void)drawPostHocDecorationsOnSelectedCell {
[[[self psmTabControlView] style] drawPostHocDecorationsOnSelectedCell:self];
}
- (CGFloat)highlightAmount {
NSTimeInterval timeSinceChange = [NSDate timeIntervalSinceReferenceDate] - _highlightChangeTime;
CGFloat amount = self.highlighted ? 1 : 0;
Loading
Loading
Loading
Loading
@@ -54,6 +54,8 @@ Protocol to be observed by all style delegate objects. These objects handle the
// Should light-tinted controls be used?
- (BOOL)useLightControls;
 
- (void)drawPostHocDecorationsOnSelectedCell:(PSMTabBarCell *)cell;
@end
 
@interface PSMTabBarControl (StyleAccessors)
Loading
Loading
Loading
Loading
@@ -361,7 +361,13 @@
textColor = [NSColor whiteColor];
}
} else {
textColor = [self textColorDefaultSelected:NO];
if (cell.tabColor && [self tabColorBrightness:cell] > 0.5) {
// This is hard to read when the app is inactive and there's a dark
// theme and dark themes give windows dark backgrounds by default.
textColor = [NSColor colorWithWhite:0.4 alpha:1];
} else {
textColor = [self textColorDefaultSelected:NO];
}
}
return textColor;
}
Loading
Loading
@@ -456,18 +462,11 @@
 
if (tabColor) {
// Alpha the non-key window's tab colors a bit to make it clearer which window is key.
CGFloat alpha = [_tabBar.window isKeyWindow] ? 0.8 : 0.6;
CGFloat alpha = [_tabBar.window isKeyWindow] ? 1.0 : 0.6;
// Alpha the inactive tab's colors a bit to make it clear which tab is active.
if (selected) {
[[tabColor colorWithAlphaComponent:alpha] set];
NSRectFillUsingOperation(cellFrame, NSCompositeSourceOver);
} else {
NSColor *startingColor = [tabColor colorWithAlphaComponent:alpha - 0.2];
NSColor *endingColor = [tabColor colorWithAlphaComponent:0];
NSGradient *gradient = [[[NSGradient alloc] initWithStartingColor:startingColor endingColor:endingColor] autorelease];
[gradient drawInRect:cellFrame angle:-90];
}
[[tabColor colorWithAlphaComponent:alpha] set];
NSRectFillUsingOperation(cellFrame, NSCompositeSourceOver);
}
 
if (horizontal) {
Loading
Loading
@@ -531,6 +530,45 @@
[self drawInteriorWithTabCell:cell inView:[cell controlView] highlightAmount:highlightAmount];
}
 
static CGFloat PerceivedBrightness(CGFloat r, CGFloat g, CGFloat b) {
static const double kRedComponentBrightness = 0.30;
static const double kGreenComponentBrightness = 0.59;
static const double kBlueComponentBrightness = 0.11;
return (kRedComponentBrightness * r +
kGreenComponentBrightness * g +
kBlueComponentBrightness * b);
}
- (CGFloat)tabColorBrightness:(PSMTabBarCell *)cell {
NSColor *tabColor = cell.tabColor ?: [self backgroundColorSelected:cell.state == NSOnState highlightAmount:0];
NSColor *safeColor = [tabColor colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
CGFloat brightness = PerceivedBrightness([safeColor redComponent],
[safeColor greenComponent],
[safeColor blueComponent]);
return brightness;
}
- (void)drawPostHocDecorationsOnSelectedCell:(PSMTabBarCell *)cell {
const BOOL anyTabHasColor = [_tabBar.cells indexOfObjectPassingTest:^BOOL(PSMTabBarCell * _Nonnull cell, NSUInteger idx, BOOL * _Nonnull stop) {
return cell.tabColor != nil;
}] != NSNotFound;
if (anyTabHasColor) {
const CGFloat brightness = [self tabColorBrightness:cell];
[[NSColor colorWithWhite:MIN(1, brightness + 0.5) alpha:1] set];
NSFrameRect(cell.frame);
if (brightness > 0.6) {
NSRect rect = NSInsetRect(cell.frame, 1, 1);
rect.origin.x += 0.25;
rect.origin.y += 0.25;
rect.size.width -= 0.5;
rect.size.height -= 0.5;
NSBezierPath *path = [NSBezierPath bezierPathWithRect:rect];
[path setLineWidth:0.5];
[[NSColor grayColor] set];
[path stroke];
}
}
}
 
- (void)drawInteriorWithTabCell:(PSMTabBarCell *)cell
inView:(NSView*)controlView
Loading
Loading
@@ -780,6 +818,11 @@
}
}
}
for (PSMTabBarCell *cell in [bar cells]) {
if (![cell isInOverflowMenu] && NSIntersectsRect([cell frame], rect) && cell.state == NSOnState) {
[cell drawPostHocDecorationsOnSelectedCell];
}
}
}
 
#pragma mark - Archiving
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment