virtual_gamepad.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include "input_common/input_engine.h"
  5. namespace InputCommon {
  6. /**
  7. * A virtual controller that is always assigned to the game input
  8. */
  9. class VirtualGamepad final : public InputEngine {
  10. public:
  11. enum class VirtualButton {
  12. ButtonA,
  13. ButtonB,
  14. ButtonX,
  15. ButtonY,
  16. StickL,
  17. StickR,
  18. TriggerL,
  19. TriggerR,
  20. TriggerZL,
  21. TriggerZR,
  22. ButtonPlus,
  23. ButtonMinus,
  24. ButtonLeft,
  25. ButtonUp,
  26. ButtonRight,
  27. ButtonDown,
  28. ButtonSL,
  29. ButtonSR,
  30. ButtonHome,
  31. ButtonCapture,
  32. };
  33. enum class VirtualStick {
  34. Left = 0,
  35. Right = 1,
  36. };
  37. explicit VirtualGamepad(std::string input_engine_);
  38. /**
  39. * Sets the status of all buttons bound with the key to pressed
  40. * @param player_index the player number that will take this action
  41. * @param button_id the id of the button
  42. * @param value indicates if the button is pressed or not
  43. */
  44. void SetButtonState(std::size_t player_index, int button_id, bool value);
  45. void SetButtonState(std::size_t player_index, VirtualButton button_id, bool value);
  46. /**
  47. * Sets the status of all buttons bound with the key to released
  48. * @param player_index the player number that will take this action
  49. * @param axis_id the id of the axis to move
  50. * @param x_value the position of the stick in the x axis
  51. * @param y_value the position of the stick in the y axis
  52. */
  53. void SetStickPosition(std::size_t player_index, int axis_id, float x_value, float y_value);
  54. void SetStickPosition(std::size_t player_index, VirtualStick axis_id, float x_value,
  55. float y_value);
  56. /// Restores all inputs into the neutral position
  57. void ResetControllers();
  58. private:
  59. /// Returns the correct identifier corresponding to the player index
  60. PadIdentifier GetIdentifier(std::size_t player_index) const;
  61. };
  62. } // namespace InputCommon