1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-24 06:07:25 +08:00
osu-lazer/osu.Game/Graphics/UserInterface/Volume/VolumeMeter.cs

88 lines
2.8 KiB
C#
Raw Normal View History

// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2016-12-06 17:56:20 +08:00
using osu.Framework.Configuration;
2016-10-10 22:19:05 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
2016-10-10 22:19:05 +08:00
using osu.Framework.Graphics.Transformations;
using osu.Framework.Input;
using osu.Game.Graphics.Sprites;
using OpenTK;
using OpenTK.Graphics;
namespace osu.Game.Graphics.UserInterface.Volume
{
internal class VolumeMeter : Container
{
private Box meterFill;
2016-11-23 19:26:46 +08:00
public BindableDouble Bindable { get; private set; } = new BindableDouble();
2016-10-10 22:19:05 +08:00
public VolumeMeter(string meterName)
{
Size = new Vector2(40, 180);
Children = new Drawable[]
{
new Box
{
Colour = Color4.Black,
RelativeSizeAxes = Axes.Both
},
new Container
{
RelativeSizeAxes = Axes.Both,
Size = new Vector2(0.5f, 0.9f),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Children = new Drawable[]
{
new Box
{
Colour = Color4.DarkGray,
RelativeSizeAxes = Axes.Both
},
meterFill = new Box
{
Colour = Color4.White,
Scale = new Vector2(1, 0),
RelativeSizeAxes = Axes.Both,
Origin = Anchor.BottomCentre,
Anchor = Anchor.BottomCentre
}
}
},
new OsuSpriteText
2016-10-14 00:11:51 +08:00
{
Text = meterName,
Anchor = Anchor.BottomCentre,
Origin = Anchor.TopCentre
2016-10-14 00:11:51 +08:00
}
};
Bindable.ValueChanged += delegate { updateFill(); };
}
2016-10-10 22:19:05 +08:00
protected override void LoadComplete()
{
base.LoadComplete();
updateFill();
}
2016-10-13 03:17:53 +08:00
public double Volume
2016-10-10 22:19:05 +08:00
{
get { return Bindable.Value; }
2016-10-13 03:17:53 +08:00
private set
{
Bindable.Value = value;
2016-10-13 03:17:53 +08:00
}
2016-10-10 22:19:05 +08:00
}
protected override bool OnWheel(InputState state)
2016-10-10 22:19:05 +08:00
{
Volume += 0.05f * state.Mouse.WheelDelta;
return true;
2016-10-10 22:19:05 +08:00
}
2016-10-13 03:17:53 +08:00
private void updateFill() => meterFill.ScaleTo(new Vector2(1, (float)Volume), 300, EasingTypes.OutQuint);
}
}