author | koda |
Sun, 09 Oct 2011 00:24:58 +0200 | |
changeset 6107 | 0741c0f0203e |
parent 6078 | 8c0cc07731e5 |
child 6700 | e04da46ee43c |
permissions | -rw-r--r-- |
3829 | 1 |
/* |
2 |
* Hedgewars-iOS, a Hedgewars port for iOS devices |
|
4976 | 3 |
* Copyright (c) 2009-2011 Vittorio Giovara <vittorio.giovara@gmail.com> |
3829 | 4 |
* |
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
17 |
* |
|
18 |
* File created on 20/04/2010. |
|
19 |
*/ |
|
20 |
||
3547 | 21 |
|
22 |
#import "SquareButtonView.h" |
|
23 |
#import <QuartzCore/QuartzCore.h> |
|
6078
8c0cc07731e5
headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
5208
diff
changeset
|
24 |
|
3547 | 25 |
|
26 |
@implementation SquareButtonView |
|
27 |
@synthesize colorArray, selectedColor, ownerDictionary; |
|
28 |
||
29 |
-(id) initWithFrame:(CGRect)frame { |
|
30 |
if ((self = [super initWithFrame:frame])) { |
|
31 |
colorIndex = -1; |
|
32 |
selectedColor = 0; |
|
33 |
||
6078
8c0cc07731e5
headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
5208
diff
changeset
|
34 |
self.colorArray = [HWUtils teamColors]; |
3547 | 35 |
|
36 |
// set the color to the first available one |
|
37 |
[self nextColor]; |
|
3697 | 38 |
|
3547 | 39 |
// this makes the button round and nice with a border |
40 |
[self.layer setCornerRadius:7.0f]; |
|
3697 | 41 |
[self.layer setMasksToBounds:YES]; |
3547 | 42 |
[self.layer setBorderWidth:2]; |
6078
8c0cc07731e5
headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
5208
diff
changeset
|
43 |
[self.layer setBorderColor:[[UIColor darkYellowColor] CGColor]]; |
3697 | 44 |
|
3547 | 45 |
// this changes the color at button press |
46 |
[self addTarget:self action:@selector(nextColor) forControlEvents:UIControlEventTouchUpInside]; |
|
47 |
} |
|
48 |
return self; |
|
49 |
} |
|
50 |
||
51 |
-(void) nextColor { |
|
52 |
colorIndex++; |
|
53 |
||
54 |
if (colorIndex >= [colorArray count]) |
|
55 |
colorIndex = 0; |
|
56 |
||
57 |
NSUInteger color = [[self.colorArray objectAtIndex:colorIndex] unsignedIntValue]; |
|
3697 | 58 |
self.backgroundColor = [UIColor colorWithRed:((color & 0x00FF0000) >> 16)/255.0f |
59 |
green:((color & 0x0000FF00) >> 8)/255.0f |
|
60 |
blue: (color & 0x000000FF)/255.0f |
|
3547 | 61 |
alpha:1.0f]; |
3697 | 62 |
|
3547 | 63 |
[ownerDictionary setObject:[NSNumber numberWithInt:color] forKey:@"color"]; |
64 |
} |
|
65 |
||
66 |
-(void) selectColor:(NSUInteger) color { |
|
67 |
if (color != selectedColor) { |
|
68 |
selectedColor = color; |
|
6078
8c0cc07731e5
headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
5208
diff
changeset
|
69 |
colorIndex = [self.colorArray indexOfObject:[NSNumber numberWithUnsignedInt:color]]; |
3697 | 70 |
|
71 |
self.backgroundColor = [UIColor colorWithRed:((color & 0x00FF0000) >> 16)/255.0f |
|
72 |
green:((color & 0x0000FF00) >> 8)/255.0f |
|
73 |
blue: (color & 0x000000FF)/255.0f |
|
3547 | 74 |
alpha:1.0f]; |
75 |
} |
|
76 |
} |
|
77 |
||
78 |
-(void) dealloc { |
|
5208 | 79 |
releaseAndNil(ownerDictionary); |
80 |
releaseAndNil(colorArray); |
|
3547 | 81 |
[super dealloc]; |
82 |
} |
|
83 |
||
84 |
||
85 |
@end |