ButtonValue.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System.Diagnostics;
  2. namespace Ryujinx.Input
  3. {
  4. public enum ButtonValueType { Key, GamepadButtonInputId, StickId }
  5. public readonly struct ButtonValue
  6. {
  7. private readonly ButtonValueType _type;
  8. private readonly uint _rawValue;
  9. public ButtonValue(Key key)
  10. {
  11. _type = ButtonValueType.Key;
  12. _rawValue = (uint)key;
  13. }
  14. public ButtonValue(GamepadButtonInputId gamepad)
  15. {
  16. _type = ButtonValueType.GamepadButtonInputId;
  17. _rawValue = (uint)gamepad;
  18. }
  19. public ButtonValue(StickInputId stick)
  20. {
  21. _type = ButtonValueType.StickId;
  22. _rawValue = (uint)stick;
  23. }
  24. public Common.Configuration.Hid.Key AsKey()
  25. {
  26. Debug.Assert(_type == ButtonValueType.Key);
  27. return (Common.Configuration.Hid.Key)_rawValue;
  28. }
  29. public Common.Configuration.Hid.Controller.GamepadInputId AsGamepadButtonInputId()
  30. {
  31. Debug.Assert(_type == ButtonValueType.GamepadButtonInputId);
  32. return (Common.Configuration.Hid.Controller.GamepadInputId)_rawValue;
  33. }
  34. public Common.Configuration.Hid.Controller.StickInputId AsGamepadStickId()
  35. {
  36. Debug.Assert(_type == ButtonValueType.StickId);
  37. return (Common.Configuration.Hid.Controller.StickInputId)_rawValue;
  38. }
  39. }
  40. }