project_files/HedgewarsMobile/Classes/ExtraCategories.m
author koda
Wed, 28 Mar 2012 00:42:57 +0200
changeset 6829 60b039d88dab
parent 6711 76e96101a84f
child 6832 fae8fd118da9
permissions -rw-r--r--
ios: use notifications instead of class methods (maybe tidier)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    17
 *
6700
e04da46ee43c the most important commit of the year
koda
parents: 6671
diff changeset
    18
 * File created on 25/10/2012.
6208
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
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    21
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    22
#import "ExtraCategories.h"
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    23
#import <QuartzCore/QuartzCore.h>
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    24
#import <CommonCrypto/CommonDigest.h>
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    25
6209
074ab6ebcb3e restore runtime compatibility with ios 3.2
koda
parents: 6208
diff changeset
    26
6300
db8fd3ff693c move two class files in a correct directory
koda
parents: 6210
diff changeset
    27
#pragma mark -
6209
074ab6ebcb3e restore runtime compatibility with ios 3.2
koda
parents: 6208
diff changeset
    28
@implementation UIScreen (safe)
074ab6ebcb3e restore runtime compatibility with ios 3.2
koda
parents: 6208
diff changeset
    29
074ab6ebcb3e restore runtime compatibility with ios 3.2
koda
parents: 6208
diff changeset
    30
-(CGFloat) safeScale {
074ab6ebcb3e restore runtime compatibility with ios 3.2
koda
parents: 6208
diff changeset
    31
    CGFloat theScale = 1.0f;
074ab6ebcb3e restore runtime compatibility with ios 3.2
koda
parents: 6208
diff changeset
    32
    if ([self respondsToSelector:@selector(scale)])
074ab6ebcb3e restore runtime compatibility with ios 3.2
koda
parents: 6208
diff changeset
    33
         theScale = [self scale];
074ab6ebcb3e restore runtime compatibility with ios 3.2
koda
parents: 6208
diff changeset
    34
    return theScale;
074ab6ebcb3e restore runtime compatibility with ios 3.2
koda
parents: 6208
diff changeset
    35
}
074ab6ebcb3e restore runtime compatibility with ios 3.2
koda
parents: 6208
diff changeset
    36
6615
65602f1ef0f8 more ios pages supporting rotaiton
koda
parents: 6300
diff changeset
    37
-(CGRect) safeBounds {
65602f1ef0f8 more ios pages supporting rotaiton
koda
parents: 6300
diff changeset
    38
    CGRect original = [self bounds];
6671
5532d5f6285c shorten the portait orientation check
koda
parents: 6670
diff changeset
    39
    if (IS_ON_PORTRAIT())
6615
65602f1ef0f8 more ios pages supporting rotaiton
koda
parents: 6300
diff changeset
    40
        return original;
6670
d57fa21781ea ios weapon setting page supports rotation
koda
parents: 6615
diff changeset
    41
    else
6615
65602f1ef0f8 more ios pages supporting rotaiton
koda
parents: 6300
diff changeset
    42
        return CGRectMake(original.origin.x, original.origin.y, original.size.height, original.size.width);
65602f1ef0f8 more ios pages supporting rotaiton
koda
parents: 6300
diff changeset
    43
}
65602f1ef0f8 more ios pages supporting rotaiton
koda
parents: 6300
diff changeset
    44
6209
074ab6ebcb3e restore runtime compatibility with ios 3.2
koda
parents: 6208
diff changeset
    45
@end
074ab6ebcb3e restore runtime compatibility with ios 3.2
koda
parents: 6208
diff changeset
    46
074ab6ebcb3e restore runtime compatibility with ios 3.2
koda
parents: 6208
diff changeset
    47
6300
db8fd3ff693c move two class files in a correct directory
koda
parents: 6210
diff changeset
    48
