From 806cb44b4ba9863b4f32caeb0e95b6b7301053db Mon Sep 17 00:00:00 2001 From: Allan Odgaard Date: Sun, 19 Aug 2012 01:31:02 +0200 Subject: [PATCH] Support loading @2x image assets Untested, but we now use imageForResource: (10.7) instead of constructing an absolute file path, so the system should take care of finding @2x assets. --- Frameworks/OakAppKit/src/NSImage Additions.mm | 30 +------------------ 1 file changed, 1 insertion(+), 29 deletions(-) diff --git a/Frameworks/OakAppKit/src/NSImage Additions.mm b/Frameworks/OakAppKit/src/NSImage Additions.mm index 0ba066da..b28a2b2e 100644 --- a/Frameworks/OakAppKit/src/NSImage Additions.mm +++ b/Frameworks/OakAppKit/src/NSImage Additions.mm @@ -3,35 +3,7 @@ @implementation NSImage (ImageFromBundle) + (NSImage*)imageNamed:(NSString*)aName inSameBundleAsClass:(id)aClass { - if(!aName) - return nil; - - NSBundle* bundle = [NSBundle bundleForClass:aClass]; - NSString* name = [NSString stringWithFormat:@"%@.%@", [bundle bundleIdentifier], aName]; - - static NSMutableDictionary* cache = [NSMutableDictionary new]; - if(NSImage* res = [cache objectForKey:name]) - return res; - - NSString* resourcePath = bundle.resourcePath; - for(NSString* resource in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:resourcePath error:nil]) - { - static NSSet* imageTypes = [[NSSet alloc] initWithArray:[NSImage imageFileTypes]]; - if([aName isEqualToString:[resource stringByDeletingPathExtension]] && [imageTypes containsObject:[resource pathExtension]]) - { - NSString* imagePath = [resourcePath stringByAppendingPathComponent:resource]; - if(NSImage* image = [[[NSImage alloc] initWithContentsOfFile:imagePath] autorelease]) - { - [cache setObject:image forKey:name]; - return image; - } - } - } - - NSBeep(); - NSLog(@"*** could not find image named ‘%@’ in %@", aName, resourcePath); - - return nil; + return [[NSBundle bundleForClass:aClass] imageForResource:aName]; } + (NSImage*)imageWithCGImage:(CGImageRef)cgImage