DInputJoystick.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright 2010 Dolphin Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include "InputCommon/ControllerInterface/CoreDevice.h"
  5. #include "InputCommon/ControllerInterface/ForceFeedback/ForceFeedbackDevice.h"
  6. namespace ciface::DInput
  7. {
  8. void InitJoystick(IDirectInput8* const idi8, HWND hwnd);
  9. class Joystick : public ForceFeedback::ForceFeedbackDevice
  10. {
  11. private:
  12. class Button : public Input
  13. {
  14. public:
  15. Button(u8 index, const BYTE& button) : m_button(button), m_index(index) {}
  16. std::string GetName() const override;
  17. ControlState GetState() const override;
  18. private:
  19. const BYTE& m_button;
  20. const u8 m_index;
  21. };
  22. class Axis : public Input
  23. {
  24. public:
  25. Axis(u8 index, const LONG& axis, LONG base, LONG range)
  26. : m_axis(axis), m_base(base), m_range(range), m_index(index)
  27. {
  28. }
  29. std::string GetName() const override;
  30. ControlState GetState() const override;
  31. private:
  32. const LONG& m_axis;
  33. const LONG m_base, m_range;
  34. const u8 m_index;
  35. };
  36. class Hat : public Input
  37. {
  38. public:
  39. Hat(u8 index, const DWORD& hat, u8 direction)
  40. : m_hat(hat), m_direction(direction), m_index(index)
  41. {
  42. }
  43. std::string GetName() const override;
  44. ControlState GetState() const override;
  45. private:
  46. const DWORD& m_hat;
  47. const u8 m_index, m_direction;
  48. };
  49. public:
  50. Core::DeviceRemoval UpdateInput() override;
  51. Joystick(const LPDIRECTINPUTDEVICE8 device);
  52. ~Joystick();
  53. std::string GetName() const override;
  54. std::string GetSource() const override;
  55. int GetSortPriority() const override { return -3; }
  56. bool IsValid() const final override;
  57. private:
  58. const LPDIRECTINPUTDEVICE8 m_device;
  59. DIJOYSTATE m_state_in{};
  60. bool m_buffered;
  61. };
  62. } // namespace ciface::DInput