2019-01-24 08:43:03 +00:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-11-20 12:19:49 +00:00
|
|
|
|
using System;
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2017-04-07 16:13:55 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-06-20 05:54:23 +00:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-04-07 16:13:55 +00:00
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
|
{
|
2017-04-08 11:53:11 +00:00
|
|
|
|
public class Bar : Container, IHasAccentColour
|
2017-04-07 16:13:55 +00:00
|
|
|
|
{
|
2017-04-10 14:49:48 +00:00
|
|
|
|
private readonly Box background;
|
2017-04-07 16:13:55 +00:00
|
|
|
|
private readonly Box bar;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-04-07 16:13:55 +00:00
|
|
|
|
private const int resize_duration = 250;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-07-22 18:50:25 +00:00
|
|
|
|
private const Easing easing = Easing.InOutCubic;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-04-07 16:13:55 +00:00
|
|
|
|
private float length;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-04-10 14:42:23 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Length of the bar, ranges from 0 to 1
|
|
|
|
|
/// </summary>
|
2017-04-07 16:13:55 +00:00
|
|
|
|
public float Length
|
|
|
|
|
{
|
2019-02-28 04:58:19 +00:00
|
|
|
|
get => length;
|
2017-04-07 16:13:55 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
2019-11-20 12:19:49 +00:00
|
|
|
|
length = Math.Clamp(value, 0, 1);
|
2017-04-07 16:13:55 +00:00
|
|
|
|
updateBarLength();
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-04-08 11:31:55 +00:00
|
|
|
|
public Color4 BackgroundColour
|
2017-04-07 16:13:55 +00:00
|
|
|
|
{
|
2019-02-28 04:31:40 +00:00
|
|
|
|
get => background.Colour;
|
|
|
|
|
set => background.Colour = value;
|
2017-04-07 16:13:55 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-04-08 11:53:11 +00:00
|
|
|
|
public Color4 AccentColour
|
2017-04-07 16:13:55 +00:00
|
|
|
|
{
|
2019-02-28 04:31:40 +00:00
|
|
|
|
get => bar.Colour;
|
|
|
|
|
set => bar.Colour = value;
|
2017-04-07 16:13:55 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-04-07 16:13:55 +00:00
|
|
|
|
private BarDirection direction = BarDirection.LeftToRight;
|
2019-02-28 04:31:40 +00:00
|
|
|
|
|
2017-04-07 16:13:55 +00:00
|
|
|
|
public BarDirection Direction
|
|
|
|
|
{
|
2019-02-28 04:58:19 +00:00
|
|
|
|
get => direction;
|
2017-04-07 16:13:55 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
direction = value;
|
|
|
|
|
updateBarLength();
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-04-07 16:13:55 +00:00
|
|
|
|
public Bar()
|
|
|
|
|
{
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
2017-04-10 14:42:23 +00:00
|
|
|
|
background = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-06-08 06:35:10 +00:00
|
|
|
|
Colour = new Color4(0, 0, 0, 0)
|
2017-04-10 14:42:23 +00:00
|
|
|
|
},
|
2017-04-07 16:13:55 +00:00
|
|
|
|
bar = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-04-12 08:52:24 +00:00
|
|
|
|
Width = 0,
|
2017-04-10 14:42:23 +00:00
|
|
|
|
},
|
2017-04-07 16:13:55 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-04-07 16:13:55 +00:00
|
|
|
|
private void updateBarLength()
|
|
|
|
|
{
|
|
|
|
|
switch (direction)
|
|
|
|
|
{
|
|
|
|
|
case BarDirection.LeftToRight:
|
|
|
|
|
case BarDirection.RightToLeft:
|
|
|
|
|
bar.ResizeTo(new Vector2(length, 1), resize_duration, easing);
|
|
|
|
|
break;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-04-07 16:13:55 +00:00
|
|
|
|
case BarDirection.TopToBottom:
|
|
|
|
|
case BarDirection.BottomToTop:
|
|
|
|
|
bar.ResizeTo(new Vector2(1, length), resize_duration, easing);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-04-07 16:13:55 +00:00
|
|
|
|
switch (direction)
|
|
|
|
|
{
|
|
|
|
|
case BarDirection.LeftToRight:
|
|
|
|
|
case BarDirection.TopToBottom:
|
|
|
|
|
bar.Anchor = Anchor.TopLeft;
|
|
|
|
|
bar.Origin = Anchor.TopLeft;
|
|
|
|
|
break;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-04-07 16:13:55 +00:00
|
|
|
|
case BarDirection.RightToLeft:
|
|
|
|
|
case BarDirection.BottomToTop:
|
|
|
|
|
bar.Anchor = Anchor.BottomRight;
|
|
|
|
|
bar.Origin = Anchor.BottomRight;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-04-07 16:13:55 +00:00
|
|
|
|
[Flags]
|
|
|
|
|
public enum BarDirection
|
|
|
|
|
{
|
2019-08-09 03:29:33 +00:00
|
|
|
|
LeftToRight = 1,
|
2017-04-07 16:13:55 +00:00
|
|
|
|
RightToLeft = 1 << 1,
|
|
|
|
|
TopToBottom = 1 << 2,
|
|
|
|
|
BottomToTop = 1 << 3,
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-04-07 16:13:55 +00:00
|
|
|
|
Vertical = TopToBottom | BottomToTop,
|
|
|
|
|
Horizontal = LeftToRight | RightToLeft,
|
|
|
|
|
}
|
2017-11-23 09:09:42 +00:00
|
|
|
|
}
|