From 967ddd7d6899aa5127d12f71e5666dc672d66b6b Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Tue, 22 Oct 2019 00:16:20 -0400 Subject: [PATCH] Refactor OSC handling --- Limelight/Input/OnScreenControls.h | 4 ++- Limelight/Input/OnScreenControls.m | 21 ++++++++++++++-- Limelight/Input/StreamView.h | 6 +++-- Limelight/Input/StreamView.m | 25 +++++++++++++------ .../StreamFrameViewController.m | 12 +++++---- 5 files changed, 51 insertions(+), 17 deletions(-) diff --git a/Limelight/Input/OnScreenControls.h b/Limelight/Input/OnScreenControls.h index 90167d3..5379a06 100644 --- a/Limelight/Input/OnScreenControls.h +++ b/Limelight/Input/OnScreenControls.h @@ -7,8 +7,8 @@ // #import -#import "StreamView.h" +@protocol EdgeDetectionDelegate; @class ControllerSupport; @interface OnScreenControls : NSObject @@ -30,5 +30,7 @@ typedef NS_ENUM(NSInteger, OnScreenControlsLevel) { - (BOOL) handleTouchUpEvent:(NSSet*)touches; - (BOOL) handleTouchMovedEvent:(NSSet*)touches; - (void) setLevel:(OnScreenControlsLevel)level; +- (OnScreenControlsLevel) getLevel; +- (void) show; @end diff --git a/Limelight/Input/OnScreenControls.m b/Limelight/Input/OnScreenControls.m index d0396ab..5993200 100644 --- a/Limelight/Input/OnScreenControls.m +++ b/Limelight/Input/OnScreenControls.m @@ -7,6 +7,7 @@ // #import "OnScreenControls.h" +#import "StreamView.h" #import "ControllerSupport.h" #import "Controller.h" #include "Limelight.h" @@ -64,6 +65,7 @@ CGRect _controlArea; UIView* _view; OnScreenControlsLevel _level; + BOOL _visible; ControllerSupport *_controllerSupport; Controller *_controller; @@ -156,14 +158,29 @@ static float L3_Y; _rightStick = [CALayer layer]; _edge = [CALayer layer]; + return self; +} + +- (void) show { + _visible = YES; + [self setupEdgeDetection]; - return self; + [self updateControls]; } - (void) setLevel:(OnScreenControlsLevel)level { _level = level; - [self updateControls]; + + // Only update controls if we're showing, otherwise + // show will do it for us. + if (_visible) { + [self updateControls]; + } +} + +- (OnScreenControlsLevel) getLevel { + return _level; } - (void) updateControls { diff --git a/Limelight/Input/StreamView.h b/Limelight/Input/StreamView.h index a92659a..2c1e97f 100644 --- a/Limelight/Input/StreamView.h +++ b/Limelight/Input/StreamView.h @@ -7,6 +7,7 @@ // #import "ControllerSupport.h" +#import "OnScreenControls.h" @protocol EdgeDetectionDelegate @@ -18,8 +19,9 @@ @property (nonatomic, retain) IBOutlet UITextField* keyInputField; -- (void) setupStreamView; -- (void) setupOnScreenControls:(ControllerSupport*)controllerSupport swipeDelegate:(id)swipeDelegate; +- (void) setupStreamView:(ControllerSupport*)controllerSupport swipeDelegate:(id)swipeDelegate; +- (void) showOnScreenControls; - (void) setMouseDeltaFactors:(float)x y:(float)y; +- (OnScreenControlsLevel) getCurrentOscState; @end diff --git a/Limelight/Input/StreamView.m b/Limelight/Input/StreamView.m index 24c15c6..83b47be 100644 --- a/Limelight/Input/StreamView.m +++ b/Limelight/Input/StreamView.m @@ -8,7 +8,6 @@ #import "StreamView.h" #include -#import "OnScreenControls.h" #import "DataManager.h" #import "ControllerSupport.h" #import "KeyboardSupport.h" @@ -47,7 +46,7 @@ #endif } -- (void) setupStreamView { +- (void) setupStreamView:(ControllerSupport*)controllerSupport swipeDelegate:(id)swipeDelegate { #if TARGET_OS_TV remotePressRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(remoteButtonPressed:)]; remotePressRecognizer.allowedPressTypes = @[@(UIPressTypeSelect)]; @@ -57,14 +56,10 @@ [self addGestureRecognizer:remotePressRecognizer]; [self addGestureRecognizer:remoteLongPressRecognizer]; -#endif -} - -- (void) setupOnScreenControls:(ControllerSupport*)controllerSupport swipeDelegate:(id)swipeDelegate { +#else onScreenControls = [[OnScreenControls alloc] initWithView:self controllerSup:controllerSupport swipeDelegate:swipeDelegate]; DataManager* dataMan = [[DataManager alloc] init]; OnScreenControlsLevel level = (OnScreenControlsLevel)[[dataMan getSettings].onscreenControls integerValue]; - if (level == OnScreenControlsLevelAuto) { [controllerSupport initAutoOnScreenControlMode:onScreenControls]; } @@ -72,7 +67,23 @@ Log(LOG_I, @"Setting manual on-screen controls level: %d", (int)level); [onScreenControls setLevel:level]; } +#endif +} + +- (void) showOnScreenControls { +#if !TARGET_OS_TV + [onScreenControls show]; [self becomeFirstResponder]; +#endif +} + +- (OnScreenControlsLevel) getCurrentOscState { + if (onScreenControls == nil) { + return OnScreenControlsLevelOff; + } + else { + return [onScreenControls getLevel]; + } } - (Boolean)isConfirmedMove:(CGPoint)currentPoint from:(CGPoint)originalPoint { diff --git a/Limelight/ViewControllers/StreamFrameViewController.m b/Limelight/ViewControllers/StreamFrameViewController.m index 0f37153..71abba2 100644 --- a/Limelight/ViewControllers/StreamFrameViewController.m +++ b/Limelight/ViewControllers/StreamFrameViewController.m @@ -24,6 +24,7 @@ UITapGestureRecognizer *_menuGestureRecognizer; UITapGestureRecognizer *_menuDoubleTapGestureRecognizer; UITextView *_overlayView; + StreamView *_streamView; } - (void)viewDidAppear:(BOOL)animated @@ -50,8 +51,6 @@ [self.navigationController setNavigationBarHidden:YES animated:YES]; - [(StreamView*)self.view setupStreamView]; - [self.stageLabel setText:[NSString stringWithFormat:@"Starting %@...", self.streamConfig.appName]]; [self.stageLabel sizeToFit]; self.stageLabel.textAlignment = NSTextAlignmentCenter; @@ -61,6 +60,10 @@ _controllerSupport = [[ControllerSupport alloc] initWithConfig:self.streamConfig]; _inactivityTimer = nil; + + _streamView = (StreamView*)self.view; + [_streamView setupStreamView:_controllerSupport swipeDelegate:self]; + #if TARGET_OS_TV if (!_menuGestureRecognizer || !_menuDoubleTapGestureRecognizer) { _menuGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(controllerPauseButtonPressed:)]; @@ -221,9 +224,8 @@ // the first frame of video. self.stageLabel.hidden = YES; self.tipLabel.hidden = YES; -#if !TARGET_OS_TV - [(StreamView*)self.view setupOnScreenControls: self->_controllerSupport swipeDelegate:self]; -#endif + + [self->_streamView showOnScreenControls]; }); }