git.y1.nz

SameBoy

Accurate GB/GBC emulator
download: https://git.y1.nz/archives/sameboy.tar.gz
README | Files | Log | Refs | LICENSE

Cocoa/NSImageNamedDarkSupport.m

      1 #import <AppKit/AppKit.h>
      2 #import <objc/runtime.h>
      3 
      4 @interface NSImageRep(PrivateAPI)
      5 @property(setter=_setAppearanceName:) NSString *_appearanceName;
      6 @end
      7 
      8 static NSImage * (*imageNamed)(Class self, SEL _cmd, NSString *name);
      9 
     10 @implementation NSImage(DarkHooks)
     11 
     12 + (NSImage *)imageNamedWithDark:(NSImageName)name
     13 {
     14     if (@available(macOS 11.0, *)) {
     15         if (![name containsString:@"~solid"]) {
     16             NSImage *solid = [self imageNamed:[name stringByAppendingString:@"~solid"]];
     17             [solid setTemplate:true];
     18             if (solid) return solid;
     19         }
     20     }
     21     NSImage *light = imageNamed(self, _cmd, name);
     22     if (@available(macOS 10.14, *)) {
     23         NSImage *dark = imageNamed(self, _cmd, [name stringByAppendingString:@"~dark"]);
     24         if (!dark) {
     25             return light;
     26         }
     27         NSImage *ret = [[NSImage alloc] initWithSize:light.size];
     28         for (NSImageRep *rep in light.representations) {
     29             [rep _setAppearanceName:NSAppearanceNameAqua];
     30             [ret addRepresentation:rep];
     31         }
     32         for (NSImageRep *rep in dark.representations) {
     33             [rep _setAppearanceName:NSAppearanceNameDarkAqua];
     34             [ret addRepresentation:rep];
     35         }
     36         return ret;
     37     }
     38     return light;
     39 }
     40 
     41 +(void)load
     42 {
     43     if (@available(macOS 10.14, *)) {
     44         imageNamed = (void *)[self methodForSelector:@selector(imageNamed:)];
     45         method_setImplementation(class_getClassMethod(self, @selector(imageNamed:)),
     46                                  [self methodForSelector:@selector(imageNamedWithDark:)]);
     47     }
     48 }
     49 @end

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.