2015-10-26 22:26:34 -04:00
|
|
|
#import "VirtualPadButton.h"
|
|
|
|
|
|
|
|
@implementation VirtualPadButton
|
|
|
|
|
2020-12-02 18:37:31 -05:00
|
|
|
- (void)draw:(CGContextRef)context
|
2015-10-26 22:26:34 -04:00
|
|
|
{
|
2020-12-02 18:37:31 -05:00
|
|
|
[self.image drawInRect:self.bounds];
|
2015-10-26 22:26:34 -04:00
|
|
|
if(self.pressed)
|
|
|
|
{
|
2015-10-31 19:20:10 -04:00
|
|
|
CGContextSaveGState(context);
|
|
|
|
CGContextSetBlendMode(context, kCGBlendModePlusDarker);
|
2020-12-02 18:37:31 -05:00
|
|
|
[self.image drawInRect:self.bounds];
|
2015-10-31 19:20:10 -04:00
|
|
|
CGContextRestoreGState(context);
|
2015-10-26 22:26:34 -04:00
|
|
|
}
|
2020-12-02 18:37:31 -05:00
|
|
|
|
2015-10-31 19:20:10 -04:00
|
|
|
if([self.caption length] != 0)
|
2015-10-26 22:26:34 -04:00
|
|
|
{
|
2020-12-02 18:37:31 -05:00
|
|
|
NSMutableParagraphStyle* paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
|
2015-10-31 19:20:10 -04:00
|
|
|
paragraphStyle.alignment = NSTextAlignmentCenter;
|
|
|
|
NSDictionary* attributes =
|
2020-12-02 18:37:31 -05:00
|
|
|
@{
|
|
|
|
NSParagraphStyleAttributeName : paragraphStyle,
|
|
|
|
NSForegroundColorAttributeName : [UIColor whiteColor]
|
|
|
|
};
|
|
|
|
|
|
|
|
CGSize textSize = [self.caption sizeWithAttributes:attributes];
|
2015-10-31 19:20:10 -04:00
|
|
|
CGRect textRect = CGRectOffset(self.bounds, 0, (self.bounds.size.height - textSize.height) / 2);
|
2020-12-02 18:37:31 -05:00
|
|
|
|
|
|
|
[self.caption drawInRect:textRect withAttributes:attributes];
|
2015-10-26 22:26:34 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-02 18:37:31 -05:00
|
|
|
- (void)onPointerDown:(CGPoint)position
|
2015-10-26 22:26:34 -04:00
|
|
|
{
|
|
|
|
self.pressed = YES;
|
|
|
|
self.padHandler->SetButtonState(self.code, true);
|
2020-12-02 18:37:31 -05:00
|
|
|
[super onPointerDown:position];
|
2015-10-26 22:26:34 -04:00
|
|
|
}
|
|
|
|
|
2020-12-02 18:37:31 -05:00
|
|
|
- (void)onPointerUp
|
2015-10-26 22:26:34 -04:00
|
|
|
{
|
|
|
|
self.pressed = NO;
|
|
|
|
self.padHandler->SetButtonState(self.code, false);
|
|
|
|
[super onPointerUp];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|