mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 19:42:55 +08:00
Merge pull request #26564 from peppy/drag-volume-controls
Allow adjusting volume controls via a drag
This commit is contained in:
commit
0adfe5f348
@ -14,7 +14,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
{
|
||||
VolumeMeter meter;
|
||||
MuteButton mute;
|
||||
Add(meter = new VolumeMeter("MASTER", 125, Color4.Blue) { Position = new Vector2(10) });
|
||||
Add(meter = new VolumeMeter("MASTER", 125, Color4.Green) { Position = new Vector2(10) });
|
||||
AddSliderStep("master volume", 0, 10, 0, i => meter.Bindable.Value = i * 0.1);
|
||||
|
||||
Add(new VolumeMeter("BIG", 250, Color4.Red)
|
||||
@ -22,6 +22,15 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Position = new Vector2(10),
|
||||
Margin = new MarginPadding { Left = 250 },
|
||||
});
|
||||
|
||||
Add(new VolumeMeter("SML", 125, Color4.Blue)
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Position = new Vector2(10),
|
||||
Margin = new MarginPadding { Right = 500 },
|
||||
});
|
||||
|
||||
Add(mute = new MuteButton
|
||||
|
@ -313,6 +313,33 @@ namespace osu.Game.Overlays.Volume
|
||||
|
||||
private void resetAcceleration() => accelerationModifier = 1;
|
||||
|
||||
private float dragDelta;
|
||||
|
||||
protected override bool OnDragStart(DragStartEvent e)
|
||||
{
|
||||
dragDelta = 0;
|
||||
adjustFromDrag(e.Delta);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void OnDrag(DragEvent e)
|
||||
{
|
||||
adjustFromDrag(e.Delta);
|
||||
base.OnDrag(e);
|
||||
}
|
||||
|
||||
private void adjustFromDrag(Vector2 delta)
|
||||
{
|
||||
const float mouse_drag_divisor = 200;
|
||||
|
||||
dragDelta += delta.Y / mouse_drag_divisor;
|
||||
|
||||
if (Math.Abs(dragDelta) < 0.01) return;
|
||||
|
||||
Volume -= dragDelta;
|
||||
dragDelta = 0;
|
||||
}
|
||||
|
||||
private void adjust(double delta, bool isPrecise)
|
||||
{
|
||||
if (delta == 0)
|
||||
|
Loading…
Reference in New Issue
Block a user