MouseWin.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #pragma once
  5. #include <Input/Mouse.h>
  6. // We're using DX8's DirectInput API
  7. #define DIRECTINPUT_VERSION 0x0800
  8. #include <dinput.h>
  9. class ApplicationWindowWin;
  10. /// Mouse interface class, keeps track of the mouse button state and of the absolute and relative movements of the mouse.
  11. class MouseWin : public Mouse
  12. {
  13. public:
  14. /// Constructor
  15. MouseWin();
  16. virtual ~MouseWin() override;
  17. /// Initialization / shutdown
  18. virtual bool Initialize(ApplicationWindow *inWindow) override;
  19. virtual void Shutdown() override;
  20. /// Update the mouse state
  21. virtual void Poll() override;
  22. virtual int GetX() const override { return mMousePos.x; }
  23. virtual int GetY() const override { return mMousePos.y; }
  24. virtual int GetDX() const override { return mMouseState.lX; }
  25. virtual int GetDY() const override { return mMouseState.lY; }
  26. virtual bool IsLeftPressed() const override { return (mMouseState.rgbButtons[0] & 0x80) != 0; }
  27. virtual bool IsRightPressed() const override { return (mMouseState.rgbButtons[1] & 0x80) != 0; }
  28. virtual bool IsMiddlePressed() const override { return (mMouseState.rgbButtons[2] & 0x80) != 0; }
  29. virtual void HideCursor() override;
  30. virtual void ShowCursor() override;
  31. private:
  32. void DetectParsecRunning();
  33. void Reset();
  34. void ResetMouse();
  35. enum
  36. {
  37. BUFFERSIZE = 64, ///< Number of keys cached
  38. };
  39. ApplicationWindowWin * mWindow;
  40. ComPtr<IDirectInput8> mDI;
  41. ComPtr<IDirectInputDevice8> mMouse;
  42. bool mIsParsecRunning; ///< If the Parsec remote desktop solution is running, if so we can't trust the mouse movement information from DX and it will make the mouse too sensitive
  43. DIMOUSESTATE mMouseState;
  44. bool mMousePosInitialized = false;
  45. POINT mMousePos;
  46. };