forked from cappuccino/cappuccino
-
Notifications
You must be signed in to change notification settings - Fork 5
/
_CPCibCustomResource.j
115 lines (94 loc) · 3.31 KB
/
_CPCibCustomResource.j
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
* _CPCibCustomResource.j
* AppKit
*
* Portions based on NSCustomResource.m (01/08/2009) in Cocotron (http://www.cocotron.org/)
* Copyright (c) 2006-2007 Christopher J. W. Lloyd
*
* Created by Francisco Tolmasky.
* Copyright 2009, 280 North, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@import <Foundation/CPObject.j>
@import <Foundation/CPString.j>
var _CPCibCustomResourceClassNameKey = @"_CPCibCustomResourceClassNameKey",
_CPCibCustomResourceResourceNameKey = @"_CPCibCustomResourceResourceNameKey",
_CPCibCustomResourcePropertiesKey = @"_CPCibCustomResourcePropertiesKey";
@implementation _CPCibCustomResource : CPObject
{
CPString _className;
CPString _resourceName;
CPDictionary _properties;
}
+ (id)imageResourceWithName:(CPString)aResourceName size:(CGSize)aSize
{
return [[self alloc] initWithClassName:@"CPImage" resourceName:aResourceName properties:[CPDictionary dictionaryWithObject:aSize forKey:@"size"]];
}
- (id)initWithClassName:(CPString)aClassName resourceName:(CPString)aResourceName properties:(CPDictionary)properties
{
self = [super init];
if (self)
{
_className = aClassName;
_resourceName = aResourceName;
_properties = properties;
}
return self;
}
- (id)initWithCoder:(CPCoder)aCoder
{
self = [super init];
if (self)
{
_className = [aCoder decodeObjectForKey:_CPCibCustomResourceClassNameKey];
_resourceName = [aCoder decodeObjectForKey:_CPCibCustomResourceResourceNameKey];
_properties = [aCoder decodeObjectForKey:_CPCibCustomResourcePropertiesKey];
}
return self;
}
- (void)encodeWithCoder:(CPCoder)aCoder
{
[aCoder encodeObject:_className forKey:_CPCibCustomResourceClassNameKey];
[aCoder encodeObject:_resourceName forKey:_CPCibCustomResourceResourceNameKey];
[aCoder encodeObject:_properties forKey:_CPCibCustomResourcePropertiesKey];
}
- (id)awakeAfterUsingCoder:(CPCoder)aCoder
{
if ([aCoder respondsToSelector:@selector(bundle)] &&
(![aCoder respondsToSelector:@selector(awakenCustomResources)] || [aCoder awakenCustomResources]))
if (_className === @"CPImage")
return [[CPImage alloc] initWithContentsOfFile:[[aCoder bundle] pathForResource:_resourceName] size:[_properties objectForKey:@"size"]];
return self;
}
@end
@implementation _CPCibCustomResource (CPImage)
- (CPString)filename
{
return [[CPBundle mainBundle] pathForResource:_resourceName];
}
- (CGSize)size
{
return [_properties objectForKey:@"size"];
}
- (BOOL)isThreePartImage
{
return NO;
}
- (BOOL)isNinePartImage
{
return NO;
}
@end