// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System.Drawing; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Input.Handlers.Tablet; using osu.Game.Configuration; 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 offsetX = new BindableNumber { MinValue = 0 }; private readonly BindableNumber offsetY = new BindableNumber { MinValue = 0 }; private readonly BindableNumber sizeX = new BindableNumber { MinValue = 0 }; private readonly BindableNumber sizeY = new BindableNumber { MinValue = 0 }; protected override string Header => "Tablet"; public TabletSettings(ITabletHandler tabletHandler) { this.tabletHandler = tabletHandler; } [BackgroundDependencyLoader] private void load(OsuConfigManager osuConfig, FrameworkConfigManager config) { // TODO: this should all eventually be replaced with a control that handles BindableSize. 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; }, 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)tabletSize).BindTo(tabletHandler.TabletSize); tabletSize.BindValueChanged(val => { // 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; updateDisplay(); }, true); } private void updateDisplay() { if (tabletSize.Value == System.Drawing.Size.Empty) { Clear(); return; } Children = new Drawable[] { new SettingsSlider { LabelText = "Offset X", Current = offsetX }, new SettingsSlider { LabelText = "Offset Y", Current = offsetY }, new SettingsSlider { LabelText = "Size X", Current = sizeX }, new SettingsSlider { LabelText = "Size Y", Current = sizeY }, new TabletAreaSelection(tabletHandler) { RelativeSizeAxes = Axes.X, Height = 100, } }; } } }