1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-15 15:27:20 +08:00

Adjust tick-based wheel control to be more correct

This commit is contained in:
Dean Herbert 2018-11-22 20:13:40 +09:00
parent a48c26d999
commit 10047e6815
2 changed files with 21 additions and 13 deletions

View File

@ -228,15 +228,19 @@ namespace osu.Game.Overlays.Volume
public void Decrease(double amount = 1, bool isPrecise = false) => adjust(-amount, isPrecise);
// because volume precision is set to 0.01, this local is required to keep track of more precise adjustments and only apply when possible.
private double adjustAccumulator;
private double scrollAccumulation;
private void adjust(double delta, bool isPrecise)
{
adjustAccumulator += delta * adjust_step * (isPrecise ? 0.1 : 1);
if (Math.Abs(adjustAccumulator) < Bindable.Precision)
return;
Volume += adjustAccumulator;
adjustAccumulator = 0;
scrollAccumulation += delta * adjust_step * (isPrecise ? 0.1 : 1);
var precision = Bindable.Precision;
while (Math.Abs(scrollAccumulation) > precision)
{
Volume += Math.Sign(scrollAccumulation) * precision;
scrollAccumulation = scrollAccumulation < 0 ? Math.Min(0, scrollAccumulation + precision) : Math.Max(0, scrollAccumulation - precision);
}
}
protected override bool OnScroll(ScrollEvent e)

View File

@ -187,15 +187,19 @@ namespace osu.Game.Screens.Edit
protected override bool OnScroll(ScrollEvent e)
{
scrollAccumulation += e.ScrollDelta.X + e.ScrollDelta.Y * (e.IsPrecise ? 0.1 : 1);
if (Math.Abs(scrollAccumulation) < 1)
return true;
if (scrollAccumulation > 0)
clock.SeekBackward(!clock.IsRunning);
else
clock.SeekForward(!clock.IsRunning);
const int precision = 1;
while (Math.Abs(scrollAccumulation) > precision)
{
if (scrollAccumulation > 0)
clock.SeekBackward(!clock.IsRunning);
else
clock.SeekForward(!clock.IsRunning);
scrollAccumulation = scrollAccumulation < 0 ? Math.Min(0, scrollAccumulation + precision) : Math.Max(0, scrollAccumulation - precision);
}
scrollAccumulation = 0;
return true;
}