osu/osu.Game/VolumeMeter.cs

85 lines
2.6 KiB
C#
Raw Normal View History

2016-10-12 19:17:53 +00:00
using osu.Framework.Configuration;
2016-10-10 14:19:05 +00:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Drawables;
using osu.Framework.Graphics.Sprites;
2016-10-10 14:19:05 +00:00
using osu.Framework.Graphics.Transformations;
using osu.Framework.Input;
using OpenTK;
using OpenTK.Graphics;
namespace osu.Game
{
internal class VolumeMeter : Container
{
private Box meterFill;
private BindableDouble volume;
2016-10-10 14:19:05 +00:00
public VolumeMeter(string meterName, BindableDouble volume)
{
this.volume = volume;
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,
RelativeSizeAxes = Axes.Both,
Origin = Anchor.BottomCentre,
Anchor = Anchor.BottomCentre
}
}
},
2016-10-13 16:11:51 +00:00
new SpriteText
{
Text = meterName,
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
Position = new Vector2(0,-20)
}
};
}
2016-10-10 14:19:05 +00:00
2016-10-12 19:17:53 +00:00
public double Volume
2016-10-10 14:19:05 +00:00
{
2016-10-12 19:17:53 +00:00
get { return volume.Value; }
private set
{
volume.Value = value;
updateFill();
}
2016-10-10 14:19:05 +00:00
}
protected override bool OnWheelUp(InputState state)
{
2016-10-12 19:17:53 +00:00
Volume += 0.05f;
return true;
2016-10-10 14:19:05 +00:00
}
protected override bool OnWheelDown(InputState state)
{
2016-10-12 19:17:53 +00:00
Volume -= 0.05f;
return true;
2016-10-10 14:19:05 +00:00
}
2016-10-12 19:17:53 +00:00
private void updateFill() => meterFill.ScaleTo(new Vector2(1, (float)Volume), 300, EasingTypes.OutQuint);
}
}