project_files/HedgewarsMobile/ExtraCategories.m
author koda
Wed, 26 Oct 2011 01:17:44 +0200
changeset 6210 923c8414e3af
parent 6209 074ab6ebcb3e
permissions -rw-r--r--
fix runtime compability with ios 3.* (hopefully) and fix a small glitch in turning off music/sounds
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
 *
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    18
 * File created on 25/10/2011.
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
074ab6ebcb3e restore runtime compatibility with ios 3.2
koda
parents: 6208
diff changeset
    27
@implementation UIScreen (safe)
074ab6ebcb3e restore runtime compatibility with ios 3.2
koda
parents: 6208
diff changeset
    28
074ab6ebcb3e restore runtime compatibility with ios 3.2
koda
parents: 6208
diff changeset
    29
-(CGFloat) safeScale {
074ab6ebcb3e restore runtime compatibility with ios 3.2
koda
parents: 6208
diff changeset
    30
    CGFloat theScale = 1.0f;
074ab6ebcb3e restore runtime compatibility with ios 3.2
koda
parents: 6208
diff changeset
    31
    if ([self respondsToSelector:@selector(scale)])
074ab6ebcb3e restore runtime compatibility with ios 3.2
koda
parents: 6208
diff changeset
    32
         theScale = [self scale];
074ab6ebcb3e restore runtime compatibility with ios 3.2
koda
parents: 6208
diff changeset
    33
    return theScale;
074ab6ebcb3e restore runtime compatibility with ios 3.2
koda
parents: 6208
diff changeset
    34
}
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
@end
074ab6ebcb3e restore runtime compatibility with ios 3.2
koda
parents: 6208
diff changeset
    37
074ab6ebcb3e restore runtime compatibility with ios 3.2
koda
parents: 6208
diff changeset
    38
6208
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    39
@implementation UITableView (backgroundColor)
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    40
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    41
-(void) setBackgroundColorForAnyTable:(UIColor *) color {
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    42
    if ([self respondsToSelector:@selector(backgroundView)]) {
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    43
        UIView *backView = [[UIView alloc] initWithFrame:self.frame];
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    44
        backView.backgroundColor = color;
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    45
        self.backgroundView = backView;
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    46
        [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
    47
        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
    48
    } else
923c8414e3af fix runtime compability with ios 3.* (hopefully) and fix a small glitch in turning off music/sounds
koda
parents: 6209
diff changeset
    49
        self.backgroundColor = color;
6208
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
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    52
@end
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    53
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    54
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    55
@implementation UIColor (HWColors)
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    56
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    57
+(UIColor *)darkYellowColor {
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    58
    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
    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
+(UIColor *)lightYellowColor {
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    62
    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
    63
}
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    64
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    65
+(UIColor *)darkBlueColor {
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    66
    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
    67
}
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    68
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    69
// 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
    70
+(UIColor *)darkBlueColorTransparent {
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    71
    return [UIColor colorWithRed:(CGFloat)0x0F/255
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    72
                           green:0
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    73
                            blue:(CGFloat)0x55/255
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    74
                           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
    75
}
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    76
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    77
+(UIColor *)blackColorTransparent {
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    78
    return [UIColor colorWithRed:0
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    79
                           green:0
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    80
                            blue:0
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    81
                           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
    82
}
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    83
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    84
@end
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
@implementation UILabel (quickStyle)
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    88
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    89
-(UILabel *)initWithFrame:(CGRect)frame andTitle:(NSString *)title {
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    90
    return [self initWithFrame:frame
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    91
                      andTitle:title
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    92
               withBorderWidth:1.5f
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    93
               withBorderColor:[UIColor darkYellowColor]
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    94
           withBackgroundColor:[UIColor darkBlueColor]];
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
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    97
-(UILabel *)initWithFrame:(CGRect)frame andTitle:(NSString *)title  withBorderWidth:(CGFloat) borderWidth {
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    98
    return [self initWithFrame:frame
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
    99
                      andTitle:title
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   100
               withBorderWidth:borderWidth
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   101
               withBorderColor:[UIColor darkYellowColor]
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   102
           withBackgroundColor:[UIColor darkBlueColorTransparent]];
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   103
}
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   104
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   105
-(UILabel *)initWithFrame:(CGRect)frame andTitle:(NSString *)title  withBorderWidth:(CGFloat) borderWidth
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   106
          withBorderColor:(UIColor *)borderColor withBackgroundColor:(UIColor *)backColor{
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   107
    UILabel *theLabel = [self initWithFrame:frame];
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   108
    theLabel.backgroundColor = backColor;
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   109
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   110
    if (title != nil) {
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   111
        theLabel.text = title;
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   112
        theLabel.textColor = [UIColor lightYellowColor];
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   113
        theLabel.textAlignment = UITextAlignmentCenter;
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   114
        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
   115
    }
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   116
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   117
    [theLabel.layer setBorderWidth:borderWidth];
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   118
    [theLabel.layer setBorderColor:borderColor.CGColor];
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   119
    [theLabel.layer setCornerRadius:8.0f];
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   120
    [theLabel.layer setMasksToBounds:YES];
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   121
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   122
    return theLabel;
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   123
}
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   124
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   125
@end
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   126
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   127
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   128
@implementation NSString (MD5)
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
-(NSString *)MD5hash {
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   131
    const char *cStr = [self UTF8String];
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   132
    unsigned char result[16];
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   133
    CC_MD5( cStr, strlen(cStr), result );
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   134
    return [NSString stringWithFormat:
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   135
            @"%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
   136
            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
   137
            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
   138
            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
   139
}
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   140
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents:
diff changeset
   141
@end