MouseMacOS.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2024 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #pragma once
  5. #include <Input/Mouse.h>
  6. class ApplicationWindowMacOS;
  7. /// Mouse interface class, keeps track of the mouse button state and of the absolute and relative movements of the mouse.
  8. class MouseMacOS : public Mouse
  9. {
  10. public:
  11. /// Initialization / shutdown
  12. virtual bool Initialize(ApplicationWindow *inWindow) override;
  13. virtual void Shutdown() override;
  14. /// Update the mouse state
  15. virtual void Poll() override;
  16. virtual int GetX() const override { return mX; }
  17. virtual int GetY() const override { return mY; }
  18. virtual int GetDX() const override { return mDeltaX; }
  19. virtual int GetDY() const override { return mDeltaY; }
  20. virtual bool IsLeftPressed() const override { return mLeftPressed; }
  21. virtual bool IsRightPressed() const override { return mRightPressed; }
  22. virtual bool IsMiddlePressed() const override { return mMiddlePressed; }
  23. virtual void HideCursor() override { }
  24. virtual void ShowCursor() override { }
  25. /// Internal callbacks
  26. void OnMouseMoved(int inX, int inY) { mX = inX; mY = inY; }
  27. void OnMouseDelta(int inDX, int inDY) { mDeltaXAcc += inDX; mDeltaYAcc += inDY; }
  28. void SetLeftPressed(bool inPressed) { mLeftPressed = inPressed; }
  29. void SetRightPressed(bool inPressed) { mRightPressed = inPressed; }
  30. void SetMiddlePressed(bool inPressed) { mMiddlePressed = inPressed; }
  31. private:
  32. ApplicationWindowMacOS * mWindow = nullptr;
  33. int mX = 0;
  34. int mY = 0;
  35. int mDeltaX = 0;
  36. int mDeltaY = 0;
  37. int mDeltaXAcc = 0;
  38. int mDeltaYAcc = 0;
  39. bool mLeftPressed = false;
  40. bool mRightPressed = false;
  41. bool mMiddlePressed = false;
  42. };