main.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. void StartJoystickEventHandler();
  17. class Keyboard;
  18. /// Gets the keyboard button device factory.
  19. Keyboard* GetKeyboard();
  20. class MotionEmu;
  21. /// Gets the motion emulation factory.
  22. MotionEmu* GetMotionEmu();
  23. /// Generates a serialized param package for creating a keyboard button device
  24. std::string GenerateKeyboardParam(int key_code);
  25. /// Generates a serialized param package for creating an analog device taking input from keyboard
  26. std::string GenerateAnalogParamFromKeys(int key_up, int key_down, int key_left, int key_right,
  27. int key_modifier, float modifier_scale);
  28. namespace Polling {
  29. enum class DeviceType { Button, Analog };
  30. /**
  31. * A class that can be used to get inputs from an input device like controllers without having to
  32. * poll the device's status yourself
  33. */
  34. class DevicePoller {
  35. public:
  36. virtual ~DevicePoller() = default;
  37. /// Setup and start polling for inputs, should be called before GetNextInput
  38. virtual void Start() = 0;
  39. /// Stop polling
  40. virtual void Stop() = 0;
  41. /**
  42. * Every call to this function returns the next input recorded since calling Start
  43. * @return A ParamPackage of the recorded input, which can be used to create an InputDevice.
  44. * If there has been no input, the package is empty
  45. */
  46. virtual Common::ParamPackage GetNextInput() = 0;
  47. };
  48. // Get all DevicePoller from all backends for a specific device type
  49. std::vector<std::unique_ptr<DevicePoller>> GetPollers(DeviceType type);
  50. } // namespace Polling
  51. } // namespace InputCommon