-
Notifications
You must be signed in to change notification settings - Fork 12
/
SMFColorSelectionMenu.m
98 lines (92 loc) · 3.36 KB
/
SMFColorSelectionMenu.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
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
//
// SMFColorSelectionMenu.m
// SMFramework
//
// Created by Thomas Cool on 11/22/10.
// Copyright 2010 tomcool.org. All rights reserved.
//
#import "SMFColorSelectionMenu.h"
#import "SMFMenuItem.h"
#import "SMFBaseAsset.h"
#import "SMFMediaPreview.h"
#import "SMFThemeInfo.h"
#import <UIKit/UIColor.h>
#define SMFFloat(val) [NSNumber numberWithFloat:(val)]
#define SMFFloatString(val) [NSString stringWithFormat:@"%.1f",(val)]
@implementation SMFColorSelectionMenu
@synthesize delegate;
@synthesize key;
+(SMFColorSelectionMenu *)colorMenuForKey:(NSString *)k andDelegate:(NSObject<SMFColorSelectionDelegate>*)del
{
SMFColorSelectionMenu *col = [[SMFColorSelectionMenu alloc] init];
[col setDelegate:del];
[col setKey:k];
return [col autorelease];
}
static float red[]= {0.0,0.0,0.6,0.0,0.33,0.0,0.66,1.0,1.0,0.5,1.0,1.0,1.0};
static float green[]={0.0,0.0,0.4,1.0,0.33,1.0,0.66,0.0,0.5,0.0,0.0,1.0,1.0};
static float blue[] ={0.0,1.0,0.2,1.0,0.33,0.0,0.66,1.0,0.0,0.5,0.0,1.0,0.0};
-(id)previewControlForItem:(long)row
{
if (row>=[_items count])
return nil;
SMFMediaPreview *p = [[SMFMediaPreview alloc] init];
SMFBaseAsset *a = [[SMFBaseAsset alloc] init];
[a setCoverArt:[[SMFThemeInfo sharedTheme] colorAppleTVNameImage]];
[a setTitle:[self titleForRow:row]];
[a setCustomKeys:[NSArray arrayWithObjects:@"Red",@"Green",@"Blue",@"Alpha",nil]
forObjects:[NSArray arrayWithObjects:SMFFloatString(red[row]),SMFFloatString(green[row]),
SMFFloatString(blue[row]),SMFFloatString(1.0),nil]];
[p setAsset:a];
[a release];
return [p autorelease];
}
-(id)init
{
self=[super init];
if (self) {
[self setListTitle:@"Select A Color"];
NSArray *strings = [NSArray arrayWithObjects:@"Black",@"Blue",@"Brown",@"Cyan",@"Dark Gray",@"Green",
@"Light Gray",@"Magenta",@"Orange",@"Purple",@"Red",@"White",@"Yellow",nil];
CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();
for(int i=0;i<[strings count];i++)
{
SMFMenuItem *it = [[SMFMenuItem alloc] init];
NSMutableDictionary *d = [[[BRThemeInfo sharedTheme]menuItemTextAttributes] mutableCopy];
const CGFloat myColor[] = {red[i], green[i], blue[i], 1.0};
CGColorRef color = CGColorCreate(rgb, myColor);
[d setObject:(id)color forKey:@"CTForegroundColor"];
CGColorRelease(color);
[it setText:[strings objectAtIndex:i] withAttributes:d];
[d release];
[_items addObject:it];
[it release];
}
CGColorSpaceRelease(rgb);
}
return self;
}
-(void)itemSelected:(long)selected
{
NSLog(@"sending message to delegate 0");
if ([self.delegate conformsToProtocol:@protocol(SMFColorSelectionDelegate)])
{
NSLog(@"sending message to delegate 1");
NSArray *colorArray = [NSArray arrayWithObjects:
SMFFloat(red[selected]),
SMFFloat(green[selected]),
SMFFloat(blue[selected]),
SMFFloat(1.0),
nil];
[[self delegate] colorSelected:colorArray forKey:[self key]];
}
}
-(void)dealloc
{
[colors release];
colors=nil;
delegate=nil;
self.key=nil;
[super dealloc];
}
@end