2019-01-24 16:43:03 +08: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 17:19:50 +08:00
|
|
|
|
|
2017-08-24 17:51:34 +08:00
|
|
|
|
using System;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-08-24 17:51:34 +08:00
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
|
{
|
|
|
|
|
public class ProgressBar : SliderBar<double>
|
|
|
|
|
{
|
|
|
|
|
public Action<double> OnSeek;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-08-24 17:51:34 +08:00
|
|
|
|
private readonly Box fill;
|
|
|
|
|
private readonly Box background;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-08-24 17:51:34 +08:00
|
|
|
|
public Color4 FillColour
|
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
|
set => fill.FadeColour(value, 150, Easing.OutQuint);
|
2017-08-24 17:51:34 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-08-24 17:51:34 +08:00
|
|
|
|
public Color4 BackgroundColour
|
|
|
|
|
{
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
background.Alpha = 1;
|
|
|
|
|
background.Colour = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-08-24 17:51:34 +08:00
|
|
|
|
public double EndTime
|
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
|
set => CurrentNumber.MaxValue = value;
|
2017-08-24 17:51:34 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-08-24 17:51:34 +08:00
|
|
|
|
public double CurrentTime
|
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
|
set => CurrentNumber.Value = value;
|
2017-08-24 17:51:34 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-02-05 14:29:32 +08:00
|
|
|
|
private readonly bool allowSeek;
|
2021-01-18 15:46:48 +08:00
|
|
|
|
|
2021-02-05 14:29:32 +08:00
|
|
|
|
public override bool HandlePositionalInput => allowSeek;
|
|
|
|
|
public override bool HandleNonPositionalInput => allowSeek;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Construct a new progress bar.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="allowSeek">Whether the user should be allowed to click/drag to adjust the value.</param>
|
|
|
|
|
public ProgressBar(bool allowSeek)
|
2017-08-24 17:51:34 +08:00
|
|
|
|
{
|
2021-02-05 14:29:32 +08:00
|
|
|
|
this.allowSeek = allowSeek;
|
2021-01-18 15:46:48 +08:00
|
|
|
|
|
2017-08-24 17:51:34 +08:00
|
|
|
|
CurrentNumber.MinValue = 0;
|
|
|
|
|
CurrentNumber.MaxValue = 1;
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-08-24 17:51:34 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
background = new Box
|
|
|
|
|
{
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
RelativeSizeAxes = Axes.Both
|
|
|
|
|
},
|
|
|
|
|
fill = new Box { RelativeSizeAxes = Axes.Y }
|
|
|
|
|
};
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-08-24 17:51:34 +08:00
|
|
|
|
protected override void UpdateValue(float value)
|
|
|
|
|
{
|
|
|
|
|
fill.Width = value * UsableWidth;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-01-08 15:31:44 +08:00
|
|
|
|
protected override void OnUserChange(double value) => OnSeek?.Invoke(value);
|
2017-08-24 17:51:34 +08:00
|
|
|
|
}
|
2018-01-05 19:21:19 +08:00
|
|
|
|
}
|