normalize legacy controller position
This commit is contained in:
1 parent
94f2e39367
commit
c8522de476
4 files changed
+46
-5
No files matched your search
@@ -261,6 +261,14 @@ static CGRect streamViewBounds;
|
|||||||
return position;
|
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 {
|
- (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 */
|
/* 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:
|
// save on-screen game controller buttons & sticks as buttonstate:
|
||||||
for (CALayer *oscButtonLayer in oscButtonLayers) {
|
for (CALayer *oscButtonLayer in oscButtonLayers) {
|
||||||
|
oscButtonLayer.position = [self normalizeWidgetPosition:oscButtonLayer.position];
|
||||||
OnScreenButtonState *buttonState = [[OnScreenButtonState alloc] initWithButtonName:oscButtonLayer.name buttonType:LegacyOscButton andPosition:[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
|
// add hidden attr here
|
||||||
buttonState.isHidden = oscButtonLayer.isHidden;
|
buttonState.isHidden = oscButtonLayer.isHidden;
|
||||||
buttonState.oscLayerSizeFactor = [OnScreenControls getControllerLayerSizeFactor:oscButtonLayer];
|
buttonState.oscLayerSizeFactor = [OnScreenControls getControllerLayerSizeFactor:oscButtonLayer];
|
||||||
@@ -300,7 +309,10 @@ static CGRect streamViewBounds;
|
|||||||
|
|
||||||
// save on-screen widget views (keyboard & mouse command) as buttonstate:
|
// save on-screen widget views (keyboard & mouse command) as buttonstate:
|
||||||
for(OnScreenWidgetView* widgetView in OnScreenWidgetViews){
|
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.alias = widgetView.buttonLabel;
|
||||||
buttonState.widthFactor = widgetView.widthFactor;
|
buttonState.widthFactor = widgetView.widthFactor;
|
||||||
buttonState.heightFactor = widgetView.heightFactor;
|
buttonState.heightFactor = widgetView.heightFactor;
|
||||||
|
|||||||
@@ -336,6 +336,15 @@ static float L3_Y;
|
|||||||
return _level;
|
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 {
|
- (void) updateControls {
|
||||||
if(self._level == OnScreenControlsLevelCustom){
|
if(self._level == OnScreenControlsLevelCustom){
|
||||||
// mark all OSC buttons that has valid coords of positions
|
// mark all OSC buttons that has valid coords of positions
|
||||||
@@ -361,7 +370,7 @@ static float L3_Y;
|
|||||||
NSLog(@"_activeCustomOscButtonPositionDict update: STARTOVER");
|
NSLog(@"_activeCustomOscButtonPositionDict update: STARTOVER");
|
||||||
for (NSData *buttonStateEncoded in oscProfile.buttonStates) {
|
for (NSData *buttonStateEncoded in oscProfile.buttonStates) {
|
||||||
OnScreenButtonState *buttonState = [NSKeyedUnarchiver unarchivedObjectOfClass:[OnScreenButtonState class] fromData:buttonStateEncoded error:nil];
|
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 ) ){
|
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
|
[_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);
|
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];
|
OnScreenButtonState *buttonState = [NSKeyedUnarchiver unarchivedObjectOfClass:[OnScreenButtonState class] fromData:buttonStateEncoded error:nil];
|
||||||
|
|
||||||
if ([buttonState.name isEqualToString:@"dPad"]) {
|
if ([buttonState.name isEqualToString:@"dPad"]) {
|
||||||
|
buttonState.position = [self denormalizeWidgetPosition:buttonState.position];
|
||||||
D_PAD_CENTER_X = buttonState.position.x;
|
D_PAD_CENTER_X = buttonState.position.x;
|
||||||
D_PAD_CENTER_Y = buttonState.position.y;
|
D_PAD_CENTER_Y = buttonState.position.y;
|
||||||
}
|
}
|
||||||
@@ -733,7 +743,7 @@ static float L3_Y;
|
|||||||
|
|
||||||
for (NSData *buttonStateEncoded in oscProfile.buttonStates) {
|
for (NSData *buttonStateEncoded in oscProfile.buttonStates) {
|
||||||
OnScreenButtonState *buttonState = [NSKeyedUnarchiver unarchivedObjectOfClass:[OnScreenButtonState class] fromData:buttonStateEncoded error:nil];
|
OnScreenButtonState *buttonState = [NSKeyedUnarchiver unarchivedObjectOfClass:[OnScreenButtonState class] fromData:buttonStateEncoded error:nil];
|
||||||
|
buttonState.position = [self denormalizeWidgetPosition:buttonState.position];
|
||||||
if ([buttonState.name isEqualToString:@"leftStickBackground"]) {
|
if ([buttonState.name isEqualToString:@"leftStickBackground"]) {
|
||||||
LS_CENTER_X = buttonState.position.x;
|
LS_CENTER_X = buttonState.position.x;
|
||||||
LS_CENTER_Y = buttonState.position.y;
|
LS_CENTER_Y = buttonState.position.y;
|
||||||
@@ -767,6 +777,7 @@ static float L3_Y;
|
|||||||
[buttonLayer.name isEqualToString:@"leftButton"] == NO &&
|
[buttonLayer.name isEqualToString:@"leftButton"] == NO &&
|
||||||
[buttonLayer.name isEqualToString:@"leftStick"] == 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
|
[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.position = buttonStateDecoded.position;
|
||||||
}
|
}
|
||||||
buttonLayer.hidden = buttonStateDecoded.isHidden;
|
buttonLayer.hidden = buttonStateDecoded.isHidden;
|
||||||
|
|||||||
@@ -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{
|
- (void) reloadOnScreenWidgetViews{
|
||||||
|
|
||||||
NSLog(@"reload on screen keyboard buttons here");
|
NSLog(@"reload on screen keyboard buttons here");
|
||||||
@@ -408,6 +416,7 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
|
|||||||
widgetView.minStickOffset = buttonState.minStickOffset;
|
widgetView.minStickOffset = buttonState.minStickOffset;
|
||||||
// Add the widgetView to the view controller's view
|
// 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.
|
[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 setLocationWithXOffset:buttonState.position.x yOffset:buttonState.position.y];
|
||||||
[widgetView resizeWidgetView]; // resize must be called after relocation
|
[widgetView resizeWidgetView]; // resize must be called after relocation
|
||||||
[widgetView adjustTransparencyWithAlpha:buttonState.backgroundAlpha];
|
[widgetView adjustTransparencyWithAlpha:buttonState.backgroundAlpha];
|
||||||
|
|||||||
@@ -68,6 +68,14 @@
|
|||||||
[[NSNotificationCenter defaultCenter] postNotificationName:@"OscLayoutCloseNotification" object:self];
|
[[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 {
|
- (void) reloadOnScreenWidgetViews {
|
||||||
[self->selectedWidgetView.stickBallLayer removeFromSuperlayer];
|
[self->selectedWidgetView.stickBallLayer removeFromSuperlayer];
|
||||||
[self->selectedWidgetView.crossMarkLayer removeFromSuperlayer];
|
[self->selectedWidgetView.crossMarkLayer removeFromSuperlayer];
|
||||||
@@ -100,6 +108,7 @@
|
|||||||
widgetView.minStickOffset = buttonState.minStickOffset;
|
widgetView.minStickOffset = buttonState.minStickOffset;
|
||||||
// Add the widgetView to the view controller's view
|
// Add the widgetView to the view controller's view
|
||||||
[self.view addSubview:widgetView];
|
[self.view addSubview:widgetView];
|
||||||
|
buttonState.position = [self denormalizeWidgetPosition:buttonState.position];
|
||||||
[widgetView setLocationWithXOffset:buttonState.position.x yOffset:buttonState.position.y];
|
[widgetView setLocationWithXOffset:buttonState.position.x yOffset:buttonState.position.y];
|
||||||
[widgetView resizeWidgetView]; // resize must be called after relocation
|
[widgetView resizeWidgetView]; // resize must be called after relocation
|
||||||
[widgetView adjustTransparencyWithAlpha:buttonState.backgroundAlpha];
|
[widgetView adjustTransparencyWithAlpha:buttonState.backgroundAlpha];
|
||||||
|
|||||||
Reference in new issue
Block a user