1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 12:47:25 +08:00
osu-lazer/osu.Game/Graphics/UserInterface/BarGraph.cs

56 lines
2.2 KiB
C#
Raw Normal View History

// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
2017-03-26 06:33:03 +08:00
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using System.Collections.Generic;
using System.Linq;
2017-03-26 06:33:03 +08:00
namespace osu.Game.Graphics.UserInterface
2017-03-26 06:33:03 +08:00
{
public class BarGraph : FillFlowContainer<Bar>
{
2017-04-04 23:17:22 +08:00
private BarDirection direction = BarDirection.BottomToTop;
public new BarDirection Direction
{
get
{
return direction;
}
set
{
direction = value;
base.Direction = (direction & BarDirection.Horizontal) > 0 ? FillDirection.Vertical : FillDirection.Horizontal;
2017-04-04 23:17:22 +08:00
foreach (var bar in Children)
{
bar.Size = (direction & BarDirection.Horizontal) > 0 ? new Vector2(1, 1.0f / Children.Count()) : new Vector2(1.0f / Children.Count(), 1);
2017-04-04 23:17:22 +08:00
bar.Direction = direction;
}
2017-04-04 23:17:22 +08:00
}
}
public IEnumerable<float> Values
{
set
{
2017-04-08 02:32:09 +08:00
List<float> values = value?.ToList() ?? new List<float>();
List<Bar> graphBars = Children.ToList();
for (int i = 0; i < values.Count; i++)
if (graphBars.Count > i)
{
graphBars[i].Length = values[i] / values.Max();
graphBars[i].Size = (direction & BarDirection.Horizontal) > 0 ? new Vector2(1, 1.0f / values.Count) : new Vector2(1.0f / values.Count, 1);
}
else
Add(new Bar
{
RelativeSizeAxes = Axes.Both,
Size = (direction & BarDirection.Horizontal) > 0 ? new Vector2(1, 1.0f / values.Count) : new Vector2(1.0f / values.Count, 1),
Length = values[i] / values.Max(),
2017-04-04 23:17:22 +08:00
Direction = Direction,
});
}
}
}
2017-04-04 23:27:08 +08:00
}