MouseWin.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. /// Mouse interface class, keeps track of the mouse button state and of the absolute and relative movements of the mouse.
  10. class MouseWin : public Mouse
  11. {
  12. public:
  13. /// Constructor
  14. MouseWin();
  15. virtual ~MouseWin() override;
  16. /// Initialization / shutdown
  17. virtual bool Initialize(Renderer *inWindow) override;
  18. virtual void Shutdown() override;
  19. /// Update the mouse state
  20. virtual void Poll() override;
  21. virtual int GetX() const override { return mMousePos.x; }
  22. virtual int GetY() const override { return mMousePos.y; }
  23. virtual int GetDX() const override { return mMouseState.lX; }
  24. virtual int GetDY() const override { return mMouseState.lY; }
  25. virtual bool IsLeftPressed() const override { return (mMouseState.rgbButtons[0] & 0x80) != 0; }
  26. virtual bool IsRightPressed() const override { return (mMouseState.rgbButtons[1] & 0x80) != 0; }
  27. virtual bool IsMiddlePressed() const override { return (mMouseState.rgbButtons[2] & 0x80) != 0; }
  28. virtual void HideCursor() override;
  29. virtual void ShowCursor() override;
  30. private:
  31. void DetectParsecRunning();
  32. void Reset();
  33. void ResetMouse();
  34. enum
  35. {
  36. BUFFERSIZE = 64, ///< Number of keys cached
  37. };
  38. Renderer * mRenderer;
  39. ComPtr<IDirectInput8> mDI;
  40. ComPtr<IDirectInputDevice8> mMouse;
  41. 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
  42. DIMOUSESTATE mMouseState;
  43. bool mMousePosInitialized = false;
  44. POINT mMousePos;
  45. };