Created
September 9, 2008 17:28
-
-
Save boucher/9714 to your computer and use it in GitHub Desktop.
checkbox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var checkboxImage, | |
checkboxAlternateImage, | |
checkboxCheckedImage, | |
checkboxCheckedAlternateImage; | |
@implementation CheckboxButton : CPButton | |
{ | |
BOOL _isChecked; | |
} | |
+ (void)initialize | |
{ | |
checkboxImage = [[CPImage alloc] initWithContentsOfFile: "Resources/Checkbox/checkbox.png" size: CPSizeMake(14, 15)], | |
checkboxAlternateImage = [[CPImage alloc] initWithContentsOfFile: "Resources/Checkbox/checkbox_h.png" size: CPSizeMake(14, 15)], | |
checkboxCheckedImage = [[CPImage alloc] initWithContentsOfFile: "Resources/Checkbox/checkbox_checked.png" size: CPSizeMake(14, 15)], | |
checkboxCheckedAlternateImage = [[CPImage alloc] initWithContentsOfFile: "Resources/Checkbox/checkbox_checked_h.png" size: CPSizeMake(14, 15)]; | |
} | |
- (id)initWithFrame:(CPRect)frame | |
{ | |
self = [super initWithFrame: frame]; | |
_isChecked = false; | |
[self setTitle:@"_"]; | |
[self setBordered:NO]; | |
// FIXME: No! | |
[_imageAndTitleView._titleField setLineBreakMode: CPLineBreakByWordWrapping]; | |
[self setImage: checkboxImage]; | |
[self setAlternateImage: checkboxAlternateImage]; | |
[self setImagePosition: CPImageLeft]; | |
[self setAlignment:CPLeftTextAlignment]; | |
return self; | |
} | |
- (void)mouseUp:(CPEvent)anEvent | |
{ | |
[super mouseUp: anEvent]; | |
[self setChecked: !_isChecked]; | |
} | |
- (BOOL)isChecked | |
{ | |
return _isChecked; | |
} | |
- (void)setChecked:(BOOL)flag | |
{ | |
_isChecked = flag; | |
if(_isChecked) | |
{ | |
[self setImage: checkboxCheckedImage]; | |
[self setAlternateImage: checkboxCheckedAlternateImage]; | |
} | |
else | |
{ | |
[self setImage: checkboxImage]; | |
[self setAlternateImage: checkboxAlternateImage]; | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment