remove unnecessary LayoutValue

This commit is contained in:
Caiyi Shyu 2024-08-02 17:45:05 +08:00
parent 06af8cb952
commit 4b5c163d93
1 changed files with 3 additions and 19 deletions

View File

@ -16,7 +16,6 @@
using osu.Framework.Graphics.Textures;
using osu.Framework.Input;
using osu.Framework.Input.Events;
using osu.Framework.Layout;
using osu.Framework.Timing;
using osuTK;
using osuTK.Graphics;
@ -63,9 +62,6 @@ public CursorTrail()
// -1 signals that the part is unusable, and should not be drawn
parts[i].InvalidationID = -1;
}
AddLayout(partSizeCache);
AddLayout(scaleRatioCache);
}
[BackgroundDependencyLoader]
@ -96,12 +92,6 @@ public Texture Texture
}
}
private readonly LayoutValue<Vector2> partSizeCache = new LayoutValue<Vector2>(Invalidation.DrawInfo | Invalidation.RequiredParentSizeToFit | Invalidation.Presence);
private Vector2 partSize => partSizeCache.IsValid
? partSizeCache.Value
: (partSizeCache.Value = new Vector2(Texture.DisplayWidth, Texture.DisplayHeight) * DrawInfo.Matrix.ExtractScale().Xy);
/// <summary>
/// The amount of time to fade the cursor trail pieces.
/// </summary>
@ -155,12 +145,6 @@ protected override bool OnMouseMove(MouseMoveEvent e)
return base.OnMouseMove(e);
}
private readonly LayoutValue<Vector2> scaleRatioCache = new LayoutValue<Vector2>(Invalidation.DrawInfo | Invalidation.RequiredParentSizeToFit | Invalidation.Presence);
private Vector2 scaleRatio => scaleRatioCache.IsValid
? scaleRatioCache.Value
: (scaleRatioCache.Value = DrawInfo.MatrixInverse.ExtractScale().Xy);
protected void AddTrail(Vector2 position)
{
position = ToLocalSpace(position);
@ -183,10 +167,10 @@ protected void AddTrail(Vector2 position)
float distance = diff.Length;
Vector2 direction = diff / distance;
Vector2 interval = partSize.X / 2.5f * IntervalMultiplier * scaleRatio;
float stopAt = distance - (AvoidDrawingNearCursor ? interval.Length : 0);
float interval = Texture.DisplayWidth / 2.5f * IntervalMultiplier;
float stopAt = distance - (AvoidDrawingNearCursor ? interval : 0);
for (Vector2 d = interval; d.Length < stopAt; d += interval)
for (float d = interval; d < stopAt; d += interval)
{
lastPosition = pos1 + direction * d;
addPart(lastPosition.Value);