input_mapping.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include "common/param_package.h"
  5. #include "common/threadsafe_queue.h"
  6. namespace InputCommon::Polling {
  7. enum class InputType;
  8. }
  9. namespace InputCommon {
  10. class InputEngine;
  11. struct MappingData;
  12. class MappingFactory {
  13. public:
  14. MappingFactory();
  15. /**
  16. * Resets all variables to begin the mapping process
  17. * @param type type of input desired to be returned
  18. */
  19. void BeginMapping(Polling::InputType type);
  20. /// Returns an input event with mapping information from the input_queue
  21. [[nodiscard]] Common::ParamPackage GetNextInput();
  22. /**
  23. * Registers mapping input data from the driver
  24. * @param data A struct containing all the information needed to create a proper
  25. * ParamPackage
  26. */
  27. void RegisterInput(const MappingData& data);
  28. /// Stop polling from all backends
  29. void StopMapping();
  30. private:
  31. /**
  32. * If provided data satisfies the requirements it will push an element to the input_queue
  33. * Supported input:
  34. * - Button: Creates a basic button ParamPackage
  35. * - HatButton: Creates a basic hat button ParamPackage
  36. * - Analog: Creates a basic analog ParamPackage
  37. * @param data A struct containing all the information needed to create a proper
  38. * ParamPackage
  39. */
  40. void RegisterButton(const MappingData& data);
  41. /**
  42. * If provided data satisfies the requirements it will push an element to the input_queue
  43. * Supported input:
  44. * - Button, HatButton: Pass the data to RegisterButton
  45. * - Analog: Stores the first axis and on the second axis creates a basic stick ParamPackage
  46. * @param data A struct containing all the information needed to create a proper
  47. * ParamPackage
  48. */
  49. void RegisterStick(const MappingData& data);
  50. /**
  51. * If provided data satisfies the requirements it will push an element to the input_queue
  52. * Supported input:
  53. * - Button, HatButton: Pass the data to RegisterButton
  54. * - Analog: Stores the first two axis and on the third axis creates a basic Motion
  55. * ParamPackage
  56. * - Motion: Creates a basic Motion ParamPackage
  57. * @param data A struct containing all the information needed to create a proper
  58. * ParamPackage
  59. */
  60. void RegisterMotion(const MappingData& data);
  61. /**
  62. * Returns true if driver can be mapped
  63. * @param data A struct containing all the information needed to create a proper
  64. * ParamPackage
  65. */
  66. bool IsDriverValid(const MappingData& data) const;
  67. Common::SPSCQueue<Common::ParamPackage> input_queue;
  68. Polling::InputType input_type{Polling::InputType::None};
  69. bool is_enabled{};
  70. int first_axis = -1;
  71. int second_axis = -1;
  72. };
  73. } // namespace InputCommon