author | tiyuri@gmail.com |
Thu, 02 Sep 2010 17:30:38 +0100 | |
changeset 3809 | 4fe006966370 |
parent 3703 | 12d17c6e8855 |
child 3829 | 81db3c85784b |
permissions | -rw-r--r-- |
3547 | 1 |
// |
2 |
// HogButtonView.m |
|
3 |
// HedgewarsMobile |
|
4 |
// |
|
5 |
// Created by Vittorio on 20/04/10. |
|
6 |
// Copyright 2010 __MyCompanyName__. All rights reserved. |
|
7 |
// |
|
8 |
||
9 |
#import "SquareButtonView.h" |
|
10 |
#import <QuartzCore/QuartzCore.h> |
|
11 |
#import "CommodityFunctions.h" |
|
12 |
#import "UIImageExtra.h" |
|
13 |
||
14 |
@implementation SquareButtonView |
|
15 |
@synthesize colorArray, selectedColor, ownerDictionary; |
|
16 |
||
17 |
-(id) initWithFrame:(CGRect)frame { |
|
18 |
if ((self = [super initWithFrame:frame])) { |
|
19 |
colorIndex = -1; |
|
20 |
selectedColor = 0; |
|
21 |
||
22 |
// list of allowed colors |
|
23 |
NSArray *colors = [[NSArray alloc] initWithObjects: [NSNumber numberWithUnsignedInt:4421353], // bluette |
|
24 |
[NSNumber numberWithUnsignedInt:4100897], // greeeen |
|
25 |
[NSNumber numberWithUnsignedInt:10632635], // violett |
|
26 |
[NSNumber numberWithUnsignedInt:16749353], // oranngy |
|
27 |
[NSNumber numberWithUnsignedInt:14483456], // reddish |
|
28 |
[NSNumber numberWithUnsignedInt:7566195], // graaaay |
|
29 |
nil]; |
|
30 |
self.colorArray = colors; |
|
31 |
[colors release]; |
|
32 |
||
33 |
// set the color to the first available one |
|
34 |
[self nextColor]; |
|
3697 | 35 |
|
3547 | 36 |
// this makes the button round and nice with a border |
37 |
[self.layer setCornerRadius:7.0f]; |
|
3697 | 38 |
[self.layer setMasksToBounds:YES]; |
3547 | 39 |
[self.layer setBorderWidth:2]; |
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
40 |
[self.layer setBorderColor:[UICOLOR_HW_YELLOW_BODER CGColor]]; |
3697 | 41 |
|
3547 | 42 |
// this changes the color at button press |
43 |
[self addTarget:self action:@selector(nextColor) forControlEvents:UIControlEventTouchUpInside]; |
|
44 |
} |
|
45 |
return self; |
|
46 |
} |
|
47 |
||
48 |
-(void) nextColor { |
|
49 |
colorIndex++; |
|
50 |
||
51 |
if (colorIndex >= [colorArray count]) |
|
52 |
colorIndex = 0; |
|
53 |
||
54 |
NSUInteger color = [[self.colorArray objectAtIndex:colorIndex] unsignedIntValue]; |
|
3697 | 55 |
self.backgroundColor = [UIColor colorWithRed:((color & 0x00FF0000) >> 16)/255.0f |
56 |
green:((color & 0x0000FF00) >> 8)/255.0f |
|
57 |
blue: (color & 0x000000FF)/255.0f |
|
3547 | 58 |
alpha:1.0f]; |
3697 | 59 |
|
3547 | 60 |
[ownerDictionary setObject:[NSNumber numberWithInt:color] forKey:@"color"]; |
61 |
} |
|
62 |
||
63 |
-(void) selectColor:(NSUInteger) color { |
|
64 |
if (color != selectedColor) { |
|
65 |
selectedColor = color; |
|
66 |
colorIndex = [colorArray indexOfObject:[NSNumber numberWithUnsignedInt:color]]; |
|
3697 | 67 |
|
68 |
self.backgroundColor = [UIColor colorWithRed:((color & 0x00FF0000) >> 16)/255.0f |
|
69 |
green:((color & 0x0000FF00) >> 8)/255.0f |
|
70 |
blue: (color & 0x000000FF)/255.0f |
|
3547 | 71 |
alpha:1.0f]; |
72 |
} |
|
73 |
} |
|
74 |
||
75 |
-(void) dealloc { |
|
76 |
[ownerDictionary release]; |
|
77 |
[colorArray release]; |
|
78 |
[super dealloc]; |
|
79 |
} |
|
80 |
||
81 |
||
82 |
@end |