mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 10:33:30 +08:00
Update to use new bindables and centered area offset
This commit is contained in:
parent
9d0c8902a6
commit
196f95ae54
@ -1,7 +1,6 @@
|
||||
// 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.
|
||||
|
||||
using System.Drawing;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
@ -11,6 +10,7 @@ using osu.Framework.Platform;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Overlays.Settings.Sections.Input;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Settings
|
||||
{
|
||||
@ -22,9 +22,6 @@ namespace osu.Game.Tests.Visual.Settings
|
||||
{
|
||||
var tabletHandler = new TestTabletHandler();
|
||||
|
||||
tabletHandler.AreaOffset.Value = new Size(10, 10);
|
||||
tabletHandler.AreaSize.Value = new Size(100, 80);
|
||||
|
||||
AddRange(new Drawable[]
|
||||
{
|
||||
new TabletSettings(tabletHandler)
|
||||
@ -36,27 +33,40 @@ namespace osu.Game.Tests.Visual.Settings
|
||||
}
|
||||
});
|
||||
|
||||
AddStep("Test with wide tablet", () => tabletHandler.SetTabletSize(new Size(160, 100)));
|
||||
AddStep("Test with square tablet", () => tabletHandler.SetTabletSize(new Size(300, 300)));
|
||||
AddStep("Test with tall tablet", () => tabletHandler.SetTabletSize(new Size(100, 300)));
|
||||
AddStep("Test with very tall tablet", () => tabletHandler.SetTabletSize(new Size(100, 700)));
|
||||
AddStep("Test no tablet present", () => tabletHandler.SetTabletSize(System.Drawing.Size.Empty));
|
||||
AddStep("Test with wide tablet", () => tabletHandler.SetTabletSize(new Vector2(160, 100)));
|
||||
AddStep("Test with square tablet", () => tabletHandler.SetTabletSize(new Vector2(300, 300)));
|
||||
AddStep("Test with tall tablet", () => tabletHandler.SetTabletSize(new Vector2(100, 300)));
|
||||
AddStep("Test with very tall tablet", () => tabletHandler.SetTabletSize(new Vector2(100, 700)));
|
||||
AddStep("Test no tablet present", () => tabletHandler.SetTabletSize(Vector2.Zero));
|
||||
}
|
||||
|
||||
public class TestTabletHandler : ITabletHandler
|
||||
{
|
||||
private readonly Bindable<Size> tabletSize = new Bindable<Size>();
|
||||
public Bindable<Vector2> AreaOffset { get; } = new Bindable<Vector2>();
|
||||
public Bindable<Vector2> AreaSize { get; } = new Bindable<Vector2>();
|
||||
|
||||
public IBindable<TabletInfo> Tablet => tablet;
|
||||
|
||||
private readonly Bindable<TabletInfo> tablet = new Bindable<TabletInfo>();
|
||||
|
||||
public BindableSize AreaOffset { get; } = new BindableSize();
|
||||
public BindableSize AreaSize { get; } = new BindableSize();
|
||||
public IBindable<Size> TabletSize => tabletSize;
|
||||
public string DeviceName { get; private set; }
|
||||
public BindableBool Enabled { get; } = new BindableBool(true);
|
||||
|
||||
public void SetTabletSize(Size size)
|
||||
public void SetTabletSize(Vector2 size)
|
||||
{
|
||||
DeviceName = size != System.Drawing.Size.Empty ? $"test tablet T-{RNG.Next(999):000}" : string.Empty;
|
||||
tabletSize.Value = size;
|
||||
tablet.Value = size != Vector2.Zero ? new TabletInfo($"test tablet T-{RNG.Next(999):000}", size) : null;
|
||||
|
||||
AreaSize.Default = new Vector2(size.X, size.Y);
|
||||
|
||||
// if it's clear the user has not configured the area, take the full area from the tablet that was just found.
|
||||
if (AreaSize.Value == Vector2.Zero)
|
||||
AreaSize.SetDefault();
|
||||
|
||||
AreaOffset.Default = new Vector2(size.X / 2, size.Y / 2);
|
||||
|
||||
// likewise with the position, use the centre point if it has not been configured.
|
||||
// it's safe to assume no user would set their centre point to 0,0 for now.
|
||||
if (AreaOffset.Value == Vector2.Zero)
|
||||
AreaOffset.SetDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
@ -23,9 +22,10 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
||||
private Container tabletContainer;
|
||||
private Container usableAreaContainer;
|
||||
|
||||
private readonly Bindable<Size> areaOffset = new BindableSize();
|
||||
private readonly Bindable<Size> areaSize = new BindableSize();
|
||||
private readonly IBindable<Size> tabletSize = new BindableSize();
|
||||
private readonly Bindable<Vector2> areaOffset = new Bindable<Vector2>();
|
||||
private readonly Bindable<Vector2> areaSize = new Bindable<Vector2>();
|
||||
|
||||
private readonly IBindable<TabletInfo> tablet = new Bindable<TabletInfo>();
|
||||
|
||||
private OsuSpriteText tabletName;
|
||||
|
||||
@ -56,6 +56,7 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
||||
},
|
||||
usableAreaContainer = new Container
|
||||
{
|
||||
Origin = Anchor.Centre,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
@ -89,24 +90,27 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
||||
areaOffset.BindTo(handler.AreaOffset);
|
||||
areaOffset.BindValueChanged(val =>
|
||||
{
|
||||
usableAreaContainer.MoveTo(new Vector2(val.NewValue.Width, val.NewValue.Height), 100, Easing.OutQuint);
|
||||
checkBounds();
|
||||
usableAreaContainer.MoveTo(val.NewValue, 100, Easing.OutQuint)
|
||||
.OnComplete(_ => checkBounds()); // required as we are using SSDQ.
|
||||
}, true);
|
||||
|
||||
areaSize.BindTo(handler.AreaSize);
|
||||
areaSize.BindValueChanged(val =>
|
||||
{
|
||||
usableAreaContainer.ResizeTo(new Vector2(val.NewValue.Width, val.NewValue.Height), 100, Easing.OutQuint);
|
||||
usableAreaContainer.ResizeTo(val.NewValue, 100, Easing.OutQuint)
|
||||
.OnComplete(_ => checkBounds()); // required as we are using SSDQ.
|
||||
}, true);
|
||||
|
||||
tablet.BindTo(handler.Tablet);
|
||||
tablet.BindValueChanged(val =>
|
||||
{
|
||||
tabletContainer.Size = val.NewValue?.Size ?? Vector2.Zero;
|
||||
tabletName.Text = val.NewValue?.Name ?? string.Empty;
|
||||
checkBounds();
|
||||
}, true);
|
||||
|
||||
tabletSize.BindTo(handler.TabletSize);
|
||||
tabletSize.BindValueChanged(val =>
|
||||
{
|
||||
tabletContainer.Size = new Vector2(val.NewValue.Width, val.NewValue.Height);
|
||||
tabletName.Text = handler.DeviceName;
|
||||
checkBounds();
|
||||
}, true);
|
||||
// initial animation should be instant.
|
||||
FinishTransforms(true);
|
||||
}
|
||||
|
||||
[Resolved]
|
||||
@ -114,10 +118,13 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
||||
|
||||
private void checkBounds()
|
||||
{
|
||||
Size areaExtent = areaOffset.Value + areaSize.Value;
|
||||
if (tablet.Value == null)
|
||||
return;
|
||||
|
||||
bool isWithinBounds = areaExtent.Width <= tabletSize.Value.Width
|
||||
&& areaExtent.Height <= tabletSize.Value.Height;
|
||||
var usableSsdq = usableAreaContainer.ScreenSpaceDrawQuad;
|
||||
|
||||
bool isWithinBounds = tabletContainer.ScreenSpaceDrawQuad.Contains(usableSsdq.TopLeft) &&
|
||||
tabletContainer.ScreenSpaceDrawQuad.Contains(usableSsdq.BottomRight);
|
||||
|
||||
usableAreaContainer.FadeColour(isWithinBounds ? colour.Blue : colour.RedLight, 100);
|
||||
}
|
||||
@ -126,13 +133,11 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
||||
{
|
||||
base.Update();
|
||||
|
||||
var size = tabletSize.Value;
|
||||
|
||||
if (size == System.Drawing.Size.Empty)
|
||||
if (!(tablet.Value?.Size is Vector2 size))
|
||||
return;
|
||||
|
||||
float fitX = size.Width / (DrawWidth - Padding.Left - Padding.Right);
|
||||
float fitY = size.Height / DrawHeight;
|
||||
float fitX = size.X / (DrawWidth - Padding.Left - Padding.Right);
|
||||
float fitY = size.Y / DrawHeight;
|
||||
|
||||
float adjust = MathF.Max(fitX, fitY);
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
// 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.
|
||||
|
||||
using System.Drawing;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
@ -18,15 +17,15 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
||||
{
|
||||
private readonly ITabletHandler tabletHandler;
|
||||
|
||||
private readonly BindableSize areaOffset = new BindableSize();
|
||||
private readonly BindableSize areaSize = new BindableSize();
|
||||
private readonly IBindable<Size> tabletSize = new BindableSize();
|
||||
private readonly Bindable<Vector2> areaOffset = new Bindable<Vector2>();
|
||||
private readonly Bindable<Vector2> areaSize = new Bindable<Vector2>();
|
||||
private readonly IBindable<TabletInfo> tablet = new Bindable<TabletInfo>();
|
||||
|
||||
private readonly BindableNumber<int> offsetX = new BindableNumber<int> { MinValue = 0 };
|
||||
private readonly BindableNumber<int> offsetY = new BindableNumber<int> { MinValue = 0 };
|
||||
private readonly BindableNumber<float> offsetX = new BindableNumber<float> { MinValue = 0 };
|
||||
private readonly BindableNumber<float> offsetY = new BindableNumber<float> { MinValue = 0 };
|
||||
|
||||
private readonly BindableNumber<int> sizeX = new BindableNumber<int> { MinValue = 10 };
|
||||
private readonly BindableNumber<int> sizeY = new BindableNumber<int> { MinValue = 10 };
|
||||
private readonly BindableNumber<float> sizeX = new BindableNumber<float> { MinValue = 10 };
|
||||
private readonly BindableNumber<float> sizeY = new BindableNumber<float> { MinValue = 10 };
|
||||
|
||||
[Resolved]
|
||||
private GameHost host { get; set; }
|
||||
@ -108,12 +107,12 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
||||
LabelText = "Aspect Ratio",
|
||||
Current = aspectRatio
|
||||
},
|
||||
new SettingsSlider<int>
|
||||
new SettingsSlider<float>
|
||||
{
|
||||
LabelText = "X Offset",
|
||||
Current = offsetX
|
||||
},
|
||||
new SettingsSlider<int>
|
||||
new SettingsSlider<float>
|
||||
{
|
||||
LabelText = "Y Offset",
|
||||
Current = offsetY
|
||||
@ -123,12 +122,12 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
||||
LabelText = "Lock aspect ratio",
|
||||
Current = aspectLock
|
||||
},
|
||||
new SettingsSlider<int>
|
||||
new SettingsSlider<float>
|
||||
{
|
||||
LabelText = "Width",
|
||||
Current = sizeX
|
||||
},
|
||||
new SettingsSlider<int>
|
||||
new SettingsSlider<float>
|
||||
{
|
||||
LabelText = "Height",
|
||||
Current = sizeY
|
||||
@ -140,23 +139,23 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
||||
areaOffset.BindTo(tabletHandler.AreaOffset);
|
||||
areaOffset.BindValueChanged(val =>
|
||||
{
|
||||
offsetX.Value = val.NewValue.Width;
|
||||
offsetY.Value = val.NewValue.Height;
|
||||
offsetX.Value = val.NewValue.X;
|
||||
offsetY.Value = val.NewValue.Y;
|
||||
}, true);
|
||||
|
||||
offsetX.BindValueChanged(val => areaOffset.Value = new Size(val.NewValue, areaOffset.Value.Height));
|
||||
offsetY.BindValueChanged(val => areaOffset.Value = new Size(areaOffset.Value.Width, val.NewValue));
|
||||
offsetX.BindValueChanged(val => areaOffset.Value = new Vector2(val.NewValue, areaOffset.Value.Y));
|
||||
offsetY.BindValueChanged(val => areaOffset.Value = new Vector2(areaOffset.Value.X, val.NewValue));
|
||||
|
||||
areaSize.BindTo(tabletHandler.AreaSize);
|
||||
areaSize.BindValueChanged(val =>
|
||||
{
|
||||
sizeX.Value = val.NewValue.Width;
|
||||
sizeY.Value = val.NewValue.Height;
|
||||
sizeX.Value = val.NewValue.X;
|
||||
sizeY.Value = val.NewValue.Y;
|
||||
}, true);
|
||||
|
||||
sizeX.BindValueChanged(val =>
|
||||
{
|
||||
areaSize.Value = new Size(val.NewValue, areaSize.Value.Height);
|
||||
areaSize.Value = new Vector2(val.NewValue, areaSize.Value.Y);
|
||||
|
||||
aspectRatioApplication?.Cancel();
|
||||
aspectRatioApplication = Schedule(() => applyAspectRatio(sizeX));
|
||||
@ -164,7 +163,7 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
||||
|
||||
sizeY.BindValueChanged(val =>
|
||||
{
|
||||
areaSize.Value = new Size(areaSize.Value.Width, val.NewValue);
|
||||
areaSize.Value = new Vector2(areaSize.Value.X, val.NewValue);
|
||||
|
||||
aspectRatioApplication?.Cancel();
|
||||
aspectRatioApplication = Schedule(() => applyAspectRatio(sizeY));
|
||||
@ -176,10 +175,12 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
||||
aspectRatioApplication = Schedule(() => forceAspectRatio(aspect.NewValue));
|
||||
});
|
||||
|
||||
tabletSize.BindTo(tabletHandler.TabletSize);
|
||||
tabletSize.BindValueChanged(val =>
|
||||
tablet.BindTo(tabletHandler.Tablet);
|
||||
tablet.BindValueChanged(val =>
|
||||
{
|
||||
bool tabletFound = tabletSize.Value != System.Drawing.Size.Empty;
|
||||
var tab = val.NewValue;
|
||||
|
||||
bool tabletFound = tab != null;
|
||||
|
||||
if (!tabletFound)
|
||||
{
|
||||
@ -192,17 +193,19 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
||||
noTabletMessage.Hide();
|
||||
|
||||
// todo: these should propagate from a TabletChanged event or similar.
|
||||
offsetX.MaxValue = val.NewValue.Width;
|
||||
sizeX.Default = sizeX.MaxValue = val.NewValue.Width;
|
||||
offsetX.MaxValue = tab.Size.X;
|
||||
offsetX.Default = tab.Size.X / 2;
|
||||
sizeX.Default = sizeX.MaxValue = tab.Size.X;
|
||||
|
||||
offsetY.MaxValue = val.NewValue.Height;
|
||||
sizeY.Default = sizeY.MaxValue = val.NewValue.Height;
|
||||
offsetY.MaxValue = tab.Size.Y;
|
||||
offsetY.Default = tab.Size.Y / 2;
|
||||
sizeY.Default = sizeY.MaxValue = tab.Size.Y;
|
||||
|
||||
areaSize.Default = new Size(sizeX.Default, sizeY.Default);
|
||||
areaSize.Default = new Vector2(sizeX.Default, sizeY.Default);
|
||||
}, true);
|
||||
}
|
||||
|
||||
private void applyAspectRatio(BindableNumber<int> sizeChanged)
|
||||
private void applyAspectRatio(BindableNumber<float> sizeChanged)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -220,9 +223,9 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
||||
|
||||
// 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)
|
||||
sizeY.Value = (int)(areaSize.Value.Width / aspectRatio.Value);
|
||||
sizeY.Value = (int)(areaSize.Value.X / aspectRatio.Value);
|
||||
else
|
||||
sizeX.Value = (int)(areaSize.Value.Height * aspectRatio.Value);
|
||||
sizeX.Value = (int)(areaSize.Value.Y * aspectRatio.Value);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@ -251,6 +254,6 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
||||
|
||||
private void updateAspectRatio() => aspectRatio.Value = curentAspectRatio;
|
||||
|
||||
private float curentAspectRatio => (float)sizeX.Value / sizeY.Value;
|
||||
private float curentAspectRatio => sizeX.Value / sizeY.Value;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user