2017-04-04 01:28:05 +08:00
|
|
|
// 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;
|
2017-04-04 01:28:05 +08:00
|
|
|
using OpenTK.Graphics;
|
2017-03-26 06:33:03 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Colour;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2017-04-04 01:28:05 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2017-03-26 06:33:03 +08:00
|
|
|
|
2017-04-04 01:28:05 +08:00
|
|
|
namespace osu.Game.Graphics.UserInterface
|
2017-03-26 06:33:03 +08:00
|
|
|
{
|
2017-04-04 01:28:05 +08:00
|
|
|
public class BarGraph : FillFlowContainer<Bar>
|
|
|
|
{
|
|
|
|
|
|
|
|
public IEnumerable<float> Values
|
|
|
|
{
|
|
|
|
set
|
|
|
|
{
|
|
|
|
List<float> values = value.ToList();
|
|
|
|
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].Width = 1.0f / values.Count;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Add(new Bar
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Width = 1.0f / values.Count,
|
|
|
|
Length = values[i] / values.Max(),
|
|
|
|
Direction = BarDirection.BottomToTop,
|
|
|
|
BackgroundColour = new Color4(0, 0, 0, 0),
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public class Bar : Container
|
2017-03-26 06:33:03 +08:00
|
|
|
{
|
2017-03-29 22:00:29 +08:00
|
|
|
private readonly Box background;
|
|
|
|
private readonly Box bar;
|
2017-03-26 06:33:03 +08:00
|
|
|
|
2017-03-29 02:18:56 +08:00
|
|
|
private const int resize_duration = 250;
|
2017-03-28 23:12:54 +08:00
|
|
|
|
2017-03-29 20:48:43 +08:00
|
|
|
private const EasingTypes easing = EasingTypes.InOutCubic;
|
|
|
|
|
2017-03-28 23:12:54 +08:00
|
|
|
private float length;
|
|
|
|
public float Length
|
2017-03-26 06:33:03 +08:00
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2017-03-28 23:12:54 +08:00
|
|
|
return length;
|
2017-03-26 06:33:03 +08:00
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
2017-04-04 01:28:05 +08:00
|
|
|
length = MathHelper.Clamp(value, 0, 1);
|
2017-03-28 23:12:54 +08:00
|
|
|
updateBarLength();
|
2017-03-26 06:33:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public SRGBColour BackgroundColour
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return background.Colour;
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
|
|
|
background.Colour = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public SRGBColour BarColour
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return bar.Colour;
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
|
|
|
bar.Colour = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-28 23:12:54 +08:00
|
|
|
private BarDirection direction = BarDirection.LeftToRight;
|
|
|
|
public BarDirection Direction
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return direction;
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
|
|
|
direction = value;
|
|
|
|
updateBarLength();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-04 01:28:05 +08:00
|
|
|
public Bar()
|
2017-03-26 06:33:03 +08:00
|
|
|
{
|
2017-04-04 01:28:05 +08:00
|
|
|
Children = new[]
|
2017-03-26 06:33:03 +08:00
|
|
|
{
|
|
|
|
background = new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
|
|
|
bar = new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2017-03-28 23:12:54 +08:00
|
|
|
|
|
|
|
private void updateBarLength()
|
|
|
|
{
|
|
|
|
switch (direction)
|
|
|
|
{
|
|
|
|
case BarDirection.LeftToRight:
|
|
|
|
case BarDirection.RightToLeft:
|
2017-03-29 20:48:43 +08:00
|
|
|
bar.ResizeTo(new Vector2(length, 1), resize_duration, easing);
|
2017-03-28 23:12:54 +08:00
|
|
|
break;
|
|
|
|
case BarDirection.TopToBottom:
|
|
|
|
case BarDirection.BottomToTop:
|
2017-03-29 20:48:43 +08:00
|
|
|
bar.ResizeTo(new Vector2(1, length), resize_duration, easing);
|
2017-03-28 23:12:54 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (direction)
|
|
|
|
{
|
|
|
|
case BarDirection.LeftToRight:
|
|
|
|
case BarDirection.TopToBottom:
|
|
|
|
bar.Anchor = Anchor.TopLeft;
|
|
|
|
bar.Origin = Anchor.TopLeft;
|
|
|
|
break;
|
|
|
|
case BarDirection.RightToLeft:
|
|
|
|
case BarDirection.BottomToTop:
|
|
|
|
bar.Anchor = Anchor.BottomRight;
|
|
|
|
bar.Origin = Anchor.BottomRight;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public enum BarDirection
|
|
|
|
{
|
|
|
|
LeftToRight,
|
|
|
|
RightToLeft,
|
|
|
|
TopToBottom,
|
|
|
|
BottomToTop,
|
2017-03-26 06:33:03 +08:00
|
|
|
}
|
|
|
|
}
|