mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 03:25:11 +08:00
Merge pull request #9590 from peppy/editor-fix-scroll-reversal
Fix reversing scroll direction not always behaving as expected
This commit is contained in:
commit
2db2f0709e
@ -175,13 +175,13 @@ namespace osu.Game.Tests.Visual.Editing
|
||||
AddAssert("Time = 50", () => Clock.CurrentTime == 50);
|
||||
AddStep("Seek(49.999)", () => Clock.Seek(49.999));
|
||||
AddStep("SeekForward, Snap", () => Clock.SeekForward(true));
|
||||
AddAssert("Time = 50", () => Clock.CurrentTime == 50);
|
||||
AddAssert("Time = 100", () => Clock.CurrentTime == 100);
|
||||
AddStep("Seek(99)", () => Clock.Seek(99));
|
||||
AddStep("SeekForward, Snap", () => Clock.SeekForward(true));
|
||||
AddAssert("Time = 100", () => Clock.CurrentTime == 100);
|
||||
AddStep("Seek(99.999)", () => Clock.Seek(99.999));
|
||||
AddStep("SeekForward, Snap", () => Clock.SeekForward(true));
|
||||
AddAssert("Time = 100", () => Clock.CurrentTime == 100);
|
||||
AddAssert("Time = 100", () => Clock.CurrentTime == 150);
|
||||
AddStep("Seek(174)", () => Clock.Seek(174));
|
||||
AddStep("SeekForward, Snap", () => Clock.SeekForward(true));
|
||||
AddAssert("Time = 175", () => Clock.CurrentTime == 175);
|
||||
|
@ -275,11 +275,22 @@ namespace osu.Game.Screens.Edit
|
||||
|
||||
protected override bool OnScroll(ScrollEvent e)
|
||||
{
|
||||
scrollAccumulation += (e.ScrollDelta.X + e.ScrollDelta.Y) * (e.IsPrecise ? 0.1 : 1);
|
||||
const double precision = 1;
|
||||
|
||||
const int precision = 1;
|
||||
double scrollComponent = e.ScrollDelta.X + e.ScrollDelta.Y;
|
||||
|
||||
while (Math.Abs(scrollAccumulation) > precision)
|
||||
double scrollDirection = Math.Sign(scrollComponent);
|
||||
|
||||
// this is a special case to handle the "pivot" scenario.
|
||||
// if we are precise scrolling in one direction then change our mind and scroll backwards,
|
||||
// the existing accumulation should be applied in the inverse direction to maintain responsiveness.
|
||||
if (Math.Sign(scrollAccumulation) != scrollDirection)
|
||||
scrollAccumulation = scrollDirection * (precision - Math.Abs(scrollAccumulation));
|
||||
|
||||
scrollAccumulation += scrollComponent * (e.IsPrecise ? 0.1 : 1);
|
||||
|
||||
// because we are doing snapped seeking, we need to add up precise scrolls until they accumulate to an arbitrary cut-off.
|
||||
while (Math.Abs(scrollAccumulation) >= precision)
|
||||
{
|
||||
if (scrollAccumulation > 0)
|
||||
seek(e, -1);
|
||||
|
@ -118,9 +118,14 @@ namespace osu.Game.Screens.Edit
|
||||
|
||||
seekTime = timingPoint.Time + closestBeat * seekAmount;
|
||||
|
||||
// limit forward seeking to only up to the next timing point's start time.
|
||||
var nextTimingPoint = ControlPointInfo.TimingPoints.FirstOrDefault(t => t.Time > timingPoint.Time);
|
||||
if (seekTime > nextTimingPoint?.Time)
|
||||
seekTime = nextTimingPoint.Time;
|
||||
|
||||
// Due to the rounding above, we may end up on the current beat. This will effectively cause 0 seeking to happen, but we don't want this.
|
||||
// Instead, we'll go to the next beat in the direction when this is the case
|
||||
if (Precision.AlmostEquals(current, seekTime))
|
||||
if (Precision.AlmostEquals(current, seekTime, 0.5f))
|
||||
{
|
||||
closestBeat += direction > 0 ? 1 : -1;
|
||||
seekTime = timingPoint.Time + closestBeat * seekAmount;
|
||||
@ -129,10 +134,6 @@ namespace osu.Game.Screens.Edit
|
||||
if (seekTime < timingPoint.Time && timingPoint != ControlPointInfo.TimingPoints.First())
|
||||
seekTime = timingPoint.Time;
|
||||
|
||||
var nextTimingPoint = ControlPointInfo.TimingPoints.FirstOrDefault(t => t.Time > timingPoint.Time);
|
||||
if (seekTime > nextTimingPoint?.Time)
|
||||
seekTime = nextTimingPoint.Time;
|
||||
|
||||
// Ensure the sought point is within the boundaries
|
||||
seekTime = Math.Clamp(seekTime, 0, TrackLength);
|
||||
SeekTo(seekTime);
|
||||
|
Loading…
Reference in New Issue
Block a user