From 94f2e39367eb5368d42899743cb903aabcdcb8cc Mon Sep 17 00:00:00 2001 From: TrueZhuangjia Date: Sat, 29 Mar 2025 19:43:03 +0800 Subject: [PATCH] passing streamViewBounds --- Limelight/Input/CustomOSC/OSCProfilesManager.h | 2 +- Limelight/Input/CustomOSC/OSCProfilesManager.m | 15 ++++++++++++--- Limelight/Input/OnScreenControls.m | 2 +- Limelight/Input/StreamView.m | 2 +- .../LayoutOnScreenControlsViewController.m | 5 +++-- .../OSCProfilesTableViewController.h | 1 + .../OSCProfilesTableViewController.m | 2 +- 7 files changed, 20 insertions(+), 9 deletions(-) diff --git a/Limelight/Input/CustomOSC/OSCProfilesManager.h b/Limelight/Input/CustomOSC/OSCProfilesManager.h index b5d1559a..73e50500 100644 --- a/Limelight/Input/CustomOSC/OSCProfilesManager.h +++ b/Limelight/Input/CustomOSC/OSCProfilesManager.h @@ -18,7 +18,7 @@ NS_ASSUME_NONNULL_BEGIN @interface OSCProfilesManager : NSObject -+ (OSCProfilesManager *) sharedManager; ++ (OSCProfilesManager *) sharedManager:(CGRect)viewBounds; + (void) setOnScreenWidgetViewsSet:(NSMutableSet* )set; #pragma mark - Getters diff --git a/Limelight/Input/CustomOSC/OSCProfilesManager.m b/Limelight/Input/CustomOSC/OSCProfilesManager.m index ffb40b93..cad2c761 100644 --- a/Limelight/Input/CustomOSC/OSCProfilesManager.m +++ b/Limelight/Input/CustomOSC/OSCProfilesManager.m @@ -15,13 +15,15 @@ @implementation OSCProfilesManager static NSMutableSet *OnScreenWidgetViews; +static CGRect streamViewBounds; #pragma mark - Initializer -+ (OSCProfilesManager *) sharedManager { ++ (OSCProfilesManager *) sharedManager:(CGRect)viewBounds { static OSCProfilesManager *_sharedManager = nil; static dispatch_once_t onceToken; - + streamViewBounds = viewBounds; + NSLog(@"bounds width: %f, height: %f", streamViewBounds.size.width, streamViewBounds.size.height); dispatch_once(&onceToken, ^{ _sharedManager = [[self alloc] init]; }); @@ -251,6 +253,13 @@ static NSMutableSet *OnScreenWidgetViews; } } +- (CGPoint)normalizeWidgetPosition:(CGPoint)position { + if(position.x > 1.0 && position.y >1.0){ + position.x = position.x / streamViewBounds.size.width; + position.y = position.y / streamViewBounds.size.height; + } + return position; +} - (NSMutableArray* ) convertOnScreenControllerAndButtonsToButtonStates:(NSMutableArray *) oscButtonLayers { /* iterate through each OSC button the user sees on screen, create an 'OnScreenButtonState' object from each button, encode each object, and then add each object to an array */ @@ -275,7 +284,7 @@ static NSMutableSet *OnScreenWidgetViews; // save on-screen game controller buttons & sticks as buttonstate: for (CALayer *oscButtonLayer in oscButtonLayers) { - OnScreenButtonState *buttonState = [[OnScreenButtonState alloc] initWithButtonName:oscButtonLayer.name buttonType:LegacyOscButton andPosition:oscButtonLayer.position]; + OnScreenButtonState *buttonState = [[OnScreenButtonState alloc] initWithButtonName:oscButtonLayer.name buttonType:LegacyOscButton andPosition:[self normalizeWidgetPosition:oscButtonLayer.position]]; // add hidden attr here buttonState.isHidden = oscButtonLayer.isHidden; buttonState.oscLayerSizeFactor = [OnScreenControls getControllerLayerSizeFactor:oscButtonLayer]; diff --git a/Limelight/Input/OnScreenControls.m b/Limelight/Input/OnScreenControls.m index b0afb9ea..5f407d10 100644 --- a/Limelight/Input/OnScreenControls.m +++ b/Limelight/Input/OnScreenControls.m @@ -204,7 +204,7 @@ static float L3_Y; self.isLayingOut = false; // set false by default (play mode instead of layout mode) _view = view; - profilesManager = [OSCProfilesManager sharedManager]; + profilesManager = [OSCProfilesManager sharedManager:view.bounds]; self.OSCButtonLayers = [[NSMutableArray alloc] init]; diff --git a/Limelight/Input/StreamView.m b/Limelight/Input/StreamView.m index a2f6a46f..a116493f 100644 --- a/Limelight/Input/StreamView.m +++ b/Limelight/Input/StreamView.m @@ -387,7 +387,7 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5; if(![self isOnScreenButtonEnabled]) return; - OSCProfilesManager* profilesManager = [OSCProfilesManager sharedManager]; + OSCProfilesManager* profilesManager = [OSCProfilesManager sharedManager: self.bounds]; OSCProfile *oscProfile = [profilesManager getSelectedProfile]; //returns the currently selected OSCProfile if(!OnScreenWidgetView.editMode){ // in edit mode, keyboard widget view will be updated within layoutool view controller. diff --git a/Limelight/ViewControllers/CustomOSCViewControl/LayoutOnScreenControlsViewController.m b/Limelight/ViewControllers/CustomOSCViewControl/LayoutOnScreenControlsViewController.m index 06bf4f47..cbaec49f 100644 --- a/Limelight/ViewControllers/CustomOSCViewControl/LayoutOnScreenControlsViewController.m +++ b/Limelight/ViewControllers/CustomOSCViewControl/LayoutOnScreenControlsViewController.m @@ -112,7 +112,7 @@ - (void) viewDidLoad { [super viewDidLoad]; - profilesManager = [OSCProfilesManager sharedManager]; + profilesManager = [OSCProfilesManager sharedManager:self.view.bounds]; self.OnScreenWidgetViews = [[NSMutableSet alloc] init]; // will be revised to read persisted data , somewhere else [OSCProfilesManager setOnScreenWidgetViewsSet:self.OnScreenWidgetViews]; // pass the keyboard button dict to profiles manager @@ -811,7 +811,8 @@ storyboard = [UIStoryboard storyboardWithName:@"iPad" bundle:nil]; } - _oscProfilesTableViewController = [storyboard instantiateViewControllerWithIdentifier:@"OSCProfilesTableViewController"] ; + _oscProfilesTableViewController = [storyboard instantiateViewControllerWithIdentifier:@"OSCProfilesTableViewController"]; + _oscProfilesTableViewController.streamViewBounds = self.view.bounds; _oscProfilesTableViewController.needToUpdateOscLayoutTVC = ^() { // a block that will be called when the modally presented 'OSCProfilesTableViewController' VC is dismissed. By the time the 'OSCProfilesTableViewController' VC is dismissed the user would have potentially selected a different OSC ofile with a different layout and they want to see this layout on this 'LayoutOnScreenControlsViewController.' This block of code will load the profile and then hide/show and move each OSC button to their appropriate position [self.layoutOSC updateControls]; // creates and saves a 'Default' OSC profile or loads the one the user selected on the previous screen diff --git a/Limelight/ViewControllers/CustomOSCViewControl/OSCProfilesTableViewController.h b/Limelight/ViewControllers/CustomOSCViewControl/OSCProfilesTableViewController.h index eb2df598..73623ede 100644 --- a/Limelight/ViewControllers/CustomOSCViewControl/OSCProfilesTableViewController.h +++ b/Limelight/ViewControllers/CustomOSCViewControl/OSCProfilesTableViewController.h @@ -21,6 +21,7 @@ NS_ASSUME_NONNULL_BEGIN @property (weak, nonatomic) IBOutlet UITableView *tableView; @property (nonatomic, copy) void (^needToUpdateOscLayoutTVC)(void); @property (nonatomic, assign) NSMutableArray *currentOSCButtonLayers; +@property (nonatomic, assign) CGRect streamViewBounds; @end diff --git a/Limelight/ViewControllers/CustomOSCViewControl/OSCProfilesTableViewController.m b/Limelight/ViewControllers/CustomOSCViewControl/OSCProfilesTableViewController.m index 93e95e97..6202038f 100644 --- a/Limelight/ViewControllers/CustomOSCViewControl/OSCProfilesTableViewController.m +++ b/Limelight/ViewControllers/CustomOSCViewControl/OSCProfilesTableViewController.m @@ -49,7 +49,7 @@ const double NAV_BAR_HEIGHT = 50; [super viewDidLoad]; - profilesManager = [OSCProfilesManager sharedManager]; + profilesManager = [OSCProfilesManager sharedManager:_streamViewBounds]; self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, NAV_BAR_HEIGHT)];