1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-22 20:58:34 +01:00
MLEM/MLEM.Input/MouseExtensions.cs

72 lines
2.4 KiB
C#
Raw Normal View History

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 {
/// <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 {
/// <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();
/// <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));
}
}
}
/// <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 {
/// <summary>
/// The left mouse button, or <see cref="MouseState.LeftButton"/>
/// </summary>
2019-09-04 18:49:59 +02:00
Left,
/// <summary>
/// The middle mouse button, or <see cref="MouseState.MiddleButton"/>
/// </summary>
2019-09-04 18:49:59 +02:00
Middle,
/// <summary>
/// The right mouse button, or <see cref="MouseState.RightButton"/>
/// </summary>
2019-09-04 18:49:59 +02:00
Right,
/// <summary>
/// The first extra mouse button, or <see cref="MouseState.XButton1"/>
/// </summary>
2019-09-04 18:49:59 +02:00
Extra1,
/// <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
}