Skip to content

Commit

Permalink
Merge pull request #6536 from Finadoggie/tip-pressure-threshold
Browse files Browse the repository at this point in the history
Add tip pressure to click threshold to tablet handler configuration
  • Loading branch information
bdach authored Feb 25, 2025
2 parents 043fd78 + aa2f9ea commit e7f3343
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
50 changes: 49 additions & 1 deletion osu.Framework.Tests/Visual/Input/TestSceneTabletInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public partial class TestSceneTabletInput : FrameworkTestScene
private readonly FillFlowContainer auxButtonFlow;
private IBindable<TabletInfo?> tablet = new Bindable<TabletInfo?>();
private IBindable<bool> tabletEnabled = new Bindable<bool>();
private readonly PenThresholdTester thresholdTester;

[Resolved]
private FrameworkConfigManager frameworkConfigManager { get; set; } = null!;
Expand All @@ -50,6 +51,7 @@ public TestSceneTabletInput()
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y
},
thresholdTester = new PenThresholdTester(),
}
};

Expand Down Expand Up @@ -101,6 +103,9 @@ protected override void LoadComplete()
yOffset => tabletHandler.AreaOffset.Value = new Vector2(
tabletHandler.AreaOffset.Value.X,
tabletHandler.AreaSize.Default.Y * yOffset));

AddSliderStep("change pen pressure threshold for click", 0, 1, 0f,
threshold => tabletHandler.PressureThreshold.Value = threshold);
}

AddToggleStep("toggle confine mode", enabled => frameworkConfigManager.SetValue(FrameworkSetting.ConfineMouseMode,
Expand All @@ -114,7 +119,7 @@ private void updateState()
else
tabletInfo.Text = "Tablet input is disabled.";

areaVisualizer.Alpha = penButtonFlow.Alpha = auxButtonFlow.Alpha = tablet.Value != null && tabletEnabled.Value ? 1 : 0;
areaVisualizer.Alpha = penButtonFlow.Alpha = auxButtonFlow.Alpha = thresholdTester.Alpha = tablet.Value != null && tabletEnabled.Value ? 1 : 0;
}

private partial class TabletAreaVisualiser : CompositeDrawable
Expand Down Expand Up @@ -279,5 +284,48 @@ protected override void OnTabletAuxiliaryButtonRelease(TabletAuxiliaryButtonRele
background.FadeOut(100);
}
}

private partial class PenThresholdTester : CompositeDrawable
{
private Box background = null!;
private SpriteText text = null!;

[BackgroundDependencyLoader]
private void load()
{
Size = new Vector2(100, 50);
InternalChildren = new Drawable[]
{
background = new Box
{
RelativeSizeAxes = Axes.Both,
},
text = new SpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
}
};
setPressed(false);
}

protected override bool OnMouseDown(MouseDownEvent e)
{
setPressed(true);
return true;
}

protected override void OnMouseUp(MouseUpEvent e)
{
base.OnMouseUp(e);
setPressed(false);
}

private void setPressed(bool pressed)
{
background.Colour = pressed ? FrameworkColour.Green : FrameworkColour.GreenDark;
text.Text = pressed ? "I am pressed" : "press me";
}
}
}
}
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 @@ -32,6 +32,11 @@ public interface ITabletHandler
/// </summary>
Bindable<float> Rotation { get; }

/// <summary>
/// The minimum pressure percentage required to click.
/// </summary>
BindableFloat PressureThreshold { get; }

BindableBool Enabled { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ public class OpenTabletDriverHandler : InputHandler, IAbsolutePointer, IRelative

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

public BindableFloat PressureThreshold { get; } = new BindableFloat(0.0f)
{
MinValue = 0f,
MaxValue = 1f,
Precision = 0.005f,
};

public IBindable<TabletInfo?> Tablet => tablet;

private readonly Bindable<TabletInfo?> tablet = new Bindable<TabletInfo?>();
Expand Down Expand Up @@ -102,7 +109,7 @@ void IRelativePointer.SetPosition(System.Numerics.Vector2 delta)
enqueueInput(new MousePositionRelativeInputFromPen { Delta = new Vector2(delta.X, delta.Y), DeviceType = lastTabletDeviceType });
}

void IPressureHandler.SetPressure(float percentage) => enqueueInput(new MouseButtonInputFromPen(percentage > 0) { DeviceType = lastTabletDeviceType });
void IPressureHandler.SetPressure(float percentage) => enqueueInput(new MouseButtonInputFromPen(percentage > PressureThreshold.Value) { DeviceType = lastTabletDeviceType });

private void handleTabletsChanged(object? sender, IEnumerable<TabletReference> tablets)
{
Expand Down

0 comments on commit e7f3343

Please sign in to comment.