// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. #nullable disable using System; using osu.Framework.Graphics.Containers; using osu.Framework.Input; using osu.Framework.Input.Bindings; using osu.Framework.Input.Events; using osu.Game.Input.Bindings; namespace osu.Game.Overlays.Volume { public partial class VolumeControlReceptor : Container, IScrollBindingHandler, IHandleGlobalKeyboardInput { public Func ActionRequested; public Func ScrollActionRequested; public bool OnPressed(KeyBindingPressEvent e) { switch (e.Action) { case GlobalAction.DecreaseVolume: case GlobalAction.IncreaseVolume: return ActionRequested?.Invoke(e.Action) == true; case GlobalAction.ToggleMute: case GlobalAction.NextVolumeMeter: case GlobalAction.PreviousVolumeMeter: if (!e.Repeat) return ActionRequested?.Invoke(e.Action) == true; return false; } return false; } public void OnReleased(KeyBindingReleaseEvent e) { } protected override bool OnScroll(ScrollEvent e) { if (e.ScrollDelta.Y == 0) return false; // forward any unhandled mouse scroll events to the volume control. ScrollActionRequested?.Invoke(GlobalAction.IncreaseVolume, e.ScrollDelta.Y, e.IsPrecise); return true; } public bool OnScroll(KeyBindingScrollEvent e) => ScrollActionRequested?.Invoke(e.Action, e.ScrollAmount, e.IsPrecise) ?? false; } }