source: trunk/SapphireTheme.m @ 123

Last change on this file since 123 was 123, checked in by pmerrill, 10 years ago
  • changed MyCompany? name to www.nanopi.net
  • added xml importing to the file import tool
File size: 1.9 KB
Line 
1//
2//  SapphireTheme.m
3//  Sapphire
4//
5//  Created by Graham Booker on 6/27/07.
6//  Copyright 2007 __www.nanopi.net__. All rights reserved.
7//
8
9#import "SapphireTheme.h"
10
11
12@implementation SapphireTheme
13
14+ (id)sharedTheme
15{
16        static SapphireTheme *shared = nil;
17        if(shared == nil)
18                shared = [[SapphireTheme alloc] init];
19       
20        return shared;
21}
22
23- (id)init
24{
25        self = [super init];
26        if(!self)
27                return nil;
28       
29        gemDict = [NSMutableDictionary new];
30        gemFiles = [[NSDictionary alloc] initWithObjectsAndKeys:
31                @"Contents/Resources/Orange_Red.png", RED_GEM_KEY,
32                @"Contents/Resources/Blue.png", BLUE_GEM_KEY,
33                @"Contents/Resources/Green.png", GREEN_GEM_KEY,
34                @"Contents/Resources/Yellow.png", YELLOW_GEM_KEY,
35                @"Contents/Resources/Gear.png", GEAR_GEM_KEY,
36                @"Contents/Resources/Cone.png", CONE_GEM_KEY,
37                @"Contents/Resources/Eye.png", EYE_GEM_KEY,
38                nil];
39       
40        return self;
41}
42
43- (void)dealloc
44{
45        [gemDict release];
46        [scene release];
47        [gemFiles release];
48        [super dealloc];
49}
50
51- (void)setScene:(BRRenderScene *)theScene
52{
53        [gemDict removeAllObjects];
54        scene = [theScene retain];
55}
56
57- (CGImageRef)loadImage:(NSString *)path
58{
59        NSString *bundlePath = [[NSBundle bundleForClass:[self class]] bundlePath];
60        NSURL *url = [NSURL fileURLWithPath:[bundlePath stringByAppendingPathComponent:path]];
61        CGImageSourceRef sourceRef = CGImageSourceCreateWithURL((CFURLRef)url, NULL);
62        CGImageRef imageRef = NULL;
63        if(sourceRef)
64        {
65                imageRef = CGImageSourceCreateImageAtIndex(sourceRef, 0, NULL);
66                CFRelease(sourceRef);
67        }
68        return imageRef;
69}
70
71- (BRTexture *)gem:(NSString *)type
72{
73        BRTexture *ret = [gemDict objectForKey:type];
74        if(ret != nil)
75                return ret;
76       
77        CGImageRef image = [self loadImage:[gemFiles objectForKey:type]];
78        if(image != NULL)
79        {
80                ret = [BRBitmapTexture textureWithImage:image context:[scene resourceContext] mipmap:YES];
81                CFRelease(image);
82        }
83        if(ret != nil)
84                [gemDict setObject:ret forKey:type];
85        return ret;
86}
87
88@end
Note: See TracBrowser for help on using the repository browser.