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

Add ability to manage output area of tablet handler #6166

Open
wants to merge 4 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
10 changes: 10 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,16 @@ public interface ITabletHandler
/// </summary>
Bindable<Vector2> AreaSize { get; }

/// <summary>
/// Position of output area inside game window, 0 is top-left position, 1 is bottom-right.
/// </summary>
Bindable<Vector2> OutputAreaPosition { get; }
Copy link
Contributor

Choose a reason for hiding this comment

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

If I understand correctly, this is the relative position of the centre of the output area? It should probably be mentioned as such in the xmldoc.


/// <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
29 changes: 25 additions & 4 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(_ => 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)
Expand Down Expand Up @@ -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;
}
Expand Down