mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 13:22:55 +08:00
Make tablet display always fit to size of settings area
This commit is contained in:
parent
d026c8da85
commit
3b7edf1333
@ -2,9 +2,9 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Input.Handlers.Tablet;
|
using osu.Framework.Input.Handlers.Tablet;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
@ -18,16 +18,13 @@ namespace osu.Game.Tests.Visual.Settings
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(GameHost host)
|
private void load(GameHost host)
|
||||||
{
|
{
|
||||||
var tabletHandler = host.AvailableInputHandlers.OfType<ITabletHandler>().FirstOrDefault();
|
var tabletHandler = new TestTabletHandler();
|
||||||
|
|
||||||
if (tabletHandler == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
tabletHandler.AreaOffset.MinValue = new Size(0, 0);
|
tabletHandler.AreaOffset.MinValue = new Size(0, 0);
|
||||||
tabletHandler.AreaOffset.MaxValue = new Size(160, 100);
|
tabletHandler.AreaOffset.MaxValue = new Size(160, 100);
|
||||||
tabletHandler.AreaOffset.Value = new Size(10, 10);
|
tabletHandler.AreaOffset.Value = new Size(10, 10);
|
||||||
|
|
||||||
tabletHandler.AreaSize.MinValue = new Size(0, 0);
|
tabletHandler.AreaSize.MinValue = new Size(10, 10);
|
||||||
tabletHandler.AreaSize.MaxValue = new Size(160, 100);
|
tabletHandler.AreaSize.MaxValue = new Size(160, 100);
|
||||||
tabletHandler.AreaSize.Value = new Size(100, 80);
|
tabletHandler.AreaSize.Value = new Size(100, 80);
|
||||||
|
|
||||||
@ -35,6 +32,23 @@ namespace osu.Game.Tests.Visual.Settings
|
|||||||
{
|
{
|
||||||
new TabletSettings(tabletHandler),
|
new TabletSettings(tabletHandler),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public class TestTabletHandler : ITabletHandler
|
||||||
|
{
|
||||||
|
private readonly Bindable<Size> tabletSize = new Bindable<Size>();
|
||||||
|
|
||||||
|
public BindableSize AreaOffset { get; } = new BindableSize();
|
||||||
|
public BindableSize AreaSize { get; } = new BindableSize();
|
||||||
|
public IBindable<Size> TabletSize => tabletSize;
|
||||||
|
public BindableBool Enabled { get; } = new BindableBool(true);
|
||||||
|
|
||||||
|
public void SetTabletSize(Size size) => tabletSize.Value = size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
@ -11,7 +12,6 @@ using osu.Framework.Input.Handlers.Tablet;
|
|||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
|
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Settings.Sections.Input
|
namespace osu.Game.Overlays.Settings.Sections.Input
|
||||||
@ -20,8 +20,8 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
|||||||
{
|
{
|
||||||
private readonly ITabletHandler handler;
|
private readonly ITabletHandler handler;
|
||||||
|
|
||||||
private readonly Container tabletContainer;
|
private Container tabletContainer;
|
||||||
private readonly Container usableAreaContainer;
|
private Container usableAreaContainer;
|
||||||
|
|
||||||
private readonly Bindable<Size> areaOffset = new BindableSize();
|
private readonly Bindable<Size> areaOffset = new BindableSize();
|
||||||
private readonly Bindable<Size> areaSize = new BindableSize();
|
private readonly Bindable<Size> areaSize = new BindableSize();
|
||||||
@ -30,53 +30,50 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
|||||||
public TabletAreaSelection(ITabletHandler handler)
|
public TabletAreaSelection(ITabletHandler handler)
|
||||||
{
|
{
|
||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
|
|
||||||
Padding = new MarginPadding(5);
|
|
||||||
|
|
||||||
InternalChildren = new Drawable[]
|
|
||||||
{
|
|
||||||
tabletContainer = new Container
|
|
||||||
{
|
|
||||||
Masking = true,
|
|
||||||
CornerRadius = 5,
|
|
||||||
BorderThickness = 2,
|
|
||||||
BorderColour = Color4.Black,
|
|
||||||
Children = new Drawable[]
|
|
||||||
{
|
|
||||||
new Box
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.Both,
|
|
||||||
Colour = Color4.White,
|
|
||||||
},
|
|
||||||
usableAreaContainer = new Container
|
|
||||||
{
|
|
||||||
Masking = true,
|
|
||||||
CornerRadius = 5,
|
|
||||||
Children = new Drawable[]
|
|
||||||
{
|
|
||||||
new Box
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.Both,
|
|
||||||
Colour = Color4.Yellow,
|
|
||||||
},
|
|
||||||
new OsuSpriteText
|
|
||||||
{
|
|
||||||
Text = "usable area",
|
|
||||||
Anchor = Anchor.Centre,
|
|
||||||
Origin = Anchor.Centre,
|
|
||||||
Colour = Color4.Black,
|
|
||||||
Font = OsuFont.Default.With(size: 12)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
|
Padding = new MarginPadding(5);
|
||||||
|
|
||||||
|
InternalChild = tabletContainer = new Container
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Masking = true,
|
||||||
|
CornerRadius = 5,
|
||||||
|
BorderThickness = 2,
|
||||||
|
BorderColour = Color4.Black,
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
new Box
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Colour = Color4.White,
|
||||||
|
},
|
||||||
|
usableAreaContainer = new Container
|
||||||
|
{
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
new Box
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Colour = Color4.Yellow,
|
||||||
|
},
|
||||||
|
new OsuSpriteText
|
||||||
|
{
|
||||||
|
Text = "usable area",
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Colour = Color4.Black,
|
||||||
|
Font = OsuFont.Default.With(size: 12)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
areaOffset.BindTo(handler.AreaOffset);
|
areaOffset.BindTo(handler.AreaOffset);
|
||||||
areaOffset.BindValueChanged(val =>
|
areaOffset.BindValueChanged(val =>
|
||||||
{
|
{
|
||||||
@ -92,8 +89,22 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
|||||||
((IBindable<Size>)tabletSize).BindTo(handler.TabletSize);
|
((IBindable<Size>)tabletSize).BindTo(handler.TabletSize);
|
||||||
tabletSize.BindValueChanged(val =>
|
tabletSize.BindValueChanged(val =>
|
||||||
{
|
{
|
||||||
tabletContainer.ResizeTo(new Vector2(tabletSize.Value.Width, tabletSize.Value.Height), 100, Easing.OutQuint);
|
tabletContainer.Size = new Vector2(val.NewValue.Width, val.NewValue.Height);
|
||||||
}, true);
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Update()
|
||||||
|
{
|
||||||
|
base.Update();
|
||||||
|
|
||||||
|
var size = tabletSize.Value;
|
||||||
|
|
||||||
|
float fitX = size.Width / DrawWidth;
|
||||||
|
float fitY = size.Height / DrawHeight;
|
||||||
|
|
||||||
|
float adjust = MathF.Max(fitX, fitY);
|
||||||
|
|
||||||
|
tabletContainer.Scale = new Vector2(1 / adjust);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user