project_files/HedgewarsMobile/Classes/ExtraCategories.m
changeset 6300 db8fd3ff693c
parent 6210 923c8414e3af
child 6615 65602f1ef0f8
equal deleted inserted replaced
6299:fa5bc796261d 6300:db8fd3ff693c
       
     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 25/10/2011.
       
    19  */
       
    20 
       
    21 
       
    22 #import "ExtraCategories.h"
       
    23 #import <QuartzCore/QuartzCore.h>
       
    24 #import <CommonCrypto/CommonDigest.h>
       
    25 
       
    26 
       
    27 #pragma mark -
       
    28 @implementation UIScreen (safe)
       
    29 
       
    30 -(CGFloat) safeScale {
       
    31     CGFloat theScale = 1.0f;
       
    32     if ([self respondsToSelector:@selector(scale)])
       
    33          theScale = [self scale];
       
    34     return theScale;
       
    35 }
       
    36 
       
    37 @end
       
    38 
       
    39 
       
    40 #pragma mark -
       
    41 @implementation UITableView (backgroundColor)
       
    42 
       
    43 -(void) setBackgroundColorForAnyTable:(UIColor *) color {
       
    44     if ([self respondsToSelector:@selector(backgroundView)]) {
       
    45         UIView *backView = [[UIView alloc] initWithFrame:self.frame];
       
    46         backView.backgroundColor = color;
       
    47         self.backgroundView = backView;
       
    48         [backView release];
       
    49         self.backgroundColor = [UIColor clearColor];
       
    50     } else
       
    51         self.backgroundColor = color;
       
    52 }
       
    53 
       
    54 @end
       
    55 
       
    56 
       
    57 #pragma mark -
       
    58 @implementation UIColor (HWColors)
       
    59 
       
    60 +(UIColor *)darkYellowColor {
       
    61     return [UIColor colorWithRed:(CGFloat)0xFE/255 green:(CGFloat)0xC0/255 blue:0 alpha:1];
       
    62 }
       
    63 
       
    64 +(UIColor *)lightYellowColor {
       
    65     return [UIColor colorWithRed:(CGFloat)0xF0/255 green:(CGFloat)0xD0/255 blue:0 alpha:1];
       
    66 }
       
    67 
       
    68 +(UIColor *)darkBlueColor {
       
    69     return [UIColor colorWithRed:(CGFloat)0x0F/255 green:0 blue:(CGFloat)0x42/255 alpha:1];
       
    70 }
       
    71 
       
    72 // older devices don't get any transparency for performance reasons
       
    73 +(UIColor *)darkBlueColorTransparent {
       
    74     return [UIColor colorWithRed:(CGFloat)0x0F/255
       
    75                            green:0
       
    76                             blue:(CGFloat)0x55/255
       
    77                            alpha:IS_NOT_POWERFUL([HWUtils modelType]) ? 1 : 0.6f];
       
    78 }
       
    79 
       
    80 +(UIColor *)blackColorTransparent {
       
    81     return [UIColor colorWithRed:0
       
    82                            green:0
       
    83                             blue:0
       
    84                            alpha:IS_NOT_POWERFUL([HWUtils modelType]) ? 1 : 0.65f];
       
    85 }
       
    86 
       
    87 @end
       
    88 
       
    89 
       
    90 #pragma mark -
       
    91 @implementation UILabel (quickStyle)
       
    92 
       
    93 -(UILabel *)initWithFrame:(CGRect)frame andTitle:(NSString *)title {
       
    94     return [self initWithFrame:frame
       
    95                       andTitle:title
       
    96                withBorderWidth:1.5f
       
    97                withBorderColor:[UIColor darkYellowColor]
       
    98            withBackgroundColor:[UIColor darkBlueColor]];
       
    99 }
       
   100 
       
   101 -(UILabel *)initWithFrame:(CGRect)frame andTitle:(NSString *)title  withBorderWidth:(CGFloat) borderWidth {
       
   102     return [self initWithFrame:frame
       
   103                       andTitle:title
       
   104                withBorderWidth:borderWidth
       
   105                withBorderColor:[UIColor darkYellowColor]
       
   106            withBackgroundColor:[UIColor darkBlueColorTransparent]];
       
   107 }
       
   108 
       
   109 -(UILabel *)initWithFrame:(CGRect)frame andTitle:(NSString *)title  withBorderWidth:(CGFloat) borderWidth
       
   110           withBorderColor:(UIColor *)borderColor withBackgroundColor:(UIColor *)backColor{
       
   111     UILabel *theLabel = [self initWithFrame:frame];
       
   112     theLabel.backgroundColor = backColor;
       
   113 
       
   114     if (title != nil) {
       
   115         theLabel.text = title;
       
   116         theLabel.textColor = [UIColor lightYellowColor];
       
   117         theLabel.textAlignment = UITextAlignmentCenter;
       
   118         theLabel.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]*80/100];
       
   119     }
       
   120 
       
   121     [theLabel.layer setBorderWidth:borderWidth];
       
   122     [theLabel.layer setBorderColor:borderColor.CGColor];
       
   123     [theLabel.layer setCornerRadius:8.0f];
       
   124     [theLabel.layer setMasksToBounds:YES];
       
   125 
       
   126     return theLabel;
       
   127 }
       
   128 
       
   129 @end
       
   130 
       
   131 
       
   132 #pragma mark -
       
   133 @implementation NSString (MD5)
       
   134 
       
   135 -(NSString *)MD5hash {
       
   136     const char *cStr = [self UTF8String];
       
   137     unsigned char result[16];
       
   138     CC_MD5( cStr, strlen(cStr), result );
       
   139     return [NSString stringWithFormat:
       
   140             @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
       
   141             result[0], result[1], result[2], result[3], result[4], result[5],
       
   142             result[6], result[7], result[8], result[9], result[10], result[11],
       
   143             result[12], result[13], result[14], result[15]];
       
   144 }
       
   145 
       
   146 @end