guide lines optimizations for legacy osc buttons

This commit is contained in:
TrueZhuangjia
2025-04-02 20:35:14 +08:00
committed by TrueZhuanjia
parent 928284990b
commit a03a50d238
5 changed files with 65 additions and 62 deletions
@@ -31,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;
- (void) updateGuidelinesForOnScreenWidget:(OnScreenWidgetView* )widget;
@end
NS_ASSUME_NONNULL_END
@@ -30,7 +30,7 @@
- (id) initWithView:(UIView*)view controllerSup:(ControllerSupport*)controllerSupport streamConfig:(StreamConfiguration*)streamConfig oscLevel:(int)oscLevel {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(updateGuidelinesForOnScreenWidget:)
selector:@selector(handleMovingOnScreenWidgetNotification:)
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];
@@ -109,9 +109,13 @@
[self._view addSubview: verticalGuideline];
}
- (void) updateGuidelinesForOnScreenWidget: (NSNotification *)notification{
/* have guidelines follow wherever the user is touching on the screen */
- (void) handleMovingOnScreenWidgetNotification: (NSNotification *)notification{
OnScreenWidgetView* widget = notification.object;
[self updateGuidelinesForOnScreenWidget:widget];
}
- (void) updateGuidelinesForOnScreenWidget: (OnScreenWidgetView* )widget{
/* have guidelines follow wherever the user is touching on the screen */
horizontalGuideline.hidden = verticalGuideline.hidden = NO;
horizontalGuideline.center = verticalGuideline.center = CGPointMake(CGRectGetMidX(widget.frame), CGRectGetMidY(widget.frame));
/*
@@ -160,6 +164,55 @@
}
- (void) updateGuidelinesForLegacyOscButton{
/* have guidelines follow wherever the user is touching on the screen */
horizontalGuideline.center = layerBeingDragged.position;
verticalGuideline.center = layerBeingDragged.position;
/*
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;
}
}
}
// 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)) {
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;
}
}
}
// 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)) {
verticalGuideline.backgroundColor = [UIColor yellowColor];
break;
}
}
}
}
#pragma mark - Queries
@@ -248,68 +301,20 @@
[[NSNotificationCenter defaultCenter] postNotificationName:@"OSCLayoutChanged" object:self]; // lets the view controller know whether to fade the undo button in or out depending on whether there are any further OSC layout changes the user is allowed to undo
/* make guide lines visible and position them over the button the user is touching */
horizontalGuideline.center = layerBeingDragged.position;
horizontalGuideline.hidden = NO;
verticalGuideline.center = layerBeingDragged.position;
verticalGuideline.hidden = NO;
[self updateGuidelinesForLegacyOscButton];
}
}
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint touchLocation = [touch locationInView:_view];
[CATransaction begin];
[CATransaction setDisableActions:YES];
layerBeingDragged.position = touchLocation; // move object to touch location
/* have guidelines follow wherever the user is touching on the screen */
horizontalGuideline.center = layerBeingDragged.position;
verticalGuideline.center = layerBeingDragged.position;
/*
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;
}
}
}
// 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)) {
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;
}
}
}
// 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)) {
verticalGuideline.backgroundColor = [UIColor yellowColor];
break;
}
}
}
[self updateGuidelinesForLegacyOscButton];
[CATransaction commit];
}
- (void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
+1 -4
View File
@@ -1037,10 +1037,7 @@ static float L3_Y;
}
- (BOOL) handleTouchMovedEvent:touches {
// Start a new transaction
[CATransaction begin];
// Disable implicit animations for onScreenStick movements
[CATransaction setDisableActions:YES];
BOOL updated = false;
@@ -1178,7 +1175,7 @@ static float L3_Y;
- (void)oscButtonTouchDownVisualEffect:(CALayer* )button{
[CATransaction begin];
[CATransaction setDisableActions:YES]; // Disable implicit animations for
[CATransaction setDisableActions:YES];
/*
if(![[_originalControllerLayerOpacityDict allKeys] containsObject:button.name]){
+1 -1
View File
@@ -367,7 +367,7 @@ import UIKit
else {self.layer.borderWidth = self.borderWidth}
label.text = "" // make touchPad display no text
if OnScreenWidgetView.editMode { //display label in edit mode to make the pad more visible
label.text = self.cmdString
label.text = self.buttonLabel
}
}
@@ -494,6 +494,7 @@
self->widgetViewSelected = true;
self->controllerLayerSelected = false;
self->selectedWidgetView = widgetView;
[self.layoutOSC updateGuidelinesForOnScreenWidget:self->selectedWidgetView]; // shows guideline immediately when widget is tapped
// setup slider values
[self.widgetSizeSlider setValue: self->selectedWidgetView.widthFactor];
[self.widgetHeightSlider setValue: self->selectedWidgetView.heightFactor];