diff --git a/Limelight/Input/CustomOSC/OSCProfilesManager.m b/Limelight/Input/CustomOSC/OSCProfilesManager.m index cad2c761..61160584 100644 --- a/Limelight/Input/CustomOSC/OSCProfilesManager.m +++ b/Limelight/Input/CustomOSC/OSCProfilesManager.m @@ -261,6 +261,14 @@ static CGRect streamViewBounds; return position; } +- (CGPoint)denormalizeWidgetPosition:(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 */ /* @@ -283,8 +291,9 @@ static CGRect streamViewBounds; // save on-screen game controller buttons & sticks as buttonstate: for (CALayer *oscButtonLayer in oscButtonLayers) { - - OnScreenButtonState *buttonState = [[OnScreenButtonState alloc] initWithButtonName:oscButtonLayer.name buttonType:LegacyOscButton andPosition:[self normalizeWidgetPosition:oscButtonLayer.position]]; + oscButtonLayer.position = [self normalizeWidgetPosition:oscButtonLayer.position]; + OnScreenButtonState *buttonState = [[OnScreenButtonState alloc] initWithButtonName:oscButtonLayer.name buttonType:LegacyOscButton andPosition:oscButtonLayer.position]; + oscButtonLayer.position = [self denormalizeWidgetPosition:oscButtonLayer.position]; // add hidden attr here buttonState.isHidden = oscButtonLayer.isHidden; buttonState.oscLayerSizeFactor = [OnScreenControls getControllerLayerSizeFactor:oscButtonLayer]; @@ -300,7 +309,10 @@ static CGRect streamViewBounds; // save on-screen widget views (keyboard & mouse command) as buttonstate: for(OnScreenWidgetView* widgetView in OnScreenWidgetViews){ - OnScreenButtonState *buttonState = [[OnScreenButtonState alloc] initWithButtonName:widgetView.cmdString buttonType:CustomOnScreenWidget andPosition:widgetView.center]; + + widgetView.center = [self normalizeWidgetPosition:widgetView.center]; + OnScreenButtonState *buttonState = [[OnScreenButtonState alloc] initWithButtonName:widgetView.buttonLabel buttonType:CustomOnScreenWidget andPosition:widgetView.center]; + widgetView.center = [self denormalizeWidgetPosition:widgetView.center]; buttonState.alias = widgetView.buttonLabel; buttonState.widthFactor = widgetView.widthFactor; buttonState.heightFactor = widgetView.heightFactor; diff --git a/Limelight/Input/OnScreenControls.m b/Limelight/Input/OnScreenControls.m index 5f407d10..1ab72758 100644 --- a/Limelight/Input/OnScreenControls.m +++ b/Limelight/Input/OnScreenControls.m @@ -336,6 +336,15 @@ static float L3_Y; return _level; } +- (CGPoint) denormalizeWidgetPosition:(CGPoint)position { + if(position.x < 1.0 && position.y < 1.0) { + position.x = position.x * _view.bounds.size.width; + position.y = position.y * _view.bounds.size.height; + NSLog(@"denormalizing position: %f, %f", position.x, position.y); + } + return position; +} + - (void) updateControls { if(self._level == OnScreenControlsLevelCustom){ // mark all OSC buttons that has valid coords of positions @@ -361,7 +370,7 @@ static float L3_Y; NSLog(@"_activeCustomOscButtonPositionDict update: STARTOVER"); for (NSData *buttonStateEncoded in oscProfile.buttonStates) { OnScreenButtonState *buttonState = [NSKeyedUnarchiver unarchivedObjectOfClass:[OnScreenButtonState class] fromData:buttonStateEncoded error:nil]; - + buttonState.position = [self denormalizeWidgetPosition:buttonState.position]; if(!buttonState.isHidden && [validPositionButtonNames containsObject:buttonState.name] && (buttonState.buttonType == LegacyOscButton || [profilesManager getIndexOfSelectedProfile] == 0 ) ){ [_activeCustomOscButtonPositionDict setObject:[NSValue valueWithCGPoint:buttonState.position] forKey:buttonState.name]; // we got a buttonname -> position dict here NSLog(@"_activeCustomOscButtonPositionDict update, button name:%@, position: %f, %f", buttonState.name, buttonState.position.x, buttonState.position.y); @@ -719,6 +728,7 @@ static float L3_Y; OnScreenButtonState *buttonState = [NSKeyedUnarchiver unarchivedObjectOfClass:[OnScreenButtonState class] fromData:buttonStateEncoded error:nil]; if ([buttonState.name isEqualToString:@"dPad"]) { + buttonState.position = [self denormalizeWidgetPosition:buttonState.position]; D_PAD_CENTER_X = buttonState.position.x; D_PAD_CENTER_Y = buttonState.position.y; } @@ -733,7 +743,7 @@ static float L3_Y; for (NSData *buttonStateEncoded in oscProfile.buttonStates) { OnScreenButtonState *buttonState = [NSKeyedUnarchiver unarchivedObjectOfClass:[OnScreenButtonState class] fromData:buttonStateEncoded error:nil]; - + buttonState.position = [self denormalizeWidgetPosition:buttonState.position]; if ([buttonState.name isEqualToString:@"leftStickBackground"]) { LS_CENTER_X = buttonState.position.x; LS_CENTER_Y = buttonState.position.y; @@ -767,6 +777,7 @@ static float L3_Y; [buttonLayer.name isEqualToString:@"leftButton"] == NO && [buttonLayer.name isEqualToString:@"leftStick"] == NO && [buttonLayer.name isEqualToString:@"rightStick"] == NO) { // Don't move these buttons since they've already been positioned correctly in the 'drawButtons' and 'drawSticks' methods called before this method is called. The 'buttonStateDecoded' object associated with these buttons contains positions relative to a parent CALayer which only exists on 'LayoutOnScreenControls'. These positions relative to the parent layers would translate incorrectly when placed on the game stream VC's 'view' layer + buttonStateDecoded.position = [self denormalizeWidgetPosition:buttonStateDecoded.position]; buttonLayer.position = buttonStateDecoded.position; } buttonLayer.hidden = buttonStateDecoded.isHidden; diff --git a/Limelight/Input/StreamView.m b/Limelight/Input/StreamView.m index a116493f..2acee362 100644 --- a/Limelight/Input/StreamView.m +++ b/Limelight/Input/StreamView.m @@ -376,6 +376,14 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5; } } +- (CGPoint)denormalizeWidgetPosition:(CGPoint)position { + if(position.x < 1.0 && position.y < 1.0){ + position.x = position.x * self.bounds.size.width; + position.y = position.y * self.bounds.size.height; + } + return position; +} + - (void) reloadOnScreenWidgetViews{ NSLog(@"reload on screen keyboard buttons here"); @@ -408,6 +416,7 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5; widgetView.minStickOffset = buttonState.minStickOffset; // Add the widgetView to the view controller's view [self->streamFrameTopLayerView addSubview:widgetView]; // add keyboard button to the stream frame view. must add it to the target view before setting location. + buttonState.position = [self denormalizeWidgetPosition:buttonState.position]; [widgetView setLocationWithXOffset:buttonState.position.x yOffset:buttonState.position.y]; [widgetView resizeWidgetView]; // resize must be called after relocation [widgetView adjustTransparencyWithAlpha:buttonState.backgroundAlpha]; diff --git a/Limelight/ViewControllers/CustomOSCViewControl/LayoutOnScreenControlsViewController.m b/Limelight/ViewControllers/CustomOSCViewControl/LayoutOnScreenControlsViewController.m index cbaec49f..0fc964c9 100644 --- a/Limelight/ViewControllers/CustomOSCViewControl/LayoutOnScreenControlsViewController.m +++ b/Limelight/ViewControllers/CustomOSCViewControl/LayoutOnScreenControlsViewController.m @@ -68,6 +68,14 @@ [[NSNotificationCenter defaultCenter] postNotificationName:@"OscLayoutCloseNotification" object:self]; } +- (CGPoint)denormalizeWidgetPosition:(CGPoint)position { + if(position.x < 1.0 && position.y < 1.0){ + position.x = position.x * self.view.bounds.size.width; + position.y = position.y * self.view.bounds.size.height; + } + return position; +} + - (void) reloadOnScreenWidgetViews { [self->selectedWidgetView.stickBallLayer removeFromSuperlayer]; [self->selectedWidgetView.crossMarkLayer removeFromSuperlayer]; @@ -100,6 +108,7 @@ widgetView.minStickOffset = buttonState.minStickOffset; // Add the widgetView to the view controller's view [self.view addSubview:widgetView]; + buttonState.position = [self denormalizeWidgetPosition:buttonState.position]; [widgetView setLocationWithXOffset:buttonState.position.x yOffset:buttonState.position.y]; [widgetView resizeWidgetView]; // resize must be called after relocation [widgetView adjustTransparencyWithAlpha:buttonState.backgroundAlpha];