From 443e24716c4f9212d0bdfc2877006b7d0b2dd028 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Wed, 14 Jun 2017 22:00:22 +0800 Subject: [PATCH] Handle relative size at LineGraph level. --- osu.Game/Graphics/UserInterface/LineGraph.cs | 45 ++++++++++++++------ 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/LineGraph.cs b/osu.Game/Graphics/UserInterface/LineGraph.cs index 36c63eb13c..c03be462dc 100644 --- a/osu.Game/Graphics/UserInterface/LineGraph.cs +++ b/osu.Game/Graphics/UserInterface/LineGraph.cs @@ -32,6 +32,8 @@ public class LineGraph : Container private Path path; + private float[] values; + /// /// A list of floats decides position of each line node. /// @@ -39,23 +41,38 @@ public IEnumerable Values { set { - path?.Expire(); - Path localPath = new Path { RelativeSizeAxes = Axes.Both }; //capture a copy to avoid potential change - Add(path = localPath); + values = value.ToArray(); + applyPath(); + } + } - var values = value.ToArray(); - int count = Math.Max(values.Length, DefaultValueCount); + public override bool Invalidate(Invalidation invalidation = Invalidation.All, Drawable source = null, bool shallPropagate = true) + { + if ((invalidation & Invalidation.DrawSize) != 0) + applyPath(); + return base.Invalidate(invalidation, source, shallPropagate); + } - float max = values.Max(), min = values.Min(); - if (MaxValue > max) max = MaxValue.Value; - if (MinValue < min) min = MinValue.Value; + private void applyPath() + { + if (values == null) return; - for (int i = 0; i < values.Length; i++) - { - float x = (i + count - values.Length) / (float)(count - 1); - float y = (max - values[i]) / (max - min); - Scheduler.AddDelayed(() => localPath.AddVertex(new Vector2(x, y)), x * transform_duration); - } + path?.Expire(); + Path localPath = new Path { RelativeSizeAxes = Axes.Both, PathWidth = 1 }; //capture a copy to avoid potential change + Add(path = localPath); + + int count = Math.Max(values.Length, DefaultValueCount); + + float max = values.Max(), min = values.Min(); + if (MaxValue > max) max = MaxValue.Value; + if (MinValue < min) min = MinValue.Value; + + for (int i = 0; i < values.Length; i++) + { + float x = (i + count - values.Length) / (float)(count - 1) * DrawWidth - 1; + float y = (max - values[i]) / (max - min) * DrawHeight - 1; + // the -1 is for inner offset in path (actually -PathWidth) + localPath.AddVertex(new Vector2(x, y)); } } }