Add isHighlighted method

This commit is contained in:
Sebastien Bramille 2017-11-13 11:16:25 +00:00 committed by Cheng Zhao
parent 6a1cfafbd8
commit 9f89bd8d8e

View file

@ -87,12 +87,10 @@ const CGFloat kVerticalTitleMargin = 2;
// | icon | title | // | icon | title |
/// ---------------- /// ----------------
BOOL highlight = [self shouldHighlight];
BOOL highlightContent = highlight | [self isDarkMode];
CGFloat thickness = [[statusItem_ statusBar] thickness]; CGFloat thickness = [[statusItem_ statusBar] thickness];
// Draw the system bar background. // Draw the system bar background.
[statusItem_ drawStatusBarBackgroundInRect:self.bounds withHighlight:highlight]; [statusItem_ drawStatusBarBackgroundInRect:self.bounds withHighlight:[self shouldHighlight]];
// Determine which image to use. // Determine which image to use.
NSImage* image = image_.get(); NSImage* image = image_.get();
@ -104,7 +102,7 @@ const CGFloat kVerticalTitleMargin = 2;
if ([image isTemplate] == YES) { if ([image isTemplate] == YES) {
NSImage* imageWithColor = [[image copy] autorelease]; NSImage* imageWithColor = [[image copy] autorelease];
[imageWithColor lockFocus]; [imageWithColor lockFocus];
[[self colorWithHighlight: highlightContent] set]; [[self colorWithHighlight: [self isHighlighted]] set];
CGRect imageBounds = CGRectMake(0,0, image.size.width, image.size.height); CGRect imageBounds = CGRectMake(0,0, image.size.width, image.size.height);
NSRectFillUsingOperation(imageBounds, NSCompositeSourceAtop); NSRectFillUsingOperation(imageBounds, NSCompositeSourceAtop);
[imageWithColor unlockFocus]; [imageWithColor unlockFocus];
@ -136,6 +134,12 @@ const CGFloat kVerticalTitleMargin = 2;
return mode && [mode isEqualToString:@"Dark"]; return mode && [mode isEqualToString:@"Dark"];
} }
- (BOOL)isHighlighted {
BOOL highlight = [self shouldHighlight];
return highlight | [self isDarkMode];
}
// The width of the full status item. // The width of the full status item.
- (CGFloat)fullWidth { - (CGFloat)fullWidth {
if (title_) if (title_)
@ -226,9 +230,7 @@ const CGFloat kVerticalTitleMargin = 2;
fullTitle = [fullTitle stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceCharacterSet]; fullTitle = [fullTitle stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceCharacterSet];
NSString * title = fullTitle; NSString * title = fullTitle;
BOOL highlight = [self shouldHighlight]; NSDictionary* attributes = [self titleAttributesWithHighlight:[self isHighlighted]];
BOOL highlightContent = highlight | [self isDarkMode];
NSDictionary* attributes = [self titleAttributesWithHighlight:highlightContent];
NSMutableAttributedString * attributedTitle = [NSMutableAttributedString.alloc initWithString:title attributes:attributes]; NSMutableAttributedString * attributedTitle = [NSMutableAttributedString.alloc initWithString:title attributes:attributes];
if (ANSI_) { if (ANSI_) {
attributedTitle = [title attributedStringParsingANSICodes]; attributedTitle = [title attributedStringParsingANSICodes];
@ -240,7 +242,7 @@ const CGFloat kVerticalTitleMargin = 2;
//NSForegroundColorAttributeName:[self colorWithHighlight: highlight] //NSForegroundColorAttributeName:[self colorWithHighlight: highlight]
[attributedTitle addAttributes:attributes range:NSMakeRange(0, attributedTitle.length)]; [attributedTitle addAttributes:attributes range:NSMakeRange(0, attributedTitle.length)];
[attributedTitle addAttribute:NSForegroundColorAttributeName value:[self colorWithHighlight: highlight] range:NSMakeRange(0, attributedTitle.length)]; [attributedTitle addAttribute:NSForegroundColorAttributeName value:[self colorWithHighlight: [self isDarkMode]] range:NSMakeRange(0, attributedTitle.length)];
return attributedTitle; return attributedTitle;
} }