Using background color attribute on entries to dispaly colorized images

This commit is contained in:
michael starke
2017-11-10 16:44:17 +01:00
parent a5161190d3
commit 6e73a390bb
6 changed files with 51 additions and 15 deletions

View File

@@ -26,6 +26,24 @@
#import "MPIconHelper.h"
@interface NSImage (MPTintedImage)
@end
@implementation NSImage (MPTintedImage)
- (NSImage *)imageWithTintColor:(NSColor *)tintColor {
/* only tint tempated images! */
if(NO == self.template) {
return self;
}
NSImage *image = [self copy];
[image lockFocus];
[tintColor set];
NSRectFillUsingOperation(NSMakeRect(0, 0, image.size.width, image.size.height), NSCompositingOperationSourceAtop);
[image unlockFocus];
image.template = NO;
return image;
}
@end
@implementation KPKNode (IconImage)
+ (NSSet *)keyPathsForValuesAffectingIconImage {
@@ -36,6 +54,7 @@
});
return [NSSet setWithArray:@[NSStringFromSelector(@selector(iconUUID)),
NSStringFromSelector(@selector(iconId)),
NSStringFromSelector(@selector(backgroundColor)),
expireDateKeyPath
]];
}
@@ -49,6 +68,10 @@
if(self.icon) {
return self.icon.image;
}
if(self.asEntry.backgroundColor) {
return [[MPIconHelper icon:(MPIconType)self.iconId] imageWithTintColor:self.asEntry.backgroundColor];
}
return [MPIconHelper icon:(MPIconType)self.iconId];
}
@end