Play-/Source/ui_ios/VirtualPadButton.mm
Jean-Philip Desjardins 95da46c153 Code style fixes.
2020-12-07 10:44:04 -05:00

47 lines
1.2 KiB
Text

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