author | antonc27 <antonc27@mail.ru> |
Mon, 10 Aug 2015 22:48:02 +0200 | |
branch | ios-revival |
changeset 11104 | eea0481d2ae1 |
parent 10108 | c68cf030eded |
child 11140 | 3fbe54013b2b |
permissions | -rw-r--r-- |
6208
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
1 |
/* |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
2 |
* Hedgewars-iOS, a Hedgewars port for iOS devices |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
3 |
* Copyright (c) 2009-2010 Vittorio Giovara <vittorio.giovara@gmail.com> |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
4 |
* |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License as published by |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
7 |
* the Free Software Foundation; version 2 of the License |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
8 |
* |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
13 |
* |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
15 |
* along with this program; if not, write to the Free Software |
10108
c68cf030eded
update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents:
6832
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
6208
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
17 |
*/ |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
18 |
|
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
19 |
|
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
20 |
#import "ExtraCategories.h" |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
21 |
#import <QuartzCore/QuartzCore.h> |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
22 |
#import <CommonCrypto/CommonDigest.h> |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
23 |
|
6209 | 24 |
|
6300 | 25 |
#pragma mark - |
6209 | 26 |
@implementation UIScreen (safe) |
27 |
||
28 |
-(CGFloat) safeScale { |
|
29 |
CGFloat theScale = 1.0f; |
|
30 |
if ([self respondsToSelector:@selector(scale)]) |
|
31 |
theScale = [self scale]; |
|
32 |
return theScale; |
|
33 |
} |
|
34 |
||
6615 | 35 |
-(CGRect) safeBounds { |
11104
eea0481d2ae1
- Some weird staff with bounds commented here
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
36 |
return [self bounds]; |
eea0481d2ae1
- Some weird staff with bounds commented here
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
37 |
// CGRect original = [self bounds]; |
eea0481d2ae1
- Some weird staff with bounds commented here
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
38 |
// if (IS_ON_PORTRAIT()) |
eea0481d2ae1
- Some weird staff with bounds commented here
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
39 |
// return original; |
eea0481d2ae1
- Some weird staff with bounds commented here
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
40 |
// else |
eea0481d2ae1
- Some weird staff with bounds commented here
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
41 |
// return CGRectMake(original.origin.x, original.origin.y, original.size.height, original.size.width); |
6615 | 42 |
} |
43 |
||
6209 | 44 |
@end |
45 |
||
46 |
||
6300 | 47 |
#pragma mark - |
6208
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
48 |
@implementation UITableView (backgroundColor) |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
49 |
|
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
50 |
-(void) setBackgroundColorForAnyTable:(UIColor *) color { |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
51 |
if ([self respondsToSelector:@selector(backgroundView)]) { |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
52 |
UIView *backView = [[UIView alloc] initWithFrame:self.frame]; |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
53 |
backView.backgroundColor = color; |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
54 |
self.backgroundView = backView; |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
55 |
[backView release]; |
6210
923c8414e3af
fix runtime compability with ios 3.* (hopefully) and fix a small glitch in turning off music/sounds
koda
parents:
6209
diff
changeset
|
56 |
self.backgroundColor = [UIColor clearColor]; |
923c8414e3af
fix runtime compability with ios 3.* (hopefully) and fix a small glitch in turning off music/sounds
koda
parents:
6209
diff
changeset
|
57 |
} else |
923c8414e3af
fix runtime compability with ios 3.* (hopefully) and fix a small glitch in turning off music/sounds
koda
parents:
6209
diff
changeset
|
58 |
self.backgroundColor = color; |
6208
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
59 |
} |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
60 |
|
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
61 |
@end |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
62 |
|
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
63 |
|
6300 | 64 |
#pragma mark - |
6208
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
65 |
@implementation UIColor (HWColors) |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
66 |
|
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
67 |
+(UIColor *)darkYellowColor { |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
68 |
return [UIColor colorWithRed:(CGFloat)0xFE/255 green:(CGFloat)0xC0/255 blue:0 alpha:1]; |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
69 |
} |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
70 |
|
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
71 |
+(UIColor *)lightYellowColor { |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
72 |
return [UIColor colorWithRed:(CGFloat)0xF0/255 green:(CGFloat)0xD0/255 blue:0 alpha:1]; |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
73 |
} |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
74 |
|
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
75 |
+(UIColor *)darkBlueColor { |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
76 |
return [UIColor colorWithRed:(CGFloat)0x0F/255 green:0 blue:(CGFloat)0x42/255 alpha:1]; |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
77 |
} |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
78 |
|
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
79 |
// older devices don't get any transparency for performance reasons |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
80 |
+(UIColor *)darkBlueColorTransparent { |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
81 |
return [UIColor colorWithRed:(CGFloat)0x0F/255 |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
82 |
green:0 |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
83 |
blue:(CGFloat)0x55/255 |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
84 |
alpha:IS_NOT_POWERFUL([HWUtils modelType]) ? 1 : 0.6f]; |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
85 |
} |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
86 |
|
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
87 |
+(UIColor *)blackColorTransparent { |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
88 |
return [UIColor colorWithRed:0 |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
89 |
green:0 |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
90 |
blue:0 |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
91 |
alpha:IS_NOT_POWERFUL([HWUtils modelType]) ? 1 : 0.65f]; |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
92 |
} |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
93 |
|
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
94 |
@end |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
95 |
|
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
96 |
|
6300 | 97 |
#pragma mark - |
6711 | 98 |
@implementation UIButton (quickStyle) |
99 |
||
100 |
-(id) initWithFrame:(CGRect) frame andTitle:(NSString *)title { |
|
101 |
[self initWithFrame:frame]; |
|
102 |
[self setTitle:title forState:UIControlStateNormal]; |
|
103 |
[self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; |
|
104 |
[self setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted]; |
|
105 |
self.titleLabel.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]]; |
|
106 |
self.backgroundColor = [UIColor blackColorTransparent]; |
|
107 |
||
108 |
[self.layer setBorderWidth:1]; |
|
109 |
[self.layer setBorderColor:[[UIColor darkYellowColor] CGColor]]; |
|
110 |
[self.layer setCornerRadius:9.0f]; |
|
111 |
[self.layer setMasksToBounds:YES]; |
|
112 |
||
113 |
return self; |
|
114 |
} |
|
115 |
||
116 |
@end |
|
117 |
||
118 |
||
119 |
#pragma mark - |
|
6208
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
120 |
@implementation UILabel (quickStyle) |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
121 |
|
6711 | 122 |
-(id) initWithFrame:(CGRect)frame andTitle:(NSString *)title { |
6208
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
123 |
return [self initWithFrame:frame |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
124 |
andTitle:title |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
125 |
withBorderWidth:1.5f |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
126 |
withBorderColor:[UIColor darkYellowColor] |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
127 |
withBackgroundColor:[UIColor darkBlueColor]]; |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
128 |
} |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
129 |
|
6711 | 130 |
-(id) initWithFrame:(CGRect)frame andTitle:(NSString *)title withBorderWidth:(CGFloat) borderWidth { |
6208
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
131 |
return [self initWithFrame:frame |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
132 |
andTitle:title |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
133 |
withBorderWidth:borderWidth |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
134 |
withBorderColor:[UIColor darkYellowColor] |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
135 |
withBackgroundColor:[UIColor darkBlueColorTransparent]]; |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
136 |
} |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
137 |
|
6711 | 138 |
-(id) initWithFrame:(CGRect)frame andTitle:(NSString *)title withBorderWidth:(CGFloat) borderWidth |
139 |
withBorderColor:(UIColor *)borderColor withBackgroundColor:(UIColor *)backColor { |
|
6208
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
140 |
UILabel *theLabel = [self initWithFrame:frame]; |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
141 |
theLabel.backgroundColor = backColor; |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
142 |
|
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
143 |
if (title != nil) { |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
144 |
theLabel.text = title; |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
145 |
theLabel.textColor = [UIColor lightYellowColor]; |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
146 |
theLabel.textAlignment = UITextAlignmentCenter; |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
147 |
theLabel.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]*80/100]; |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
148 |
} |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
149 |
|
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
150 |
[theLabel.layer setBorderWidth:borderWidth]; |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
151 |
[theLabel.layer setBorderColor:borderColor.CGColor]; |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
152 |
[theLabel.layer setCornerRadius:8.0f]; |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
153 |
[theLabel.layer setMasksToBounds:YES]; |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
154 |
|
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
155 |
return theLabel; |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
156 |
} |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
157 |
|
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
158 |
@end |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
159 |
|
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
160 |
|
6300 | 161 |
#pragma mark - |
6208
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
162 |
@implementation NSString (MD5) |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
163 |
|
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
164 |
-(NSString *)MD5hash { |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
165 |
const char *cStr = [self UTF8String]; |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
166 |
unsigned char result[16]; |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
167 |
CC_MD5( cStr, strlen(cStr), result ); |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
168 |
return [NSString stringWithFormat: |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
169 |
@"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
170 |
result[0], result[1], result[2], result[3], result[4], result[5], |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
171 |
result[6], result[7], result[8], result[9], result[10], result[11], |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
172 |
result[12], result[13], result[14], result[15]]; |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
173 |
} |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
174 |
|
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff
changeset
|
175 |
@end |