Play-/Source/ui_ios/VirtualPadButton.mm

48 lines
1.2 KiB
Text
Raw Permalink Normal View History

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)
{
CGContextSaveGState(context);
CGContextSetBlendMode(context, kCGBlendModePlusDarker);
2020-12-02 18:37:31 -05:00
[self.image drawInRect:self.bounds];
CGContextRestoreGState(context);
2015-10-26 22:26:34 -04:00
}
2020-12-02 18:37:31 -05: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];
paragraphStyle.alignment = NSTextAlignmentCenter;
NSDictionary* attributes =
2020-12-02 18:37:31 -05:00
@{
NSParagraphStyleAttributeName : paragraphStyle,
NSForegroundColorAttributeName : [UIColor whiteColor]
};
CGSize textSize = [self.caption sizeWithAttributes:attributes];
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