project_files/HedgewarsMobile/Classes/MapPreviewButtonView.m
changeset 6109 f6726ec81e64
parent 6078 8c0cc07731e5
child 6115 485cfecadc9a
equal deleted inserted replaced
6108:7a8da11a6144 6109:f6726ec81e64
    22 #import "MapPreviewButtonView.h"
    22 #import "MapPreviewButtonView.h"
    23 #import "MapConfigViewController.h"
    23 #import "MapConfigViewController.h"
    24 #import "UIImageExtra.h"
    24 #import "UIImageExtra.h"
    25 #import "ServerSetup.h"
    25 #import "ServerSetup.h"
    26 #import <pthread.h>
    26 #import <pthread.h>
       
    27 #import <QuartzCore/QuartzCore.h>
       
    28 
    27 
    29 
    28 #define INDICATOR_TAG 7654
    30 #define INDICATOR_TAG 7654
    29 
    31 
    30 @implementation MapPreviewButtonView
    32 @implementation MapPreviewButtonView
    31 @synthesize delegate;
    33 @synthesize delegate;
    32 
    34 
    33 -(id) initWithFrame:(CGRect)frame {
    35 -(id) initWithFrame:(CGRect)frame {
    34     if ((self = [super initWithFrame:frame])) {
    36     if ((self = [super initWithFrame:frame])) {
    35         delegate = nil;
    37         delegate = nil;
    36         [self setBackgroundImageRounded:[UIImage whiteImage:frame.size] forState:UIControlStateNormal];
    38         self.backgroundColor = [UIColor whiteColor];
    37     }
    39         self.layer.cornerRadius = 12;
    38     return self;
       
    39 }
       
    40 
       
    41 -(id) initWithCoder:(NSCoder *)aDecoder {
       
    42     if ((self = [super initWithCoder:aDecoder])) {
       
    43         delegate = nil;
       
    44         [self setBackgroundImageRounded:[UIImage whiteImage:self.frame.size] forState:UIControlStateNormal];
       
    45     }
    40     }
    46     return self;
    41     return self;
    47 }
    42 }
    48 
    43 
    49 -(void) dealloc {
    44 -(void) dealloc {
    51     [super dealloc];
    46     [super dealloc];
    52 }
    47 }
    53 
    48 
    54 #pragma mark -
    49 #pragma mark -
    55 #pragma mark image wrappers
    50 #pragma mark image wrappers
    56 -(void) setBackgroundImageRounded:(UIImage *)image forState:(UIControlState)state {
    51 -(void) setImageRounded:(UIImage *)image forState:(UIControlState)controlState {
    57     // TODO:http://stackoverflow.com/questions/4272476/setbackgroundimage-behaviour-changed-on-ipad-4-2
    52     [self setImage:[image makeRoundCornersOfSize:CGSizeMake(12, 12)] forState:controlState];
    58     [self setBackgroundImage:[image makeRoundCornersOfSize:CGSizeMake(12, 12)] forState:state];
    53 }
    59 }
    54 
    60 
    55 -(void) setImageRounded:(UIImage *)image {
    61 -(void) setImageRounded:(UIImage *)image forState:(UIControlState)state {
       
    62     [self setImage:[image makeRoundCornersOfSize:CGSizeMake(12, 12)] forState:state];
       
    63 }
       
    64 
       
    65 -(void) setImageRoundedForNormalState:(UIImage *)image {
       
    66     [self setImageRounded:image forState:UIControlStateNormal];
    56     [self setImageRounded:image forState:UIControlStateNormal];
    67 }
    57 }
    68 
    58 
    69 #pragma mark -
    59 #pragma mark -
    70 #pragma mark preview 
    60 #pragma mark preview 
   161     UIImage *previewImage = [[UIImage alloc] initWithCGImage:previewCGImage];
   151     UIImage *previewImage = [[UIImage alloc] initWithCGImage:previewCGImage];
   162     CGImageRelease(previewCGImage);
   152     CGImageRelease(previewCGImage);
   163     previewCGImage = nil;
   153     previewCGImage = nil;
   164 
   154 
   165     // all these are performed on the main thread to prevent a leak
   155     // all these are performed on the main thread to prevent a leak
   166     [self performSelectorOnMainThread:@selector(setImageRoundedForNormalState:)
   156     [self performSelectorOnMainThread:@selector(setImageRounded:)
   167                            withObject:previewImage
   157                            withObject:previewImage
   168                         waitUntilDone:NO];
   158                         waitUntilDone:NO];
   169     [previewImage release];
   159     [previewImage release];
   170     [self performSelectorOnMainThread:@selector(setLabelText:)
   160     [self performSelectorOnMainThread:@selector(setLabelText:)
   171                            withObject:[NSString stringWithFormat:@"%d", maxHogs]
   161                            withObject:[NSString stringWithFormat:@"%d", maxHogs]