1 // Copyright 2010 Dolphin Emulator Project
2 // Licensed under GPLv2+
3 // Refer to the license.txt file included.
4 
5 #pragma once
6 
7 #include "InputCommon/ControllerInterface/Device.h"
8 #include "InputCommon/ControllerInterface/ForceFeedback/ForceFeedbackDevice.h"
9 
10 namespace ciface::DInput
11 {
12 void InitJoystick(IDirectInput8* const idi8, HWND hwnd);
13 
14 class Joystick : public ForceFeedback::ForceFeedbackDevice
15 {
16 private:
17   class Button : public Input
18   {
19   public:
Button(u8 index,const BYTE & button)20     Button(u8 index, const BYTE& button) : m_button(button), m_index(index) {}
21     std::string GetName() const override;
22     ControlState GetState() const override;
23 
24   private:
25     const BYTE& m_button;
26     const u8 m_index;
27   };
28 
29   class Axis : public Input
30   {
31   public:
Axis(u8 index,const LONG & axis,LONG base,LONG range)32     Axis(u8 index, const LONG& axis, LONG base, LONG range)
33         : m_axis(axis), m_base(base), m_range(range), m_index(index)
34     {
35     }
36     std::string GetName() const override;
37     ControlState GetState() const override;
38 
39   private:
40     const LONG& m_axis;
41     const LONG m_base, m_range;
42     const u8 m_index;
43   };
44 
45   class Hat : public Input
46   {
47   public:
Hat(u8 index,const DWORD & hat,u8 direction)48     Hat(u8 index, const DWORD& hat, u8 direction)
49         : m_hat(hat), m_direction(direction), m_index(index)
50     {
51     }
52     std::string GetName() const override;
53     ControlState GetState() const override;
54 
55   private:
56     const DWORD& m_hat;
57     const u8 m_index, m_direction;
58   };
59 
60 public:
61   void UpdateInput() override;
62 
63   Joystick(const LPDIRECTINPUTDEVICE8 device);
64   ~Joystick();
65 
66   std::string GetName() const override;
67   std::string GetSource() const override;
68 
69   bool IsValid() const final override;
70 
71 private:
72   const LPDIRECTINPUTDEVICE8 m_device;
73 
74   DIJOYSTATE m_state_in;
75 
76   bool m_buffered;
77 };
78 }  // namespace ciface::DInput
79