2021-03-15 17:37:46 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2021-08-13 14:20:52 +08:00
|
|
|
|
using osu.Framework;
|
2021-03-15 17:37:46 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
|
using osu.Framework.Graphics;
|
2021-03-16 22:47:08 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2021-03-15 17:37:46 +08:00
|
|
|
|
using osu.Framework.Input.Handlers.Tablet;
|
2021-07-15 11:50:34 +08:00
|
|
|
|
using osu.Framework.Localisation;
|
2021-03-16 16:57:50 +08:00
|
|
|
|
using osu.Framework.Platform;
|
|
|
|
|
using osu.Framework.Threading;
|
2021-08-13 14:20:52 +08:00
|
|
|
|
using osu.Game.Graphics;
|
2022-05-31 13:01:42 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2021-03-16 22:47:08 +08:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2021-03-16 22:57:05 +08:00
|
|
|
|
using osuTK;
|
2021-07-16 22:03:44 +08:00
|
|
|
|
using osu.Game.Localisation;
|
2021-08-13 14:20:52 +08:00
|
|
|
|
using osu.Game.Online.Chat;
|
2021-03-15 17:37:46 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Settings.Sections.Input
|
|
|
|
|
{
|
|
|
|
|
public class TabletSettings : SettingsSubsection
|
|
|
|
|
{
|
2021-09-04 14:35:46 +08:00
|
|
|
|
public TabletAreaSelection AreaSelection { get; private set; }
|
|
|
|
|
|
2021-03-15 17:37:46 +08:00
|
|
|
|
private readonly ITabletHandler tabletHandler;
|
|
|
|
|
|
2021-08-16 18:45:50 +08:00
|
|
|
|
private readonly Bindable<bool> enabled = new BindableBool(true);
|
|
|
|
|
|
2021-03-17 11:50:02 +08:00
|
|
|
|
private readonly Bindable<Vector2> areaOffset = new Bindable<Vector2>();
|
|
|
|
|
private readonly Bindable<Vector2> areaSize = new Bindable<Vector2>();
|
|
|
|
|
private readonly IBindable<TabletInfo> tablet = new Bindable<TabletInfo>();
|
2021-03-15 17:37:46 +08:00
|
|
|
|
|
2021-03-17 11:50:02 +08:00
|
|
|
|
private readonly BindableNumber<float> offsetX = new BindableNumber<float> { MinValue = 0 };
|
|
|
|
|
private readonly BindableNumber<float> offsetY = new BindableNumber<float> { MinValue = 0 };
|
2021-03-15 17:37:46 +08:00
|
|
|
|
|
2021-03-17 11:50:02 +08:00
|
|
|
|
private readonly BindableNumber<float> sizeX = new BindableNumber<float> { MinValue = 10 };
|
|
|
|
|
private readonly BindableNumber<float> sizeY = new BindableNumber<float> { MinValue = 10 };
|
2021-03-15 17:37:46 +08:00
|
|
|
|
|
2021-03-30 11:40:50 +08:00
|
|
|
|
private readonly BindableNumber<float> rotation = new BindableNumber<float> { MinValue = 0, MaxValue = 360 };
|
|
|
|
|
|
2021-03-16 16:57:50 +08:00
|
|
|
|
[Resolved]
|
|
|
|
|
private GameHost host { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2021-03-19 19:05:18 +08:00
|
|
|
|
/// Based on ultrawide monitor configurations.
|
2021-03-16 16:57:50 +08:00
|
|
|
|
/// </summary>
|
2021-03-19 19:05:18 +08:00
|
|
|
|
private const float largest_feasible_aspect_ratio = 21f / 9;
|
2021-03-16 16:04:22 +08:00
|
|
|
|
|
|
|
|
|
private readonly BindableNumber<float> aspectRatio = new BindableFloat(1)
|
|
|
|
|
{
|
2021-03-16 16:57:50 +08:00
|
|
|
|
MinValue = 1 / largest_feasible_aspect_ratio,
|
|
|
|
|
MaxValue = largest_feasible_aspect_ratio,
|
2021-03-16 16:04:22 +08:00
|
|
|
|
Precision = 0.01f,
|
|
|
|
|
};
|
|
|
|
|
|
2021-03-16 16:57:50 +08:00
|
|
|
|
private readonly BindableBool aspectLock = new BindableBool();
|
|
|
|
|
|
|
|
|
|
private ScheduledDelegate aspectRatioApplication;
|
|
|
|
|
|
2021-03-16 22:47:08 +08:00
|
|
|
|
private FillFlowContainer mainSettings;
|
|
|
|
|
|
2021-08-13 14:20:52 +08:00
|
|
|
|
private FillFlowContainer noTabletMessage;
|
2021-03-16 22:47:08 +08:00
|
|
|
|
|
2021-07-16 22:03:44 +08:00
|
|
|
|
protected override LocalisableString Header => TabletSettingsStrings.Tablet;
|
2021-03-15 17:37:46 +08:00
|
|
|
|
|
|
|
|
|
public TabletSettings(ITabletHandler tabletHandler)
|
|
|
|
|
{
|
|
|
|
|
this.tabletHandler = tabletHandler;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2022-09-16 20:08:25 +08:00
|
|
|
|
private void load(OsuColour colours, LocalisationManager localisation)
|
2021-03-15 17:37:46 +08:00
|
|
|
|
{
|
2021-03-16 17:40:21 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2021-03-19 19:13:51 +08:00
|
|
|
|
new SettingsCheckbox
|
|
|
|
|
{
|
2021-07-16 22:03:44 +08:00
|
|
|
|
LabelText = CommonStrings.Enabled,
|
2021-03-19 19:13:51 +08:00
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
2021-08-16 18:45:50 +08:00
|
|
|
|
Current = enabled,
|
2021-03-19 19:13:51 +08:00
|
|
|
|
},
|
2021-08-13 14:20:52 +08:00
|
|
|
|
noTabletMessage = new FillFlowContainer
|
2021-03-16 17:40:21 +08:00
|
|
|
|
{
|
2021-08-13 14:20:52 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Padding = new MarginPadding { Horizontal = SettingsPanel.CONTENT_MARGINS },
|
|
|
|
|
Spacing = new Vector2(5f),
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Text = TabletSettingsStrings.NoTabletDetected,
|
|
|
|
|
},
|
2022-05-31 13:01:42 +08:00
|
|
|
|
new LinkFlowContainer(cp => cp.Colour = colours.Yellow)
|
2021-08-13 14:20:52 +08:00
|
|
|
|
{
|
|
|
|
|
TextAnchor = Anchor.TopCentre,
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
2022-05-31 13:01:42 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2021-08-13 14:20:52 +08:00
|
|
|
|
}.With(t =>
|
|
|
|
|
{
|
2021-08-13 14:26:53 +08:00
|
|
|
|
if (RuntimeInfo.OS == RuntimeInfo.Platform.Windows || RuntimeInfo.OS == RuntimeInfo.Platform.Linux)
|
|
|
|
|
{
|
|
|
|
|
t.NewLine();
|
2022-09-16 20:08:25 +08:00
|
|
|
|
var formattedSource = MessageFormatter.FormatText(localisation.GetLocalisedBindableString(TabletSettingsStrings.NoTabletDetectedDescription(RuntimeInfo.OS == RuntimeInfo.Platform.Windows
|
2022-01-11 23:11:07 +08:00
|
|
|
|
? @"https://opentabletdriver.net/Wiki/FAQ/Windows"
|
2022-09-16 20:08:25 +08:00
|
|
|
|
: @"https://opentabletdriver.net/Wiki/FAQ/Linux")).Value);
|
2022-09-16 17:31:02 +08:00
|
|
|
|
t.AddLinks(formattedSource.Text, formattedSource.Links);
|
2021-08-13 14:26:53 +08:00
|
|
|
|
}
|
2021-08-13 14:20:52 +08:00
|
|
|
|
}),
|
|
|
|
|
}
|
2021-03-16 17:40:21 +08:00
|
|
|
|
},
|
2021-03-16 22:47:08 +08:00
|
|
|
|
mainSettings = new FillFlowContainer
|
2021-03-16 17:40:21 +08:00
|
|
|
|
{
|
2021-03-16 22:47:08 +08:00
|
|
|
|
Alpha = 0,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2021-03-16 22:57:05 +08:00
|
|
|
|
Spacing = new Vector2(0, 8),
|
2021-03-16 22:47:08 +08:00
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Children = new Drawable[]
|
2021-03-16 17:40:21 +08:00
|
|
|
|
{
|
2021-09-04 14:35:46 +08:00
|
|
|
|
AreaSelection = new TabletAreaSelection(tabletHandler)
|
2021-03-16 22:47:08 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Height = 300,
|
|
|
|
|
},
|
|
|
|
|
new DangerousSettingsButton
|
|
|
|
|
{
|
2021-07-16 22:03:44 +08:00
|
|
|
|
Text = TabletSettingsStrings.ResetToFullArea,
|
2021-03-16 22:47:08 +08:00
|
|
|
|
Action = () =>
|
|
|
|
|
{
|
|
|
|
|
aspectLock.Value = false;
|
|
|
|
|
|
|
|
|
|
areaOffset.SetDefault();
|
|
|
|
|
areaSize.SetDefault();
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
new SettingsButton
|
|
|
|
|
{
|
2021-07-16 22:03:44 +08:00
|
|
|
|
Text = TabletSettingsStrings.ConformToCurrentGameAspectRatio,
|
2021-03-16 22:47:08 +08:00
|
|
|
|
Action = () =>
|
|
|
|
|
{
|
|
|
|
|
forceAspectRatio((float)host.Window.ClientSize.Width / host.Window.ClientSize.Height);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
new SettingsSlider<float>
|
|
|
|
|
{
|
2021-03-17 12:23:23 +08:00
|
|
|
|
TransferValueOnCommit = true,
|
2021-07-16 22:03:44 +08:00
|
|
|
|
LabelText = TabletSettingsStrings.XOffset,
|
2021-03-16 22:47:08 +08:00
|
|
|
|
Current = offsetX
|
|
|
|
|
},
|
2021-03-17 11:50:02 +08:00
|
|
|
|
new SettingsSlider<float>
|
2021-03-16 22:47:08 +08:00
|
|
|
|
{
|
2021-03-17 12:23:23 +08:00
|
|
|
|
TransferValueOnCommit = true,
|
2021-07-16 22:03:44 +08:00
|
|
|
|
LabelText = TabletSettingsStrings.YOffset,
|
2021-03-16 22:47:08 +08:00
|
|
|
|
Current = offsetY
|
|
|
|
|
},
|
2021-03-30 11:32:42 +08:00
|
|
|
|
new SettingsSlider<float>
|
2021-03-30 11:40:50 +08:00
|
|
|
|
{
|
|
|
|
|
TransferValueOnCommit = true,
|
2021-07-16 22:03:44 +08:00
|
|
|
|
LabelText = TabletSettingsStrings.Rotation,
|
2021-03-30 11:40:50 +08:00
|
|
|
|
Current = rotation
|
|
|
|
|
},
|
2021-10-10 01:54:20 +08:00
|
|
|
|
new RotationPresetButtons(tabletHandler)
|
|
|
|
|
{
|
|
|
|
|
Padding = new MarginPadding
|
|
|
|
|
{
|
|
|
|
|
Horizontal = SettingsPanel.CONTENT_MARGINS
|
|
|
|
|
}
|
|
|
|
|
},
|
2021-03-30 11:40:50 +08:00
|
|
|
|
new SettingsSlider<float>
|
2021-03-30 11:32:42 +08:00
|
|
|
|
{
|
|
|
|
|
TransferValueOnCommit = true,
|
2021-07-16 22:03:44 +08:00
|
|
|
|
LabelText = TabletSettingsStrings.AspectRatio,
|
2021-03-30 11:32:42 +08:00
|
|
|
|
Current = aspectRatio
|
|
|
|
|
},
|
2021-03-16 22:47:08 +08:00
|
|
|
|
new SettingsCheckbox
|
|
|
|
|
{
|
2021-07-16 22:03:44 +08:00
|
|
|
|
LabelText = TabletSettingsStrings.LockAspectRatio,
|
2021-03-16 22:47:08 +08:00
|
|
|
|
Current = aspectLock
|
|
|
|
|
},
|
2021-03-17 11:50:02 +08:00
|
|
|
|
new SettingsSlider<float>
|
2021-03-16 22:47:08 +08:00
|
|
|
|
{
|
2021-03-17 12:23:23 +08:00
|
|
|
|
TransferValueOnCommit = true,
|
2021-07-16 22:03:44 +08:00
|
|
|
|
LabelText = CommonStrings.Width,
|
2021-03-16 22:47:08 +08:00
|
|
|
|
Current = sizeX
|
|
|
|
|
},
|
2021-03-17 11:50:02 +08:00
|
|
|
|
new SettingsSlider<float>
|
2021-03-16 22:47:08 +08:00
|
|
|
|
{
|
2021-03-17 12:23:23 +08:00
|
|
|
|
TransferValueOnCommit = true,
|
2021-07-16 22:03:44 +08:00
|
|
|
|
LabelText = CommonStrings.Height,
|
2021-03-16 22:47:08 +08:00
|
|
|
|
Current = sizeY
|
|
|
|
|
},
|
2021-03-16 17:40:21 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
};
|
2021-03-17 13:18:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
2021-03-16 17:40:21 +08:00
|
|
|
|
|
2021-08-16 18:45:50 +08:00
|
|
|
|
enabled.BindTo(tabletHandler.Enabled);
|
|
|
|
|
enabled.BindValueChanged(_ => Scheduler.AddOnce(updateVisibility));
|
|
|
|
|
|
2021-03-30 11:40:50 +08:00
|
|
|
|
rotation.BindTo(tabletHandler.Rotation);
|
|
|
|
|
|
2021-03-15 17:37:46 +08:00
|
|
|
|
areaOffset.BindTo(tabletHandler.AreaOffset);
|
2022-09-26 14:10:02 +08:00
|
|
|
|
areaOffset.BindValueChanged(val => Schedule(() =>
|
2021-03-15 17:37:46 +08:00
|
|
|
|
{
|
2021-03-17 11:50:02 +08:00
|
|
|
|
offsetX.Value = val.NewValue.X;
|
|
|
|
|
offsetY.Value = val.NewValue.Y;
|
2022-09-26 14:10:02 +08:00
|
|
|
|
}), true);
|
2021-03-15 17:37:46 +08:00
|
|
|
|
|
2021-03-17 11:50:02 +08:00
|
|
|
|
offsetX.BindValueChanged(val => areaOffset.Value = new Vector2(val.NewValue, areaOffset.Value.Y));
|
|
|
|
|
offsetY.BindValueChanged(val => areaOffset.Value = new Vector2(areaOffset.Value.X, val.NewValue));
|
2021-03-15 17:37:46 +08:00
|
|
|
|
|
|
|
|
|
areaSize.BindTo(tabletHandler.AreaSize);
|
2022-09-26 14:10:02 +08:00
|
|
|
|
areaSize.BindValueChanged(val => Schedule(() =>
|
2021-03-15 17:37:46 +08:00
|
|
|
|
{
|
2021-03-17 11:50:02 +08:00
|
|
|
|
sizeX.Value = val.NewValue.X;
|
|
|
|
|
sizeY.Value = val.NewValue.Y;
|
2022-09-26 14:10:02 +08:00
|
|
|
|
}), true);
|
2021-03-16 17:40:21 +08:00
|
|
|
|
|
|
|
|
|
sizeX.BindValueChanged(val =>
|
|
|
|
|
{
|
2021-03-17 11:50:02 +08:00
|
|
|
|
areaSize.Value = new Vector2(val.NewValue, areaSize.Value.Y);
|
2021-03-16 16:04:22 +08:00
|
|
|
|
|
2021-03-16 16:57:50 +08:00
|
|
|
|
aspectRatioApplication?.Cancel();
|
2021-03-16 17:40:21 +08:00
|
|
|
|
aspectRatioApplication = Schedule(() => applyAspectRatio(sizeX));
|
|
|
|
|
});
|
2021-03-15 17:37:46 +08:00
|
|
|
|
|
2021-03-16 17:40:21 +08:00
|
|
|
|
sizeY.BindValueChanged(val =>
|
|
|
|
|
{
|
2021-03-17 11:50:02 +08:00
|
|
|
|
areaSize.Value = new Vector2(areaSize.Value.X, val.NewValue);
|
2021-03-16 17:40:21 +08:00
|
|
|
|
|
|
|
|
|
aspectRatioApplication?.Cancel();
|
|
|
|
|
aspectRatioApplication = Schedule(() => applyAspectRatio(sizeY));
|
|
|
|
|
});
|
2021-03-15 17:37:46 +08:00
|
|
|
|
|
2021-03-19 19:15:29 +08:00
|
|
|
|
updateAspectRatio();
|
2021-03-16 16:57:50 +08:00
|
|
|
|
aspectRatio.BindValueChanged(aspect =>
|
|
|
|
|
{
|
2021-03-16 17:14:29 +08:00
|
|
|
|
aspectRatioApplication?.Cancel();
|
|
|
|
|
aspectRatioApplication = Schedule(() => forceAspectRatio(aspect.NewValue));
|
2021-03-16 16:57:50 +08:00
|
|
|
|
});
|
|
|
|
|
|
2021-03-17 11:50:02 +08:00
|
|
|
|
tablet.BindTo(tabletHandler.Tablet);
|
2022-09-26 14:10:02 +08:00
|
|
|
|
tablet.BindValueChanged(val => Schedule(() =>
|
2021-03-15 17:37:46 +08:00
|
|
|
|
{
|
2021-08-16 18:45:50 +08:00
|
|
|
|
Scheduler.AddOnce(updateVisibility);
|
2021-03-20 19:29:24 +08:00
|
|
|
|
|
2021-03-17 11:50:02 +08:00
|
|
|
|
var tab = val.NewValue;
|
|
|
|
|
|
|
|
|
|
bool tabletFound = tab != null;
|
2021-03-16 22:47:08 +08:00
|
|
|
|
if (!tabletFound)
|
2021-03-16 14:57:29 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2021-03-17 11:50:02 +08:00
|
|
|
|
offsetX.MaxValue = tab.Size.X;
|
|
|
|
|
offsetX.Default = tab.Size.X / 2;
|
|
|
|
|
sizeX.Default = sizeX.MaxValue = tab.Size.X;
|
2021-03-15 17:37:46 +08:00
|
|
|
|
|
2021-03-17 11:50:02 +08:00
|
|
|
|
offsetY.MaxValue = tab.Size.Y;
|
|
|
|
|
offsetY.Default = tab.Size.Y / 2;
|
|
|
|
|
sizeY.Default = sizeY.MaxValue = tab.Size.Y;
|
2021-03-15 17:37:46 +08:00
|
|
|
|
|
2021-03-17 11:50:02 +08:00
|
|
|
|
areaSize.Default = new Vector2(sizeX.Default, sizeY.Default);
|
2022-09-26 14:10:02 +08:00
|
|
|
|
}), true);
|
2021-03-15 17:37:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-16 18:45:50 +08:00
|
|
|
|
private void updateVisibility()
|
2021-03-20 19:29:24 +08:00
|
|
|
|
{
|
2021-08-16 21:07:41 +08:00
|
|
|
|
mainSettings.Hide();
|
|
|
|
|
noTabletMessage.Hide();
|
|
|
|
|
|
2021-08-16 18:45:50 +08:00
|
|
|
|
if (!tabletHandler.Enabled.Value)
|
|
|
|
|
return;
|
2021-03-20 19:29:24 +08:00
|
|
|
|
|
2021-08-16 21:07:41 +08:00
|
|
|
|
if (tablet.Value != null)
|
|
|
|
|
mainSettings.Show();
|
|
|
|
|
else
|
2021-03-20 19:29:24 +08:00
|
|
|
|
noTabletMessage.Show();
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-17 11:50:02 +08:00
|
|
|
|
private void applyAspectRatio(BindableNumber<float> sizeChanged)
|
2021-03-16 16:57:50 +08:00
|
|
|
|
{
|
2021-03-16 17:14:29 +08:00
|
|
|
|
try
|
2021-03-16 16:57:50 +08:00
|
|
|
|
{
|
2021-03-16 17:14:29 +08:00
|
|
|
|
if (!aspectLock.Value)
|
|
|
|
|
{
|
2021-03-20 19:34:41 +08:00
|
|
|
|
float proposedAspectRatio = currentAspectRatio;
|
2021-03-16 17:40:21 +08:00
|
|
|
|
|
2021-03-16 17:14:29 +08:00
|
|
|
|
if (proposedAspectRatio >= aspectRatio.MinValue && proposedAspectRatio <= aspectRatio.MaxValue)
|
|
|
|
|
{
|
2021-03-16 17:40:21 +08:00
|
|
|
|
// aspect ratio was in a valid range.
|
2021-03-16 17:14:29 +08:00
|
|
|
|
updateAspectRatio();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-03-16 16:57:50 +08:00
|
|
|
|
|
2021-03-16 17:40:21 +08:00
|
|
|
|
// if lock is applied (or the specified values were out of range) aim to adjust the axis the user was not adjusting to conform.
|
|
|
|
|
if (sizeChanged == sizeX)
|
2021-03-17 11:50:02 +08:00
|
|
|
|
sizeY.Value = (int)(areaSize.Value.X / aspectRatio.Value);
|
2021-03-16 17:14:29 +08:00
|
|
|
|
else
|
2021-03-17 11:50:02 +08:00
|
|
|
|
sizeX.Value = (int)(areaSize.Value.Y * aspectRatio.Value);
|
2021-03-16 16:57:50 +08:00
|
|
|
|
}
|
2021-03-16 17:14:29 +08:00
|
|
|
|
finally
|
2021-03-16 16:57:50 +08:00
|
|
|
|
{
|
2021-03-16 17:14:29 +08:00
|
|
|
|
// cancel any event which may have fired while updating variables as a result of aspect ratio limitations.
|
|
|
|
|
// this avoids a potential feedback loop.
|
|
|
|
|
aspectRatioApplication?.Cancel();
|
2021-03-16 16:57:50 +08:00
|
|
|
|
}
|
2021-03-16 17:14:29 +08:00
|
|
|
|
}
|
2021-03-16 16:57:50 +08:00
|
|
|
|
|
|
|
|
|
private void forceAspectRatio(float aspectRatio)
|
|
|
|
|
{
|
|
|
|
|
aspectLock.Value = false;
|
|
|
|
|
|
|
|
|
|
int proposedHeight = (int)(sizeX.Value / aspectRatio);
|
|
|
|
|
|
|
|
|
|
if (proposedHeight < sizeY.MaxValue)
|
|
|
|
|
sizeY.Value = proposedHeight;
|
|
|
|
|
else
|
|
|
|
|
sizeX.Value = (int)(sizeY.Value * aspectRatio);
|
|
|
|
|
|
2021-03-16 17:14:29 +08:00
|
|
|
|
updateAspectRatio();
|
|
|
|
|
|
2021-03-16 16:57:50 +08:00
|
|
|
|
aspectRatioApplication?.Cancel();
|
|
|
|
|
aspectLock.Value = true;
|
|
|
|
|
}
|
2021-03-16 17:40:21 +08:00
|
|
|
|
|
2021-03-20 19:34:41 +08:00
|
|
|
|
private void updateAspectRatio() => aspectRatio.Value = currentAspectRatio;
|
2021-03-16 17:40:21 +08:00
|
|
|
|
|
2021-03-20 19:34:41 +08:00
|
|
|
|
private float currentAspectRatio => sizeX.Value / sizeY.Value;
|
2021-03-15 17:37:46 +08:00
|
|
|
|
}
|
|
|
|
|
}
|