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