2019-01-24 08:43:03 +00:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Input;
|
|
|
|
|
using osu.Framework.Input.Bindings;
|
2021-03-30 10:42:40 +00:00
|
|
|
|
using osu.Framework.Input.Events;
|
2021-04-14 04:10:45 +00:00
|
|
|
|
using osu.Framework.Threading;
|
|
|
|
|
using osu.Game.Extensions;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Game.Input.Bindings;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Volume
|
|
|
|
|
{
|
2019-08-27 09:42:49 +00:00
|
|
|
|
public class VolumeControlReceptor : Container, IScrollBindingHandler<GlobalAction>, IHandleGlobalKeyboardInput
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
public Func<GlobalAction, bool> ActionRequested;
|
2018-07-05 07:50:04 +00:00
|
|
|
|
public Func<GlobalAction, float, bool, bool> ScrollActionRequested;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-04-14 04:10:45 +00:00
|
|
|
|
private ScheduledDelegate keyRepeat;
|
|
|
|
|
|
|
|
|
|
public bool OnPressed(GlobalAction action)
|
|
|
|
|
{
|
|
|
|
|
switch (action)
|
|
|
|
|
{
|
|
|
|
|
case GlobalAction.DecreaseVolume:
|
|
|
|
|
case GlobalAction.IncreaseVolume:
|
|
|
|
|
keyRepeat?.Cancel();
|
|
|
|
|
keyRepeat = this.BeginKeyRepeat(Scheduler, () => ActionRequested?.Invoke(action), 150);
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
case GlobalAction.ToggleMute:
|
2021-07-04 12:47:07 +00:00
|
|
|
|
case GlobalAction.NextVolumeMeter:
|
|
|
|
|
case GlobalAction.PreviousVolumeMeter:
|
2021-04-14 04:10:45 +00:00
|
|
|
|
ActionRequested?.Invoke(action);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnReleased(GlobalAction action)
|
|
|
|
|
{
|
|
|
|
|
keyRepeat?.Cancel();
|
|
|
|
|
}
|
2020-03-02 09:59:38 +00:00
|
|
|
|
|
2021-03-30 10:42:40 +00:00
|
|
|
|
protected override bool OnScroll(ScrollEvent e)
|
|
|
|
|
{
|
2021-04-18 14:50:09 +00:00
|
|
|
|
if (e.ScrollDelta.Y == 0)
|
|
|
|
|
return false;
|
|
|
|
|
|
2021-03-30 10:42:40 +00:00
|
|
|
|
// forward any unhandled mouse scroll events to the volume control.
|
|
|
|
|
ScrollActionRequested?.Invoke(GlobalAction.IncreaseVolume, e.ScrollDelta.Y, e.IsPrecise);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-02 09:59:38 +00:00
|
|
|
|
public bool OnScroll(GlobalAction action, float amount, bool isPrecise) =>
|
|
|
|
|
ScrollActionRequested?.Invoke(action, amount, isPrecise) ?? false;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|