2022-01-20 18:27:56 +00:00
|
|
|
// This file Copyright © 2011-2022 Transmission authors and contributors.
|
|
|
|
// It may be used under the MIT (SPDX: MIT) license.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2011-10-22 20:45:20 +00:00
|
|
|
|
|
|
|
#import "NSImageAdditions.h"
|
|
|
|
|
|
|
|
@implementation NSImage (NSImageAdditions)
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSImage*)imageWithColor:(NSColor*)color
|
2011-10-22 20:45:20 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSImage* coloredImage = [self copy];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-10-22 20:45:20 +00:00
|
|
|
[coloredImage lockFocus];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-10-22 20:45:20 +00:00
|
|
|
[color set];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSSize const size = coloredImage.size;
|
2021-10-31 15:18:27 +00:00
|
|
|
NSRectFillUsingOperation(NSMakeRect(0.0, 0.0, size.width, size.height), NSCompositingOperationSourceAtop);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-10-22 20:45:20 +00:00
|
|
|
[coloredImage unlockFocus];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2017-07-29 16:14:22 +00:00
|
|
|
return coloredImage;
|
2011-10-22 20:45:20 +00:00
|
|
|
}
|
|
|
|
|
2021-12-05 23:42:54 +00:00
|
|
|
+ (NSImage*)systemSymbol:(NSString*)symbolName withFallback:(NSString*)fallbackName
|
|
|
|
{
|
|
|
|
if (@available(macOS 11.0, *))
|
|
|
|
{
|
|
|
|
return [NSImage imageWithSystemSymbolName:symbolName accessibilityDescription:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [NSImage imageNamed:fallbackName];
|
|
|
|
}
|
|
|
|
|
2011-10-22 20:45:20 +00:00
|
|
|
@end
|