From a791f7e621e34a0f0bdafbc18fa108a5e4ad228e Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 6 Apr 2024 15:16:41 +0300 Subject: [PATCH] Add an option to enable single-touch A+B combo in iOS, closes #587 --- iOS/GBBackgroundView.m | 4 ++++ iOS/GBHorizontalLayout.m | 3 +++ iOS/GBLayout.h | 2 ++ iOS/GBSettingsViewController.m | 6 ++++++ iOS/GBVerticalLayout.m | 2 ++ 5 files changed, 17 insertions(+) diff --git a/iOS/GBBackgroundView.m b/iOS/GBBackgroundView.m index 63e4fb2d4..05cdc2209 100644 --- a/iOS/GBBackgroundView.m +++ b/iOS/GBBackgroundView.m @@ -332,6 +332,10 @@ static GB_key_mask_t angleToKeyMask(double angle) else if (CGPointSquaredDistance(point, _layout.selectLocation) <= buttonRadiusSquared) { mask |= GB_KEY_SELECT_MASK; } + else if ([[NSUserDefaults standardUserDefaults] boolForKey:@"GBEnableABCombo"] && + CGPointSquaredDistance(point, _layout.abComboLocation) <= buttonRadiusSquared) { + mask |= GB_KEY_A_MASK | GB_KEY_B_MASK; + } else if (!dpadHandled && fabs(point.x - _layout.dpadLocation.x) <= dpadRadius && fabs(point.y - _layout.dpadLocation.y) <= dpadRadius) { diff --git a/iOS/GBHorizontalLayout.m b/iOS/GBHorizontalLayout.m index 4f8dd33e7..94891eb6a 100644 --- a/iOS/GBHorizontalLayout.m +++ b/iOS/GBHorizontalLayout.m @@ -85,6 +85,9 @@ self.bLocation = (CGPoint){self.bLocation.x + self.cutout, self.bLocation.y}; self.startLocation = (CGPoint){self.startLocation.x + self.cutout, self.startLocation.y}; self.selectLocation = (CGPoint){self.selectLocation.x + self.cutout, self.selectLocation.y}; + self.abComboLocation = (CGPoint){(self.aLocation.x + self.bLocation.x) / 2, + (self.aLocation.y + self.bLocation.y) / 2}; + UIGraphicsBeginImageContextWithOptions(resolution, true, 1); [self drawBackground]; diff --git a/iOS/GBLayout.h b/iOS/GBLayout.h index dd2228c99..acba9b2c6 100644 --- a/iOS/GBLayout.h +++ b/iOS/GBLayout.h @@ -6,6 +6,7 @@ @property (readonly) CGPoint dpadLocation; @property (readonly) CGPoint aLocation; @property (readonly) CGPoint bLocation; +@property (readonly) CGPoint abComboLocation; @property (readonly) CGPoint startLocation; @property (readonly) CGPoint selectLocation; - (CGRect)viewRectForOrientation:(UIInterfaceOrientation)orientation; @@ -19,6 +20,7 @@ @property CGPoint dpadLocation; @property CGPoint aLocation; @property CGPoint bLocation; +@property CGPoint abComboLocation; @property CGPoint startLocation; @property CGPoint selectLocation; @property (readonly) CGSize resolution; diff --git a/iOS/GBSettingsViewController.m b/iOS/GBSettingsViewController.m index d7958e3a3..c796cfad5 100644 --- a/iOS/GBSettingsViewController.m +++ b/iOS/GBSettingsViewController.m @@ -321,6 +321,12 @@ static NSString const *typeLightTemp = @"typeLightTemp"; return @"Directional input is determined by the touch position."; }, }, + @{ + @"items": @[ + @{@"type": typeCheck, @"pref": @"GBEnableABCombo", @"title": @"Single-Touch A+B"}, + ], + @"footer": @"Enable this option to allow pressing A+B by touching the space between the two buttons", + }, @{ @"header": @"Horizontal Swipe Behavior", @"items": @[ diff --git a/iOS/GBVerticalLayout.m b/iOS/GBVerticalLayout.m index e42696014..9ee26ae18 100644 --- a/iOS/GBVerticalLayout.m +++ b/iOS/GBVerticalLayout.m @@ -54,6 +54,8 @@ round(buttonsCenter.y + buttonsDelta.height / 2) }; + self.abComboLocation = buttonsCenter; + double controlsTop = self.dpadLocation.y - 80 * self.factor; double middleSpace = self.bLocation.x - buttonRadius - (self.dpadLocation.x + 80 * self.factor);