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 all 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
12 changes: 12 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,18 @@ public interface ITabletHandler
/// </summary>
Bindable<Vector2> AreaSize { get; }

/// <summary>
/// The relative position of the output area in the game window.
/// Values range from (0,0) for top-left to (1,1) for bottom-right.
/// Has no effect when <see cref="OutputAreaSize"/> is (1,1).
/// </summary>
Bindable<Vector2> OutputAreaPosition { get; }

/// <summary>
/// Relative size of output area inside game window.
/// </summary>
Bindable<Vector2> OutputAreaSize { get; }

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

public Bindable<Vector2> AreaSize { 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;
Expand All @@ -58,6 +62,11 @@ public override bool Initialize(GameHost host)
AreaSize.BindValueChanged(_ => updateTabletAndInputArea(device));
Rotation.BindValueChanged(_ => updateTabletAndInputArea(device), true);

OutputAreaPosition.BindValueChanged(_ => updateOutputArea(host.Window));
OutputAreaSize.BindValueChanged(_ => updateOutputArea(host.Window));

updateOutputArea(host.Window);

Enabled.BindValueChanged(enabled =>
{
if (enabled.NewValue)
Expand Down Expand Up @@ -106,8 +115,6 @@ private void handleTabletsChanged(object? sender, IEnumerable<TabletReference> t
updateTabletAndInputArea(device);
updateOutputArea(host.Window);
}
else
tablet.Value = null;
Comment on lines -109 to -110
Copy link
Collaborator

Choose a reason for hiding this comment

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

what is this change? this removal does not look correct in this context

}

private void handleDeviceReported(object? sender, IDeviceReport report)
Expand All @@ -128,14 +135,16 @@ private void updateOutputArea(IWindow window)
{
case AbsoluteOutputMode absoluteOutputMode:
{
float outputWidth, outputHeight;
Vector2 windowSize = new Vector2(window.ClientSize.Width, window.ClientSize.Height);
Vector2 scaledSize = windowSize * OutputAreaSize.Value;
Vector2 offset = windowSize * (OutputAreaPosition.Value - (new Vector2(0.5f))) * (Vector2.One - OutputAreaSize.Value);
Vector2 position = (windowSize / 2) + offset;

// 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 = scaledSize.X,
Height = scaledSize.Y,
Position = position.ToSystemNumerics()
};
break;
}
Expand Down