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