mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 19:12:57 +08:00
Update transform using masking.
This commit is contained in:
parent
443e24716c
commit
3b64dfe0fd
@ -23,14 +23,15 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public float? MinValue { get; set; }
|
public float? MinValue { get; set; }
|
||||||
|
|
||||||
private const float transform_duration = 250;
|
private const double transform_duration = 500;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Hold an empty area if values are less.
|
/// Hold an empty area if values are less.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int DefaultValueCount;
|
public int DefaultValueCount;
|
||||||
|
|
||||||
private Path path;
|
private readonly Container<Path> maskingContainer;
|
||||||
|
private readonly Path path;
|
||||||
|
|
||||||
private float[] values;
|
private float[] values;
|
||||||
|
|
||||||
@ -43,9 +44,21 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
{
|
{
|
||||||
values = value.ToArray();
|
values = value.ToArray();
|
||||||
applyPath();
|
applyPath();
|
||||||
|
maskingContainer.Width = 0;
|
||||||
|
maskingContainer.ResizeWidthTo(1, transform_duration, EasingTypes.OutQuint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LineGraph()
|
||||||
|
{
|
||||||
|
Add(maskingContainer = new Container<Path>
|
||||||
|
{
|
||||||
|
Masking = true,
|
||||||
|
RelativeSizeAxes = Axes.Both
|
||||||
|
});
|
||||||
|
maskingContainer.Add(path = new Path { RelativeSizeAxes = Axes.Both, PathWidth = 1 });
|
||||||
|
}
|
||||||
|
|
||||||
public override bool Invalidate(Invalidation invalidation = Invalidation.All, Drawable source = null, bool shallPropagate = true)
|
public override bool Invalidate(Invalidation invalidation = Invalidation.All, Drawable source = null, bool shallPropagate = true)
|
||||||
{
|
{
|
||||||
if ((invalidation & Invalidation.DrawSize) != 0)
|
if ((invalidation & Invalidation.DrawSize) != 0)
|
||||||
@ -57,10 +70,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
{
|
{
|
||||||
if (values == null) return;
|
if (values == null) return;
|
||||||
|
|
||||||
path?.Expire();
|
path.ClearVertices();
|
||||||
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);
|
int count = Math.Max(values.Length, DefaultValueCount);
|
||||||
|
|
||||||
float max = values.Max(), min = values.Min();
|
float max = values.Max(), min = values.Min();
|
||||||
@ -72,7 +82,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
float x = (i + count - values.Length) / (float)(count - 1) * DrawWidth - 1;
|
float x = (i + count - values.Length) / (float)(count - 1) * DrawWidth - 1;
|
||||||
float y = (max - values[i]) / (max - min) * DrawHeight - 1;
|
float y = (max - values[i]) / (max - min) * DrawHeight - 1;
|
||||||
// the -1 is for inner offset in path (actually -PathWidth)
|
// the -1 is for inner offset in path (actually -PathWidth)
|
||||||
localPath.AddVertex(new Vector2(x, y));
|
path.AddVertex(new Vector2(x, y));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user