1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-26 03:52:57 +08:00
osu-lazer/osu.Game/Screens/Play/SongProgressBar.cs

118 lines
3.8 KiB
C#
Raw Normal View History

2017-03-22 19:54:21 +08:00
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2017-06-23 00:42:29 +08:00
using System;
2017-03-22 19:54:21 +08:00
using OpenTK;
using OpenTK.Graphics;
2017-03-22 19:54:21 +08:00
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes;
2017-06-23 00:42:29 +08:00
using osu.Framework.Graphics.UserInterface;
2017-03-22 19:54:21 +08:00
namespace osu.Game.Screens.Play
{
2017-06-23 00:42:29 +08:00
public class SongProgressBar : SliderBar<double>
2017-03-22 19:54:21 +08:00
{
2017-06-23 00:42:29 +08:00
public Action<double> OnSeek;
2017-06-24 16:15:53 +08:00
private readonly Box fill;
private readonly Container handleBase;
2017-06-23 00:42:29 +08:00
public Color4 FillColour
{
2017-06-23 00:42:29 +08:00
set { fill.Colour = value; }
}
2017-06-23 00:42:29 +08:00
public double StartTime
2017-03-22 19:54:21 +08:00
{
2017-06-23 00:42:29 +08:00
set { CurrentNumber.MinValue = value; }
}
2017-06-23 00:42:29 +08:00
public double EndTime
{
set { CurrentNumber.MaxValue = value; }
}
2017-03-22 19:54:21 +08:00
2017-06-23 00:42:29 +08:00
public double CurrentTime
{
set { CurrentNumber.Value = value; }
}
2017-06-23 00:42:29 +08:00
public SongProgressBar(float barHeight, float handleBarHeight, Vector2 handleSize)
{
CurrentNumber.MinValue = 0;
CurrentNumber.MaxValue = 1;
RelativeSizeAxes = Axes.X;
Height = barHeight + handleBarHeight + handleSize.Y;
Children = new Drawable[]
{
2017-06-24 16:15:53 +08:00
new Box
2017-03-22 19:54:21 +08:00
{
2017-06-23 00:42:29 +08:00
Name = "Background",
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
RelativeSizeAxes = Axes.X,
Height = barHeight,
Colour = Color4.Black,
Alpha = 0.5f,
Depth = 1,
},
fill = new Box
{
Name = "Fill",
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Height = barHeight,
},
handleBase = new Container
{
Name = "HandleBar container",
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
Width = 2,
Height = barHeight + handleBarHeight,
Colour = Color4.White,
Position = new Vector2(2, 0),
Children = new Drawable[]
2017-03-22 19:54:21 +08:00
{
2017-06-23 00:42:29 +08:00
new Box
2017-03-22 19:54:21 +08:00
{
2017-06-23 00:42:29 +08:00
Name = "HandleBar box",
RelativeSizeAxes = Axes.Both,
},
new Container
{
Name = "Handle container",
Origin = Anchor.BottomCentre,
Anchor = Anchor.TopCentre,
Size = handleSize,
CornerRadius = 5,
Masking = true,
Children = new Drawable[]
2017-03-22 19:54:21 +08:00
{
2017-06-23 00:42:29 +08:00
new Box
{
Name = "Handle box",
RelativeSizeAxes = Axes.Both,
Colour = Color4.White
}
2017-03-22 19:54:21 +08:00
}
}
}
}
2017-06-23 00:42:29 +08:00
};
2017-03-22 19:54:21 +08:00
}
2017-06-23 00:42:29 +08:00
protected override void UpdateValue(float value)
{
var xFill = value * UsableWidth;
fill.Width = xFill;
handleBase.MoveToX(xFill);
}
protected override void OnUserChange() => OnSeek?.Invoke(Current);
2017-03-22 19:54:21 +08:00
}
}