author | koda |
Wed, 23 Jun 2010 01:00:52 +0200 | |
changeset 3535 | 9e78c1f3d8d8 |
parent 3514 | 59dbd31e9953 |
permissions | -rw-r--r-- |
3361 | 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" |
|
3479 | 10 |
#import <QuartzCore/QuartzCore.h> |
3361 | 11 |
#import "CommodityFunctions.h" |
12 |
#import "UIImageExtra.h" |
|
13 |
||
14 |
@implementation SquareButtonView |
|
3364 | 15 |
@synthesize colorArray, selectedColor, ownerDictionary; |
3361 | 16 |
|
17 |
-(id) initWithFrame:(CGRect)frame { |
|
18 |
if ((self = [super initWithFrame:frame])) { |
|
19 |
colorIndex = -1; |
|
3364 | 20 |
selectedColor = 0; |
21 |
||
3361 | 22 |
// list of allowed colors |
3364 | 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]; |
|
3361 | 30 |
self.colorArray = colors; |
31 |
[colors release]; |
|
32 |
||
33 |
// set the color to the first available one |
|
34 |
[self nextColor]; |
|
35 |
||
3535
9e78c1f3d8d8
update the project to ios4 by removing pre-3.2 references
koda
parents:
3514
diff
changeset
|
36 |
// this makes the button round and nice with a border |
3361 | 37 |
[self.layer setCornerRadius:7.0f]; |
38 |
[self.layer setMasksToBounds:YES]; |
|
3535
9e78c1f3d8d8
update the project to ios4 by removing pre-3.2 references
koda
parents:
3514
diff
changeset
|
39 |
[self.layer setBorderWidth:2]; |
3361 | 40 |
|
41 |
// this changes the color at button press |
|
42 |
[self addTarget:self action:@selector(nextColor) forControlEvents:UIControlEventTouchUpInside]; |
|
43 |
} |
|
44 |
return self; |
|
45 |
} |
|
46 |
||
47 |
-(void) nextColor { |
|
48 |
colorIndex++; |
|
3535
9e78c1f3d8d8
update the project to ios4 by removing pre-3.2 references
koda
parents:
3514
diff
changeset
|
49 |
|
3361 | 50 |
if (colorIndex >= [colorArray count]) |
51 |
colorIndex = 0; |
|
3364 | 52 |
|
3361 | 53 |
NSUInteger color = [[self.colorArray objectAtIndex:colorIndex] unsignedIntValue]; |
3535
9e78c1f3d8d8
update the project to ios4 by removing pre-3.2 references
koda
parents:
3514
diff
changeset
|
54 |
self.backgroundColor = [UIColor colorWithRed:((color & 0x00FF0000) >> 16)/255.0f |
9e78c1f3d8d8
update the project to ios4 by removing pre-3.2 references
koda
parents:
3514
diff
changeset
|
55 |
green:((color & 0x0000FF00) >> 8)/255.0f |
9e78c1f3d8d8
update the project to ios4 by removing pre-3.2 references
koda
parents:
3514
diff
changeset
|
56 |
blue: (color & 0x000000FF)/255.0f |
9e78c1f3d8d8
update the project to ios4 by removing pre-3.2 references
koda
parents:
3514
diff
changeset
|
57 |
alpha:1.0f]; |
3361 | 58 |
|
3364 | 59 |
[ownerDictionary setObject:[NSNumber numberWithInt:color] forKey:@"color"]; |
60 |
} |
|
61 |
||
62 |
-(void) selectColor:(NSUInteger) color { |
|
63 |
if (color != selectedColor) { |
|
64 |
selectedColor = color; |
|
3535
9e78c1f3d8d8
update the project to ios4 by removing pre-3.2 references
koda
parents:
3514
diff
changeset
|
65 |
colorIndex = [colorArray indexOfObject:[NSNumber numberWithUnsignedInt:color]]; |
3364 | 66 |
|
3535
9e78c1f3d8d8
update the project to ios4 by removing pre-3.2 references
koda
parents:
3514
diff
changeset
|
67 |
self.backgroundColor = [UIColor colorWithRed:((color & 0x00FF0000) >> 16)/255.0f |
9e78c1f3d8d8
update the project to ios4 by removing pre-3.2 references
koda
parents:
3514
diff
changeset
|
68 |
green:((color & 0x0000FF00) >> 8)/255.0f |
9e78c1f3d8d8
update the project to ios4 by removing pre-3.2 references
koda
parents:
3514
diff
changeset
|
69 |
blue: (color & 0x000000FF)/255.0f |
9e78c1f3d8d8
update the project to ios4 by removing pre-3.2 references
koda
parents:
3514
diff
changeset
|
70 |
alpha:1.0f]; |
3364 | 71 |
} |
3361 | 72 |
} |
73 |
||
74 |
-(void) dealloc { |
|
3364 | 75 |
[ownerDictionary release]; |
3361 | 76 |
[colorArray release]; |
77 |
[super dealloc]; |
|
78 |
} |
|
79 |
||
80 |
||
81 |
@end |