mirror of
https://github.com/osukey/osukey.git
synced 2025-06-22 19:57:56 +09:00
Adjust tick-based wheel control to be more correct
This commit is contained in:
parent
a48c26d999
commit
10047e6815
@ -228,15 +228,19 @@ namespace osu.Game.Overlays.Volume
|
|||||||
public void Decrease(double amount = 1, bool isPrecise = false) => adjust(-amount, isPrecise);
|
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.
|
// 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)
|
private void adjust(double delta, bool isPrecise)
|
||||||
{
|
{
|
||||||
adjustAccumulator += delta * adjust_step * (isPrecise ? 0.1 : 1);
|
scrollAccumulation += delta * adjust_step * (isPrecise ? 0.1 : 1);
|
||||||
if (Math.Abs(adjustAccumulator) < Bindable.Precision)
|
|
||||||
return;
|
var precision = Bindable.Precision;
|
||||||
Volume += adjustAccumulator;
|
|
||||||
adjustAccumulator = 0;
|
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)
|
protected override bool OnScroll(ScrollEvent e)
|
||||||
|
@ -187,15 +187,19 @@ namespace osu.Game.Screens.Edit
|
|||||||
protected override bool OnScroll(ScrollEvent e)
|
protected override bool OnScroll(ScrollEvent e)
|
||||||
{
|
{
|
||||||
scrollAccumulation += e.ScrollDelta.X + e.ScrollDelta.Y * (e.IsPrecise ? 0.1 : 1);
|
scrollAccumulation += e.ScrollDelta.X + e.ScrollDelta.Y * (e.IsPrecise ? 0.1 : 1);
|
||||||
if (Math.Abs(scrollAccumulation) < 1)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
|
const int precision = 1;
|
||||||
|
|
||||||
|
while (Math.Abs(scrollAccumulation) > precision)
|
||||||
|
{
|
||||||
if (scrollAccumulation > 0)
|
if (scrollAccumulation > 0)
|
||||||
clock.SeekBackward(!clock.IsRunning);
|
clock.SeekBackward(!clock.IsRunning);
|
||||||
else
|
else
|
||||||
clock.SeekForward(!clock.IsRunning);
|
clock.SeekForward(!clock.IsRunning);
|
||||||
|
|
||||||
scrollAccumulation = 0;
|
scrollAccumulation = scrollAccumulation < 0 ? Math.Min(0, scrollAccumulation + precision) : Math.Max(0, scrollAccumulation - precision);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user