My favorites | Sign in
Project Home Downloads Wiki Issues Source
Repository:
Checkout   Browse   Changes   Clones  
Changes to /AppKit/NSColor.subproj/NSColor.m
e5277a40a7e8 vs. 2470bd80abf4 Compare: vs.  Format:
Revision 2470bd80abf4
Go to: 
Project members, sign in to write a code review
/AppKit/NSColor.subproj/NSColor.m   e5277a40a7e8 /AppKit/NSColor.subproj/NSColor.m   2470bd80abf4
1 /* Copyright (c) 2006 Christopher J. W. Lloyd 1 /* Copyright (c) 2006-2007 Christopher J. W. Lloyd
2 2
3 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 3 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4 4
5 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 5 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6 6
7 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 7 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
8 8
9 // Original - Christopher Lloyd <cjwl@objc.net> 9 // Original - Christopher Lloyd <cjwl@objc.net>
10 #import <AppKit/NSColor.h> 10 #import <AppKit/NSColor.h>
11 #import <AppKit/NSColor_whiteCalibrated.h> 11 #import <AppKit/NSColor_whiteCalibrated.h>
12 #import <AppKit/NSColor_rgbCalibrated.h> 12 #import <AppKit/NSColor_rgbCalibrated.h>
13 #import <AppKit/NSColor_whiteDevice.h> 13 #import <AppKit/NSColor_whiteDevice.h>
14 #import <AppKit/NSColor_rgbDevice.h> 14 #import <AppKit/NSColor_rgbDevice.h>
15 #import <AppKit/NSColor_cmykDevice.h> 15 #import <AppKit/NSColor_cmykDevice.h>
16 #import <AppKit/NSColor_catalog.h> 16 #import <AppKit/NSColor_catalog.h>
17 17
18 #import <AppKit/NSGraphics.h> 18 #import <AppKit/NSGraphics.h>
19 #import <AppKit/NSGraphicsContext.h> 19 #import <AppKit/NSGraphicsContext.h>
20 20
21 #import <AppKit/NSPasteboard.h> 21 #import <AppKit/NSPasteboard.h>
22 #import <AppKit/NSNibKeyedUnarchiver.h> 22 #import <AppKit/NSNibKeyedUnarchiver.h>
23 23
24 @implementation NSColor 24 @implementation NSColor
25 25
26 -(void)encodeWithCoder:(NSCoder *)coder { 26 -(void)encodeWithCoder:(NSCoder *)coder {
27 NSUnimplementedMethod(); 27 NSUnimplementedMethod();
28 } 28 }
29 29
30 -initWithCoder:(NSCoder *)coder { 30 -initWithCoder:(NSCoder *)coder {
31 if([coder isKindOfClass:[NSNibKeyedUnarchiver class]]){ 31 if([coder isKindOfClass:[NSNibKeyedUnarchiver class]]){
32 NSNibKeyedUnarchiver *keyed=(NSNibKeyedUnarchiver *)coder; 32 NSNibKeyedUnarchiver *keyed=(NSNibKeyedUnarchiver *)coder;
33 int colorSpace=[keyed decodeIntForKey:@"NSColorSpace"]; 33 int colorSpace=[keyed decodeIntForKey:@"NSColorSpace"];
34 NSColor *result; 34 NSColor *result;
35 35
36 switch(colorSpace){ 36 switch(colorSpace){
37 37
38 case 1:{ 38 case 1:{
39 // NSComponents data 39 // NSComponents data
40 // NSCustomColorSpace NSColorSpace 40 // NSCustomColorSpace NSColorSpace
41 unsigned length; 41 unsigned length;
42 const char *rgb=[keyed decodeBytesForKey:@"NSRGB" returnedLength:&length]; 42 const char *rgb=[keyed decodeBytesForKey:@"NSRGB" returnedLength:&length];
43 NSString *string=[NSString stringWithCString:rgb length:length]; 43 NSString *string=[NSString stringWithCString:rgb length:length];
44 NSArray *components=[string componentsSeparatedByString:@" "]; 44 NSArray *components=[string componentsSeparatedByString:@" "];
45 float values[4]={0,0,0,1}; 45 float values[4]={0,0,0,1};
46 int i,count=[components count]; 46 int i,count=[components count];
47 47
48 for(i=0;i<count && i<4;i++) 48 for(i=0;i<count && i<4;i++)
49 values[i]=[[components objectAtIndex:i] floatValue]; 49 values[i]=[[components objectAtIndex:i] floatValue];
50 50
51 result=[NSColor colorWithCalibratedRed:values[0] green:values[1] blue:values[2] alpha:values[3]]; 51 result=[NSColor colorWithCalibratedRed:values[0] green:values[1] blue:values[2] alpha:values[3]];
52 } 52 }
53 break; 53 break;
54 54
55 case 2:{ 55 case 2:{
56 unsigned length; 56 unsigned length;
57 const char *rgb=[keyed decodeBytesForKey:@"NSRGB" returnedLength:&length]; 57 const char *rgb=[keyed decodeBytesForKey:@"NSRGB" returnedLength:&length];
58 NSString *string=[NSString stringWithCString:rgb length:length]; 58 NSString *string=[NSString stringWithCString:rgb length:length];
59 NSArray *components=[string componentsSeparatedByString:@" "]; 59 NSArray *components=[string componentsSeparatedByString:@" "];
60 float values[4]={0,0,0,1}; 60 float values[4]={0,0,0,1};
61 int i,count=[components count]; 61 int i,count=[components count];
62 62
63 for(i=0;i<count && i<4;i++) 63 for(i=0;i<count && i<4;i++)
64 values[i]=[[components objectAtIndex:i] floatValue]; 64 values[i]=[[components objectAtIndex:i] floatValue];
65 65
66 result=[NSColor colorWithDeviceRed:values[0] green:values[1] blue:values[2] alpha:values[3]]; 66 result=[NSColor colorWithDeviceRed:values[0] green:values[1] blue:values[2] alpha:values[3]];
67 } 67 }
68 break; 68 break;
69 69
70 case 3:{ 70 case 3:{
71 unsigned length; 71 unsigned length;
72 const char *white=[keyed decodeBytesForKey:@"NSWhite" returnedLength:&length]; 72 const char *white=[keyed decodeBytesForKey:@"NSWhite" returnedLength:&length];
73 NSString *string=[NSString stringWithCString:white length:length-1]; 73 NSString *string=[NSString stringWithCString:white length:length-1];
74 NSArray *components=[string componentsSeparatedByString:@" "]; 74 NSArray *components=[string componentsSeparatedByString:@" "];
75 float values[2]={0,1}; 75 float values[2]={0,1};
76 int i,count=[components count]; 76 int i,count=[components count];
77 77
78 for(i=0;i<count && i<2;i++) 78 for(i=0;i<count && i<2;i++)
79 values[i]=[[components objectAtIndex:i] floatValue]; 79 values[i]=[[components objectAtIndex:i] floatValue];
80 80
81 result=[NSColor colorWithCalibratedWhite:values[0] alpha:values[1]]; 81 result=[NSColor colorWithCalibratedWhite:values[0] alpha:values[1]];
82 } 82 }
83 break; 83 break;
84 84
85 case 4:{ 85 case 4:{
86 unsigned length; 86 unsigned length;
87 const char *white=[keyed decodeBytesForKey:@"NSWhite" returnedLength:&length]; 87 const char *white=[keyed decodeBytesForKey:@"NSWhite" returnedLength:&length];
88 NSString *string=[NSString stringWithCString:white length:length]; 88 NSString *string=[NSString stringWithCString:white length:length];
89 NSArray *components=[string componentsSeparatedByString:@" "]; 89 NSArray *components=[string componentsSeparatedByString:@" "];
90 float values[2]={0,1}; 90 float values[2]={0,1};
91 int i,count=[components count]; 91 int i,count=[components count];
92 92
93 for(i=0;i<count && i<2;i++) 93 for(i=0;i<count && i<2;i++)
94 values[i]=[[components objectAtIndex:i] floatValue]; 94 values[i]=[[components objectAtIndex:i] floatValue];
95 95
96 result=[NSColor colorWithDeviceWhite:values[0] alpha:values[1]]; 96 result=[NSColor colorWithDeviceWhite:values[0] alpha:values[1]];
97 } 97 }
98 break; 98 break;
99 99
100 case 5:{ 100 case 5:{
101 // NSComponents data 101 // NSComponents data
102 // NSCustomColorSpace NSColorSpace 102 // NSCustomColorSpace NSColorSpace
103 unsigned length; 103 unsigned length;
104 const char *cmyk=[keyed decodeBytesForKey:@"NSCMYK" returnedLength:&length]; 104 const char *cmyk=[keyed decodeBytesForKey:@"NSCMYK" returnedLength:&length];
105 NSString *string=[NSString stringWithCString:cmyk length:length]; 105 NSString *string=[NSString stringWithCString:cmyk length:length];
106 NSArray *components=[string componentsSeparatedByString:@" "]; 106 NSArray *components=[string componentsSeparatedByString:@" "];
107 float values[5]={0,0,0,0,1}; 107 float values[5]={0,0,0,0,1};
108 int i,count=[components count]; 108 int i,count=[components count];
109 109
110 for(i=0;i<count && i<5;i++) 110 for(i=0;i<count && i<5;i++)
111 values[i]=[[components objectAtIndex:i] floatValue]; 111 values[i]=[[components objectAtIndex:i] floatValue];
112 112
113 result=[NSColor colorWithDeviceCyan:values[0] magenta:values[1] yellow:values[2] black:values[3] alpha:values[4]]; 113 result=[NSColor colorWithDeviceCyan:values[0] magenta:values[1] yellow:values[2] black:values[3] alpha:values[4]];
114 } 114 }
115 break; 115 break;
116 116
117 case 6:{ 117 case 6:{
118 NSString *catalogName=[keyed decodeObjectForKey:@"NSCatalogName"]; 118 NSString *catalogName=[keyed decodeObjectForKey:@"NSCatalogName"];
119 NSString *colorName=[keyed decodeObjectForKey:@"NSColorName"]; 119 NSString *colorName=[keyed decodeObjectForKey:@"NSColorName"];
120 NSColor *color=[keyed decodeObjectForKey:@"NSColor"]; // backup ? 120 NSColor *color=[keyed decodeObjectForKey:@"NSColor"]; // backup ?
121 121
122 if((result=[NSColor colorWithCatalogName:catalogName colorName:colorName])==nil) 122 if((result=[NSColor colorWithCatalogName:catalogName colorName:colorName])==nil)
123 result=color; 123 result=color;
124 } 124 }
125 break; 125 break;
126 126
127 default: 127 default:
128 NSLog(@"-[%@ %s] unknown color space %d",isa,SELNAME(_cmd),colorSpace); 128 NSLog(@"-[%@ %s] unknown color space %d",isa,SELNAME(_cmd),colorSpace);
129 result=[NSColor blackColor]; 129 result=[NSColor blackColor];
130 break; 130 break;
131 } 131 }
132 132
133 return [result retain]; 133 return [result retain];
134 } 134 }
135 else { 135 else {
136 NSString *space=[coder decodeObject]; 136 NSString *space=[coder decodeObject];
137 137
138 [self dealloc]; 138 [self dealloc];
139 139
140 if([space isEqualToString:@"NSDeviceCMYKColorSpace"]){ 140 if([space isEqualToString:@"NSDeviceCMYKColorSpace"]){
141 float c,m,y,k,a; 141 float c,m,y,k,a;
142 142
143 [coder decodeValuesOfObjCTypes:"fffff",&c,&m,&y,&k,&a]; 143 [coder decodeValuesOfObjCTypes:"fffff",&c,&m,&y,&k,&a];
144 144
145 return [[NSColor colorWithDeviceCyan:c magenta:m yellow:y black:k alpha:a] retain]; 145 return [[NSColor colorWithDeviceCyan:c magenta:m yellow:y black:k alpha:a] retain];
146 } 146 }
147 else if([space isEqualToString:@"NSDeviceWhiteColorSpace"]){ 147 else if([space isEqualToString:@"NSDeviceWhiteColorSpace"]){
148 float w,a; 148 float w,a;
149 149
150 [coder decodeValuesOfObjCTypes:"ff",&w,&a]; 150 [coder decodeValuesOfObjCTypes:"ff",&w,&a];
151 151
152 return [[NSColor colorWithDeviceWhite:w alpha:a] retain]; 152 return [[NSColor colorWithDeviceWhite:w alpha:a] retain];
153 } 153 }
154 else if([space isEqualToString:@"NSCalibratedWhiteColorSpace"]){ 154 else if([space isEqualToString:@"NSCalibratedWhiteColorSpace"]){
155 float w,a; 155 float w,a;
156 156
157 [coder decodeValuesOfObjCTypes:"ff",&w,&a]; 157 [coder decodeValuesOfObjCTypes:"ff",&w,&a];
158 158
159 return [[NSColor colorWithCalibratedWhite:w alpha:a] retain]; 159 return [[NSColor colorWithCalibratedWhite:w alpha:a] retain];
160 } 160 }
161 else if([space isEqualToString:@"NSDeviceRGBColorSpace"]){ 161 else if([space isEqualToString:@"NSDeviceRGBColorSpace"]){
162 float r,g,b,a; 162 float r,g,b,a;
163 163
164 [coder decodeValuesOfObjCTypes:"ffff",&r,&g,&b,&a]; 164 [coder decodeValuesOfObjCTypes:"ffff",&r,&g,&b,&a];
165 165
166 return [[NSColor colorWithDeviceRed:r green:g blue:b alpha:a] retain]; 166 return [[NSColor colorWithDeviceRed:r green:g blue:b alpha:a] retain];
167 } 167 }
168 else if([space isEqualToString:@"NSCalibratedRGBColorSpace"]){ 168 else if([space isEqualToString:@"NSCalibratedRGBColorSpace"]){
169 float r,g,b,a; 169 float r,g,b,a;
170 170
171 [coder decodeValuesOfObjCTypes:"ffff",&r,&g,&b,&a]; 171 [coder decodeValuesOfObjCTypes:"ffff",&r,&g,&b,&a];
172 172
173 return [[NSColor colorWithCalibratedRed:r green:g blue:b alpha:a] retain]; 173 return [[NSColor colorWithCalibratedRed:r green:g blue:b alpha:a] retain];
174 } 174 }
175 else if([space isEqualToString:@"NSNamedColorSpace"]){ 175 else if([space isEqualToString:@"NSNamedColorSpace"]){
176 NSString *catalog=[coder decodeObject]; 176 NSString *catalog=[coder decodeObject];
177 NSString *color=[coder decodeObject]; 177 NSString *color=[coder decodeObject];
178 178
179 return [[NSColor colorWithCatalogName:catalog colorName:color] retain]; 179 return [[NSColor colorWithCatalogName:catalog colorName:color] retain];
180 } 180 }
181 else { 181 else {
182 [NSException raise:@"UnknownColor" format:@"Unknown color space %@",space]; 182 [NSException raise:@"UnknownColor" format:@"Unknown color space %@",space];
183 return nil; 183 return nil;
184 } 184 }
185 } 185 }
186 } 186 }
187 187
188 -copyWithZone:(NSZone *)zone { 188 -copyWithZone:(NSZone *)zone {
189 return [self retain]; 189 return [self retain];
190 } 190 }
191 191
192 +(NSColor *)highlightColor { 192 +(NSColor *)highlightColor {
193 return [NSColor colorWithCatalogName:@"System" colorName:@"highlightColor"]; 193 return [NSColor colorWithCatalogName:@"System" colorName:@"highlightColor"];
194 } 194 }
195 195
196 +(NSColor *)shadowColor { 196 +(NSColor *)shadowColor {
197 return [NSColor colorWithCatalogName:@"System" colorName:@"shadowColor"]; 197 return [NSColor colorWithCatalogName:@"System" colorName:@"shadowColor"];
198 } 198 }
199 199
200 +(NSColor *)gridColor { 200 +(NSColor *)gridColor {
201 return [NSColor colorWithCatalogName:@"System" colorName:@"gridColor"]; 201 return [NSColor colorWithCatalogName:@"System" colorName:@"gridColor"];
202 } 202 }
203 203
204 +(NSColor *)controlColor { 204 +(NSColor *)controlColor {
205 return [NSColor colorWithCatalogName:@"System" colorName:@"controlColor"]; 205 return [NSColor colorWithCatalogName:@"System" colorName:@"controlColor"];
206 } 206 }
207 207
208 +(NSColor *)selectedControlColor { 208 +(NSColor *)selectedControlColor {
209 return [NSColor colorWithCatalogName:@"System" colorName:@"selectedControlColor"]; 209 return [NSColor colorWithCatalogName:@"System" colorName:@"selectedControlColor"];
210 } 210 }
211 211
212 +(NSColor *)controlTextColor { 212 +(NSColor *)controlTextColor {
213 return [NSColor colorWithCatalogName:@"System" colorName:@"controlTextColor"]; 213 return [NSColor colorWithCatalogName:@"System" colorName:@"controlTextColor"];
214 } 214 }
215 215
216 +(NSColor *)selectedControlTextColor { 216 +(NSColor *)selectedControlTextColor {
217 return [NSColor colorWithCatalogName:@"System" colorName:@"selectedControlTextColor"]; 217 return [NSColor colorWithCatalogName:@"System" colorName:@"selectedControlTextColor"];
218 } 218 }
219 219
220 +(NSColor *)disabledControlTextColor { 220 +(NSColor *)disabledControlTextColor {
221 return [NSColor colorWithCatalogName:@"System" colorName:@"disabledControlTextColor"]; 221 return [NSColor colorWithCatalogName:@"System" colorName:@"disabledControlTextColor"];
222 } 222 }
223 223
224 +(NSColor *)controlBackgroundColor { 224 +(NSColor *)controlBackgroundColor {
225 return [NSColor colorWithCatalogName:@"System" colorName:@"controlBackgroundColor"]; 225 return [NSColor colorWithCatalogName:@"System" colorName:@"controlBackgroundColor"];
226 } 226 }
227 227
228 +(NSColor *)controlDarkShadowColor { 228 +(NSColor *)controlDarkShadowColor {
229 return [NSColor colorWithCatalogName:@"System" colorName:@"controlDarkShadowColor"]; 229 return [NSColor colorWithCatalogName:@"System" colorName:@"controlDarkShadowColor"];
230 } 230 }
231 231
232 +(NSColor *)controlHighlightColor { 232 +(NSColor *)controlHighlightColor {
233 return [NSColor colorWithCatalogName:@"System" colorName:@"controlHighlightColor"]; 233 return [NSColor colorWithCatalogName:@"System" colorName:@"controlHighlightColor"];
234 } 234 }
235 235
236 +(NSColor *)controlLightHighlightColor { 236 +(NSColor *)controlLightHighlightColor {
237 return [NSColor colorWithCatalogName:@"System" colorName:@"controlLightHighlightColor"]; 237 return [NSColor colorWithCatalogName:@"System" colorName:@"controlLightHighlightColor"];
238 } 238 }
239 239
240 +(NSColor *)controlShadowColor { 240 +(NSColor *)controlShadowColor {
241 return [NSColor colorWithCatalogName:@"System" colorName:@"controlShadowColor"]; 241 return [NSColor colorWithCatalogName:@"System" colorName:@"controlShadowColor"];
242 } 242 }
243 243
244 +(NSColor *)textColor { 244 +(NSColor *)textColor {
245 return [NSColor colorWithCatalogName:@"System" colorName:@"textColor"]; 245 return [NSColor colorWithCatalogName:@"System" colorName:@"textColor"];
246 } 246 }
247 247
248 +(NSColor *)textBackgroundColor { 248 +(NSColor *)textBackgroundColor {
249 return [NSColor colorWithCatalogName:@"System" colorName:@"textBackgroundColor"]; 249 return [NSColor colorWithCatalogName:@"System" colorName:@"textBackgroundColor"];
250 } 250 }
251 251
252 +(NSColor *)selectedTextColor { 252 +(NSColor *)selectedTextColor {
253 return [NSColor colorWithCatalogName:@"System" colorName:@"selectedTextColor"]; 253 return [NSColor colorWithCatalogName:@"System" colorName:@"selectedTextColor"];
254 } 254 }
255 255
256 +(NSColor *)selectedTextBackgroundColor { 256 +(NSColor *)selectedTextBackgroundColor {
257 return [NSColor colorWithCatalogName:@"System" colorName:@"selectedTextBackgroundColor"]; 257 return [NSColor colorWithCatalogName:@"System" colorName:@"selectedTextBackgroundColor"];
258 } 258 }
259 259
260 +(NSColor *)headerColor { 260 +(NSColor *)headerColor {
261 return [NSColor colorWithCatalogName:@"System" colorName:@"headerColor"]; 261 return [NSColor colorWithCatalogName:@"System" colorName:@"headerColor"];
262 } 262 }
263 263
264 +(NSColor *)headerTextColor { 264 +(NSColor *)headerTextColor {
265 return [NSColor colorWithCatalogName:@"System" colorName:@"headerTextColor"]; 265 return [NSColor colorWithCatalogName:@"System" colorName:@"headerTextColor"];
266 } 266 }
267 267
268 +(NSColor *)scrollBarColor { 268 +(NSColor *)scrollBarColor {
269 return [NSColor colorWithCatalogName:@"System" colorName:@"scrollBarColor"]; 269 return [NSColor colorWithCatalogName:@"System" colorName:@"scrollBarColor"];
270 } 270 }
271 271
272 +(NSColor *)knobColor { 272 +(NSColor *)knobColor {
273 return [NSColor colorWithCatalogName:@"System" colorName:@"knobColor"]; 273 return [NSColor colorWithCatalogName:@"System" colorName:@"knobColor"];
274 } 274 }
275 275
276 +(NSColor *)selectedKnobColor { 276 +(NSColor *)selectedKnobColor {
277 return [NSColor colorWithCatalogName:@"System" colorName:@"selectedKnobColor"]; 277 return [NSColor colorWithCatalogName:@"System" colorName:@"selectedKnobColor"];
278 } 278 }
279 279
280 +(NSColor *)windowBackgroundColor { 280 +(NSColor *)windowBackgroundColor {
281 return [NSColor controlColor]; 281 return [NSColor controlColor];
282 } 282 }
283 283
284 +(NSColor *)menuBackgroundColor { 284 +(NSColor *)menuBackgroundColor {
285 return [NSColor colorWithCatalogName:@"System" colorName:@"menuBackgroundColor"]; 285 return [NSColor colorWithCatalogName:@"System" colorName:@"menuBackgroundColor"];
286 } 286 }
287 287
288 +(NSColor *)menuItemTextColor { 288 +(NSColor *)menuItemTextColor {
289 return [NSColor colorWithCatalogName:@"System" colorName:@"menuItemTextColor"]; 289 return [NSColor colorWithCatalogName:@"System" colorName:@"menuItemTextColor"];
290 } 290 }
291 291
292 +(NSColor *)clearColor { 292 +(NSColor *)clearColor {
293 return [NSColor colorWithCalibratedRed:0 green:0 blue:0 alpha:0]; 293 return [NSColor colorWithCalibratedRed:0 green:0 blue:0 alpha:0];
294 } 294 }
295 295
296 +(NSColor *)blackColor { 296 +(NSColor *)blackColor {
297 return [NSColor_whiteCalibrated blackColor]; 297 return [NSColor_whiteCalibrated blackColor];
298 } 298 }
299 299
300 +(NSColor *)blueColor { 300 +(NSColor *)blueColor {
301 return [NSColor colorWithCalibratedRed:0.0 green:0.0 blue:1.0 alpha:1.0]; 301 return [NSColor colorWithCalibratedRed:0.0 green:0.0 blue:1.0 alpha:1.0];
302 } 302 }
303 303
304 +(NSColor *)brownColor { 304 +(NSColor *)brownColor {
305 return [NSColor colorWithCalibratedRed:0.6 green:0.4 blue:0.2 alpha:1.0]; 305 return [NSColor colorWithCalibratedRed:0.6 green:0.4 blue:0.2 alpha:1.0];
306 } 306 }
307 307
308 +(NSColor *)cyanColor { 308 +(NSColor *)cyanColor {
309 return [NSColor colorWithCalibratedRed:0.0 green:1.0 blue:1.0 alpha:1.0]; 309 return [NSColor colorWithCalibratedRed:0.0 green:1.0 blue:1.0 alpha:1.0];
310 } 310 }
311 311
312 +(NSColor *)darkGrayColor { 312 +(NSColor *)darkGrayColor {
313 return [NSColor_whiteCalibrated darkGrayColor]; 313 return [NSColor_whiteCalibrated darkGrayColor];
314 } 314 }
315 315
316 +(NSColor *)grayColor { 316 +(NSColor *)grayColor {
317 return [NSColor_whiteCalibrated grayColor]; 317 return [NSColor_whiteCalibrated grayColor];
318 } 318 }
319 319
320 +(NSColor *)greenColor { 320 +(NSColor *)greenColor {
321 return [NSColor colorWithCalibratedRed:0.0 green:1.0 blue:0.0 alpha:1.0]; 321 return [NSColor colorWithCalibratedRed:0.0 green:1.0 blue:0.0 alpha:1.0];
322 } 322 }
323 323
324 +(NSColor *)lightGrayColor { 324 +(NSColor *)lightGrayColor {
325 return [NSColor_whiteCalibrated lightGrayColor]; 325 return [NSColor_whiteCalibrated lightGrayColor];
326 } 326 }
327 327
328 +(NSColor *)magentaColor { 328 +(NSColor *)magentaColor {
329 return [NSColor colorWithCalibratedRed:1.0 green:0.0 blue:1.0 alpha:1.0]; 329 return [NSColor colorWithCalibratedRed:1.0 green:0.0 blue:1.0 alpha:1.0];
330 } 330 }
331 331
332 +(NSColor *)orangeColor { 332 +(NSColor *)orangeColor {
333 return [NSColor colorWithCalibratedRed:1.0 green:0.5 blue:0.0 alpha:1.0]; 333 return [NSColor colorWithCalibratedRed:1.0 green:0.5 blue:0.0 alpha:1.0];
334 } 334 }
335 335
336 +(NSColor *)purpleColor { 336 +(NSColor *)purpleColor {
337 return [NSColor colorWithCalibratedRed:0.5 green:0.0 blue:0.5 alpha:1.0]; 337 return [NSColor colorWithCalibratedRed:0.5 green:0.0 blue:0.5 alpha:1.0];
338 } 338 }
339 339
340 +(NSColor *)redColor { 340 +(NSColor *)redColor {
341 return [NSColor colorWithCalibratedRed:1.0 green:0.0 blue:0.0 alpha:1.0]; 341 return [NSColor colorWithCalibratedRed:1.0 green:0.0 blue:0.0 alpha:1.0];
342 } 342 }
343 343
344 +(NSColor *)whiteColor { 344 +(NSColor *)whiteColor {
345 return [NSColor_whiteCalibrated whiteColor]; 345 return [NSColor_whiteCalibrated whiteColor];
346 } 346 }
347 347
348 +(NSColor *)yellowColor { 348 +(NSColor *)yellowColor {
349 return [NSColor colorWithCalibratedRed:1.0 green:1.0 blue:0.0 alpha:1.0]; 349 return [NSColor colorWithCalibratedRed:1.0 green:1.0 blue:0.0 alpha:1.0];
350 } 350 }
351 351
352 +(NSColor *)colorWithDeviceWhite:(float)white alpha:(float)alpha { 352 +(NSColor *)colorWithDeviceWhite:(float)white alpha:(float)alpha {
353 return [NSColor_whiteDevice colorWithGray:white alpha:alpha]; 353 return [NSColor_whiteDevice colorWithGray:white alpha:alpha];
354 } 354 }
355 355
356 +(NSColor *)colorWithDeviceRed:(float)red green:(float)green blue:(float)blue alpha:(float)alpha { 356 +(NSColor *)colorWithDeviceRed:(float)red green:(float)green blue:(float)blue alpha:(float)alpha {
357 return [NSColor_rgbDevice colorWithRed:red green:green blue:blue alpha:alpha]; 357 return [NSColor_rgbDevice colorWithRed:red green:green blue:blue alpha:alpha];
358 } 358 }
359 359
360 +(NSColor *)colorWithDeviceHue:(float)hue saturation:(float)saturation brightness:(float)brightness alpha:(float)alpha { 360 +(NSColor *)colorWithDeviceHue:(float)hue saturation:(float)saturation brightness:(float)brightness alpha:(float)alpha {
361 return [NSColor_rgbDevice colorWithHue:hue saturation:saturation brightness:brightness alpha:alpha]; 361 return [NSColor_rgbDevice colorWithHue:hue saturation:saturation brightness:brightness alpha:alpha];
362 } 362 }
363 363
364 +(NSColor *)colorWithDeviceCyan:(float)cyan magenta:(float)magenta yellow:(float)yellow black:(float)black alpha:(float)alpha { 364 +(NSColor *)colorWithDeviceCyan:(float)cyan magenta:(float)magenta yellow:(float)yellow black:(float)black alpha:(float)alpha {
365 return [NSColor_cmykDevice colorWithCyan:cyan magenta:magenta yellow:yellow black:black alpha:alpha]; 365 return [NSColor_cmykDevice colorWithCyan:cyan magenta:magenta yellow:yellow black:black alpha:alpha];
366 } 366 }
367 367
368 +(NSColor *)colorWithCalibratedWhite:(float)white alpha:(float)alpha { 368 +(NSColor *)colorWithCalibratedWhite:(float)white alpha:(float)alpha {
369 return [NSColor_whiteCalibrated colorWithGray:white alpha:alpha]; 369 return [NSColor_whiteCalibrated colorWithGray:white alpha:alpha];
370 } 370 }
371 371
372 +(NSColor *)colorWithCalibratedRed:(float)red green:(float)green blue:(float)blue alpha:(float)alpha { 372 +(NSColor *)colorWithCalibratedRed:(float)red green:(float)green blue:(float)blue alpha:(float)alpha {
373 return [NSColor_rgbCalibrated colorWithRed:red green:green blue:blue alpha:alpha]; 373 return [NSColor_rgbCalibrated colorWithRed:red green:green blue:blue alpha:alpha];
374 } 374 }
375 375
376 +(NSColor *)colorWithCalibratedHue:(float)hue saturation:(float)saturation brightness:(float)brightness alpha:(float)alpha { 376 +(NSColor *)colorWithCalibratedHue:(float)hue saturation:(float)saturation brightness:(float)brightness alpha:(float)alpha {
377 return [NSColor_rgbCalibrated colorWithHue:hue saturation:saturation brightness:brightness alpha:alpha]; 377 return [NSColor_rgbCalibrated colorWithHue:hue saturation:saturation brightness:brightness alpha:alpha];
378 } 378 }
379 379
380 +(NSColor *)colorWithCatalogName:(NSString *)catalogName colorName:(NSString *)colorName { 380 +(NSColor *)colorWithCatalogName:(NSString *)catalogName colorName:(NSString *)colorName {
381 return [NSColor_catalog colorWithCatalogName:catalogName colorName:colorName]; 381 return [NSColor_catalog colorWithCatalogName:catalogName colorName:colorName];
382 } 382 }
383 383
384 +(NSColor *)colorFromPasteboard:(NSPasteboard *)pasteboard { 384 +(NSColor *)colorFromPasteboard:(NSPasteboard *)pasteboard {
385 NSData *data=[pasteboard dataForType:NSColorPboardType]; 385 NSData *data=[pasteboard dataForType:NSColorPboardType];
386 386
387 return [NSUnarchiver unarchiveObjectWithData:data]; 387 return [NSUnarchiver unarchiveObjectWithData:data];
388 } 388 }
389 389
390 -(NSString *)colorSpaceName { 390 -(NSString *)colorSpaceName {
391 NSInvalidAbstractInvocation(); 391 NSInvalidAbstractInvocation();
392 return nil; 392 return nil;
393 } 393 }
394 394
395 -(void)getWhite:(float *)white alpha:(float *)alpha { 395 -(void)getWhite:(float *)white alpha:(float *)alpha {
396 NSInvalidAbstractInvocation(); 396 NSInvalidAbstractInvocation();
397 } 397 }
398 398
399 -(void)getRed:(float *)red green:(float *)green blue:(float *)blue alpha:(float *)alpha { 399 -(void)getRed:(float *)red green:(float *)green blue:(float *)blue alpha:(float *)alpha {
400 NSInvalidAbstractInvocation(); 400 NSInvalidAbstractInvocation();
401 } 401 }
402 402
403 -(void)getHue:(float *)hue saturation:(float *)saturation brightness:(float *)brightness alpha:(float *)alpha { 403 -(void)getHue:(float *)hue saturation:(float *)saturation brightness:(float *)brightness alpha:(float *)alpha {
404 NSInvalidAbstractInvocation(); 404 NSInvalidAbstractInvocation();
405 } 405 }
406 406
407 -(void)getCyan:(float *)cyan magenta:(float *)magenta yellow:(float *)yellow black:(float *)black alpha:(float *)alpha { 407 -(void)getCyan:(float *)cyan magenta:(float *)magenta yellow:(float *)yellow black:(float *)black alpha:(float *)alpha {
408 NSInvalidAbstractInvocation(); 408 NSInvalidAbstractInvocation();
409 } 409 }
410 410
411 -(float)whiteComponent { 411 -(float)whiteComponent {
412 float white, alpha; 412 float white, alpha;
413 413
414 [self getWhite:&white alpha:&alpha]; 414 [self getWhite:&white alpha:&alpha];
415 return white; 415 return white;
416 } 416 }
417 417
418 -(float)redComponent { 418 -(float)redComponent {
419 float red,green,blue,alpha; 419 float red,green,blue,alpha;
420 420
421 [self getRed:&red green:&green blue:&blue alpha:&alpha]; 421 [self getRed:&red green:&green blue:&blue alpha:&alpha];
422 422
423 return red; 423 return red;
424 } 424 }
425 425
426 -(float)greenComponent { 426 -(float)greenComponent {
427 float red,green,blue,alpha; 427 float red,green,blue,alpha;
428 428
429 [self getRed:&red green:&green blue:&blue alpha:&alpha]; 429 [self getRed:&red green:&green blue:&blue alpha:&alpha];
430 430
431 return green; 431 return green;
432 } 432 }
433 433
434 -(float)blueComponent { 434 -(float)blueComponent {
435 float red,green,blue,alpha; 435 float red,green,blue,alpha;
436 436
437 [self getRed:&red green:&green blue:&blue alpha:&alpha]; 437 [self getRed:&red green:&green blue:&blue alpha:&alpha];
438 438
439 return blue; 439 return blue;
440 } 440 }
441 441
442 -(float)hueComponent { 442 -(float)hueComponent {
443 float hue,saturation,brightness,alpha; 443 float hue,saturation,brightness,alpha;
444 444
445 [self getHue:&hue saturation:&saturation brightness:&brightness alpha:&alpha]; 445 [self getHue:&hue saturation:&saturation brightness:&brightness alpha:&alpha];
446 446
447 return hue; 447 return hue;
448 } 448 }
449 449
450 -(float)saturationComponent { 450 -(float)saturationComponent {
451 float hue,saturation,brightness,alpha; 451 float hue,saturation,brightness,alpha;
452 452
453 [self getHue:&hue saturation:&saturation brightness:&brightness alpha:&alpha]; 453 [self getHue:&hue saturation:&saturation brightness:&brightness alpha:&alpha];
454 454
455 return saturation; 455 return saturation;
456 } 456 }
457 457
458 -(float)brightnessComponent { 458 -(float)brightnessComponent {
459 float hue,saturation,brightness,alpha; 459 float hue,saturation,brightness,alpha;
460 460
461 [self getHue:&hue saturation:&saturation brightness:&brightness alpha:&alpha]; 461 [self getHue:&hue saturation:&saturation brightness:&brightness alpha:&alpha];
462 462
463 return brightness; 463 return brightness;
464 } 464 }
465 465
466 -(float)cyanComponent { 466 -(float)cyanComponent {
467 float cyan, magenta, yellow, black, alpha; 467 float cyan, magenta, yellow, black, alpha;
468 468
469 [self getCyan:&cyan magenta:&magenta yellow:&yellow black:&black alpha:&alpha]; 469 [self getCyan:&cyan magenta:&magenta yellow:&yellow black:&black alpha:&alpha];
470 return cyan; 470 return cyan;
471 } 471 }
472 472
473 -(float)magentaComponent { 473 -(float)magentaComponent {
474 float cyan, magenta, yellow, black, alpha; 474 float cyan, magenta, yellow, black, alpha;
475 475
476 [self getCyan:&cyan magenta:&magenta yellow:&yellow black:&black alpha:&alpha]; 476 [self getCyan:&cyan magenta:&magenta yellow:&yellow black:&black alpha:&alpha];
477 return magenta; 477 return magenta;
478 } 478 }
479 479
480 -(float)yellowComponent { 480 -(float)yellowComponent {
481 float cyan, magenta, yellow, black, alpha; 481 float cyan, magenta, yellow, black, alpha;
482 482
483 [self getCyan:&cyan magenta:&magenta yellow:&yellow black:&black alpha:&alpha]; 483 [self getCyan:&cyan magenta:&magenta yellow:&yellow black:&black alpha:&alpha];
484 return yellow; 484 return yellow;
485 } 485 }
486 486
487 -(float)blackComponent { 487 -(float)blackComponent {
488 float cyan, magenta, yellow, black, alpha; 488 float cyan, magenta, yellow, black, alpha;
489 489
490 [self getCyan:&cyan magenta:&magenta yellow:&yellow black:&black alpha:&alpha]; 490 [self getCyan:&cyan magenta:&magenta yellow:&yellow black:&black alpha:&alpha];
491 return black; 491 return black;
492 } 492 }
493 493
494 -(float)alphaComponent { 494 -(float)alphaComponent {
495 return 1.0; 495 return 1.0;
496 } 496 }
497 497
498 -(NSColor *)colorUsingColorSpaceName:(NSString *)colorSpace { 498 -(NSColor *)colorUsingColorSpaceName:(NSString *)colorSpace {
499 return [self colorUsingColorSpaceName:colorSpace device:nil]; 499 return [self colorUsingColorSpaceName:colorSpace device:nil];
500 } 500 }
501 501
502 -(NSColor *)colorUsingColorSpaceName:(NSString *)colorSpace device:(NSDictionary *)device { 502 -(NSColor *)colorUsingColorSpaceName:(NSString *)colorSpace device:(NSDictionary *)device {
503 if([[self colorSpaceName] isEqualToString:colorSpace]) 503 if([[self colorSpaceName] isEqualToString:colorSpace])
504 return self; 504 return self;
505 505
506 return nil; 506 return nil;
507 } 507 }
508 508
509 -(NSColor *)blendedColorWithFraction:(float)fraction ofColor:(NSColor *)color { 509 -(NSColor *)blendedColorWithFraction:(float)fraction ofColor:(NSColor *)color {
510 NSColor *primary=[color colorUsingColorSpaceName:NSCalibratedRGBColorSpace]; 510 NSColor *primary=[color colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
511 NSColor *secondary=[self colorUsingColorSpaceName:NSCalibratedRGBColorSpace]; 511 NSColor *secondary=[self colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
512 512
513 if(primary==nil || secondary==nil) 513 if(primary==nil || secondary==nil)
514 return nil; 514 return nil;
515 else { 515 else {
516 float pr,pg,pb,pa; 516 float pr,pg,pb,pa;
517 float sr,sg,sb,sa; 517 float sr,sg,sb,sa;
518 float rr,rg,rb,ra; 518 float rr,rg,rb,ra;
519 519
520 [primary getRed:&pr green:&pg blue:&pb alpha:&pa]; 520 [primary getRed:&pr green:&pg blue:&pb alpha:&pa];
521 [secondary getRed:&sr green:&sg blue:&sb alpha:&sa]; 521 [secondary getRed:&sr green:&sg blue:&sb alpha:&sa];
522 522
523 rr=pr*fraction+sr*(1-fraction); 523 rr=pr*fraction+sr*(1-fraction);
524 rg=pg*fraction+sg*(1-fraction); 524 rg=pg*fraction+sg*(1-fraction);
525 rb=pb*fraction+sb*(1-fraction); 525 rb=pb*fraction+sb*(1-fraction);
526 ra=pa*fraction+sa*(1-fraction); 526 ra=pa*fraction+sa*(1-fraction);
527 527
528 return [NSColor colorWithCalibratedRed:rr green:rg blue:rb alpha:ra]; 528 return [NSColor colorWithCalibratedRed:rr green:rg blue:rb alpha:ra];
529 } 529 }
530 } 530 }
531 531
532 -(void)set { 532 -(void)set {
533 NSInvalidAbstractInvocation(); 533 NSInvalidAbstractInvocation();
534 } 534 }
535 535
536 -(void)drawSwatchInRect:(NSRect)rect { 536 -(void)drawSwatchInRect:(NSRect)rect {
537 [self set]; 537 [self set];
538 NSRectFill(rect); 538 NSRectFill(rect);
539 } 539 }
540 540
541 -(void)writeToPasteboard:(NSPasteboard *)pasteboard { 541 -(void)writeToPasteboard:(NSPasteboard *)pasteboard {
542 NSData *data=[NSArchiver archivedDataWithRootObject:self]; 542 NSData *data=[NSArchiver archivedDataWithRootObject:self];
543 543
544 [pasteboard setData:data forType:NSColorPboardType]; 544 [pasteboard setData:data forType:NSColorPboardType];
545 } 545 }
546 546
547 @end 547 @end
Powered by Google Project Hosting