From 301c8580c87956efae8060b4aa131f251b37a67c Mon Sep 17 00:00:00 2001 From: TrueZhuangjia Date: Wed, 29 Jan 2025 21:13:38 +0800 Subject: [PATCH] - onScreenWidget guidelines alignment with OnScreenControl CALayers - stage manager version --- .../Input/CustomOSC/LayoutOnScreenControls.h | 3 +- .../Input/CustomOSC/LayoutOnScreenControls.m | 69 +++++++++++++++++-- Limelight/Input/OnScreenControls.m | 2 +- Limelight/Input/OnScreenWidgetView.swift | 12 ++-- Limelight/Limelight-Info.plist | 2 +- .../LayoutOnScreenControlsViewController.m | 4 +- 6 files changed, 80 insertions(+), 12 deletions(-) diff --git a/Limelight/Input/CustomOSC/LayoutOnScreenControls.h b/Limelight/Input/CustomOSC/LayoutOnScreenControls.h index c0573605..d90832a3 100644 --- a/Limelight/Input/CustomOSC/LayoutOnScreenControls.h +++ b/Limelight/Input/CustomOSC/LayoutOnScreenControls.h @@ -8,6 +8,7 @@ #import #import "OnScreenControls.h" +#import "Moonlight-Swift.h" NS_ASSUME_NONNULL_BEGIN /** @@ -30,7 +31,7 @@ NS_ASSUME_NONNULL_BEGIN - (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; - (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event; - (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event; - +// - (void) updateGuidelinesForOnScreenWidget:(OnScreenWidgetView* )widget; @end NS_ASSUME_NONNULL_END diff --git a/Limelight/Input/CustomOSC/LayoutOnScreenControls.m b/Limelight/Input/CustomOSC/LayoutOnScreenControls.m index eb56037e..60741ae1 100644 --- a/Limelight/Input/CustomOSC/LayoutOnScreenControls.m +++ b/Limelight/Input/CustomOSC/LayoutOnScreenControls.m @@ -10,7 +10,6 @@ #import "OSCProfilesTableViewController.h" #import "OnScreenButtonState.h" #import "OSCProfilesManager.h" -#import "Moonlight-Swift.h" @interface LayoutOnScreenControls () @end @@ -26,7 +25,16 @@ @synthesize _view; @synthesize layoutChanges; + + + - (id) initWithView:(UIView*)view controllerSup:(ControllerSupport*)controllerSupport streamConfig:(StreamConfiguration*)streamConfig oscLevel:(int)oscLevel { + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(updateGuidelinesForOnScreenWidget:) + name:@"OnScreenWidgetMovedByTouch" // This is a special notification for reloading the on screen keyboard buttons. which can't be executed by _oscProfilesTableViewController.needToUpdateOscLayoutTVC code block, and has to be triggered by a notification + object:nil]; + + _view = view; _view.multipleTouchEnabled = false; @@ -101,6 +109,57 @@ [self._view addSubview: verticalGuideline]; } +- (void) updateGuidelinesForOnScreenWidget: (NSNotification *)notification{ + /* have guidelines follow wherever the user is touching on the screen */ + OnScreenWidgetView* widget = notification.object; + horizontalGuideline.hidden = verticalGuideline.hidden = NO; + horizontalGuideline.center = verticalGuideline.center = CGPointMake(CGRectGetMidX(widget.frame), CGRectGetMidY(widget.frame)); + /* + Telegraph to the user whether the horizontal and/or vertical guidelines line up with one or more of the buttons on screen by doing the following: + -Change horizontal guideline color to yellow if its y-position is almost equal to that of one of the buttons on screen. + -Change vertical guideline color to yellow if its x-position is almost equal to that of one of the buttons on screen. + */ + + horizontalGuideline.backgroundColor = [UIColor blueColor]; // change horizontal guideline back to blue if it doesn't line up with one of the on screen buttons + for (CALayer *button in self.OSCButtonLayers) { // horizontal guideline position check + if ((layerBeingDragged != button) && !button.isHidden) { + if ((horizontalGuideline.center.y < button.position.y + 1) && + (horizontalGuideline.center.y > button.position.y - 1)) { + horizontalGuideline.backgroundColor = [UIColor yellowColor]; + break; + } + } + } + for(UIView* view in self.layoutToolVC.view.subviews){ + if ([view isKindOfClass:[OnScreenWidgetView class]] && view != widget) { + if ((horizontalGuideline.center.y < view.center.y + 1) && (horizontalGuideline.center.y > view.center.y - 1)) { + horizontalGuideline.backgroundColor = [UIColor yellowColor]; + break; + } + } + } + + verticalGuideline.backgroundColor = [UIColor blueColor]; // change vertical guideline back to blue if it doesn't line up with one of the on screen buttons + for (CALayer *button in self.OSCButtonLayers) { // vertical guideline position check + if ((layerBeingDragged != button) && !button.isHidden) { + if ((verticalGuideline.center.x < button.position.x + 1) && + (verticalGuideline.center.x > button.position.x - 1)) { + verticalGuideline.backgroundColor = [UIColor yellowColor]; + break; + } + } + } + for(UIView* view in self.layoutToolVC.view.subviews){ + if ([view isKindOfClass:[OnScreenWidgetView class]] && view != widget) { + if ((verticalGuideline.center.x < view.center.x + 1) && (verticalGuideline.center.x > view.center.x - 1)) { + verticalGuideline.backgroundColor = [UIColor yellowColor]; + break; + } + } + } + +} + #pragma mark - Queries @@ -198,6 +257,7 @@ UITouch *touch = [touches anyObject]; CGPoint touchLocation = [touch locationInView:_view]; + layerBeingDragged.position = touchLocation; // move object to touch location /* have guidelines follow wherever the user is touching on the screen */ @@ -206,8 +266,8 @@ /* Telegraph to the user whether the horizontal and/or vertical guidelines line up with one or more of the buttons on screen by doing the following: - -Change horizontal guideline color to white if its y-position is almost equal to that of one of the buttons on screen. - -Change vertical guideline color to white if its x-position is almost equal to that of one of the buttons on screen. + -Change horizontal guideline color to yellow if its y-position is almost equal to that of one of the buttons on screen. + -Change vertical guideline color to yellow if its x-position is almost equal to that of one of the buttons on screen. */ horizontalGuideline.backgroundColor = [UIColor blueColor]; // change horizontal guideline back to blue if it doesn't line up with one of the on screen buttons for (CALayer *button in self.OSCButtonLayers) { // horizontal guideline position check @@ -219,6 +279,7 @@ } } } + // alignment with onScreenWidgets for(UIView* view in self.layoutToolVC.view.subviews){ if ([view isKindOfClass:[OnScreenWidgetView class]]) { if ((horizontalGuideline.center.y < view.center.y + 1) && (horizontalGuideline.center.y > view.center.y - 1)) { @@ -238,6 +299,7 @@ } } } + // alignment with onScreenWidgets for(UIView* view in self.layoutToolVC.view.subviews){ if ([view isKindOfClass:[OnScreenWidgetView class]]) { if ((verticalGuideline.center.x < view.center.x + 1) && (verticalGuideline.center.x > view.center.x - 1)) { @@ -246,7 +308,6 @@ } } } - } - (void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { diff --git a/Limelight/Input/OnScreenControls.m b/Limelight/Input/OnScreenControls.m index a4cb8477..9f279a26 100644 --- a/Limelight/Input/OnScreenControls.m +++ b/Limelight/Input/OnScreenControls.m @@ -258,7 +258,7 @@ static float L3_Y; _rightStickBackground = [CALayer layer]; _leftStick = [CALayer layer]; _rightStick = [CALayer layer]; - + [self.OSCButtonLayers addObject:_aButton]; [self.OSCButtonLayers addObject:_bButton]; [self.OSCButtonLayers addObject:_xButton]; diff --git a/Limelight/Input/OnScreenWidgetView.swift b/Limelight/Input/OnScreenWidgetView.swift index 44622e60..4d27820e 100644 --- a/Limelight/Input/OnScreenWidgetView.swift +++ b/Limelight/Input/OnScreenWidgetView.swift @@ -683,7 +683,7 @@ import UIKit self.onScreenControls.sendLeftStickTouchPadEvent(targetX, targetY) } //========================================================================================================== - + // Touch event handling override func touchesBegan(_ touches: Set, with event: UIEvent?) { @@ -781,11 +781,15 @@ import UIKit private func moveByTouch(touch: UITouch){ let currentLocation = touch.location(in: superview) - let offsetX = currentLocation.x - storedLocation.x - let offsetY = currentLocation.y - storedLocation.y - center = CGPoint(x: center.x + offsetX, y: center.y + offsetY) + // let offsetX = currentLocation.x - storedLocation.x + // let offsetY = currentLocation.y - storedLocation.y + // center = CGPoint(x: center.x + offsetX, y: center.y + offsetY) + center = currentLocation; //NSLog("x coord: %f, y coord: %f", self.frame.origin.x, self.frame.origin.y) storedLocation = currentLocation // Update initial center for next movement + if OnScreenWidgetView.editMode { + NotificationCenter.default.post(name: Notification.Name("OnScreenWidgetMovedByTouch"), object:self) // inform the layoutOnScreenControl to update guideLines for this widget view + } } override func touchesMoved(_ touches: Set, with event: UIEvent?) { diff --git a/Limelight/Limelight-Info.plist b/Limelight/Limelight-Info.plist index f29ea4d0..541e31d5 100644 --- a/Limelight/Limelight-Info.plist +++ b/Limelight/Limelight-Info.plist @@ -74,7 +74,7 @@ armv7 UIRequiresFullScreen - + UIStatusBarHidden UISupportedInterfaceOrientations diff --git a/Limelight/ViewControllers/CustomOSCViewControl/LayoutOnScreenControlsViewController.m b/Limelight/ViewControllers/CustomOSCViewControl/LayoutOnScreenControlsViewController.m index 65515333..19ed2137 100644 --- a/Limelight/ViewControllers/CustomOSCViewControl/LayoutOnScreenControlsViewController.m +++ b/Limelight/ViewControllers/CustomOSCViewControl/LayoutOnScreenControlsViewController.m @@ -733,7 +733,9 @@ } - (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { - + // for OnScreenWidgets: + + // -------- for OSC buttons [self.layoutOSC touchesMoved:touches withEvent:event]; if ([self.layoutOSC isLayer:self.layoutOSC.layerBeingDragged