allow tablet area to be dragged

This commit is contained in:
Gabe Livengood 2023-02-20 00:06:20 -05:00
parent b5dda407a8
commit c86c1a9029

View File

@ -11,6 +11,7 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events;
using osu.Framework.Input.Handlers.Tablet; using osu.Framework.Input.Handlers.Tablet;
using osu.Framework.Utils; using osu.Framework.Utils;
using osu.Game.Graphics; using osu.Game.Graphics;
@ -66,7 +67,7 @@ namespace osu.Game.Overlays.Settings.Sections.Input
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Colour = colour.Gray1, Colour = colour.Gray1,
}, },
usableAreaContainer = new Container usableAreaContainer = new UsableAreaContainer(handler)
{ {
Origin = Anchor.Centre, Origin = Anchor.Centre,
Children = new Drawable[] Children = new Drawable[]
@ -225,4 +226,28 @@ namespace osu.Game.Overlays.Settings.Sections.Input
tabletContainer.Scale = new Vector2(1 / adjust); tabletContainer.Scale = new Vector2(1 / adjust);
} }
} }
public partial class UsableAreaContainer : Container
{
private readonly Bindable<Vector2> areaOffset;
public UsableAreaContainer(ITabletHandler tabletHandler)
{
areaOffset = tabletHandler.AreaOffset.GetBoundCopy();
}
protected override bool OnDragStart(DragStartEvent e) => true;
protected override void OnDrag(DragEvent e)
{
var newPos = Position + e.Delta;
this.MoveTo(Vector2.Clamp(newPos, Vector2.Zero, Parent.Size));
}
protected override void OnDragEnd(DragEndEvent e)
{
areaOffset.Value = Position;
base.OnDragEnd(e);
}
}
} }