From be0cc7badcb1669aff29a3e2cabc3468787ab67b Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sat, 26 Nov 2016 19:25:58 +0900 Subject: [PATCH] Code tidying. --- osu.Game/Graphics/Cursor/CursorTrail.cs | 76 ++++++++++++------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/osu.Game/Graphics/Cursor/CursorTrail.cs b/osu.Game/Graphics/Cursor/CursorTrail.cs index 741fdbad73..d65e20c47d 100644 --- a/osu.Game/Graphics/Cursor/CursorTrail.cs +++ b/osu.Game/Graphics/Cursor/CursorTrail.cs @@ -56,6 +56,8 @@ namespace osu.Game.Graphics.Cursor const int MAX_SPRITES = 2048; + Vector2? lastPosition; + protected override DrawNode CreateDrawNode() => new TrailDrawNode(); protected override void ApplyDrawNode(DrawNode node) @@ -67,43 +69,6 @@ namespace osu.Game.Graphics.Cursor tNode.Time = time; } - Vector2? last; - - protected override bool OnMouseMove(InputState state) - { - if (last == null) - { - last = state.Mouse.Position; - return base.OnMouseMove(state); - } - - Vector2 pos1 = last.Value; - Vector2 pos2 = state.Mouse.Position; - - Vector2 diff = (pos2 - pos1); - float distance = diff.Length; - Vector2 direction = diff / distance; - - float interval = this[0].DrawSize.X / 2; - - for (float d = interval; d < distance; d += interval) - { - last = pos1 + direction * d; - addPosition(last.Value); - } - - return base.OnMouseMove(state); - } - - private void addPosition(Vector2 pos) - { - var s = this[currentIndex]; - s.Position = pos; - s.Alpha = time + 1f; - - currentIndex = (currentIndex + 1) % MAX_SPRITES; - } - public CursorTrail() { RelativeSizeAxes = Axes.Both; @@ -140,9 +105,44 @@ namespace osu.Game.Graphics.Cursor timeOffset = Time.Current; } + protected override bool OnMouseMove(InputState state) + { + if (lastPosition == null) + { + lastPosition = state.Mouse.Position; + return base.OnMouseMove(state); + } + + Vector2 pos1 = lastPosition.Value; + Vector2 pos2 = state.Mouse.Position; + + Vector2 diff = pos2 - pos1; + float distance = diff.Length; + Vector2 direction = diff / distance; + + float interval = this[0].DrawSize.X / 2; + + for (float d = interval; d < distance; d += interval) + { + lastPosition = pos1 + direction * d; + addPosition(lastPosition.Value); + } + + return base.OnMouseMove(state); + } + + private void addPosition(Vector2 pos) + { + var s = this[currentIndex]; + s.Position = pos; + s.Alpha = time + 1f; + + currentIndex = (currentIndex + 1) % MAX_SPRITES; + } + class TrailDrawNode : ContainerDrawNode { - public Shader Shader; + public new Shader Shader; public float Time; public override void Draw(IVertexBatch vertexBatch)