Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose tablet OutputSize #6460

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions osu.Framework/Input/Handlers/Tablet/ITabletHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public interface ITabletHandler
/// </summary>
Bindable<Vector2> AreaSize { get; }

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

/// <summary>
/// Information on the currently connected tablet device. May be null if no tablet is detected.
/// </summary>
Expand Down
17 changes: 9 additions & 8 deletions osu.Framework/Input/Handlers/Tablet/OpenTabletDriverHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class OpenTabletDriverHandler : InputHandler, IAbsolutePointer, IRelative

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

public Bindable<Vector2> OutputSize { get; } = new Bindable<Vector2>();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sold on this API design. I'd say this should be nullable, and if the output size is null, then it is presumed that the output area is the whole window (which would fall back to the old logic). Curious of other thoughts on this though @ppy/team-client

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OutputAreaSize now has a default value of Vector2(1f, 1f). So it behaves correctly on first launch.
OutputAreaPosition does not have a default value, but it's unused until the scaling mode is changed, at which point it will have been populated. I could give it a default of Vector2(0.5f, 0.5f) if that would be preferable.

I'm also open to making them nullable if that would be better.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at things in their current state, I think I'm fine with the proposed API? Better than nullable values IMHO.


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

public IBindable<TabletInfo?> Tablet => tablet;
Expand All @@ -52,10 +54,11 @@ public override bool Initialize(GameHost host)

outputMode = new AbsoluteTabletMode(this);

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

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

Enabled.BindValueChanged(enabled =>
Expand Down Expand Up @@ -104,7 +107,7 @@ private void handleTabletsChanged(object? sender, IEnumerable<TabletReference> t
outputMode.Tablet = device.CreateReference();

updateTabletAndInputArea(device);
updateOutputArea(host.Window);
updateOutputArea();
}
else
tablet.Value = null;
Expand All @@ -119,7 +122,7 @@ private void handleDeviceReported(object? sender, IDeviceReport report)
handleAuxiliaryReport(auxiliaryReport);
}

private void updateOutputArea(IWindow window)
private void updateOutputArea()
{
if (device == null)
return;
Expand All @@ -128,14 +131,12 @@ private void updateOutputArea(IWindow window)
{
case AbsoluteOutputMode absoluteOutputMode:
{
float outputWidth, outputHeight;

// 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 = OutputSize.Value.X,
Height = OutputSize.Value.Y,
Position = new System.Numerics.Vector2(host.Window.Size.Width / 2f, host.Window.Size.Height / 2f)
};
break;
}
Expand Down