2021-03-15 15:25:50 +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 13:45:21 +08:00
|
|
|
using System;
|
2021-03-15 17:37:46 +08:00
|
|
|
using System.Drawing;
|
2021-03-15 15:25:50 +08:00
|
|
|
using osu.Framework.Allocation;
|
2021-03-15 17:37:46 +08:00
|
|
|
using osu.Framework.Bindables;
|
2021-03-15 15:25:50 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2021-03-15 17:37:46 +08:00
|
|
|
using osu.Framework.Input.Handlers.Tablet;
|
2021-03-15 15:25:50 +08:00
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
2021-03-15 17:37:46 +08:00
|
|
|
namespace osu.Game.Overlays.Settings.Sections.Input
|
2021-03-15 15:25:50 +08:00
|
|
|
{
|
2021-03-15 17:37:46 +08:00
|
|
|
public class TabletAreaSelection : CompositeDrawable
|
2021-03-15 15:25:50 +08:00
|
|
|
{
|
2021-03-15 17:37:46 +08:00
|
|
|
private readonly ITabletHandler handler;
|
2021-03-15 15:25:50 +08:00
|
|
|
|
2021-03-16 13:45:21 +08:00
|
|
|
private Container tabletContainer;
|
|
|
|
private Container usableAreaContainer;
|
2021-03-15 15:25:50 +08:00
|
|
|
|
2021-03-15 17:37:46 +08:00
|
|
|
private readonly Bindable<Size> areaOffset = new BindableSize();
|
|
|
|
private readonly Bindable<Size> areaSize = new BindableSize();
|
|
|
|
private readonly Bindable<Size> tabletSize = new BindableSize();
|
|
|
|
|
|
|
|
public TabletAreaSelection(ITabletHandler handler)
|
2021-03-15 15:25:50 +08:00
|
|
|
{
|
2021-03-15 17:37:46 +08:00
|
|
|
this.handler = handler;
|
2021-03-16 13:45:21 +08:00
|
|
|
}
|
2021-03-15 15:25:50 +08:00
|
|
|
|
2021-03-16 13:45:21 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2021-03-15 17:37:46 +08:00
|
|
|
Padding = new MarginPadding(5);
|
2021-03-15 15:25:50 +08:00
|
|
|
|
2021-03-16 13:45:21 +08:00
|
|
|
InternalChild = tabletContainer = new Container
|
2021-03-15 15:25:50 +08:00
|
|
|
{
|
2021-03-16 13:45:21 +08:00
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Masking = true,
|
|
|
|
CornerRadius = 5,
|
|
|
|
BorderThickness = 2,
|
|
|
|
BorderColour = Color4.Black,
|
|
|
|
Children = new Drawable[]
|
2021-03-15 15:25:50 +08:00
|
|
|
{
|
2021-03-16 13:45:21 +08:00
|
|
|
new Box
|
2021-03-15 15:25:50 +08:00
|
|
|
{
|
2021-03-16 13:45:21 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = Color4.White,
|
|
|
|
},
|
|
|
|
usableAreaContainer = new Container
|
|
|
|
{
|
|
|
|
Children = new Drawable[]
|
2021-03-15 15:25:50 +08:00
|
|
|
{
|
2021-03-16 13:45:21 +08:00
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = Color4.Yellow,
|
|
|
|
},
|
|
|
|
new OsuSpriteText
|
2021-03-15 15:25:50 +08:00
|
|
|
{
|
2021-03-16 13:45:21 +08:00
|
|
|
Text = "usable area",
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Colour = Color4.Black,
|
|
|
|
Font = OsuFont.Default.With(size: 12)
|
2021-03-15 15:25:50 +08:00
|
|
|
}
|
2021-03-16 13:45:21 +08:00
|
|
|
}
|
|
|
|
},
|
2021-03-15 15:25:50 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-03-15 17:37:46 +08:00
|
|
|
areaOffset.BindTo(handler.AreaOffset);
|
|
|
|
areaOffset.BindValueChanged(val =>
|
|
|
|
{
|
|
|
|
usableAreaContainer.MoveTo(new Vector2(val.NewValue.Width, val.NewValue.Height), 100, Easing.OutQuint);
|
|
|
|
}, true);
|
2021-03-15 15:25:50 +08:00
|
|
|
|
2021-03-15 17:37:46 +08:00
|
|
|
areaSize.BindTo(handler.AreaSize);
|
|
|
|
areaSize.BindValueChanged(val =>
|
|
|
|
{
|
|
|
|
usableAreaContainer.ResizeTo(new Vector2(val.NewValue.Width, val.NewValue.Height), 100, Easing.OutQuint);
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
((IBindable<Size>)tabletSize).BindTo(handler.TabletSize);
|
|
|
|
tabletSize.BindValueChanged(val =>
|
|
|
|
{
|
2021-03-16 13:45:21 +08:00
|
|
|
tabletContainer.Size = new Vector2(val.NewValue.Width, val.NewValue.Height);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2021-03-15 15:25:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|