Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6a2274a
Start of Input.ComCommon documentation
devvoid Jul 12, 2019
c29a540
Start of Input.Common documentation
devvoid Jul 12, 2019
8b3f7eb
Merge remote-tracking branch 'origin/input.common-docs' into input.co…
devvoid Jul 12, 2019
cfad5e7
Document most structs
devvoid Jul 12, 2019
f56e516
Remove mention of d-pad
devvoid Jul 12, 2019
cb74225
Change some key names for parity with input
devvoid Jul 12, 2019
bebc935
Make Position2D powers of two
devvoid Jul 12, 2019
c5fbda5
Document enums
devvoid Jul 12, 2019
9e203b0
Document interfaces and Deadzone
devvoid Jul 12, 2019
4f7bf3a
Correct template mistake
devvoid Jul 12, 2019
d1174b2
Document Thumbstick
devvoid Jul 12, 2019
5893929
Update src/Input/Silk.NET.Input.Common/Enums/DeadzoneMethod.cs
devvoid Jul 13, 2019
7cfb9aa
Update src/Input/Silk.NET.Input.Common/Enums/DeadzoneMethod.cs
devvoid Jul 13, 2019
038e5ff
Update src/Input/Silk.NET.Input.Common/Enums/DeadzoneMethod.cs
devvoid Jul 13, 2019
f132b5c
Update src/Input/Silk.NET.Input.Common/Enums/Key.cs
devvoid Jul 13, 2019
50a42bc
Update src/Input/Silk.NET.Input.Common/Interfaces/IGamepad.cs
devvoid Jul 13, 2019
46a6eb3
Update src/Input/Silk.NET.Input.Common/Interfaces/IJoystick.cs
devvoid Jul 13, 2019
4ad63a8
Update src/Input/Silk.NET.Input.Common/Interfaces/IGamepad.cs
devvoid Jul 13, 2019
273786e
Update src/Input/Silk.NET.Input.Common/Interfaces/IJoystick.cs
devvoid Jul 13, 2019
f523602
Update src/Input/Silk.NET.Input.Common/Interfaces/IJoystick.cs
devvoid Jul 13, 2019
2aa3232
Update src/Input/Silk.NET.Input.Common/Interfaces/IInputPlatform.cs
devvoid Jul 13, 2019
e9b89a6
Update src/Input/Silk.NET.Input.Common/Interfaces/IJoystick.cs
devvoid Jul 13, 2019
0bd92d9
Update src/Input/Silk.NET.Input.Common/Interfaces/IJoystick.cs
devvoid Jul 13, 2019
55556b7
Update IMouse.cs
devvoid Jul 13, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion documentation/proposals/Proposal - Input.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public interface IGamepad : IInputDevice
event Action<IGamepad, Button> ButtonDown;
event Action<IGamepad, Button> ButtonUp;
event Action<IGamepad, Thumbstick> ThumbstickMoved;
event Action<IGamepad, Thumbstick> TriggerMoved;
event Action<IGamepad, Trigger> TriggerMoved;
}
```

Expand Down
15 changes: 15 additions & 0 deletions src/Input/Silk.NET.Input.Common/Axis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,26 @@

namespace Silk.NET.Input.Common
{
/// <summary>
/// Represents an axis on a joystick.
/// </summary>
public struct Axis
{
/// <summary>
/// The index of this axis, used to determine which axis it is.
/// </summary>
public int Index { get; }

/// <summary>
/// The position of this axis.
/// </summary>
public float Position { get; }

/// <summary>
/// Creates a new instance of the Axis struct.
/// </summary>
/// <param name="index">The index of the new axis.</param>
/// <param name="position">The position of the new axis.</param>
public Axis(int index, float position)
{
Index = index;
Expand Down
14 changes: 14 additions & 0 deletions src/Input/Silk.NET.Input.Common/Button.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,24 @@

namespace Silk.NET.Input.Common
{
/// <summary>
/// Represents a joystick button.
/// </summary>
public struct Button
{
/// <summary>
/// The name of this button. Only guaranteed to be valid if this comes from an <see cref="IGamepad"/>.
/// </summary>
public ButtonName Name { get; }

/// <summary>
/// The index of this button. Use this if this button comes from an <see cref="IJoystick"/>.
/// </summary>
public int Index { get; }

/// <summary>
/// Whether or not this button is currently pressed.
/// </summary>
public bool Pressed { get; }

public Button(ButtonName name, int index, bool pressed)
Expand Down
15 changes: 15 additions & 0 deletions src/Input/Silk.NET.Input.Common/Deadzone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,26 @@

namespace Silk.NET.Input.Common
{
/// <summary>
/// The deadzone to use for a joystick/gamepad's sticks.
/// </summary>
public struct Deadzone
{
/// <summary>
/// The size of the deadzone to use.
/// </summary>
public float Value { get; }

/// <summary>
/// The deadzone method to use.
/// </summary>
public DeadzoneMethod Method { get; }

/// <summary>
/// Creates a new instance of the Deadzone struct.
/// </summary>
/// <param name="value">The deadzone size.</param>
/// <param name="method">The deadzone method.</param>
public Deadzone(float value, DeadzoneMethod method)
{
Value = value;
Expand Down
3 changes: 3 additions & 0 deletions src/Input/Silk.NET.Input.Common/Enums/ButtonName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

namespace Silk.NET.Input.Common
{
/// <summary>
/// The different names a <see cref="Button"/> can have.
/// </summary>
public enum ButtonName
{
A,
Expand Down
29 changes: 27 additions & 2 deletions src/Input/Silk.NET.Input.Common/Enums/DeadzoneMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,36 @@

namespace Silk.NET.Input.Common
{
/// <summary>
/// Available methods to control the deadzone of a control stick.
/// </summary>
public enum DeadzoneMethod
{
// y = x except where |x| is between 0 and d (the deadzone value)
/// <summary>
/// The traditional deadzone method.
/// </summary>
/// <remarks>
/// <para>
/// y = x except where |x| is between 0 and d
/// </para>
/// <para>
/// y is the output, x is the raw value, and d is the deadzone value.
/// </para>
/// </remarks>
Traditional,
// y = (1 - d)x + (d * sgn(x))

/// <summary>
/// A more adaptive deadzone method; if the value is within the deadzone, equal to 0. After exiting the
/// deadzone, the output increases linearly.
/// </summary>
/// <remarks>
/// <para>
/// y = (1 - d)x + (d * sgn(x))
/// </para>
/// <para>
/// y is the output, x is the raw value, and d is the deadzone value.
/// </para>
/// </remarks>
AdaptiveGradient
}
}
8 changes: 8 additions & 0 deletions src/Input/Silk.NET.Input.Common/Enums/Key.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@

namespace Silk.NET.Input.Common
{
/// <summary>
/// Represents the keys on a keyboard.
/// </summary>
/// <remarks>
/// <para>
/// The exact number of function keys provided depends on the current input backend.
/// </para>
/// </remarks>
public enum Key
{
Unknown = 0,
Expand Down
8 changes: 8 additions & 0 deletions src/Input/Silk.NET.Input.Common/Enums/MouseButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@

namespace Silk.NET.Input.Common
{
/// <summary>
/// Represents the indices of the mouse buttons.
/// </summary>
/// <remarks>
/// <para>
/// The number of buttons provided depends on the input backend currently being used.
/// </para>
/// </remarks>
public enum MouseButton
{
Left,
Expand Down
11 changes: 7 additions & 4 deletions src/Input/Silk.NET.Input.Common/Enums/Position2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@

namespace Silk.NET.Input.Common
{
/// <summary>
/// Represents the position of a joystick <see cref="Hat"/>
/// </summary>
[Flags]
public enum Position2D
{
Up,
Down,
Left,
Right,
Up = 1,
Down = 2,
Left = 4,
Right = 8,

UpLeft = Up | Left,
UpRight = Up | Right,
Expand Down
15 changes: 15 additions & 0 deletions src/Input/Silk.NET.Input.Common/Hat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,26 @@

namespace Silk.NET.Input.Common
{
/// <summary>
/// Represents a joystick hat.
/// </summary>
public struct Hat
{
/// <summary>
/// The index of this hat.
/// </summary>
public int Index { get; }

/// <summary>
/// The position of this hat.
/// </summary>
public Position2D Position { get; }

/// <summary>
/// Creates a new instance of the Hat struct.
/// </summary>
/// <param name="index">The index of the hat.</param>
/// <param name="position">The position of the hat.</param>
public Hat(int index, Position2D position)
{
Index = index;
Expand Down
38 changes: 36 additions & 2 deletions src/Input/Silk.NET.Input.Common/Interfaces/IGamepad.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,49 @@

namespace Silk.NET.Input.Common
{
/// <summary>
/// Represents a gamepad/controller with a set amount of thumbsticks, buttons, and triggers.
/// </summary>
public interface IGamepad : IInputDevice
{
/// <summary>
/// A list of all available buttons.
/// </summary>
IReadOnlyCollection<Button> Buttons { get; }

/// <summary>
/// A list of all available thumbsticks.
/// </summary>
IReadOnlyCollection<Thumbstick> Thumbsticks { get; }

/// <summary>
/// A list of all available triggers.
/// </summary>
IReadOnlyCollection<Trigger> Triggers { get; }

/// <summary>
/// The deadzone for this gamepad.
/// </summary>
Deadzone Deadzone { get; set; }

/// <summary>
/// Called when a button is pressed.
/// </summary>
event Action<IGamepad, Button> ButtonDown;

/// <summary>
/// Called when a button is released.
/// </summary>
event Action<IGamepad, Button> ButtonUp;

/// <summary>
/// Called when a thumbstick is moved.
/// </summary>
event Action<IGamepad, Thumbstick> ThumbstickMoved;
event Action<IGamepad, Thumbstick> TriggerMoved;

/// <summary>
/// Called when a trigger is moved.
/// </summary>
event Action<IGamepad, Trigger> TriggerMoved;
}
}
}
26 changes: 26 additions & 0 deletions src/Input/Silk.NET.Input.Common/Interfaces/IInputContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,39 @@

namespace Silk.NET.Input.Common
{
/// <summary>
/// An interface representing the input context.
/// </summary>
public interface IInputContext
{
/// <summary>
/// A handle to the underlying window.
/// </summary>
IntPtr Handle { get; }

/// <summary>
/// A list of all available gamepads.
/// </summary>
IReadOnlyCollection<IGamepad> Gamepads { get; }

/// <summary>
/// A list of all available joysticks.
/// </summary>
IReadOnlyCollection<IJoystick> Joysticks { get; }

/// <summary>
/// A list of all available keyboards.
/// </summary>
IReadOnlyCollection<IKeyboard> Keyboards { get; }

/// <summary>
/// A list of all available mice.
/// </summary>
IReadOnlyCollection<IMouse> Mice { get; }

/// <summary>
/// A list of all other available input devices.
/// </summary>
IReadOnlyCollection<IInputDevice> OtherDevices { get; }
}
}
18 changes: 18 additions & 0 deletions src/Input/Silk.NET.Input.Common/Interfaces/IInputDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,29 @@

namespace Silk.NET.Input.Common
{
/// <summary>
/// Generic interface representing an input device.
/// </summary>
public interface IInputDevice
{
/// <summary>
/// The name of this device, as reported by the hardware.
/// </summary>
string Name { get; }

/// <summary>
/// The index of this device.
/// </summary>
int Index { get; }

/// <summary>
/// Whether or not this device is currently connected.
/// </summary>
bool IsConnected { get; }

/// <summary>
/// Called when the connection of this device changes.
/// </summary>
event Action<IInputDevice, bool> ConnectionChanged;
}
}
14 changes: 14 additions & 0 deletions src/Input/Silk.NET.Input.Common/Interfaces/IInputPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,23 @@

namespace Silk.NET.Input.Common
{
/// <summary>
/// An interface representing an input platform.
/// </summary>
public interface IInputPlatform
{
/// <summary>
/// If this platform is applicable to this window.
/// </summary>
/// <param name="window">The window to check.</param>
/// <returns>Whether or not this platform is applicable.</returns>
bool IsApplicable(IWindow window);

/// <summary>
/// Get an input context for this window.
/// </summary>
/// <param name="window">The window to get a context for.</param>
/// <returns>The context.</returns>
IInputContext GetInput(IWindow window);
}
}
Loading