mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 20:32:55 +08:00
Add toggle for cursor trail interpolation
This commit is contained in:
parent
1d225ba81e
commit
3b1b7910bb
@ -106,6 +106,11 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
|
|||||||
|
|
||||||
private Vector2 size => texture.Size * Scale;
|
private Vector2 size => texture.Size * Scale;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether to interpolate mouse movements and add trail pieces at intermediate points.
|
||||||
|
/// </summary>
|
||||||
|
protected virtual bool InterpolateMovements => true;
|
||||||
|
|
||||||
private Vector2? lastPosition;
|
private Vector2? lastPosition;
|
||||||
private readonly InputResampler resampler = new InputResampler();
|
private readonly InputResampler resampler = new InputResampler();
|
||||||
|
|
||||||
@ -126,29 +131,41 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
|
|||||||
{
|
{
|
||||||
Trace.Assert(lastPosition.HasValue);
|
Trace.Assert(lastPosition.HasValue);
|
||||||
|
|
||||||
// ReSharper disable once PossibleInvalidOperationException
|
if (InterpolateMovements)
|
||||||
Vector2 pos1 = lastPosition.Value;
|
|
||||||
Vector2 diff = pos2 - pos1;
|
|
||||||
float distance = diff.Length;
|
|
||||||
Vector2 direction = diff / distance;
|
|
||||||
|
|
||||||
float interval = size.X / 2 * 0.9f;
|
|
||||||
|
|
||||||
for (float d = interval; d < distance; d += interval)
|
|
||||||
{
|
{
|
||||||
lastPosition = pos1 + direction * d;
|
// ReSharper disable once PossibleInvalidOperationException
|
||||||
|
Vector2 pos1 = lastPosition.Value;
|
||||||
|
Vector2 diff = pos2 - pos1;
|
||||||
|
float distance = diff.Length;
|
||||||
|
Vector2 direction = diff / distance;
|
||||||
|
|
||||||
parts[currentIndex].Position = lastPosition.Value;
|
float interval = size.X / 2 * 0.9f;
|
||||||
parts[currentIndex].Time = time;
|
|
||||||
++parts[currentIndex].InvalidationID;
|
|
||||||
|
|
||||||
currentIndex = (currentIndex + 1) % max_sprites;
|
for (float d = interval; d < distance; d += interval)
|
||||||
|
{
|
||||||
|
lastPosition = pos1 + direction * d;
|
||||||
|
addPart(lastPosition.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lastPosition = pos2;
|
||||||
|
addPart(lastPosition.Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return base.OnMouseMove(e);
|
return base.OnMouseMove(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addPart(Vector2 screenSpacePosition)
|
||||||
|
{
|
||||||
|
parts[currentIndex].Position = screenSpacePosition;
|
||||||
|
parts[currentIndex].Time = time;
|
||||||
|
++parts[currentIndex].InvalidationID;
|
||||||
|
|
||||||
|
currentIndex = (currentIndex + 1) % max_sprites;
|
||||||
|
}
|
||||||
|
|
||||||
protected override DrawNode CreateDrawNode() => new TrailDrawNode(this);
|
protected override DrawNode CreateDrawNode() => new TrailDrawNode(this);
|
||||||
|
|
||||||
private struct TrailPart
|
private struct TrailPart
|
||||||
|
Loading…
Reference in New Issue
Block a user