// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using System.Collections.Generic; using Android.Views; using osu.Framework.Extensions.EnumExtensions; using osuTK.Input; namespace osu.Framework.Android.Input { public static class AndroidInputExtensions { /// /// Returns the corresponding s for a mouse button given as a . /// /// The given button state. Must not be a raw state or a non-mouse button. /// The corresponding s. /// Thrown if the provided button is not a public static IEnumerable ToMouseButtons(this MotionEventButtonState motionEventMouseButton) { if (motionEventMouseButton.HasFlagFast(MotionEventButtonState.Primary)) yield return MouseButton.Left; if (motionEventMouseButton.HasFlagFast(MotionEventButtonState.Secondary)) yield return MouseButton.Right; if (motionEventMouseButton.HasFlagFast(MotionEventButtonState.Tertiary)) yield return MouseButton.Middle; if (motionEventMouseButton.HasFlagFast(MotionEventButtonState.Back)) yield return MouseButton.Button1; if (motionEventMouseButton.HasFlagFast(MotionEventButtonState.Forward)) yield return MouseButton.Button2; } /// /// Returns the corresponding for a mouse button given as a . /// /// The given keycode. Should be or . /// The corresponding . /// true if this is a valid . public static bool TryGetMouseButton(this Keycode keycode, out MouseButton button) { switch (keycode) { case Keycode.Back: button = MouseButton.Button1; return true; case Keycode.Forward: button = MouseButton.Button2; return true; } button = MouseButton.LastButton; return false; } } }