osu/osu.Game/Overlays/Volume/VolumeControlReceptor.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

58 lines
1.9 KiB
C#
Raw Normal View History

// 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
2022-06-17 07:37:17 +00:00
#nullable disable
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;
using osu.Game.Input.Bindings;
2018-04-13 09:19:50 +00:00
2018-03-03 18:08:35 +00:00
namespace osu.Game.Overlays.Volume
{
2019-08-27 09:42:49 +00:00
public partial class VolumeControlReceptor : Container, IScrollBindingHandler<GlobalAction>, IHandleGlobalKeyboardInput
{
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-09-16 09:26:12 +00:00
public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
{
2021-09-16 09:26:12 +00:00
switch (e.Action)
{
case GlobalAction.DecreaseVolume:
case GlobalAction.IncreaseVolume:
ActionRequested?.Invoke(e.Action);
return true;
case GlobalAction.ToggleMute:
case GlobalAction.NextVolumeMeter:
case GlobalAction.PreviousVolumeMeter:
if (!e.Repeat)
ActionRequested?.Invoke(e.Action);
return true;
}
return false;
}
2021-09-16 09:26:12 +00:00
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
{
}
2021-03-30 10:42:40 +00:00
protected override bool OnScroll(ScrollEvent e)
{
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;
}
2021-09-16 09:26:12 +00:00
public bool OnScroll(KeyBindingScrollEvent<GlobalAction> e) =>
ScrollActionRequested?.Invoke(e.Action, e.ScrollAmount, e.IsPrecise) ?? false;
}
}