forked from flit/MidiKeys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ColourDefaults.m
37 lines (28 loc) · 1.07 KB
/
ColourDefaults.m
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
//
// ColourDefaults.mm
// MidiKeys
//
// Created by Chris Reed on Sat Oct 26 2002.
// Copyright (c) 2002 Chris Reed. All rights reserved.
//
#import "ColourDefaults.h"
@implementation NSUserDefaults (ColourDefaults)
// save color as a string with the components separated by spaces
- (NSColor *)colorForKey:(NSString *)key
{
NSString *colorString = [self stringForKey:key];
if (!colorString)
return nil;
NSArray *componentArray = [colorString componentsSeparatedByString:@" "];
if ([componentArray count] != 4)
return nil;
id components[4];
[componentArray getObjects:(id *)&components]; // we know the length is 4
return [NSColor colorWithCalibratedRed:[components[0] floatValue] green:[components[1] floatValue] blue:[components[2] floatValue] alpha:[components[3] floatValue]];
}
- (void)setColor:(NSColor *)theColor forKey:(NSString *)key
{
NSString *colorString = [NSString stringWithFormat:@"%g %g %g %g", [theColor redComponent], [theColor greenComponent], [theColor blueComponent], [theColor alphaComponent]];
[self setObject:colorString forKey:key];
}
@end