2021-01-19 07:29:07 +00:00
|
|
|
using SDL2;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
2021-01-22 08:20:07 +00:00
|
|
|
namespace MoonWorks.Input
|
2021-01-19 07:29:07 +00:00
|
|
|
{
|
2021-01-22 08:20:07 +00:00
|
|
|
public class Inputs
|
2021-01-19 07:29:07 +00:00
|
|
|
{
|
|
|
|
public Keyboard Keyboard { get; }
|
2021-01-22 08:20:07 +00:00
|
|
|
public Mouse Mouse { get; }
|
2021-01-19 07:29:07 +00:00
|
|
|
|
|
|
|
List<Gamepad> gamepads = new List<Gamepad>();
|
|
|
|
|
2021-01-22 08:20:07 +00:00
|
|
|
internal Inputs()
|
2021-01-19 07:29:07 +00:00
|
|
|
{
|
|
|
|
Keyboard = new Keyboard();
|
2021-01-22 08:20:07 +00:00
|
|
|
Mouse = new Mouse();
|
2021-01-19 07:29:07 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < SDL.SDL_NumJoysticks(); i++)
|
|
|
|
{
|
|
|
|
if (SDL.SDL_IsGameController(i) == SDL.SDL_bool.SDL_TRUE)
|
|
|
|
{
|
|
|
|
gamepads.Add(new Gamepad(SDL.SDL_GameControllerOpen(i)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Assumes that SDL_PumpEvents has been called!
|
|
|
|
internal void Update()
|
|
|
|
{
|
|
|
|
Keyboard.Update();
|
2021-01-22 08:20:07 +00:00
|
|
|
Mouse.Update();
|
2021-01-19 07:29:07 +00:00
|
|
|
|
|
|
|
foreach (var gamepad in gamepads)
|
|
|
|
{
|
|
|
|
gamepad.Update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Gamepad GetGamepad(int slot)
|
|
|
|
{
|
|
|
|
return gamepads[slot];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|