mirror of
https://github.com/moonlight-stream/moonlight-ios.git
synced 2026-06-16 21:50:57 +00:00
Replace home-rolled edge swipe gesture recognizer with UIScreenEdgePanGestureRecognizer
This commit is contained in:
@@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
@protocol EdgeDetectionDelegate;
|
|
||||||
@class ControllerSupport;
|
@class ControllerSupport;
|
||||||
|
|
||||||
@interface OnScreenControls : NSObject
|
@interface OnScreenControls : NSObject
|
||||||
@@ -25,7 +24,7 @@ typedef NS_ENUM(NSInteger, OnScreenControlsLevel) {
|
|||||||
OnScreenControlsLevelAutoGCExtendedGamepadWithStickButtons
|
OnScreenControlsLevelAutoGCExtendedGamepadWithStickButtons
|
||||||
};
|
};
|
||||||
|
|
||||||
- (id) initWithView:(UIView*)view controllerSup:(ControllerSupport*)controllerSupport swipeDelegate:(id<EdgeDetectionDelegate>)edgeDelegate;
|
- (id) initWithView:(UIView*)view controllerSup:(ControllerSupport*)controllerSupport;
|
||||||
- (BOOL) handleTouchDownEvent:(NSSet*)touches;
|
- (BOOL) handleTouchDownEvent:(NSSet*)touches;
|
||||||
- (BOOL) handleTouchUpEvent:(NSSet*)touches;
|
- (BOOL) handleTouchUpEvent:(NSSet*)touches;
|
||||||
- (BOOL) handleTouchMovedEvent:(NSSet*)touches;
|
- (BOOL) handleTouchMovedEvent:(NSSet*)touches;
|
||||||
|
|||||||
@@ -36,7 +36,6 @@
|
|||||||
CALayer* _l1Button;
|
CALayer* _l1Button;
|
||||||
CALayer* _l2Button;
|
CALayer* _l2Button;
|
||||||
CALayer* _l3Button;
|
CALayer* _l3Button;
|
||||||
CALayer* _edge;
|
|
||||||
|
|
||||||
UITouch* _aTouch;
|
UITouch* _aTouch;
|
||||||
UITouch* _bTouch;
|
UITouch* _bTouch;
|
||||||
@@ -53,7 +52,6 @@
|
|||||||
UITouch* _l1Touch;
|
UITouch* _l1Touch;
|
||||||
UITouch* _l2Touch;
|
UITouch* _l2Touch;
|
||||||
UITouch* _l3Touch;
|
UITouch* _l3Touch;
|
||||||
UITouch* _edgeTouch;
|
|
||||||
|
|
||||||
NSDate* l3TouchStart;
|
NSDate* l3TouchStart;
|
||||||
NSDate* r3TouchStart;
|
NSDate* r3TouchStart;
|
||||||
@@ -69,7 +67,6 @@
|
|||||||
|
|
||||||
ControllerSupport *_controllerSupport;
|
ControllerSupport *_controllerSupport;
|
||||||
Controller *_controller;
|
Controller *_controller;
|
||||||
id<EdgeDetectionDelegate> _edgeDelegate;
|
|
||||||
NSMutableArray* _deadTouches;
|
NSMutableArray* _deadTouches;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,12 +111,11 @@ 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 swipeDelegate:(id<EdgeDetectionDelegate>)swipeDelegate {
|
- (id) initWithView:(UIView*)view controllerSup:(ControllerSupport*)controllerSupport {
|
||||||
self = [self init];
|
self = [self init];
|
||||||
_view = view;
|
_view = view;
|
||||||
_controllerSupport = controllerSupport;
|
_controllerSupport = controllerSupport;
|
||||||
_controller = [controllerSupport getOscController];
|
_controller = [controllerSupport getOscController];
|
||||||
_edgeDelegate = swipeDelegate;
|
|
||||||
_deadTouches = [[NSMutableArray alloc] init];
|
_deadTouches = [[NSMutableArray alloc] init];
|
||||||
|
|
||||||
_iPad = ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad);
|
_iPad = ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad);
|
||||||
@@ -156,7 +152,6 @@ static float L3_Y;
|
|||||||
_rightStickBackground = [CALayer layer];
|
_rightStickBackground = [CALayer layer];
|
||||||
_leftStick = [CALayer layer];
|
_leftStick = [CALayer layer];
|
||||||
_rightStick = [CALayer layer];
|
_rightStick = [CALayer layer];
|
||||||
_edge = [CALayer layer];
|
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@@ -164,8 +159,6 @@ static float L3_Y;
|
|||||||
- (void) show {
|
- (void) show {
|
||||||
_visible = YES;
|
_visible = YES;
|
||||||
|
|
||||||
[self setupEdgeDetection];
|
|
||||||
|
|
||||||
[self updateControls];
|
[self updateControls];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,11 +247,6 @@ static float L3_Y;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setupEdgeDetection {
|
|
||||||
_edge.frame = CGRectMake(0, 0, 5, _view.frame.size.height);
|
|
||||||
[_view.layer addSublayer:_edge];
|
|
||||||
}
|
|
||||||
|
|
||||||
// For GCExtendedGamepad controls we move start, select, L3, and R3 to the button
|
// For GCExtendedGamepad controls we move start, select, L3, and R3 to the button
|
||||||
- (void) setupExtendedGamepadControls {
|
- (void) setupExtendedGamepadControls {
|
||||||
// Start with the default complex layout
|
// Start with the default complex layout
|
||||||
@@ -650,8 +638,6 @@ static float L3_Y;
|
|||||||
buttonTouch = true;
|
buttonTouch = true;
|
||||||
} else if (touch == _r3Touch) {
|
} else if (touch == _r3Touch) {
|
||||||
buttonTouch = true;
|
buttonTouch = true;
|
||||||
} else if (touch == _edgeTouch) {
|
|
||||||
buttonTouch = true;
|
|
||||||
}
|
}
|
||||||
if ([_deadTouches containsObject:touch]) {
|
if ([_deadTouches containsObject:touch]) {
|
||||||
updated = true;
|
updated = true;
|
||||||
@@ -771,9 +757,6 @@ static float L3_Y;
|
|||||||
}
|
}
|
||||||
_rsTouch = touch;
|
_rsTouch = touch;
|
||||||
stickTouch = true;
|
stickTouch = true;
|
||||||
} else if ([_edge.presentationLayer hitTest:touchLocation]) {
|
|
||||||
_edgeTouch = touch;
|
|
||||||
updated = true;
|
|
||||||
}
|
}
|
||||||
if (!updated && !stickTouch && [self isInDeadZone:touch]) {
|
if (!updated && !stickTouch && [self isInDeadZone:touch]) {
|
||||||
[_deadTouches addObject:touch];
|
[_deadTouches addObject:touch];
|
||||||
@@ -857,11 +840,6 @@ static float L3_Y;
|
|||||||
else if (touch == _r3Touch) {
|
else if (touch == _r3Touch) {
|
||||||
_r3Touch = nil;
|
_r3Touch = nil;
|
||||||
touched = true;
|
touched = true;
|
||||||
} else if (touch == _edgeTouch) {
|
|
||||||
_edgeTouch = nil;
|
|
||||||
if ([touch locationInView:_view].x >= _view.frame.size.width / 4) {
|
|
||||||
[_edgeDelegate edgeSwiped];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if ([_deadTouches containsObject:touch]) {
|
if ([_deadTouches containsObject:touch]) {
|
||||||
[_deadTouches removeObject:touch];
|
[_deadTouches removeObject:touch];
|
||||||
|
|||||||
@@ -11,12 +11,6 @@
|
|||||||
#import "Moonlight-Swift.h"
|
#import "Moonlight-Swift.h"
|
||||||
#import "StreamConfiguration.h"
|
#import "StreamConfiguration.h"
|
||||||
|
|
||||||
@protocol EdgeDetectionDelegate <NSObject>
|
|
||||||
|
|
||||||
- (void) edgeSwiped;
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
@protocol UserInteractionDelegate <NSObject>
|
@protocol UserInteractionDelegate <NSObject>
|
||||||
|
|
||||||
- (void) userInteractionBegan;
|
- (void) userInteractionBegan;
|
||||||
@@ -31,7 +25,6 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
- (void) setupStreamView:(ControllerSupport*)controllerSupport
|
- (void) setupStreamView:(ControllerSupport*)controllerSupport
|
||||||
swipeDelegate:(id<EdgeDetectionDelegate>)swipeDelegate
|
|
||||||
interactionDelegate:(id<UserInteractionDelegate>)interactionDelegate
|
interactionDelegate:(id<UserInteractionDelegate>)interactionDelegate
|
||||||
config:(StreamConfiguration*)streamConfig;
|
config:(StreamConfiguration*)streamConfig;
|
||||||
- (void) showOnScreenControls;
|
- (void) showOnScreenControls;
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void) setupStreamView:(ControllerSupport*)controllerSupport
|
- (void) setupStreamView:(ControllerSupport*)controllerSupport
|
||||||
swipeDelegate:(id<EdgeDetectionDelegate>)swipeDelegate
|
|
||||||
interactionDelegate:(id<UserInteractionDelegate>)interactionDelegate
|
interactionDelegate:(id<UserInteractionDelegate>)interactionDelegate
|
||||||
config:(StreamConfiguration*)streamConfig {
|
config:(StreamConfiguration*)streamConfig {
|
||||||
self->interactionDelegate = interactionDelegate;
|
self->interactionDelegate = interactionDelegate;
|
||||||
@@ -71,7 +70,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 swipeDelegate:swipeDelegate];
|
onScreenControls = [[OnScreenControls alloc] initWithView:self controllerSup:controllerSupport];
|
||||||
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");
|
||||||
@@ -631,8 +630,10 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
|
|||||||
LiSendScrollEvent(deltaZ);
|
LiSendScrollEvent(deltaZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !TARGET_OS_TV
|
||||||
- (BOOL)isMultipleTouchEnabled {
|
- (BOOL)isMultipleTouchEnabled {
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -15,9 +15,9 @@
|
|||||||
#if TARGET_OS_TV
|
#if TARGET_OS_TV
|
||||||
@import GameController;
|
@import GameController;
|
||||||
|
|
||||||
@interface StreamFrameViewController : GCEventViewController <ConnectionCallbacks, EdgeDetectionDelegate, InputPresenceDelegate, UserInteractionDelegate, UIScrollViewDelegate>
|
@interface StreamFrameViewController : GCEventViewController <ConnectionCallbacks, InputPresenceDelegate, UserInteractionDelegate, UIScrollViewDelegate>
|
||||||
#else
|
#else
|
||||||
@interface StreamFrameViewController : UIViewController <ConnectionCallbacks, EdgeDetectionDelegate, InputPresenceDelegate, UserInteractionDelegate, UIScrollViewDelegate>
|
@interface StreamFrameViewController : UIViewController <ConnectionCallbacks, InputPresenceDelegate, UserInteractionDelegate, UIScrollViewDelegate>
|
||||||
#endif
|
#endif
|
||||||
@property (nonatomic) StreamConfiguration* streamConfig;
|
@property (nonatomic) StreamConfiguration* streamConfig;
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,10 @@
|
|||||||
StreamView *_streamView;
|
StreamView *_streamView;
|
||||||
UIScrollView *_scrollView;
|
UIScrollView *_scrollView;
|
||||||
BOOL _userIsInteracting;
|
BOOL _userIsInteracting;
|
||||||
|
|
||||||
|
#if !TARGET_OS_TV
|
||||||
|
UIScreenEdgePanGestureRecognizer *_exitSwipeRecognizer;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)viewDidAppear:(BOOL)animated
|
- (void)viewDidAppear:(BOOL)animated
|
||||||
@@ -86,7 +90,7 @@
|
|||||||
_inactivityTimer = nil;
|
_inactivityTimer = nil;
|
||||||
|
|
||||||
_streamView = [[StreamView alloc] initWithFrame:self.view.frame];
|
_streamView = [[StreamView alloc] initWithFrame:self.view.frame];
|
||||||
[_streamView setupStreamView:_controllerSupport swipeDelegate:self interactionDelegate:self config:self.streamConfig];
|
[_streamView setupStreamView:_controllerSupport interactionDelegate:self config:self.streamConfig];
|
||||||
|
|
||||||
#if TARGET_OS_TV
|
#if TARGET_OS_TV
|
||||||
if (!_menuGestureRecognizer || !_menuDoubleTapGestureRecognizer) {
|
if (!_menuGestureRecognizer || !_menuDoubleTapGestureRecognizer) {
|
||||||
@@ -101,8 +105,12 @@
|
|||||||
|
|
||||||
[self.view addGestureRecognizer:_menuGestureRecognizer];
|
[self.view addGestureRecognizer:_menuGestureRecognizer];
|
||||||
[self.view addGestureRecognizer:_menuDoubleTapGestureRecognizer];
|
[self.view addGestureRecognizer:_menuDoubleTapGestureRecognizer];
|
||||||
#endif
|
#else
|
||||||
|
_exitSwipeRecognizer = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(edgeSwiped)];
|
||||||
|
_exitSwipeRecognizer.edges = UIRectEdgeLeft;
|
||||||
|
|
||||||
|
[self.view addGestureRecognizer:_exitSwipeRecognizer];
|
||||||
|
#endif
|
||||||
|
|
||||||
_tipLabel = [[UILabel alloc] init];
|
_tipLabel = [[UILabel alloc] init];
|
||||||
[_tipLabel setUserInteractionEnabled:NO];
|
[_tipLabel setUserInteractionEnabled:NO];
|
||||||
|
|||||||
Reference in New Issue
Block a user