equal
deleted
inserted
replaced
20 #import "SquareButtonView.h" |
20 #import "SquareButtonView.h" |
21 #import <QuartzCore/QuartzCore.h> |
21 #import <QuartzCore/QuartzCore.h> |
22 |
22 |
23 |
23 |
24 @implementation SquareButtonView |
24 @implementation SquareButtonView |
25 @synthesize colorArray, selectedColor, ownerDictionary; |
25 @synthesize ownerDictionary, colorIndex, selectedColor, colorArray; |
26 |
26 |
27 -(id) initWithFrame:(CGRect)frame { |
27 -(id) initWithFrame:(CGRect)frame { |
28 if ((self = [super initWithFrame:frame])) { |
28 if ((self = [super initWithFrame:frame])) { |
29 colorIndex = -1; |
29 self.colorIndex = 0; |
30 selectedColor = 0; |
30 self.selectedColor = 0; |
31 |
31 |
32 self.colorArray = [HWUtils teamColors]; |
32 self.colorArray = [HWUtils teamColors]; |
33 |
33 |
34 // set the color to the first available one |
34 // set the color to the first available one |
35 [self nextColor]; |
35 [self nextColor]; |
45 } |
45 } |
46 return self; |
46 return self; |
47 } |
47 } |
48 |
48 |
49 -(void) nextColor { |
49 -(void) nextColor { |
50 colorIndex++; |
50 self.colorIndex++; |
51 |
51 |
52 if (colorIndex >= [colorArray count]) |
52 if (self.colorIndex >= [self.colorArray count]) |
53 colorIndex = 0; |
53 self.colorIndex = 0; |
54 |
54 |
55 NSUInteger color = [[self.colorArray objectAtIndex:colorIndex] unsignedIntValue]; |
55 NSNumber *colorNumber = [self.colorArray objectAtIndex:colorIndex]; |
56 self.backgroundColor = [UIColor colorWithRed:((color & 0x00FF0000) >> 16)/255.0f |
56 [self.ownerDictionary setObject:colorNumber forKey:@"color"]; |
57 green:((color & 0x0000FF00) >> 8)/255.0f |
57 NSUInteger color = [colorNumber unsignedIntValue]; |
58 blue: (color & 0x000000FF)/255.0f |
58 [self selectColor:color]; |
59 alpha:1.0f]; |
|
60 |
|
61 [ownerDictionary setObject:[NSNumber numberWithInt:color] forKey:@"color"]; |
|
62 } |
59 } |
63 |
60 |
64 -(void) selectColor:(NSUInteger) color { |
61 -(void) selectColor:(NSUInteger) color { |
65 if (color != selectedColor) { |
62 if (color != self.selectedColor) { |
66 selectedColor = color; |
63 self.selectedColor = color; |
67 colorIndex = [self.colorArray indexOfObject:[NSNumber numberWithUnsignedInt:color]]; |
64 self.colorIndex = [self.colorArray indexOfObject:[NSNumber numberWithUnsignedInt:color]]; |
68 |
65 |
69 self.backgroundColor = [UIColor colorWithRed:((color & 0x00FF0000) >> 16)/255.0f |
66 self.backgroundColor = [UIColor colorWithRed:((color & 0x00FF0000) >> 16)/255.0f |
70 green:((color & 0x0000FF00) >> 8)/255.0f |
67 green:((color & 0x0000FF00) >> 8)/255.0f |
71 blue: (color & 0x000000FF)/255.0f |
68 blue: (color & 0x000000FF)/255.0f |
72 alpha:1.0f]; |
69 alpha:1.0f]; |