1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 06:42:56 +08:00

Improve LineGraph invalidation logic

This commit is contained in:
Dean Herbert 2017-12-22 18:58:35 +09:00
parent 8c50fa0b84
commit 1a318c5c2b
2 changed files with 39 additions and 10 deletions

View File

@ -2,14 +2,25 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays;
using osu.Game.Overlays.Profile;
using osu.Game.Users;
namespace osu.Game.Tests.Visual
{
public class TestCaseUserProfile : OsuTestCase
{
public override IReadOnlyList<Type> RequiredTypes => new[]
{
typeof(ProfileHeader),
typeof(UserProfileOverlay),
typeof(RankChart),
typeof(LineGraph),
};
public TestCaseUserProfile()
{
var profile = new UserProfileOverlay();

View File

@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Caching;
using OpenTK;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@ -47,7 +48,16 @@ namespace osu.Game.Graphics.UserInterface
set
{
values = value.ToArray();
applyPath();
float max = values.Max(), min = values.Min();
if (MaxValue > max) max = MaxValue.Value;
if (MinValue < min) min = MinValue.Value;
ActualMaxValue = max;
ActualMinValue = min;
pathCached.Invalidate();
maskingContainer.Width = 0;
maskingContainer.ResizeWidthTo(1, transform_duration, Easing.OutQuint);
}
@ -63,13 +73,28 @@ namespace osu.Game.Graphics.UserInterface
});
}
private bool pending;
public override bool Invalidate(Invalidation invalidation = Invalidation.All, Drawable source = null, bool shallPropagate = true)
{
if ((invalidation & Invalidation.DrawSize) != 0)
applyPath();
if ((invalidation & Invalidation.DrawSize) > 0)
pathCached.Invalidate();
return base.Invalidate(invalidation, source, shallPropagate);
}
private Cached pathCached = new Cached();
protected override void Update()
{
base.Update();
if (!pathCached.IsValid)
{
applyPath();
pathCached.Validate();
}
}
private void applyPath()
{
path.ClearVertices();
@ -77,13 +102,6 @@ namespace osu.Game.Graphics.UserInterface
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;
ActualMaxValue = max;
ActualMinValue = min;
for (int i = 0; i < values.Length; i++)
{
float x = (i + count - values.Length) / (float)(count - 1) * DrawWidth - 1;