Implement ABXY swap for on-screen controls

This commit is contained in:
Cameron Gutman
2022-07-21 20:54:57 -05:00
parent a80fa5cfbb
commit 6678488edc
3 changed files with 20 additions and 11 deletions

View File

@@ -9,6 +9,7 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
@class ControllerSupport; @class ControllerSupport;
@class StreamConfiguration;
@interface OnScreenControls : NSObject @interface OnScreenControls : NSObject
@@ -24,7 +25,7 @@ typedef NS_ENUM(NSInteger, OnScreenControlsLevel) {
OnScreenControlsLevelAutoGCExtendedGamepadWithStickButtons OnScreenControlsLevelAutoGCExtendedGamepadWithStickButtons
}; };
- (id) initWithView:(UIView*)view controllerSup:(ControllerSupport*)controllerSupport; - (id) initWithView:(UIView*)view controllerSup:(ControllerSupport*)controllerSupport streamConfig:(StreamConfiguration*)streamConfig;
- (BOOL) handleTouchDownEvent:(NSSet*)touches; - (BOOL) handleTouchDownEvent:(NSSet*)touches;
- (BOOL) handleTouchUpEvent:(NSSet*)touches; - (BOOL) handleTouchUpEvent:(NSSet*)touches;
- (BOOL) handleTouchMovedEvent:(NSSet*)touches; - (BOOL) handleTouchMovedEvent:(NSSet*)touches;

View File

@@ -68,6 +68,7 @@
ControllerSupport *_controllerSupport; ControllerSupport *_controllerSupport;
Controller *_controller; Controller *_controller;
NSMutableArray* _deadTouches; NSMutableArray* _deadTouches;
BOOL _swapABXY;
} }
static const float EDGE_WIDTH = .05; static const float EDGE_WIDTH = .05;
@@ -111,12 +112,13 @@ static float L2_Y;
static float L3_X; static float L3_X;
static float L3_Y; static float L3_Y;
- (id) initWithView:(UIView*)view controllerSup:(ControllerSupport*)controllerSupport { - (id) initWithView:(UIView*)view controllerSup:(ControllerSupport*)controllerSupport streamConfig:(StreamConfiguration*)streamConfig {
self = [self init]; self = [self init];
_view = view; _view = view;
_controllerSupport = controllerSupport; _controllerSupport = controllerSupport;
_controller = [controllerSupport getOscController]; _controller = [controllerSupport getOscController];
_deadTouches = [[NSMutableArray alloc] init]; _deadTouches = [[NSMutableArray alloc] init];
_swapABXY = streamConfig.swapABXYButtons;
_iPad = ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad); _iPad = ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad);
_controlArea = CGRectMake(0, 0, _view.frame.size.width, _view.frame.size.height); _controlArea = CGRectMake(0, 0, _view.frame.size.width, _view.frame.size.height);
@@ -372,27 +374,33 @@ static float L3_Y;
} }
- (void) drawButtons { - (void) drawButtons {
// create A button
UIImage* aButtonImage = [UIImage imageNamed:@"AButton"]; UIImage* aButtonImage = [UIImage imageNamed:@"AButton"];
UIImage* bButtonImage = [UIImage imageNamed:@"BButton"];
UIImage* xButtonImage = [UIImage imageNamed:@"XButton"];
UIImage* yButtonImage = [UIImage imageNamed:@"YButton"];
CGRect aButtonFrame = CGRectMake(BUTTON_CENTER_X - aButtonImage.size.width / 2, BUTTON_CENTER_Y + BUTTON_DIST, aButtonImage.size.width, aButtonImage.size.height);
CGRect bButtonFrame = CGRectMake(BUTTON_CENTER_X + BUTTON_DIST, BUTTON_CENTER_Y - bButtonImage.size.height / 2, bButtonImage.size.width, bButtonImage.size.height);
CGRect xButtonFrame = CGRectMake(BUTTON_CENTER_X - BUTTON_DIST - xButtonImage.size.width, BUTTON_CENTER_Y - xButtonImage.size.height/ 2, xButtonImage.size.width, xButtonImage.size.height);
CGRect yButtonFrame = CGRectMake(BUTTON_CENTER_X - yButtonImage.size.width / 2, BUTTON_CENTER_Y - BUTTON_DIST - yButtonImage.size.height, yButtonImage.size.width, yButtonImage.size.height);
// create A button
_aButton.contents = (id) aButtonImage.CGImage; _aButton.contents = (id) aButtonImage.CGImage;
_aButton.frame = CGRectMake(BUTTON_CENTER_X - aButtonImage.size.width / 2, BUTTON_CENTER_Y + BUTTON_DIST, aButtonImage.size.width, aButtonImage.size.height); _aButton.frame = _swapABXY ? bButtonFrame : aButtonFrame;
[_view.layer addSublayer:_aButton]; [_view.layer addSublayer:_aButton];
// create B button // create B button
UIImage* bButtonImage = [UIImage imageNamed:@"BButton"]; _bButton.frame = _swapABXY ? aButtonFrame : bButtonFrame;
_bButton.frame = CGRectMake(BUTTON_CENTER_X + BUTTON_DIST, BUTTON_CENTER_Y - bButtonImage.size.height / 2, bButtonImage.size.width, bButtonImage.size.height);
_bButton.contents = (id) bButtonImage.CGImage; _bButton.contents = (id) bButtonImage.CGImage;
[_view.layer addSublayer:_bButton]; [_view.layer addSublayer:_bButton];
// create X Button // create X Button
UIImage* xButtonImage = [UIImage imageNamed:@"XButton"]; _xButton.frame = _swapABXY ? yButtonFrame : xButtonFrame;
_xButton.frame = CGRectMake(BUTTON_CENTER_X - BUTTON_DIST - xButtonImage.size.width, BUTTON_CENTER_Y - xButtonImage.size.height/ 2, xButtonImage.size.width, xButtonImage.size.height);
_xButton.contents = (id) xButtonImage.CGImage; _xButton.contents = (id) xButtonImage.CGImage;
[_view.layer addSublayer:_xButton]; [_view.layer addSublayer:_xButton];
// create Y Button // create Y Button
UIImage* yButtonImage = [UIImage imageNamed:@"YButton"]; _yButton.frame = _swapABXY ? xButtonFrame : yButtonFrame;
_yButton.frame = CGRectMake(BUTTON_CENTER_X - yButtonImage.size.width / 2, BUTTON_CENTER_Y - BUTTON_DIST - yButtonImage.size.height, yButtonImage.size.width, yButtonImage.size.height);
_yButton.contents = (id) yButtonImage.CGImage; _yButton.contents = (id) yButtonImage.CGImage;
[_view.layer addSublayer:_yButton]; [_view.layer addSublayer:_yButton];

View File

@@ -71,7 +71,7 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
self->touchHandler = [[RelativeTouchHandler alloc] initWithView:self]; self->touchHandler = [[RelativeTouchHandler alloc] initWithView:self];
} }
onScreenControls = [[OnScreenControls alloc] initWithView:self controllerSup:controllerSupport]; onScreenControls = [[OnScreenControls alloc] initWithView:self controllerSup:controllerSupport streamConfig:streamConfig];
OnScreenControlsLevel level = (OnScreenControlsLevel)[settings.onscreenControls integerValue]; OnScreenControlsLevel level = (OnScreenControlsLevel)[settings.onscreenControls integerValue];
if (settings.absoluteTouchMode) { if (settings.absoluteTouchMode) {
Log(LOG_I, @"On-screen controls disabled in absolute touch mode"); Log(LOG_I, @"On-screen controls disabled in absolute touch mode");