1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 16:07:24 +08:00

Merge pull request #26564 from peppy/drag-volume-controls

Allow adjusting volume controls via a drag
This commit is contained in:
Salman Ahmed 2024-01-17 09:09:36 +03:00 committed by GitHub
commit 0adfe5f348
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 37 additions and 1 deletions

View File

@ -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

View File

@ -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)