Permalink
Browse files

lazy load all images

  • Loading branch information...
1 parent f011e6a commit ac42856287e5a2703f7d1c0fbd95625386f6d96e @itod committed Jun 28, 2010
@@ -54,6 +54,8 @@
D3DEC239107013A7006B582A /* UMENavigationBar.m in Sources */ = {isa = PBXBuildFile; fileRef = D3DEC237107013A7006B582A /* UMENavigationBar.m */; };
D3DEC242107013DF006B582A /* UMEBarButtonItem.h in Headers */ = {isa = PBXBuildFile; fileRef = D3DEC240107013DF006B582A /* UMEBarButtonItem.h */; settings = {ATTRIBUTES = (Public, ); }; };
D3DEC243107013DF006B582A /* UMENavigationBar.h in Headers */ = {isa = PBXBuildFile; fileRef = D3DEC241107013DF006B582A /* UMENavigationBar.h */; settings = {ATTRIBUTES = (Public, ); }; };
+ D3E20CAB11D850A9006C9532 /* UMEImageCache.h in Headers */ = {isa = PBXBuildFile; fileRef = D3E20CA911D850A9006C9532 /* UMEImageCache.h */; };
+ D3E20CAC11D850A9006C9532 /* UMEImageCache.m in Sources */ = {isa = PBXBuildFile; fileRef = D3E20CAA11D850A9006C9532 /* UMEImageCache.m */; };
D3E571BF109123B900810BCD /* UMEActivityBarButtonItem.m in Sources */ = {isa = PBXBuildFile; fileRef = D3E571BD109123B900810BCD /* UMEActivityBarButtonItem.m */; };
D3E571C1109123F000810BCD /* UMEActivityBarButtonItem.h in Headers */ = {isa = PBXBuildFile; fileRef = D3E571C0109123F000810BCD /* UMEActivityBarButtonItem.h */; settings = {ATTRIBUTES = (Public, ); }; };
D3E571C41091249B00810BCD /* UMEActivityBarButtonItemButton.h in Headers */ = {isa = PBXBuildFile; fileRef = D3E571C21091249B00810BCD /* UMEActivityBarButtonItemButton.h */; };
@@ -247,6 +249,8 @@
D3DEC237107013A7006B582A /* UMENavigationBar.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = UMENavigationBar.m; path = src/UMENavigationBar.m; sourceTree = "<group>"; };
D3DEC240107013DF006B582A /* UMEBarButtonItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UMEBarButtonItem.h; path = include/UMEKit/UMEBarButtonItem.h; sourceTree = "<group>"; };
D3DEC241107013DF006B582A /* UMENavigationBar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UMENavigationBar.h; path = include/UMEKit/UMENavigationBar.h; sourceTree = "<group>"; };
+ D3E20CA911D850A9006C9532 /* UMEImageCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UMEImageCache.h; path = src/UMEImageCache.h; sourceTree = "<group>"; };
+ D3E20CAA11D850A9006C9532 /* UMEImageCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = UMEImageCache.m; path = src/UMEImageCache.m; sourceTree = "<group>"; };
D3E571BD109123B900810BCD /* UMEActivityBarButtonItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = UMEActivityBarButtonItem.m; path = src/UMEActivityBarButtonItem.m; sourceTree = "<group>"; };
D3E571C0109123F000810BCD /* UMEActivityBarButtonItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UMEActivityBarButtonItem.h; path = include/UMEKit/UMEActivityBarButtonItem.h; sourceTree = "<group>"; };
D3E571C21091249B00810BCD /* UMEActivityBarButtonItemButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UMEActivityBarButtonItemButton.h; path = src/UMEActivityBarButtonItemButton.h; sourceTree = "<group>"; };
@@ -481,6 +485,8 @@
D343404C10741E2200C31EFA /* UMEGeometry.h */,
D34341A910743EE500C31EFA /* UMEInterface.h */,
32DBCF5E0370ADEE00C91783 /* UMEKit_Prefix.pch */,
+ D3E20CA911D850A9006C9532 /* UMEImageCache.h */,
+ D3E20CAA11D850A9006C9532 /* UMEImageCache.m */,
D3C3B251108562DA00ED4547 /* Internal */,
);
name = "Other Sources";
@@ -718,6 +724,7 @@
D3EB8C50117A65EE003C4A2E /* UMEToolbar.h in Headers */,
D350D2F1117BB44200A21B6A /* UMEPopoverController.h in Headers */,
D3EA864F117BBA24000988EE /* UMEPopoverView.h in Headers */,
+ D3E20CAB11D850A9006C9532 /* UMEImageCache.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -937,6 +944,7 @@
D3EB8C4E117A65D8003C4A2E /* UMEToolbar.m in Sources */,
D350D2E3117BB25A00A21B6A /* UMEPopoverController.m in Sources */,
D3EA8650117BBA24000988EE /* UMEPopoverView.m in Sources */,
+ D3E20CAC11D850A9006C9532 /* UMEImageCache.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Oops, something went wrong.
View
@@ -0,0 +1,13 @@
+//
+// UMEImageCache.h
+// UMEKit
+//
+// Created by Todd Ditchendorf on 6/27/10.
+// Copyright 2010 Todd Ditchendorf. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+extern NSImage *UMEImageNamed(NSString *name);
+
+#define UMEIMG(name) UMEImageNamed((name))
View
@@ -0,0 +1,28 @@
+//
+// UMEImageCache.m
+// UMEKit
+//
+// Created by Todd Ditchendorf on 6/27/10.
+// Copyright 2010 Todd Ditchendorf. All rights reserved.
+//
+
+#import "UMEImageCache.h"
+#import <UMEKit/UMEToolbar.h>
+
+NSImage *UMEImageNamed(NSString *name) {
+ static NSMutableDictionary *sImageCache = nil;
+
+ if (!sImageCache) {
+ sImageCache = [[NSMutableDictionary alloc] init];
+ }
+
+ NSImage *img = [sImageCache objectForKey:name];
+ if (!img) {
+ NSBundle *b = [NSBundle bundleForClass:[UMEToolbar class]];
+
+ img = [[[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:name]] autorelease];
+ [sImageCache setObject:img forKey:name];
+ }
+
+ return img;
+}
@@ -16,15 +16,14 @@
#import <UMEKit/UMEBarButtonItem.h>
#import <QuartzCore/QuartzCore.h>
#import "UMEFlippedView.h"
+#import "UMEImageCache.h"
#define SIDE_VIEW_PADDING 4
#define LABEL_HEIGHT 20
#define LABEL_OFFSET_Y 12
#define LABEL_FONT_SIZE 16
#define MAX_TITLE_WIDTH_RATIO .5
-static NSImage *sBackgroundImage = nil;
-
@interface UMEBarButtonItem ()
- (void)sizeToFit;
- (void)layout;
@@ -57,14 +56,6 @@ - (void)layout;
@implementation UMENavigationBar
-+ (void)initialize {
- if ([UMENavigationBar class] == self) {
- NSString *path = [[NSBundle bundleForClass:self] pathForImageResource:@"navbar_bg"];
- sBackgroundImage = [[NSImage alloc] initWithContentsOfFile:path];
- }
-}
-
-
- (id)initWithFrame:(NSRect)r {
if (self = [super initWithFrame:r]) {
[self setWantsLayer:YES];
@@ -378,7 +369,7 @@ - (void)viewWillDraw {
- (void)drawRect:(NSRect)dirtyRect {
NSRect bounds = [self bounds];
- NSDrawThreePartImage(bounds, sBackgroundImage, sBackgroundImage, sBackgroundImage, NO, NSCompositeSourceOver, 1, YES);
+ NSDrawThreePartImage(bounds, UMEIMG(@"navbar_bg"), UMEIMG(@"navbar_bg"), UMEIMG(@"navbar_bg"), NO, NSCompositeSourceOver, 1, YES);
}
@synthesize containerView;
View
@@ -13,21 +13,12 @@
// limitations under the License.
#import <UMEKit/UMETabBar.h>
+#import "UMEImageCache.h"
#define TABBAR_HEIGHT 60.0
-static NSImage *sBackgroundImage = nil;
-
@implementation UMETabBar
-+ (void)initialize {
- if ([UMETabBar class] == self) {
- NSString *path = [[NSBundle bundleForClass:self] pathForImageResource:@"tabbar_bg"];
- sBackgroundImage = [[NSImage alloc] initWithContentsOfFile:path];
- }
-}
-
-
- (id)initWithFrame:(NSRect)r {
if (self = [super initWithFrame:r]) {
@@ -48,7 +39,7 @@ - (BOOL)isFlipped {
- (void)drawRect:(NSRect)dirtyRect {
NSRect bounds = [self bounds];
- NSDrawThreePartImage(bounds, sBackgroundImage, sBackgroundImage, sBackgroundImage, NO, NSCompositeSourceOver, 1, YES);
+ NSDrawThreePartImage(bounds, UMEIMG(@"tabbar_bg"), UMEIMG(@"tabbar_bg"), UMEIMG(@"tabbar_bg"), NO, NSCompositeSourceOver, 1, YES);
}
@end
@@ -13,6 +13,7 @@
// limitations under the License.
#import "UMETabBarItemButtonCell.h"
+#import "UMEImageCache.h"
#import <UMEKit/UMETabBarItem.h>
#define MIN_WIDTH 40
@@ -22,12 +23,6 @@
static NSShadow *sTitleShadow = nil;
-static NSImage *sLeftImageHi = nil;
-static NSImage *sCenterImageHi = nil;
-static NSImage *sRightImageHi = nil;
-
-static NSImage *sBackgroundImage = nil;
-
@interface UMETabBarItemButtonCell ()
- (void)commonInit;
@end
@@ -43,14 +38,6 @@ + (void)initialize {
[sTitleShadow setShadowOffset:NSMakeSize(0, 1)];
[sTitleShadow setShadowBlurRadius:0];
- NSBundle *b = [NSBundle bundleForClass:self];
-
- sLeftImageHi = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"tabbar_button_bg_hi_01"]];
- sCenterImageHi = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"tabbar_button_bg_hi_02"]];
- sRightImageHi = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"tabbar_button_bg_hi_03"]];
-
- sBackgroundImage = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"tabbar_bg"]];
-
[pool release];
}
}
@@ -101,13 +88,13 @@ - (void)drawInteriorWithFrame:(NSRect)r inView:(NSView *)cv {
return;
}
- NSDrawThreePartImage(r, sBackgroundImage, sBackgroundImage, sBackgroundImage, NO, NSCompositeSourceOver, 1, YES);
+ NSDrawThreePartImage(r, UMEIMG(@"tabbar_bg"), UMEIMG(@"tabbar_bg"), UMEIMG(@"tabbar_bg"), NO, NSCompositeSourceOver, 1, YES);
// draw bg image
if (NSOnState == [self state]) {
- NSImage *leftImage = sLeftImageHi;
- NSImage *centerImage = sCenterImageHi;
- NSImage *rightImage = sRightImageHi;
+ NSImage *leftImage = UMEIMG(@"tabbar_button_bg_hi_01");
+ NSImage *centerImage = UMEIMG(@"tabbar_button_bg_hi_02");
+ NSImage *rightImage = UMEIMG(@"tabbar_button_bg_hi_03");
[leftImage setFlipped:[cv isFlipped]];
[centerImage setFlipped:[cv isFlipped]];
View
@@ -7,15 +7,11 @@
//
#import "UMEToolbar.h"
+#import "UMEImageCache.h"
#define ITEM_X 4.0
#define ITEM_MARGIN 5.0
-static NSImage *sDefaultBackgroundImage = nil;
-static NSImage *sBlackBackgroundImage = nil;
-static NSImage *sGrayBackgroundImage = nil;
-static NSImage *sNavyBackgroundImage = nil;
-
@interface UMEBarButtonItem ()
- (void)sizeToFit;
@property (nonatomic) UMEBarStyle barStyle; // default is UMEBarStyleDefault
@@ -27,19 +23,6 @@ - (void)layoutItems;
@implementation UMEToolbar
-+ (void)initialize {
- if ([UMEToolbar class] == self) {
-
- NSBundle *b = [NSBundle bundleForClass:[UMEToolbar class]];
-
- sDefaultBackgroundImage = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"toolbar_bg_default"]];
- sBlackBackgroundImage = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"toolbar_bg_black"]];
- sGrayBackgroundImage = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"toolbar_bg_gray"]];
- sNavyBackgroundImage = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"toolbar_bg_navy"]];
- }
-}
-
-
- (id)initWithFrame:(NSRect)frame {
if (self = [super initWithFrame:frame]) {
self.barStyle = UMEBarStyleDefault;
@@ -83,16 +66,16 @@ - (void)drawRect:(NSRect)dirtyRect {
switch (barStyle) {
case UMEBarStyleDefault:
- bgImg = sDefaultBackgroundImage;
+ bgImg = UMEIMG(@"toolbar_bg_default");
break;
case UMEBarStyleBlack:
- bgImg = sBlackBackgroundImage;
+ bgImg = UMEIMG(@"toolbar_bg_black");
break;
case UMEBarStyleGray:
- bgImg = sGrayBackgroundImage;
+ bgImg = UMEIMG(@"toolbar_bg_gray");
break;
case UMEBarStyleNavy:
- bgImg = sNavyBackgroundImage;
+ bgImg = UMEIMG(@"toolbar_bg_navy");
break;
default:
break;

0 comments on commit ac42856

Please sign in to comment.