diff --git a/osu.Framework/Input/Handlers/Tablet/ITabletHandler.cs b/osu.Framework/Input/Handlers/Tablet/ITabletHandler.cs index 85870b2446..102eeda87f 100644 --- a/osu.Framework/Input/Handlers/Tablet/ITabletHandler.cs +++ b/osu.Framework/Input/Handlers/Tablet/ITabletHandler.cs @@ -22,6 +22,18 @@ public interface ITabletHandler /// Bindable AreaSize { get; } + /// + /// Relative position of center of output area in game window, padded by half of . + /// Values between zero and one for each axe will always place the area inside window: + /// (0; 0) is most top-left position, (1;1) is most bottom-right position. Does nothing if equals to (1; 1). + /// + Bindable OutputAreaPosition { get; } + + /// + /// Relative size of output area inside game window. + /// + Bindable OutputAreaSize { get; } + /// /// Information on the currently connected tablet device. May be null if no tablet is detected. /// diff --git a/osu.Framework/Input/Handlers/Tablet/OpenTabletDriverHandler.cs b/osu.Framework/Input/Handlers/Tablet/OpenTabletDriverHandler.cs index 2f3b442139..f2678615c6 100644 --- a/osu.Framework/Input/Handlers/Tablet/OpenTabletDriverHandler.cs +++ b/osu.Framework/Input/Handlers/Tablet/OpenTabletDriverHandler.cs @@ -38,6 +38,10 @@ public class OpenTabletDriverHandler : InputHandler, IAbsolutePointer, IRelative public Bindable AreaSize { get; } = new Bindable(); + public Bindable OutputAreaPosition { get; } = new Bindable(); + + public Bindable OutputAreaSize { get; } = new Bindable(new Vector2(1f, 1f)); + public Bindable Rotation { get; } = new Bindable(); public IBindable Tablet => tablet; @@ -58,6 +62,11 @@ public override bool Initialize(GameHost host) AreaSize.BindValueChanged(_ => updateInputArea(device), true); Rotation.BindValueChanged(_ => updateInputArea(device), true); + OutputAreaPosition.BindValueChanged(_ => updateOutputArea(host.Window)); + OutputAreaSize.BindValueChanged(_ => updateOutputArea(host.Window)); + + updateOutputArea(host.Window); + Enabled.BindValueChanged(enabled => { if (enabled.NewValue) @@ -126,14 +135,26 @@ private void updateOutputArea(IWindow window) { case AbsoluteOutputMode absoluteOutputMode: { - float outputWidth, outputHeight; + // window size & pos + float outputWidth = window.ClientSize.Width; + float outputHeight = window.ClientSize.Height; + float posX = outputWidth / 2; + float posY = outputHeight / 2; + + // applying "output area" + float areaOffsX = (1f - OutputAreaSize.Value.X) * (OutputAreaPosition.Value.X - 0.5f) * outputWidth; + float areaOffsY = (1f - OutputAreaSize.Value.Y) * (OutputAreaPosition.Value.Y - 0.5f) * outputHeight; + outputWidth *= OutputAreaSize.Value.X; + outputHeight *= OutputAreaSize.Value.Y; + posX += areaOffsX; + posY += areaOffsY; // Set output area in pixels absoluteOutputMode.Output = new Area { - Width = outputWidth = window.ClientSize.Width, - Height = outputHeight = window.ClientSize.Height, - Position = new System.Numerics.Vector2(outputWidth / 2, outputHeight / 2) + Width = outputWidth, + Height = outputHeight, + Position = new System.Numerics.Vector2(posX, posY) }; break; }