#pragma mark -
6208
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    49
@implementation UITableView (backgroundColor)
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    50
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    51
-(void) setBackgroundColorForAnyTable:(UIColor *) color {
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    52
    if ([self respondsToSelector:@selector(backgroundView)]) {
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    53
        UIView *backView = [[UIView alloc] initWithFrame:self.frame];
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    54
        backView.backgroundColor = color;
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    55
        self.backgroundView = backView;
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    56
        [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
    57
        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
    58
    } else
923c8414e3af fix runtime compability with ios 3.* (hopefully) and fix a small glitch in turning off music/sounds
koda
parents: 6209
diff changeset
    59
        self.backgroundColor = color;
6208
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
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    62
@end
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    63
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    64
6300
db8fd3ff693c move two class files in a correct directory
koda
parents: 6210
diff changeset
    65
#pragma mark -
6208
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    66
@implementation UIColor (HWColors)
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    67
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    68
+(UIColor *)darkYellowColor {
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    69
    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
    70
}
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    71
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    72
+(UIColor *)lightYellowColor {
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    73
    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
    74
}
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    75
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    76
+(UIColor *)darkBlueColor {
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    77
    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
    78
}
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    79
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    80
// 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
    81
+(UIColor *)darkBlueColorTransparent {
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    82
    return [UIColor colorWithRed:(CGFloat)0x0F/255
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    83
                           green:0
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    84
                            blue:(CGFloat)0x55/255
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    85
                           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
    86
}
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    87
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    88
+(UIColor *)blackColorTransparent {
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    89
    return [UIColor colorWithRed:0
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    90
                           green:0
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    91
                            blue:0
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    92
                           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
    93
}
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    94
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    95
@end
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    96
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    97
6300
db8fd3ff693c move two class files in a correct directory
koda
parents: 6210
diff changeset
    98
#pragma mark -
6711
76e96101a84f prepare a styled button
koda
parents: 6700
diff changeset
    99
@implementation UIButton (quickStyle)
76e96101a84f prepare a styled button
koda
parents: 6700
diff changeset
   100
76e96101a84f prepare a styled button
koda
parents: 6700
diff changeset
   101
-(id) initWithFrame:(CGRect) frame andTitle:(NSString *)title {
76e96101a84f prepare a styled button
koda
parents: 6700
diff changeset
   102
    [self initWithFrame:frame];
76e96101a84f prepare a styled button
koda
parents: 6700
diff changeset
   103
    [self setTitle:title forState:UIControlStateNormal];
76e96101a84f prepare a styled button
koda
parents: 6700
diff changeset
   104
    [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
76e96101a84f prepare a styled button
koda
parents: 6700
diff changeset
   105
    [self setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
76e96101a84f prepare a styled button
koda
parents: 6700
diff changeset
   106
    self.titleLabel.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]];
76e96101a84f prepare a styled button
koda
parents: 6700
diff changeset
   107
    self.backgroundColor = [UIColor blackColorTransparent];
76e96101a84f prepare a styled button
koda
parents: 6700
diff changeset
   108
76e96101a84f prepare a styled button
koda
parents: 6700
diff changeset
   109
    [self.layer setBorderWidth:1];
76e96101a84f prepare a styled button
koda
parents: 6700
diff changeset
   110
    [self.layer setBorderColor:[[UIColor darkYellowColor] CGColor]];
76e96101a84f prepare a styled button
koda
parents: 6700
diff changeset
   111
    [self.layer setCornerRadius:9.0f];
76e96101a84f prepare a styled button
koda
parents: 6700
diff changeset
   112
    [self.layer setMasksToBounds:YES];
76e96101a84f prepare a styled button
koda
parents: 6700
diff changeset
   113
76e96101a84f prepare a styled button
koda
parents: 6700
diff changeset
   114
    return self;
76e96101a84f prepare a styled button
koda
parents: 6700
diff changeset
   115
}
76e96101a84f prepare a styled button
koda
parents: 6700
diff changeset
   116
76e96101a84f prepare a styled button
koda
parents: 6700
diff changeset
   117
@end
76e96101a84f prepare a styled button
koda
parents: 6700
diff changeset
   118
76e96101a84f prepare a styled button
koda
parents: 6700
diff changeset
   119
76e96101a84f prepare a styled button
koda
parents: 6700
diff changeset
   120
#pragma mark -
6208
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   121
@implementation UILabel (quickStyle)
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   122
6711
76e96101a84f prepare a styled button
koda
parents: 6700
diff changeset
   123
-(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
   124
    return [self initWithFrame:frame
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   125
                      andTitle:title
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   126
               withBorderWidth:1.5f
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   127
               withBorderColor:[UIColor darkYellowColor]
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   128
           withBackgroundColor:[UIColor darkBlueColor]];
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   129
}
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   130
6711
76e96101a84f prepare a styled button
koda
parents: 6700
diff changeset
   131
-(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
   132
    return [self initWithFrame:frame
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   133
                      andTitle:title
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   134
               withBorderWidth:borderWidth
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   135
               withBorderColor:[UIColor darkYellowColor]
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   136
           withBackgroundColor:[UIColor darkBlueColorTransparent]];
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   137
}
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   138
6711
76e96101a84f prepare a styled button
koda
parents: 6700
diff changeset
   139
-(id) initWithFrame:(CGRect)frame andTitle:(NSString *)title withBorderWidth:(CGFloat) borderWidth
76e96101a84f prepare a styled button
koda
parents: 6700
diff changeset
   140
          withBorderColor:(UIColor *)borderColor withBackgroundColor:(UIColor *)backColor {
6208
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   141
    UILabel *theLabel = [self initWithFrame:frame];
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   142
    theLabel.backgroundColor = backColor;
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   143
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   144
    if (title != nil) {
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   145
        theLabel.text = title;
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   146
        theLabel.textColor = [UIColor lightYellowColor];
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   147
        theLabel.textAlignment = UITextAlignmentCenter;
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   148
        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
   149
    }
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   150
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   151
    [theLabel.layer setBorderWidth:borderWidth];
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   152
    [theLabel.layer setBorderColor:borderColor.CGColor];
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   153
    [theLabel.layer setCornerRadius:8.0f];
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   154
    [theLabel.layer setMasksToBounds:YES];
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   155
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   156
    return theLabel;
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
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   159
@end
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   160
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   161
6300
db8fd3ff693c move two class files in a correct directory
koda
parents: 6210
diff changeset
   162
#pragma mark -
6208
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   163
@implementation NSString (MD5)
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   164
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   165
-(NSString *)MD5hash {
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   166
    const char *cStr = [self UTF8String];
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   167
    unsigned char result[16];
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   168
    CC_MD5( cStr, strlen(cStr), result );
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   169
    return [NSString stringWithFormat:
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   170
            @"%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
   171
            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
   172
            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
   173
            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
   174
}
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   175
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   176
@end