Skip to content

Commit 6f9d43d

Browse files
authored
IGamepad: Add extension methods to return a Thumbstick (#1469)
* Start working on extension methods to return a Thumbstick * Rename GamepadExtensions.First to FirstButton, add FirstThumbstick * Add new Thumbstick and ThumbstickButton methods, deprecate old * Add new extension methods to PublicAPI I'm not entirely sure if this is correct, or what these files even are, really, but I feel this is probably what's expected. * Move new methods to unshipped PublicAPI * Remove FirstThumbstick method, document thrown exception * Rename FirstButton back to First
1 parent fbe4112 commit 6f9d43d

File tree

5 files changed

+44
-0
lines changed

5 files changed

+44
-0
lines changed

src/Input/Silk.NET.Input.Common/GamepadExtensions.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,40 @@ private static Button First(IGamepad gamepad, ButtonName name) // now without th
7171
/// <summary>
7272
/// Gets the <see cref="ButtonName.LeftStick" /> button.
7373
/// </summary>
74+
[Obsolete($"This method is obsolete! Use {nameof(LeftThumbstickButton)}")]
7475
public static Button LeftStick(this IGamepad gamepad) => First(gamepad, ButtonName.LeftStick);
7576

7677
/// <summary>
7778
/// Gets the <see cref="ButtonName.RightStick" /> button.
7879
/// </summary>
80+
[Obsolete($"This method is obsolete! Use {nameof(RightThumbstickButton)}")]
7981
public static Button RightStick(this IGamepad gamepad) => First(gamepad, ButtonName.RightStick);
82+
83+
/// <summary>
84+
/// Gets the left <see cref="Thumbstick"/>.
85+
/// </summary>
86+
/// <remarks>
87+
/// If the input backend does not support this thumbstick, a <see cref="IndexOutOfRangeException"/> will be thrown.
88+
/// </remarks>
89+
public static Thumbstick LeftThumbstick(this IGamepad gamepad) => gamepad.Thumbsticks[0];
90+
91+
/// <summary>
92+
/// Gets the right <see cref="Thumbstick"/>.
93+
/// </summary>
94+
/// <remarks>
95+
/// If the input backend does not support this thumbstick, a <see cref="IndexOutOfRangeException"/> will be thrown.
96+
/// </remarks>
97+
public static Thumbstick RightThumbstick(this IGamepad gamepad) => gamepad.Thumbsticks[1];
98+
99+
/// <summary>
100+
/// Gets the <see cref="ButtonName.LeftStick" /> button.
101+
/// </summary>
102+
public static Button LeftThumbstickButton(this IGamepad gamepad) => First(gamepad, ButtonName.LeftStick);
103+
104+
/// <summary>
105+
/// Gets the <see cref="ButtonName.RightStick" /> button.
106+
/// </summary>
107+
public static Button RightThumbstickButton(this IGamepad gamepad) => First(gamepad, ButtonName.RightStick);
80108

81109
/// <summary>
82110
/// Gets the <see cref="ButtonName.DPadUp" /> button.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
#nullable enable
2+
static Silk.NET.Input.GamepadExtensions.LeftThumbstick(this Silk.NET.Input.IGamepad! gamepad) -> Silk.NET.Input.Thumbstick
3+
static Silk.NET.Input.GamepadExtensions.LeftThumbstickButton(this Silk.NET.Input.IGamepad! gamepad) -> Silk.NET.Input.Button
4+
static Silk.NET.Input.GamepadExtensions.RightThumbstick(this Silk.NET.Input.IGamepad! gamepad) -> Silk.NET.Input.Thumbstick
5+
static Silk.NET.Input.GamepadExtensions.RightThumbstickButton(this Silk.NET.Input.IGamepad! gamepad) -> Silk.NET.Input.Button
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
#nullable enable
2+
static Silk.NET.Input.GamepadExtensions.LeftThumbstick(this Silk.NET.Input.IGamepad! gamepad) -> Silk.NET.Input.Thumbstick
3+
static Silk.NET.Input.GamepadExtensions.LeftThumbstickButton(this Silk.NET.Input.IGamepad! gamepad) -> Silk.NET.Input.Button
4+
static Silk.NET.Input.GamepadExtensions.RightThumbstick(this Silk.NET.Input.IGamepad! gamepad) -> Silk.NET.Input.Thumbstick
5+
static Silk.NET.Input.GamepadExtensions.RightThumbstickButton(this Silk.NET.Input.IGamepad! gamepad) -> Silk.NET.Input.Button
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
#nullable enable
2+
static Silk.NET.Input.GamepadExtensions.LeftThumbstick(this Silk.NET.Input.IGamepad! gamepad) -> Silk.NET.Input.Thumbstick
3+
static Silk.NET.Input.GamepadExtensions.LeftThumbstickButton(this Silk.NET.Input.IGamepad! gamepad) -> Silk.NET.Input.Button
4+
static Silk.NET.Input.GamepadExtensions.RightThumbstick(this Silk.NET.Input.IGamepad! gamepad) -> Silk.NET.Input.Thumbstick
5+
static Silk.NET.Input.GamepadExtensions.RightThumbstickButton(this Silk.NET.Input.IGamepad! gamepad) -> Silk.NET.Input.Button
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
#nullable enable
2+
static Silk.NET.Input.GamepadExtensions.LeftThumbstick(this Silk.NET.Input.IGamepad! gamepad) -> Silk.NET.Input.Thumbstick
3+
static Silk.NET.Input.GamepadExtensions.LeftThumbstickButton(this Silk.NET.Input.IGamepad! gamepad) -> Silk.NET.Input.Button
4+
static Silk.NET.Input.GamepadExtensions.RightThumbstick(this Silk.NET.Input.IGamepad! gamepad) -> Silk.NET.Input.Thumbstick
5+
static Silk.NET.Input.GamepadExtensions.RightThumbstickButton(this Silk.NET.Input.IGamepad! gamepad) -> Silk.NET.Input.Button

0 commit comments

Comments
 (0)