author | koda |
Sat, 25 Sep 2010 03:04:22 +0200 | |
changeset 3902 | 3aac7ca07b0e |
parent 3829 | 81db3c85784b |
child 3917 | 4c243b1eac97 |
permissions | -rw-r--r-- |
3829 | 1 |
/* |
2 |
* Hedgewars-iOS, a Hedgewars port for iOS devices |
|
3 |
* Copyright (c) 2009-2010 Vittorio Giovara <vittorio.giovara@gmail.com> |
|
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> |
|
24 |
#import "CommodityFunctions.h" |
|
25 |
#import "UIImageExtra.h" |
|
26 |
||
27 |
@implementation SquareButtonView |
|
28 |
@synthesize colorArray, selectedColor, ownerDictionary; |
|
29 |
||
30 |
-(id) initWithFrame:(CGRect)frame { |
|
31 |
if ((self = [super initWithFrame:frame])) { |
|
32 |
colorIndex = -1; |
|
33 |
selectedColor = 0; |
|
34 |
||
35 |
// list of allowed colors |
|
36 |
NSArray *colors = [[NSArray alloc] initWithObjects: [NSNumber numberWithUnsignedInt:4421353], // bluette |
|
37 |
[NSNumber numberWithUnsignedInt:4100897], // greeeen |
|
38 |
[NSNumber numberWithUnsignedInt:10632635], // violett |
|
39 |
[NSNumber numberWithUnsignedInt:16749353], // oranngy |
|
40 |
[NSNumber numberWithUnsignedInt:14483456], // reddish |
|
41 |
[NSNumber numberWithUnsignedInt:7566195], // graaaay |
|
42 |
nil]; |
|
43 |
self.colorArray = colors; |
|
44 |
[colors release]; |
|
45 |
||
46 |
// set the color to the first available one |
|
47 |
[self nextColor]; |
|
3697 | 48 |
|
3547 | 49 |
// this makes the button round and nice with a border |
50 |
[self.layer setCornerRadius:7.0f]; |
|
3697 | 51 |
[self.layer setMasksToBounds:YES]; |
3547 | 52 |
[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
|
53 |
[self.layer setBorderColor:[UICOLOR_HW_YELLOW_BODER CGColor]]; |
3697 | 54 |
|
3547 | 55 |
// this changes the color at button press |
56 |
[self addTarget:self action:@selector(nextColor) forControlEvents:UIControlEventTouchUpInside]; |
|
57 |
} |
|
58 |
return self; |
|
59 |
} |
|
60 |
||
61 |
-(void) nextColor { |
|
62 |
colorIndex++; |
|
63 |
||
64 |
if (colorIndex >= [colorArray count]) |
|
65 |
colorIndex = 0; |
|
66 |
||
67 |
NSUInteger color = [[self.colorArray objectAtIndex:colorIndex] unsignedIntValue]; |
|
3697 | 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]; |
3697 | 72 |
|
3547 | 73 |
[ownerDictionary setObject:[NSNumber numberWithInt:color] forKey:@"color"]; |
74 |
} |
|
75 |
||
76 |
-(void) selectColor:(NSUInteger) color { |
|
77 |
if (color != selectedColor) { |
|
78 |
selectedColor = color; |
|
79 |
colorIndex = [colorArray indexOfObject:[NSNumber numberWithUnsignedInt:color]]; |
|
3697 | 80 |
|
81 |
self.backgroundColor = [UIColor colorWithRed:((color & 0x00FF0000) >> 16)/255.0f |
|
82 |
green:((color & 0x0000FF00) >> 8)/255.0f |
|
83 |
blue: (color & 0x000000FF)/255.0f |
|
3547 | 84 |
alpha:1.0f]; |
85 |
} |
|
86 |
} |
|
87 |
||
88 |
-(void) dealloc { |
|
89 |
[ownerDictionary release]; |
|
90 |
[colorArray release]; |
|
91 |
[super dealloc]; |
|
92 |
} |
|
93 |
||
94 |
||
95 |
@end |