diff --git a/iOS/GBBackgroundView.m b/iOS/GBBackgroundView.m index ca6e1281c..88787170b 100644 --- a/iOS/GBBackgroundView.m +++ b/iOS/GBBackgroundView.m @@ -82,7 +82,7 @@ static GB_key_mask_t angleToKeyMask(double angle) @implementation GBBackgroundView { NSMutableSet *_touches; - UITouch *_swipePadTouch; + UITouch *_padTouch; CGPoint _padSwipeOrigin; UITouch *_screenTouch; UITouch *_logoTouch; @@ -219,10 +219,10 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event else if (CGRectContainsPoint(logoRect, point) && !_logoTouch) { _logoTouch = touch; } - else if (_usesSwipePad && !_swipePadTouch) { + else if (!_padTouch) { if (fabs(point.x - dpadLocation.x) <= dpadRadius && fabs(point.y - dpadLocation.y) <= dpadRadius) { - _swipePadTouch = touch; + _padTouch = touch; _padSwipeOrigin = point; } } @@ -233,8 +233,8 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { - if (_swipePadTouch && [touches containsObject:_swipePadTouch]) { - _swipePadTouch = nil; + if (_padTouch && [touches containsObject:_padTouch]) { + _padTouch = nil; } if (_screenTouch && [touches containsObject:_screenTouch]) { @@ -298,8 +298,8 @@ - (void)touchesChanged bool dpadHandled = false; if (_usesSwipePad) { dpadHandled = true; - if (_swipePadTouch) { - CGPoint point = [_swipePadTouch locationInView:self]; + if (_padTouch) { + CGPoint point = [_padTouch locationInView:self]; double squaredDistance = CGPointSquaredDistance(point, _padSwipeOrigin); if (squaredDistance > 16 * 16) { double angle = CGPointAngle(point, _padSwipeOrigin); @@ -315,7 +315,7 @@ - (void)touchesChanged } } for (UITouch *touch in _touches) { - if (touch == _swipePadTouch) continue; + if (_usesSwipePad && touch == _padTouch) continue; CGPoint point = [touch locationInView:self]; if (touch == _screenTouch) { @@ -364,7 +364,17 @@ - (void)touchesChanged point.x *= factor; point.y *= factor; - if (CGPointSquaredDistance(point, _layout.aLocation) <= buttonRadiusSquared) { + if (!dpadHandled && + (touch == _padTouch || + (fabs(point.x - _layout.dpadLocation.x) <= dpadRadius && + fabs(point.y - _layout.dpadLocation.y) <= dpadRadius) + ) && (fabs(point.x - _layout.dpadLocation.x) >= dpadRadius / 5 || + fabs(point.y - _layout.dpadLocation.y) >= dpadRadius / 5)) { + dpadHandled = true; // Don't handle the dpad twice + double angle = CGPointAngle(point, _layout.dpadLocation); + mask |= angleToKeyMask(angle); + } + else if (CGPointSquaredDistance(point, _layout.aLocation) <= buttonRadiusSquared) { mask |= GB_KEY_A_MASK; } else if (CGPointSquaredDistance(point, _layout.bLocation) <= buttonRadiusSquared) { @@ -380,13 +390,6 @@ - (void)touchesChanged 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) { - dpadHandled = true; // Don't handle the dpad twice - double angle = CGPointAngle(point, _layout.dpadLocation); - mask |= angleToKeyMask(angle); - } } if (mask != _lastMask) { _aButtonView.image = [_layout.theme imageNamed:(mask & GB_KEY_A_MASK)? @"buttonAPressed" : @"buttonA"];