diff --git a/Limelight/Input/OnScreenControls.h b/Limelight/Input/OnScreenControls.h index cae34f6..23ee57b 100644 --- a/Limelight/Input/OnScreenControls.h +++ b/Limelight/Input/OnScreenControls.h @@ -7,6 +7,7 @@ // #import +#import "StreamView.h" @class ControllerSupport; @@ -23,7 +24,7 @@ typedef NS_ENUM(NSInteger, OnScreenControlsLevel) { OnScreenControlsLevelAutoGCExtendedGamepad, }; -- (id) initWithView:(UIView*)view controllerSup:(ControllerSupport*)controllerSupport; +- (id) initWithView:(UIView*)view controllerSup:(ControllerSupport*)controllerSupport swipeDelegate:(id)edgeDelegate; - (BOOL) handleTouchDownEvent:(NSSet*)touches; - (BOOL) handleTouchUpEvent:(NSSet*)touches; - (BOOL) handleTouchMovedEvent:(NSSet*)touches; diff --git a/Limelight/Input/OnScreenControls.m b/Limelight/Input/OnScreenControls.m index dc52175..b9159e2 100644 --- a/Limelight/Input/OnScreenControls.m +++ b/Limelight/Input/OnScreenControls.m @@ -35,6 +35,7 @@ CALayer* _l1Button; CALayer* _l2Button; CALayer* _l3Button; + CALayer* _edge; UITouch* _aTouch; UITouch* _bTouch; @@ -54,6 +55,7 @@ UITouch* _l1Touch; UITouch* _l2Touch; UITouch* _l3Touch; + UITouch* _edgeTouch; NSDate* l3TouchStart; NSDate* r3TouchStart; @@ -66,8 +68,11 @@ ControllerSupport *_controllerSupport; Controller *_controller; + id _edgeDelegate; } +static const float EDGE_WIDTH = .1; + static const float BUTTON_SIZE = 50; static const float BUTTON_DIST = 20; static float BUTTON_CENTER_X; @@ -115,12 +120,13 @@ static float L2_Y; static float L3_X; static float L3_Y; -- (id) initWithView:(UIView*)view controllerSup:(ControllerSupport*)controllerSupport { +- (id) initWithView:(UIView*)view controllerSup:(ControllerSupport*)controllerSupport swipeDelegate:(id)swipeDelegate { self = [self init]; _view = view; _controllerSupport = controllerSupport; _controller = [[Controller alloc] init]; _controller.playerIndex = 0; + _edgeDelegate = swipeDelegate; _aButton = [CALayer layer]; _bButton = [CALayer layer]; @@ -142,7 +148,10 @@ static float L3_Y; _rightStickBackground = [CALayer layer]; _leftStick = [CALayer layer]; _rightStick = [CALayer layer]; + _edge = [CALayer layer]; + [self setupEdgeDetection]; + return self; } @@ -210,6 +219,11 @@ static float L3_Y; } } +- (void) setupEdgeDetection { + _edge.frame = CGRectMake(0, 0, _view.frame.size.width * EDGE_WIDTH, _view.frame.size.height); + [_view.layer addSublayer:_edge]; +} + // For GCExtendedGamepad controls we move start, select, L3, and R3 to the button - (void) setupExtendedGamepadControls { // Start with the default complex layout @@ -518,7 +532,7 @@ static float L3_Y; BOOL stickTouch = false; for (UITouch* touch in touches) { CGPoint touchLocation = [touch locationInView:_view]; - + if ([_aButton.presentationLayer hitTest:touchLocation]) { [_controllerSupport setButtonFlag:_controller flags:A_FLAG]; _aTouch = touch; @@ -621,6 +635,8 @@ static float L3_Y; } _rsTouch = touch; stickTouch = true; + } else if ([_edge.presentationLayer hitTest:touchLocation]) { + _edgeTouch = touch; } } if (updated) { @@ -711,6 +727,11 @@ static float L3_Y; else if (touch == _r3Touch) { _r3Touch = nil; touched = true; + } else if (touch == _edgeTouch) { + _edgeTouch = nil; + if (![_edge.presentationLayer hitTest:[touch locationInView:_view]]) { + [_edgeDelegate edgeSwiped]; + } } } if (updated) { diff --git a/Limelight/Input/StreamView.h b/Limelight/Input/StreamView.h index 2eebf66..b18c813 100644 --- a/Limelight/Input/StreamView.h +++ b/Limelight/Input/StreamView.h @@ -9,9 +9,15 @@ #import #import "ControllerSupport.h" +@protocol EdgeDetectionDelegate + +- (void) edgeSwiped; + +@end + @interface StreamView : UIView -- (void) setupOnScreenControls:(ControllerSupport*)controllerSupport; +- (void) setupOnScreenControls:(ControllerSupport*)controllerSupport swipeDelegate:(id)swipeDelegate; - (void) setMouseDeltaFactors:(float)x y:(float)y; @end diff --git a/Limelight/Input/StreamView.m b/Limelight/Input/StreamView.m index b190d30..e3054d7 100644 --- a/Limelight/Input/StreamView.m +++ b/Limelight/Input/StreamView.m @@ -29,8 +29,8 @@ screenFactor = [[UIScreen mainScreen] scale]; } -- (void) setupOnScreenControls:(ControllerSupport*)controllerSupport { - onScreenControls = [[OnScreenControls alloc] initWithView:self controllerSup:controllerSupport]; +- (void) setupOnScreenControls:(ControllerSupport*)controllerSupport swipeDelegate:(id)swipeDelegate { + onScreenControls = [[OnScreenControls alloc] initWithView:self controllerSup:controllerSupport swipeDelegate:swipeDelegate]; DataManager* dataMan = [[DataManager alloc] init]; OnScreenControlsLevel level = (OnScreenControlsLevel)[[dataMan retrieveSettings].onscreenControls integerValue]; diff --git a/Limelight/ViewControllers/StreamFrameViewController.h b/Limelight/ViewControllers/StreamFrameViewController.h index 0bd2d92..f9bf163 100644 --- a/Limelight/ViewControllers/StreamFrameViewController.h +++ b/Limelight/ViewControllers/StreamFrameViewController.h @@ -8,10 +8,11 @@ #import "Connection.h" #import "StreamConfiguration.h" +#import "StreamView.h" #import -@interface StreamFrameViewController : UIViewController +@interface StreamFrameViewController : UIViewController @property (strong, nonatomic) IBOutlet UILabel *stageLabel; @property (strong, nonatomic) IBOutlet UIActivityIndicatorView *spinner; @property (nonatomic) StreamConfiguration* streamConfig; diff --git a/Limelight/ViewControllers/StreamFrameViewController.m b/Limelight/ViewControllers/StreamFrameViewController.m index bfa0e1f..d1ff824 100644 --- a/Limelight/ViewControllers/StreamFrameViewController.m +++ b/Limelight/ViewControllers/StreamFrameViewController.m @@ -11,7 +11,6 @@ #import "VideoDecoderRenderer.h" #import "StreamManager.h" #import "ControllerSupport.h" -#import "StreamView.h" #include #include @@ -70,14 +69,7 @@ [self.spinner stopAnimating]; [self.stageLabel setText:@"Waiting for first frame..."]; [self.stageLabel sizeToFit]; - [(StreamView*)self.view setupOnScreenControls: _controllerSupport]; - UIScreenEdgePanGestureRecognizer* swipeGesture = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(edgeSwiped)]; - swipeGesture.edges = UIRectEdgeLeft; - if (swipeGesture == nil) { - Log(LOG_E, @"An error occured trying to create UIScreenEdgePanGestureRecognizer"); - } else { - [self.view addGestureRecognizer:swipeGesture]; - } + [(StreamView*)self.view setupOnScreenControls: _controllerSupport swipeDelegate:self]; }); }