author | koda |
Sun, 17 Apr 2011 22:38:24 +0200 | |
changeset 5155 | f2165724605c |
parent 4976 | 088d40d8aba2 |
child 5208 | 878e551f0b4a |
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> |
|
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 |
||
3917 | 35 |
self.colorArray = getAvailableColors(); |
3547 | 36 |
|
37 |
// set the color to the first available one |
|
38 |
[self nextColor]; |
|
3697 | 39 |
|
3547 | 40 |
// this makes the button round and nice with a border |
41 |
[self.layer setCornerRadius:7.0f]; |
|
3697 | 42 |
[self.layer setMasksToBounds:YES]; |
3547 | 43 |
[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
|
44 |
[self.layer setBorderColor:[UICOLOR_HW_YELLOW_BODER CGColor]]; |
3697 | 45 |
|
3547 | 46 |
// this changes the color at button press |
47 |
[self addTarget:self action:@selector(nextColor) forControlEvents:UIControlEventTouchUpInside]; |
|
48 |
} |
|
49 |
return self; |
|
50 |
} |
|
51 |
||
52 |
-(void) nextColor { |
|
53 |
colorIndex++; |
|
54 |
||
55 |
if (colorIndex >= [colorArray count]) |
|
56 |
colorIndex = 0; |
|
57 |
||
58 |
NSUInteger color = [[self.colorArray objectAtIndex:colorIndex] unsignedIntValue]; |
|
3697 | 59 |
self.backgroundColor = [UIColor colorWithRed:((color & 0x00FF0000) >> 16)/255.0f |
60 |
green:((color & 0x0000FF00) >> 8)/255.0f |
|
61 |
blue: (color & 0x000000FF)/255.0f |
|
3547 | 62 |
alpha:1.0f]; |
3697 | 63 |
|
3547 | 64 |
[ownerDictionary setObject:[NSNumber numberWithInt:color] forKey:@"color"]; |
65 |
} |
|
66 |
||
67 |
-(void) selectColor:(NSUInteger) color { |
|
68 |
if (color != selectedColor) { |
|
69 |
selectedColor = color; |
|
70 |
colorIndex = [colorArray indexOfObject:[NSNumber numberWithUnsignedInt:color]]; |
|
3697 | 71 |
|
72 |
self.backgroundColor = [UIColor colorWithRed:((color & 0x00FF0000) >> 16)/255.0f |
|
73 |
green:((color & 0x0000FF00) >> 8)/255.0f |
|
74 |
blue: (color & 0x000000FF)/255.0f |
|
3547 | 75 |
alpha:1.0f]; |
76 |
} |
|
77 |
} |
|
78 |
||
79 |
-(void) dealloc { |
|
80 |
[ownerDictionary release]; |
|
81 |
[colorArray release]; |
|
82 |
[super dealloc]; |
|
83 |
} |
|
84 |
||
85 |
||
86 |
@end |