- onScreenWidget guidelines alignment with OnScreenControl CALayers

- stage manager version
This commit is contained in:
TrueZhuangjia committed 2025-01-29 21:13:38 +08:00
1 parent 9b9b278a14
commit 301c8580c8
5 files changed
+77 -9

No files matched your search

@@ -8,6 +8,7 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "OnScreenControls.h" #import "OnScreenControls.h"
#import "Moonlight-Swift.h"
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
/** /**
@@ -30,7 +31,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; - (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event; - (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event; - (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
// - (void) updateGuidelinesForOnScreenWidget:(OnScreenWidgetView* )widget;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
@@ -10,7 +10,6 @@
#import "OSCProfilesTableViewController.h" #import "OSCProfilesTableViewController.h"
#import "OnScreenButtonState.h" #import "OnScreenButtonState.h"
#import "OSCProfilesManager.h" #import "OSCProfilesManager.h"
#import "Moonlight-Swift.h"
@interface LayoutOnScreenControls () @interface LayoutOnScreenControls ()
@end @end
@@ -26,7 +25,16 @@
@synthesize _view; @synthesize _view;
@synthesize layoutChanges; @synthesize layoutChanges;
- (id) initWithView:(UIView*)view controllerSup:(ControllerSupport*)controllerSupport streamConfig:(StreamConfiguration*)streamConfig oscLevel:(int)oscLevel { - (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 = view;
_view.multipleTouchEnabled = false; _view.multipleTouchEnabled = false;
@@ -101,6 +109,57 @@
[self._view addSubview: verticalGuideline]; [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 #pragma mark - Queries
@@ -198,6 +257,7 @@
UITouch *touch = [touches anyObject]; UITouch *touch = [touches anyObject];
CGPoint touchLocation = [touch locationInView:_view]; CGPoint touchLocation = [touch locationInView:_view];
layerBeingDragged.position = touchLocation; // move object to touch location layerBeingDragged.position = touchLocation; // move object to touch location
/* have guidelines follow wherever the user is touching on the screen */ /* 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: 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 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 white if its x-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 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 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){ for(UIView* view in self.layoutToolVC.view.subviews){
if ([view isKindOfClass:[OnScreenWidgetView class]]) { if ([view isKindOfClass:[OnScreenWidgetView class]]) {
if ((horizontalGuideline.center.y < view.center.y + 1) && (horizontalGuideline.center.y > view.center.y - 1)) { 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){ for(UIView* view in self.layoutToolVC.view.subviews){
if ([view isKindOfClass:[OnScreenWidgetView class]]) { if ([view isKindOfClass:[OnScreenWidgetView class]]) {
if ((verticalGuideline.center.x < view.center.x + 1) && (verticalGuideline.center.x > view.center.x - 1)) { 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 { - (void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
+7 -3
View File
@@ -781,11 +781,15 @@ import UIKit
private func moveByTouch(touch: UITouch){ private func moveByTouch(touch: UITouch){
let currentLocation = touch.location(in: superview) let currentLocation = touch.location(in: superview)
let offsetX = currentLocation.x - storedLocation.x // let offsetX = currentLocation.x - storedLocation.x
let offsetY = currentLocation.y - storedLocation.y // let offsetY = currentLocation.y - storedLocation.y
center = CGPoint(x: center.x + offsetX, y: center.y + offsetY) // 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) //NSLog("x coord: %f, y coord: %f", self.frame.origin.x, self.frame.origin.y)
storedLocation = currentLocation // Update initial center for next movement 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<UITouch>, with event: UIEvent?) { override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
+1 -1
View File
@@ -74,7 +74,7 @@
<string>armv7</string> <string>armv7</string>
</array> </array>
<key>UIRequiresFullScreen</key> <key>UIRequiresFullScreen</key>
<true/> <false/>
<key>UIStatusBarHidden</key> <key>UIStatusBarHidden</key>
<true/> <true/>
<key>UISupportedInterfaceOrientations</key> <key>UISupportedInterfaceOrientations</key>
@@ -733,6 +733,8 @@
} }
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { - (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
// for OnScreenWidgets:
// -------- for OSC buttons // -------- for OSC buttons
[self.layoutOSC touchesMoved:touches withEvent:event]; [self.layoutOSC touchesMoved:touches withEvent:event];