diff --git a/src/Input/Axis.cs b/src/Input/Axis.cs index e358c384..8bfb2b33 100644 --- a/src/Input/Axis.cs +++ b/src/Input/Axis.cs @@ -3,6 +3,9 @@ using SDL2; namespace MoonWorks.Input { + /// + /// Represents a specific joystick direction on a gamepad. + /// public class Axis { public Gamepad Parent { get; } diff --git a/src/Input/AxisButtonCode.cs b/src/Input/AxisButtonCode.cs index cd8c92c9..4e050920 100644 --- a/src/Input/AxisButtonCode.cs +++ b/src/Input/AxisButtonCode.cs @@ -1,5 +1,8 @@ namespace MoonWorks.Input { + /// + /// Can be used to access a gamepad axis virtual button without a direct reference to the button object. + /// public enum AxisButtonCode { LeftX_Left, diff --git a/src/Input/AxisCode.cs b/src/Input/AxisCode.cs index 258ad690..9808856a 100644 --- a/src/Input/AxisCode.cs +++ b/src/Input/AxisCode.cs @@ -1,6 +1,9 @@ namespace MoonWorks.Input { - // Enum values are equivalent to SDL GameControllerAxis + /// + /// Can be used to access a gamepad axis without a direct reference to the axis object. + /// Enum values are equivalent to SDL_GameControllerAxis. + /// public enum AxisCode { LeftX, diff --git a/src/Input/ButtonCode.cs b/src/Input/ButtonCode.cs index d6070815..fc1afb5b 100644 --- a/src/Input/ButtonCode.cs +++ b/src/Input/ButtonCode.cs @@ -1,6 +1,9 @@ namespace MoonWorks.Input { - // Enum values are equivalent to the SDL GameControllerButton value. + /// + /// Can be used to access a gamepad button without a direct reference to the button object. + /// Enum values are equivalent to the SDL GameControllerButton value. + /// public enum GamepadButtonCode { A, diff --git a/src/Input/ButtonState.cs b/src/Input/ButtonState.cs index 444e9163..bfb58b58 100644 --- a/src/Input/ButtonState.cs +++ b/src/Input/ButtonState.cs @@ -1,14 +1,40 @@ namespace MoonWorks.Input { + /// + /// Container for the current state of a binary input. + /// public struct ButtonState { public ButtonStatus ButtonStatus { get; } + /// + /// True if the button was pressed this frame. + /// public bool IsPressed => ButtonStatus == ButtonStatus.Pressed; + + /// + /// True if the button was pressed this frame and the previous frame. + /// public bool IsHeld => ButtonStatus == ButtonStatus.Held; + + /// + /// True if the button was either pressed or continued to be held this frame. + /// public bool IsDown => ButtonStatus == ButtonStatus.Pressed || ButtonStatus == ButtonStatus.Held; + + /// + /// True if the button was let go this frame. + /// public bool IsReleased => ButtonStatus == ButtonStatus.Released; + + /// + /// True if the button was not pressed this frame or the previous frame. + /// public bool IsIdle => ButtonStatus == ButtonStatus.Idle; + + /// + /// True if the button was either idle or released this frame. + /// public bool IsUp => ButtonStatus == ButtonStatus.Idle || ButtonStatus == ButtonStatus.Released; public ButtonState(ButtonStatus buttonStatus) @@ -43,7 +69,7 @@ } /// - /// Combines two button states. Useful for alt controls or input buffering. + /// Combines two button states. Useful for alt control sets or input buffering. /// public static ButtonState operator |(ButtonState a, ButtonState b) { diff --git a/src/Input/ButtonStatus.cs b/src/Input/ButtonStatus.cs index 0f8930f6..5b066857 100644 --- a/src/Input/ButtonStatus.cs +++ b/src/Input/ButtonStatus.cs @@ -1,5 +1,8 @@ namespace MoonWorks.Input { + /// + /// Represents the current status of a binary input. + /// public enum ButtonStatus { /// diff --git a/src/Input/DeviceKind.cs b/src/Input/DeviceKind.cs deleted file mode 100644 index 1663788a..00000000 --- a/src/Input/DeviceKind.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace MoonWorks.Input -{ - public enum DeviceKind - { - None, - Keyboard, - Mouse, - Gamepad, - } -} diff --git a/src/Input/Gamepad.cs b/src/Input/Gamepad.cs index 8ed4f5b4..58224f62 100644 --- a/src/Input/Gamepad.cs +++ b/src/Input/Gamepad.cs @@ -5,6 +5,12 @@ using SDL2; namespace MoonWorks.Input { + /// + /// A Gamepad input abstraction that represents input coming from a console controller or other such devices. + /// The button names map to a standard Xbox 360 controller. + /// For different controllers the relative position of the face buttons will determine the button mapping. + /// For example on a DualShock controller the Cross button will map to the A button. + /// public class Gamepad { internal IntPtr Handle; @@ -51,7 +57,14 @@ namespace MoonWorks.Input public bool IsDummy => Handle == IntPtr.Zero; + /// + /// True if any input on the gamepad is active. Useful for input remapping. + /// public bool AnyPressed { get; private set; } + + /// + /// Contains a reference to an arbitrary VirtualButton that was pressed on the gamepad this frame. Useful for input remapping. + /// public VirtualButton AnyPressedButton { get; private set; } private Dictionary EnumToButton; @@ -195,7 +208,7 @@ namespace MoonWorks.Input }; } - public void Register(IntPtr handle) + internal void Register(IntPtr handle) { Handle = handle; @@ -203,7 +216,7 @@ namespace MoonWorks.Input JoystickInstanceID = SDL.SDL_JoystickInstanceID(joystickHandle); } - public void Unregister() + internal void Unregister() { Handle = IntPtr.Zero; JoystickInstanceID = -1; @@ -267,16 +280,25 @@ namespace MoonWorks.Input ) == 0; } + /// + /// Obtains a gamepad button object given a button code. + /// public GamepadButton Button(GamepadButtonCode buttonCode) { return EnumToButton[(SDL.SDL_GameControllerButton) buttonCode]; } + /// + /// Obtains an axis button object given a button code. + /// public AxisButton Button(AxisButtonCode axisButtonCode) { return AxisButtonCodeToAxisButton[axisButtonCode]; } + /// + /// Obtains a trigger button object given a button code. + /// public TriggerButton Button(TriggerCode triggerCode) { return TriggerCodeToTriggerButton[triggerCode]; diff --git a/src/Input/Input.cs b/src/Input/Input.cs index 5ac31dfe..4df0b270 100644 --- a/src/Input/Input.cs +++ b/src/Input/Input.cs @@ -3,18 +3,36 @@ using System; namespace MoonWorks.Input { + /// + /// The main container class for all input tracking. + /// Your Game class will automatically have a reference to this class. + /// public class Inputs { public const int MAX_GAMEPADS = 4; + /// + /// The reference to the Keyboard input abstraction. + /// public Keyboard Keyboard { get; } + + /// + /// The reference to the Mouse input abstraction. + /// public Mouse Mouse { get; } - Gamepad[] gamepads; + Gamepad[] Gamepads; public static event Action TextInput; + /// + /// True if any input on any input device is active. Useful for input remapping. + /// public bool AnyPressed { get; private set; } + + /// + /// Contains a reference to an arbitrary VirtualButton that was pressed this frame. Useful for input remapping. + /// public VirtualButton AnyPressedButton { get; private set; } internal Inputs() @@ -22,12 +40,12 @@ namespace MoonWorks.Input Keyboard = new Keyboard(); Mouse = new Mouse(); - gamepads = new Gamepad[MAX_GAMEPADS]; + Gamepads = new Gamepad[MAX_GAMEPADS]; // initialize dummy controllers for (var slot = 0; slot < MAX_GAMEPADS; slot += 1) { - gamepads[slot] = new Gamepad(IntPtr.Zero, slot); + Gamepads[slot] = new Gamepad(IntPtr.Zero, slot); } } @@ -53,7 +71,7 @@ namespace MoonWorks.Input AnyPressedButton = Mouse.AnyPressedButton; } - foreach (var gamepad in gamepads) + foreach (var gamepad in Gamepads) { gamepad.Update(); @@ -65,6 +83,11 @@ namespace MoonWorks.Input } } + /// + /// Returns true if a gamepad is currently connected in the given slot. + /// + /// Range: 0-3 + /// public bool GamepadExists(int slot) { if (slot < 0 || slot >= MAX_GAMEPADS) @@ -72,13 +95,19 @@ namespace MoonWorks.Input return false; } - return !gamepads[slot].IsDummy; + return !Gamepads[slot].IsDummy; } - // From 0-4 + /// + /// Gets a gamepad associated with the given slot. + /// The first n slots are guaranteed to occupied with gamepads if they are connected. + /// If a gamepad does not exist for the given slot, a dummy object with all inputs in default state will be returned. + /// You can check if a gamepad is connected in a slot with the GamepadExists function. + /// + /// Range: 0-3 public Gamepad GetGamepad(int slot) { - return gamepads[slot]; + return Gamepads[slot]; } internal void AddGamepad(int index) @@ -95,7 +124,7 @@ namespace MoonWorks.Input } else { - gamepads[slot].Register(openResult); + Gamepads[slot].Register(openResult); System.Console.WriteLine($"Gamepad added to slot {slot}!"); } return; @@ -109,10 +138,10 @@ namespace MoonWorks.Input { for (int slot = 0; slot < MAX_GAMEPADS; slot += 1) { - if (joystickInstanceID == gamepads[slot].JoystickInstanceID) + if (joystickInstanceID == Gamepads[slot].JoystickInstanceID) { - SDL.SDL_GameControllerClose(gamepads[slot].Handle); - gamepads[slot].Unregister(); + SDL.SDL_GameControllerClose(Gamepads[slot].Handle); + Gamepads[slot].Unregister(); System.Console.WriteLine($"Removing gamepad from slot {slot}!"); return; } diff --git a/src/Input/KeyCode.cs b/src/Input/KeyCode.cs index d39a2abe..0d75e1f0 100644 --- a/src/Input/KeyCode.cs +++ b/src/Input/KeyCode.cs @@ -1,6 +1,9 @@ namespace MoonWorks.Input { - // Enum values are equivalent to the SDL Scancode value. + /// + /// Can be used to determine key state without a direct reference to the virtual button object. + /// Enum values are equivalent to the SDL Scancode value. + /// public enum KeyCode : int { Unknown = 0, diff --git a/src/Input/Keyboard.cs b/src/Input/Keyboard.cs index 72e34339..442363c1 100644 --- a/src/Input/Keyboard.cs +++ b/src/Input/Keyboard.cs @@ -4,12 +4,22 @@ using SDL2; namespace MoonWorks.Input { + /// + /// The keyboard input device abstraction. + /// public class Keyboard { + /// + /// True if any button on the keyboard is active. Useful for input remapping. + /// public bool AnyPressed { get; private set; } + + /// + /// Contains a reference to an arbitrary KeyboardButton that was pressed this frame. Useful for input remapping. + /// public KeyboardButton AnyPressedButton { get; private set; } - public IntPtr State { get; private set; } + internal IntPtr State { get; private set; } private KeyCode[] KeyCodes; private KeyboardButton[] Keys { get; } @@ -78,41 +88,65 @@ namespace MoonWorks.Input } } + /// + /// True if the button was pressed this frame. + /// public bool IsPressed(KeyCode keycode) { return Keys[(int) keycode].IsPressed; } + /// + /// True if the button was pressed this frame and the previous frame. + /// public bool IsHeld(KeyCode keycode) { return Keys[(int) keycode].IsHeld; } + /// + /// True if the button was either pressed or continued to be held this frame. + /// public bool IsDown(KeyCode keycode) { return Keys[(int) keycode].IsDown; } + /// + /// True if the button was let go this frame. + /// public bool IsReleased(KeyCode keycode) { return Keys[(int) keycode].IsReleased; } + /// + /// True if the button was not pressed this frame or the previous frame. + /// public bool IsIdle(KeyCode keycode) { return Keys[(int) keycode].IsIdle; } + /// + /// True if the button was either idle or released this frame. + /// public bool IsUp(KeyCode keycode) { return Keys[(int) keycode].IsUp; } + /// + /// Gets a reference to a keyboard button object using a key code. + /// public KeyboardButton Button(KeyCode keycode) { return Keys[(int) keycode]; } + /// + /// Gets the state of a keyboard button from a key code. + /// public ButtonState ButtonState(KeyCode keycode) { return Keys[(int) keycode].State; diff --git a/src/Input/Mouse.cs b/src/Input/Mouse.cs index 008c5772..fa0a7e8c 100644 --- a/src/Input/Mouse.cs +++ b/src/Input/Mouse.cs @@ -3,6 +3,9 @@ using SDL2; namespace MoonWorks.Input { + /// + /// The mouse input device abstraction. + /// public class Mouse { public MouseButton LeftButton { get; } @@ -21,12 +24,23 @@ namespace MoonWorks.Input internal int WheelRaw; private int previousWheelRaw = 0; + /// + /// True if any button on the keyboard is active. Useful for input remapping. + /// public bool AnyPressed { get; private set; } + + /// + /// Contains a reference to an arbitrary MouseButton that was pressed this frame. Useful for input remapping. + /// public MouseButton AnyPressedButton { get; private set; } - public uint ButtonMask { get; private set; } + internal uint ButtonMask { get; private set; } private bool relativeMode; + /// + /// If set to true, the cursor is hidden, the mouse position is constrained to the window, + /// and relative mouse motion will be reported even if the mouse is at the edge of the window. + /// public bool RelativeMode { get => relativeMode; @@ -42,6 +56,9 @@ namespace MoonWorks.Input } private bool hidden; + /// + /// If set to true, the OS cursor will not be shown in your application window. + /// public bool Hidden { get => hidden; @@ -54,7 +71,7 @@ namespace MoonWorks.Input private readonly Dictionary CodeToButton; - public Mouse() + internal Mouse() { LeftButton = new MouseButton(this, MouseButtonCode.Left, SDL.SDL_BUTTON_LMASK); MiddleButton = new MouseButton(this, MouseButtonCode.Middle, SDL.SDL_BUTTON_MMASK); @@ -99,11 +116,17 @@ namespace MoonWorks.Input } } + /// + /// Gets a button from the mouse given a MouseButtonCode. + /// public MouseButton Button(MouseButtonCode buttonCode) { return CodeToButton[buttonCode]; } + /// + /// Gets a button state from a mouse button corresponding to the given MouseButtonCode. + /// public ButtonState ButtonState(MouseButtonCode buttonCode) { return CodeToButton[buttonCode].State; diff --git a/src/Input/MouseButtonCode.cs b/src/Input/MouseButtonCode.cs index e886858f..e6421fda 100644 --- a/src/Input/MouseButtonCode.cs +++ b/src/Input/MouseButtonCode.cs @@ -1,5 +1,8 @@ namespace MoonWorks.Input { + /// + /// Can be used to determine virtual mouse button state without a direct reference to the button object. + /// public enum MouseButtonCode { Left, diff --git a/src/Input/Trigger.cs b/src/Input/Trigger.cs index dd5ba0e1..63169732 100644 --- a/src/Input/Trigger.cs +++ b/src/Input/Trigger.cs @@ -3,6 +3,9 @@ using SDL2; namespace MoonWorks.Input { + /// + /// Represents a trigger input on a gamepad. + /// public class Trigger { public Gamepad Parent { get; } diff --git a/src/Input/TriggerCode.cs b/src/Input/TriggerCode.cs index 346ef0a9..10b15049 100644 --- a/src/Input/TriggerCode.cs +++ b/src/Input/TriggerCode.cs @@ -1,6 +1,9 @@ namespace MoonWorks.Input { - // Enum values correspond to SDL GameControllerAxis + /// + /// Can be used to determine trigger state or trigger virtual button state without direct reference to the trigger object or virtual button object. + /// Enum values correspond to SDL_GameControllerAxis. + /// public enum TriggerCode { Left = 4, diff --git a/src/Input/VirtualButton.cs b/src/Input/VirtualButton.cs index 2e0afe96..26fe5307 100644 --- a/src/Input/VirtualButton.cs +++ b/src/Input/VirtualButton.cs @@ -1,5 +1,8 @@ namespace MoonWorks.Input { + /// + /// VirtualButtons map inputs to binary inputs, like a trigger threshold or joystick axis threshold. + /// public abstract class VirtualButton { public ButtonState State { get; protected set; } diff --git a/src/Input/VirtualButtons/AxisButton.cs b/src/Input/VirtualButtons/AxisButton.cs index 62ae02b3..3c27a58b 100644 --- a/src/Input/VirtualButtons/AxisButton.cs +++ b/src/Input/VirtualButtons/AxisButton.cs @@ -1,5 +1,9 @@ namespace MoonWorks.Input { + /// + /// A virtual button corresponding to a direction on a joystick. + /// If the axis value exceeds the threshold, it will be treated as a press. + /// public class AxisButton : VirtualButton { public Axis Parent { get; } diff --git a/src/Input/VirtualButtons/EmptyButton.cs b/src/Input/VirtualButtons/EmptyButton.cs index 0c290357..e5e5a155 100644 --- a/src/Input/VirtualButtons/EmptyButton.cs +++ b/src/Input/VirtualButtons/EmptyButton.cs @@ -1,5 +1,8 @@ namespace MoonWorks.Input { + /// + /// A dummy button that can never be pressed. Used for the dummy gamepad. + /// public class EmptyButton : VirtualButton { internal override bool CheckPressed() diff --git a/src/Input/VirtualButtons/GamepadButton.cs b/src/Input/VirtualButtons/GamepadButton.cs index 33c56bd1..48def338 100644 --- a/src/Input/VirtualButtons/GamepadButton.cs +++ b/src/Input/VirtualButtons/GamepadButton.cs @@ -2,6 +2,9 @@ using SDL2; namespace MoonWorks.Input { + /// + /// A virtual button corresponding to a gamepad button. + /// public class GamepadButton : VirtualButton { public Gamepad Parent { get; } diff --git a/src/Input/VirtualButtons/KeyboardButton.cs b/src/Input/VirtualButtons/KeyboardButton.cs index e285ccd9..e9a1d158 100644 --- a/src/Input/VirtualButtons/KeyboardButton.cs +++ b/src/Input/VirtualButtons/KeyboardButton.cs @@ -2,6 +2,9 @@ using System.Runtime.InteropServices; namespace MoonWorks.Input { + /// + /// A virtual button corresponding to a keyboard button. + /// public class KeyboardButton : VirtualButton { Keyboard Parent; diff --git a/src/Input/VirtualButtons/MouseButton.cs b/src/Input/VirtualButtons/MouseButton.cs index 4637114d..393c66c4 100644 --- a/src/Input/VirtualButtons/MouseButton.cs +++ b/src/Input/VirtualButtons/MouseButton.cs @@ -1,5 +1,8 @@ namespace MoonWorks.Input { + /// + /// A virtual button corresponding to a mouse button. + /// public class MouseButton : VirtualButton { Mouse Parent; diff --git a/src/Input/VirtualButtons/TriggerButton.cs b/src/Input/VirtualButtons/TriggerButton.cs index f0a93cb4..634d3bf2 100644 --- a/src/Input/VirtualButtons/TriggerButton.cs +++ b/src/Input/VirtualButtons/TriggerButton.cs @@ -1,5 +1,9 @@ namespace MoonWorks.Input { + /// + /// A virtual button corresponding to a trigger on a gamepad. + /// If the trigger value exceeds the threshold, it will be treated as a press. + /// public class TriggerButton : VirtualButton { public Trigger Parent { get; } diff --git a/src/Window.cs b/src/Window.cs index 4b45d39f..163aa6e7 100644 --- a/src/Window.cs +++ b/src/Window.cs @@ -5,6 +5,11 @@ using SDL2; namespace MoonWorks { + /// + /// Represents a window in the client operating system. + /// Every Game has a MainWindow automatically. + /// You can create dditional Windows if you desire. They must be Claimed by the GraphicsDevice to be rendered to. + /// public class Window : IDisposable { internal IntPtr Handle { get; }