2019-09-04 18:49:59 +02:00
|
|
|
using System;
|
2019-09-04 21:10:51 +02:00
|
|
|
using System.Linq;
|
2019-09-04 18:49:59 +02:00
|
|
|
using Microsoft.Xna.Framework.Input;
|
2019-09-04 21:10:51 +02:00
|
|
|
using MLEM.Misc;
|
2019-09-04 18:49:59 +02:00
|
|
|
|
|
|
|
namespace MLEM.Input {
|
2020-05-21 17:21:34 +02:00
|
|
|
/// <summary>
|
|
|
|
/// A set of extension methods for dealing with <see cref="MouseButton"/> and <see cref="Mouse"/>
|
|
|
|
/// </summary>
|
2019-09-04 18:49:59 +02:00
|
|
|
public static class MouseExtensions {
|
|
|
|
|
2020-05-21 17:21:34 +02:00
|
|
|
/// <summary>
|
|
|
|
/// All enum values of <see cref="MouseButton"/>
|
|
|
|
/// </summary>
|
2019-09-04 21:10:51 +02:00
|
|
|
public static readonly MouseButton[] MouseButtons = EnumHelper.GetValues<MouseButton>().ToArray();
|
|
|
|
|
2020-05-21 17:21:34 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Returns the <see cref="ButtonState"/> of the given mouse button.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="state">The mouse's current state</param>
|
|
|
|
/// <param name="button">The button whose state to query</param>
|
|
|
|
/// <returns>The state of the button</returns>
|
|
|
|
/// <exception cref="ArgumentException">If a mouse button out of range is passed</exception>
|
2019-09-04 18:49:59 +02:00
|
|
|
public static ButtonState GetState(this MouseState state, MouseButton button) {
|
|
|
|
switch (button) {
|
|
|
|
case MouseButton.Left:
|
|
|
|
return state.LeftButton;
|
|
|
|
case MouseButton.Middle:
|
|
|
|
return state.MiddleButton;
|
|
|
|
case MouseButton.Right:
|
|
|
|
return state.RightButton;
|
|
|
|
case MouseButton.Extra1:
|
|
|
|
return state.XButton1;
|
|
|
|
case MouseButton.Extra2:
|
|
|
|
return state.XButton2;
|
|
|
|
default:
|
|
|
|
throw new ArgumentException(nameof(button));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-05-21 17:21:34 +02:00
|
|
|
/// <summary>
|
|
|
|
/// This enum is a list of possible mouse buttons.
|
|
|
|
/// It serves as a wrapper around <see cref="MouseState"/>'s button properties.
|
|
|
|
/// </summary>
|
2019-09-04 18:49:59 +02:00
|
|
|
public enum MouseButton {
|
|
|
|
|
2020-05-21 17:21:34 +02:00
|
|
|
/// <summary>
|
|
|
|
/// The left mouse button, or <see cref="MouseState.LeftButton"/>
|
|
|
|
/// </summary>
|
2019-09-04 18:49:59 +02:00
|
|
|
Left,
|
2020-05-21 17:21:34 +02:00
|
|
|
/// <summary>
|
|
|
|
/// The middle mouse button, or <see cref="MouseState.MiddleButton"/>
|
|
|
|
/// </summary>
|
2019-09-04 18:49:59 +02:00
|
|
|
Middle,
|
2020-05-21 17:21:34 +02:00
|
|
|
/// <summary>
|
|
|
|
/// The right mouse button, or <see cref="MouseState.RightButton"/>
|
|
|
|
/// </summary>
|
2019-09-04 18:49:59 +02:00
|
|
|
Right,
|
2020-05-21 17:21:34 +02:00
|
|
|
/// <summary>
|
|
|
|
/// The first extra mouse button, or <see cref="MouseState.XButton1"/>
|
|
|
|
/// </summary>
|
2019-09-04 18:49:59 +02:00
|
|
|
Extra1,
|
2020-05-21 17:21:34 +02:00
|
|
|
/// <summary>
|
|
|
|
/// The second extra mouse button, or <see cref="MouseState.XButton2"/>
|
|
|
|
/// </summary>
|
2019-09-04 18:49:59 +02:00
|
|
|
Extra2
|
|
|
|
|
|
|
|
}
|
2022-06-17 18:23:47 +02:00
|
|
|
}
|