input_mapping.h 2.9 KB

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