Skip to content

Commit

Permalink
Merge remote-tracking branch 'feodor0090/tablet-output-area' into scr…
Browse files Browse the repository at this point in the history
…een-scaling-tablet-output

# Conflicts:
#	osu.Framework/Input/Handlers/Tablet/ITabletHandler.cs
#	osu.Framework/Input/Handlers/Tablet/OpenTabletDriverHandler.cs
  • Loading branch information
DanielPower committed Dec 16, 2024
2 parents 9820c11 + f8aab30 commit 082e586
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 22 deletions.
12 changes: 7 additions & 5 deletions osu.Framework/Input/Handlers/Tablet/ITabletHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,21 @@ public interface ITabletHandler
Bindable<Vector2> AreaOffset { get; }

/// <summary>
/// The size of the area which should be mapped to the game window.
/// Relative position of center of output area in game window, padded by half of <see cref="OutputAreaSize"/>.
/// 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 <see cref="OutputAreaSize"/> equals to (1; 1).
/// </summary>
Bindable<Vector2> AreaSize { get; }
Bindable<Vector2> OutputAreaPosition { get; }

/// <summary>
/// The size of the area on the window which the input should be mapped to.
/// Relative size of output area inside game window.
/// </summary>
Bindable<Vector2> OutputSize { get; }
Bindable<Vector2> OutputAreaSize { get; }

/// <summary>
/// Information on the currently connected tablet device. May be null if no tablet is detected.
/// </summary>
IBindable<TabletInfo?> Tablet { get; }
IBindable<TabletInfo> Tablet { get; }

/// <summary>
/// The rotation of the tablet area in degrees.
Expand Down
52 changes: 35 additions & 17 deletions osu.Framework/Input/Handlers/Tablet/OpenTabletDriverHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ public class OpenTabletDriverHandler : InputHandler, IAbsolutePointer, IRelative

public Bindable<Vector2> AreaSize { get; } = new Bindable<Vector2>();

public Bindable<Vector2> OutputSize { get; } = new Bindable<Vector2>();
public Bindable<Vector2> OutputAreaPosition { get; } = new Bindable<Vector2>();

public Bindable<Vector2> OutputAreaSize { get; } = new Bindable<Vector2>(new Vector2(1f, 1f));

public Bindable<float> Rotation { get; } = new Bindable<float>();

public IBindable<TabletInfo?> Tablet => tablet;
public IBindable<TabletInfo> Tablet => tablet;

private readonly Bindable<TabletInfo?> tablet = new Bindable<TabletInfo?>();
private readonly Bindable<TabletInfo> tablet = new Bindable<TabletInfo>();

private Task? lastInitTask;

Expand All @@ -54,12 +56,16 @@ public override bool Initialize(GameHost host)

outputMode = new AbsoluteTabletMode(this);

host.Window.Resized += updateOutputArea;
host.Window.Resized += () => updateOutputArea(host.Window);

AreaOffset.BindValueChanged(_ => updateInputArea(device));
AreaSize.BindValueChanged(_ => updateInputArea(device), true);
Rotation.BindValueChanged(_ => updateInputArea(device), true);

AreaOffset.BindValueChanged(_ => updateTabletAndInputArea(device));
AreaSize.BindValueChanged(_ => updateTabletAndInputArea(device));
OutputSize.BindValueChanged(_ => updateOutputArea());
Rotation.BindValueChanged(_ => updateTabletAndInputArea(device), true);
OutputAreaPosition.BindValueChanged(_ => updateOutputArea(host.Window));
OutputAreaSize.BindValueChanged(_ => updateOutputArea(host.Window));

updateOutputArea(host.Window);

Enabled.BindValueChanged(enabled =>
{
Expand Down Expand Up @@ -106,11 +112,9 @@ private void handleTabletsChanged(object? sender, IEnumerable<TabletReference> t
device.OutputMode = outputMode;
outputMode.Tablet = device.CreateReference();

updateTabletAndInputArea(device);
updateOutputArea();
updateInputArea(device);
updateOutputArea(host.Window);
}
else
tablet.Value = null;
}

private void handleDeviceReported(object? sender, IDeviceReport report)
Expand All @@ -122,7 +126,7 @@ private void handleDeviceReported(object? sender, IDeviceReport report)
handleAuxiliaryReport(auxiliaryReport);
}

private void updateOutputArea()
private void updateOutputArea(IWindow window)
{
if (device == null)
return;
Expand All @@ -131,19 +135,33 @@ private void updateOutputArea()
{
case AbsoluteOutputMode absoluteOutputMode:
{
// 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 = OutputSize.Value.X,
Height = OutputSize.Value.Y,
Position = new System.Numerics.Vector2(host.Window.Size.Width / 2f, host.Window.Size.Height / 2f)
Width = outputWidth,
Height = outputHeight,
Position = new System.Numerics.Vector2(posX, posY)
};
break;
}
}
}

private void updateTabletAndInputArea(InputDeviceTree? inputDevice)
private void updateInputArea(InputDeviceTree? inputDevice)
{
if (inputDevice == null)
return;
Expand Down

0 comments on commit 082e586

Please sign in to comment.