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.
|
|
|
|
|
|
2021-03-16 16:04:22 +08:00
|
|
|
|
using System;
|
2021-03-15 17:37:46 +08:00
|
|
|
|
using System.Drawing;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Input.Handlers.Tablet;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Settings.Sections.Input
|
|
|
|
|
{
|
|
|
|
|
public class TabletSettings : SettingsSubsection
|
|
|
|
|
{
|
|
|
|
|
private readonly ITabletHandler tabletHandler;
|
|
|
|
|
|
|
|
|
|
private readonly BindableSize areaOffset = new BindableSize();
|
|
|
|
|
private readonly BindableSize areaSize = new BindableSize();
|
|
|
|
|
private readonly BindableSize tabletSize = new BindableSize();
|
|
|
|
|
|
|
|
|
|
private readonly BindableNumber<int> offsetX = new BindableNumber<int> { MinValue = 0 };
|
|
|
|
|
private readonly BindableNumber<int> offsetY = new BindableNumber<int> { MinValue = 0 };
|
|
|
|
|
|
|
|
|
|
private readonly BindableNumber<int> sizeX = new BindableNumber<int> { MinValue = 0 };
|
|
|
|
|
private readonly BindableNumber<int> sizeY = new BindableNumber<int> { MinValue = 0 };
|
|
|
|
|
|
2021-03-16 16:04:22 +08:00
|
|
|
|
private SettingsButton aspectResetButton;
|
|
|
|
|
|
|
|
|
|
private readonly BindableNumber<float> aspectRatio = new BindableFloat(1)
|
|
|
|
|
{
|
|
|
|
|
MinValue = 0.5f,
|
|
|
|
|
MaxValue = 2,
|
|
|
|
|
Precision = 0.01f,
|
|
|
|
|
};
|
|
|
|
|
|
2021-03-15 17:37:46 +08:00
|
|
|
|
protected override string Header => "Tablet";
|
|
|
|
|
|
|
|
|
|
public TabletSettings(ITabletHandler tabletHandler)
|
|
|
|
|
{
|
|
|
|
|
this.tabletHandler = tabletHandler;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2021-03-16 14:57:29 +08:00
|
|
|
|
private void load()
|
2021-03-15 17:37:46 +08:00
|
|
|
|
{
|
|
|
|
|
areaOffset.BindTo(tabletHandler.AreaOffset);
|
|
|
|
|
areaOffset.BindValueChanged(val =>
|
|
|
|
|
{
|
|
|
|
|
offsetX.Value = val.NewValue.Width;
|
|
|
|
|
offsetY.Value = val.NewValue.Height;
|
|
|
|
|
}, 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));
|
|
|
|
|
|
|
|
|
|
areaSize.BindTo(tabletHandler.AreaSize);
|
|
|
|
|
areaSize.BindValueChanged(val =>
|
|
|
|
|
{
|
|
|
|
|
sizeX.Value = val.NewValue.Width;
|
|
|
|
|
sizeY.Value = val.NewValue.Height;
|
2021-03-16 16:04:22 +08:00
|
|
|
|
|
|
|
|
|
float proposedAspectRatio = (float)sizeX.Value / sizeY.Value;
|
|
|
|
|
|
|
|
|
|
aspectRatio.Value = proposedAspectRatio;
|
|
|
|
|
|
|
|
|
|
if (proposedAspectRatio < aspectRatio.MinValue || proposedAspectRatio > aspectRatio.MaxValue)
|
|
|
|
|
{
|
|
|
|
|
// apply aspect ratio restrictions to keep things in a usable state.
|
|
|
|
|
|
|
|
|
|
// correction is always going to be below 1.
|
|
|
|
|
float correction = proposedAspectRatio > aspectRatio.Value
|
|
|
|
|
? aspectRatio.Value / proposedAspectRatio
|
|
|
|
|
: proposedAspectRatio / aspectRatio.Value;
|
|
|
|
|
|
|
|
|
|
if (val.NewValue.Width != val.OldValue.Width)
|
|
|
|
|
{
|
|
|
|
|
if (val.NewValue.Width > val.OldValue.Width)
|
|
|
|
|
correction = 1 / correction;
|
|
|
|
|
areaSize.Value = new Size(areaSize.Value.Width, (int)(val.NewValue.Height * correction));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (val.NewValue.Height > val.OldValue.Height)
|
|
|
|
|
correction = 1 / correction;
|
|
|
|
|
areaSize.Value = new Size((int)(val.NewValue.Width * correction), areaSize.Value.Height);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-03-15 17:37:46 +08:00
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
|
|
sizeX.BindValueChanged(val => areaSize.Value = new Size(val.NewValue, areaSize.Value.Height));
|
|
|
|
|
sizeY.BindValueChanged(val => areaSize.Value = new Size(areaSize.Value.Width, val.NewValue));
|
|
|
|
|
|
|
|
|
|
((IBindable<Size>)tabletSize).BindTo(tabletHandler.TabletSize);
|
|
|
|
|
tabletSize.BindValueChanged(val =>
|
|
|
|
|
{
|
2021-03-16 14:57:29 +08:00
|
|
|
|
if (tabletSize.Value == System.Drawing.Size.Empty)
|
|
|
|
|
return;
|
|
|
|
|
|
2021-03-15 17:37:46 +08:00
|
|
|
|
// todo: these should propagate from a TabletChanged event or similar.
|
|
|
|
|
offsetX.MaxValue = val.NewValue.Width;
|
|
|
|
|
sizeX.Default = sizeX.MaxValue = val.NewValue.Width;
|
|
|
|
|
|
|
|
|
|
offsetY.MaxValue = val.NewValue.Height;
|
|
|
|
|
sizeY.Default = sizeY.MaxValue = val.NewValue.Height;
|
|
|
|
|
|
2021-03-16 15:24:51 +08:00
|
|
|
|
areaSize.Default = new Size(sizeX.Default, sizeY.Default);
|
|
|
|
|
|
2021-03-15 17:37:46 +08:00
|
|
|
|
updateDisplay();
|
|
|
|
|
}, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateDisplay()
|
|
|
|
|
{
|
2021-03-16 14:57:29 +08:00
|
|
|
|
if (Children.Count > 0)
|
2021-03-15 17:37:46 +08:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2021-03-16 15:24:51 +08:00
|
|
|
|
new TabletAreaSelection(tabletHandler)
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Height = 300,
|
|
|
|
|
},
|
|
|
|
|
new SettingsButton
|
|
|
|
|
{
|
|
|
|
|
Text = "Reset to full area",
|
|
|
|
|
Action = () =>
|
|
|
|
|
{
|
|
|
|
|
areaOffset.SetDefault();
|
|
|
|
|
areaSize.SetDefault();
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
new SettingsCheckbox
|
|
|
|
|
{
|
|
|
|
|
LabelText = "Lock aspect ratio",
|
|
|
|
|
},
|
2021-03-16 16:04:22 +08:00
|
|
|
|
aspectResetButton = new SettingsButton
|
|
|
|
|
{
|
|
|
|
|
Text = "Take aspect ratio from screen size",
|
|
|
|
|
},
|
|
|
|
|
new SettingsSlider<float>
|
|
|
|
|
{
|
|
|
|
|
LabelText = "Aspect Ratio",
|
|
|
|
|
Current = aspectRatio
|
|
|
|
|
},
|
2021-03-15 17:37:46 +08:00
|
|
|
|
new SettingsSlider<int>
|
|
|
|
|
{
|
2021-03-16 15:24:51 +08:00
|
|
|
|
LabelText = "X Offset",
|
2021-03-15 17:37:46 +08:00
|
|
|
|
Current = offsetX
|
|
|
|
|
},
|
|
|
|
|
new SettingsSlider<int>
|
|
|
|
|
{
|
2021-03-16 15:24:51 +08:00
|
|
|
|
LabelText = "Y Offset",
|
2021-03-15 17:37:46 +08:00
|
|
|
|
Current = offsetY
|
|
|
|
|
},
|
|
|
|
|
new SettingsSlider<int>
|
|
|
|
|
{
|
2021-03-16 15:24:51 +08:00
|
|
|
|
LabelText = "Width",
|
2021-03-15 17:37:46 +08:00
|
|
|
|
Current = sizeX
|
|
|
|
|
},
|
|
|
|
|
new SettingsSlider<int>
|
|
|
|
|
{
|
2021-03-16 15:24:51 +08:00
|
|
|
|
LabelText = "Height",
|
2021-03-15 17:37:46 +08:00
|
|
|
|
Current = sizeY
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|