main.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright 2017 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <memory>
  6. #include <string>
  7. #include <vector>
  8. namespace Common {
  9. class ParamPackage;
  10. }
  11. namespace InputCommon {
  12. /// Initializes and registers all built-in input device factories.
  13. void Init();
  14. /// Deregisters all built-in input device factories and shuts them down.
  15. void Shutdown();
  16. class Keyboard;
  17. /// Gets the keyboard button device factory.
  18. Keyboard* GetKeyboard();
  19. class MotionEmu;
  20. /// Gets the motion emulation factory.
  21. MotionEmu* GetMotionEmu();
  22. /// Generates a serialized param package for creating a keyboard button device
  23. std::string GenerateKeyboardParam(int key_code);
  24. /// Generates a serialized param package for creating an analog device taking input from keyboard
  25. std::string GenerateAnalogParamFromKeys(int key_up, int key_down, int key_left, int key_right,
  26. int key_modifier, float modifier_scale);
  27. namespace Polling {
  28. enum class DeviceType { Button, Analog };
  29. /**
  30. * A class that can be used to get inputs from an input device like controllers without having to
  31. * poll the device's status yourself
  32. */
  33. class DevicePoller {
  34. public:
  35. virtual ~DevicePoller() = default;
  36. /// Setup and start polling for inputs, should be called before GetNextInput
  37. virtual void Start() = 0;
  38. /// Stop polling
  39. virtual void Stop() = 0;
  40. /**
  41. * Every call to this function returns the next input recorded since calling Start
  42. * @return A ParamPackage of the recorded input, which can be used to create an InputDevice.
  43. * If there has been no input, the package is empty
  44. */
  45. virtual Common::ParamPackage GetNextInput() = 0;
  46. };
  47. // Get all DevicePoller from all backends for a specific device type
  48. std::vector<std::unique_ptr<DevicePoller>> GetPollers(DeviceType type);
  49. } // namespace Polling
  50. } // namespace InputCommon