Play-/Source/ui_ios/VirtualPadStick.mm

43 lines
1.1 KiB
Text
Raw Permalink Normal View History

2015-10-26 22:26:34 -04:00
#import "VirtualPadStick.h"
@implementation VirtualPadStick
2020-12-02 18:37:31 -05:00
- (void)draw:(CGContextRef)context
2015-10-26 22:26:34 -04:00
{
2015-10-27 10:29:11 -04:00
auto offsetBounds = CGRectOffset(self.bounds, self.offset.x, self.offset.y);
2020-12-02 18:37:31 -05:00
[self.image drawInRect:offsetBounds];
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
{
2015-10-27 10:29:11 -04:00
self.pressPosition = position;
self.offset = CGPointMake(0, 0);
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)onPointerMove:(CGPoint)position
2015-10-27 10:29:11 -04:00
{
float radius = self.bounds.size.width;
float offsetX = position.x - self.pressPosition.x;
float offsetY = position.y - self.pressPosition.y;
2020-12-02 18:37:31 -05:00
offsetX = std::min<float>(offsetX, radius);
2015-10-27 10:29:11 -04:00
offsetX = std::max<float>(offsetX, -radius);
2020-12-02 18:37:31 -05:00
offsetY = std::min<float>(offsetY, radius);
2015-10-27 10:29:11 -04:00
offsetY = std::max<float>(offsetY, -radius);
self.offset = CGPointMake(offsetX, offsetY);
self.padHandler->SetAxisState(self.codeX, offsetX / radius);
self.padHandler->SetAxisState(self.codeY, offsetY / radius);
2020-12-02 18:37:31 -05:00
[super onPointerMove:position];
2015-10-27 10:29:11 -04:00
}
2020-12-02 18:37:31 -05:00
- (void)onPointerUp
2015-10-26 22:26:34 -04:00
{
2015-10-27 10:29:11 -04:00
self.pressPosition = CGPointMake(0, 0);
self.offset = CGPointMake(0, 0);
self.padHandler->SetAxisState(self.codeX, 0);
self.padHandler->SetAxisState(self.codeY, 0);
2015-10-26 22:26:34 -04:00
[super onPointerUp];
}
@end