project_files/HedgewarsMobile/Classes/SquareButtonView.m
changeset 3697 d5b30d6373fc
parent 3547 02875b1145b7
child 3703 12d17c6e8855
equal deleted inserted replaced
3695:c11abf387a7d 3697:d5b30d6373fc
    30         self.colorArray = colors;
    30         self.colorArray = colors;
    31         [colors release];
    31         [colors release];
    32 
    32 
    33         // set the color to the first available one
    33         // set the color to the first available one
    34         [self nextColor];
    34         [self nextColor];
    35         
    35 
    36         // this makes the button round and nice with a border
    36         // this makes the button round and nice with a border
    37         [self.layer setCornerRadius:7.0f];
    37         [self.layer setCornerRadius:7.0f];
    38         [self.layer setMasksToBounds:YES];        
    38         [self.layer setMasksToBounds:YES];
    39         [self.layer setBorderWidth:2];
    39         [self.layer setBorderWidth:2];
    40         
    40 
    41         // this changes the color at button press
    41         // this changes the color at button press
    42         [self addTarget:self action:@selector(nextColor) forControlEvents:UIControlEventTouchUpInside];
    42         [self addTarget:self action:@selector(nextColor) forControlEvents:UIControlEventTouchUpInside];
    43     }
    43     }
    44     return self;
    44     return self;
    45 }
    45 }
    49 
    49 
    50     if (colorIndex >= [colorArray count])
    50     if (colorIndex >= [colorArray count])
    51         colorIndex = 0;
    51         colorIndex = 0;
    52 
    52 
    53     NSUInteger color = [[self.colorArray objectAtIndex:colorIndex] unsignedIntValue];
    53     NSUInteger color = [[self.colorArray objectAtIndex:colorIndex] unsignedIntValue];
    54     self.backgroundColor = [UIColor colorWithRed:((color & 0x00FF0000) >> 16)/255.0f 
    54     self.backgroundColor = [UIColor colorWithRed:((color & 0x00FF0000) >> 16)/255.0f
    55                                            green:((color & 0x0000FF00) >> 8)/255.0f 
    55                                            green:((color & 0x0000FF00) >> 8)/255.0f
    56                                             blue: (color & 0x000000FF)/255.0f 
    56                                             blue: (color & 0x000000FF)/255.0f
    57                                            alpha:1.0f];
    57                                            alpha:1.0f];
    58     
    58 
    59     [ownerDictionary setObject:[NSNumber numberWithInt:color] forKey:@"color"];
    59     [ownerDictionary setObject:[NSNumber numberWithInt:color] forKey:@"color"];
    60 }
    60 }
    61 
    61 
    62 -(void) selectColor:(NSUInteger) color {
    62 -(void) selectColor:(NSUInteger) color {
    63     if (color != selectedColor) {
    63     if (color != selectedColor) {
    64         selectedColor = color;
    64         selectedColor = color;
    65         colorIndex = [colorArray indexOfObject:[NSNumber numberWithUnsignedInt:color]];
    65         colorIndex = [colorArray indexOfObject:[NSNumber numberWithUnsignedInt:color]];
    66         
    66 
    67         self.backgroundColor = [UIColor colorWithRed:((color & 0x00FF0000) >> 16)/255.0f 
    67         self.backgroundColor = [UIColor colorWithRed:((color & 0x00FF0000) >> 16)/255.0f
    68                                                green:((color & 0x0000FF00) >> 8)/255.0f 
    68                                                green:((color & 0x0000FF00) >> 8)/255.0f
    69                                                 blue: (color & 0x000000FF)/255.0f 
    69                                                 blue: (color & 0x000000FF)/255.0f
    70                                                alpha:1.0f];
    70                                                alpha:1.0f];
    71     }
    71     }
    72 }
    72 }
    73 
    73 
    74 -(void) dealloc {
    74 -(void) dealloc {