1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-28 17:02:55 +08:00

Show aspect ratio for current usable area

This commit is contained in:
Dean Herbert 2021-03-17 13:03:06 +09:00
parent 196f95ae54
commit fb7d095e4a

View File

@ -29,6 +29,9 @@ namespace osu.Game.Overlays.Settings.Sections.Input
private OsuSpriteText tabletName; private OsuSpriteText tabletName;
private Box usableFill;
private OsuSpriteText usableAreaText;
public TabletAreaSelection(ITabletHandler handler) public TabletAreaSelection(ITabletHandler handler)
{ {
this.handler = handler; this.handler = handler;
@ -59,17 +62,16 @@ namespace osu.Game.Overlays.Settings.Sections.Input
Origin = Anchor.Centre, Origin = Anchor.Centre,
Children = new Drawable[] Children = new Drawable[]
{ {
new Box usableFill = new Box
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Alpha = 0.6f, Alpha = 0.6f,
}, },
new OsuSpriteText usableAreaText = new OsuSpriteText
{ {
Text = "usable area",
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
Colour = Color4.Black, Colour = Color4.White,
Font = OsuFont.Default.With(size: 12) Font = OsuFont.Default.With(size: 12)
} }
} }
@ -99,6 +101,12 @@ namespace osu.Game.Overlays.Settings.Sections.Input
{ {
usableAreaContainer.ResizeTo(val.NewValue, 100, Easing.OutQuint) usableAreaContainer.ResizeTo(val.NewValue, 100, Easing.OutQuint)
.OnComplete(_ => checkBounds()); // required as we are using SSDQ. .OnComplete(_ => checkBounds()); // required as we are using SSDQ.
int x = (int)val.NewValue.X;
int y = (int)val.NewValue.Y;
int commonDivider = greatestCommonDivider(x, y);
usableAreaText.Text = $"{(float)x / commonDivider}:{(float)y / commonDivider}";
}, true); }, true);
tablet.BindTo(handler.Tablet); tablet.BindTo(handler.Tablet);
@ -113,6 +121,18 @@ namespace osu.Game.Overlays.Settings.Sections.Input
FinishTransforms(true); FinishTransforms(true);
} }
private static int greatestCommonDivider(int a, int b)
{
while (b != 0)
{
int remainder = a % b;
a = b;
b = remainder;
}
return a;
}
[Resolved] [Resolved]
private OsuColour colour { get; set; } private OsuColour colour { get; set; }
@ -126,7 +146,7 @@ namespace osu.Game.Overlays.Settings.Sections.Input
bool isWithinBounds = tabletContainer.ScreenSpaceDrawQuad.Contains(usableSsdq.TopLeft) && bool isWithinBounds = tabletContainer.ScreenSpaceDrawQuad.Contains(usableSsdq.TopLeft) &&
tabletContainer.ScreenSpaceDrawQuad.Contains(usableSsdq.BottomRight); tabletContainer.ScreenSpaceDrawQuad.Contains(usableSsdq.BottomRight);
usableAreaContainer.FadeColour(isWithinBounds ? colour.Blue : colour.RedLight, 100); usableFill.FadeColour(isWithinBounds ? colour.Blue : colour.RedLight, 100);
} }
protected override void Update() protected override void Update()