BarrierInputMouse.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <BarrierInput/RawInputNotificationBus_Barrier.h>
  10. #include <AzFramework/Input/Devices/Mouse/InputDeviceMouse.h>
  11. #include <AzCore/std/parallel/mutex.h>
  12. ////////////////////////////////////////////////////////////////////////////////////////////////////
  13. namespace BarrierInput
  14. {
  15. ////////////////////////////////////////////////////////////////////////////////////////////////
  16. //! Barrier specific implementation for mouse input devices.
  17. class InputDeviceMouseBarrier : public AzFramework::InputDeviceMouse::Implementation
  18. , public RawInputNotificationBusBarrier::Handler
  19. {
  20. public:
  21. ////////////////////////////////////////////////////////////////////////////////////////////
  22. // Allocator
  23. AZ_CLASS_ALLOCATOR(InputDeviceMouseBarrier, AZ::SystemAllocator);
  24. ////////////////////////////////////////////////////////////////////////////////////////////
  25. //! Custom factory create function
  26. //! \param[in] inputDevice Reference to the input device being implemented
  27. static Implementation* Create(AzFramework::InputDeviceMouse& inputDevice);
  28. ////////////////////////////////////////////////////////////////////////////////////////////
  29. //! Constructor
  30. //! \param[in] inputDevice Reference to the input device being implemented
  31. InputDeviceMouseBarrier(AzFramework::InputDeviceMouse& inputDevice);
  32. ////////////////////////////////////////////////////////////////////////////////////////////
  33. //! Destructor
  34. ~InputDeviceMouseBarrier() override;
  35. private:
  36. ////////////////////////////////////////////////////////////////////////////////////////////
  37. //! \ref AzFramework::InputDeviceMouse::Implementation::IsConnected
  38. bool IsConnected() const override;
  39. ////////////////////////////////////////////////////////////////////////////////////////////
  40. //! \ref AzFramework::InputDeviceMouse::Implementation::SetSystemCursorState
  41. void SetSystemCursorState(AzFramework::SystemCursorState systemCursorState) override;
  42. ////////////////////////////////////////////////////////////////////////////////////////////
  43. //! \ref AzFramework::InputDeviceMouse::Implementation::GetSystemCursorState
  44. AzFramework::SystemCursorState GetSystemCursorState() const override;
  45. ////////////////////////////////////////////////////////////////////////////////////////////
  46. //! \ref AzFramework::InputDeviceMouse::Implementation::SetSystemCursorPositionNormalized
  47. void SetSystemCursorPositionNormalized(AZ::Vector2 positionNormalized) override;
  48. ////////////////////////////////////////////////////////////////////////////////////////////
  49. //! \ref AzFramework::InputDeviceMouse::Implementation::GetSystemCursorPositionNormalized
  50. AZ::Vector2 GetSystemCursorPositionNormalized() const override;
  51. ////////////////////////////////////////////////////////////////////////////////////////////
  52. //! \ref AzFramework::InputDeviceMouse::Implementation::TickInputDevice
  53. void TickInputDevice() override;
  54. ////////////////////////////////////////////////////////////////////////////////////////////
  55. //! \ref RawInputNotificationsBarrier::OnRawMouseButtonDownEvent
  56. void OnRawMouseButtonDownEvent(uint32_t buttonIndex) override;
  57. ////////////////////////////////////////////////////////////////////////////////////////////
  58. //! \ref RawInputNotificationsBarrier::OnRawMouseButtonUpEvent
  59. void OnRawMouseButtonUpEvent(uint32_t buttonIndex) override;
  60. ////////////////////////////////////////////////////////////////////////////////////////////
  61. //! \ref RawInputNotificationsBarrier::OnRawMouseMovementEvent
  62. void OnRawMouseMovementEvent(float movementX, float movementY) override;
  63. ////////////////////////////////////////////////////////////////////////////////////////////
  64. //! \ref RawInputNotificationsBarrier::OnRawMousePositionEvent
  65. void OnRawMousePositionEvent(float positionX, float positionY) override;
  66. ////////////////////////////////////////////////////////////////////////////////////////////
  67. //! Thread safe method to queue raw button events to be processed in the main thread update
  68. //! \param[in] buttonIndex The index of the button
  69. //! \param[in] rawButtonState The raw button state
  70. void ThreadSafeQueueRawButtonEvent(uint32_t buttonIndex, bool rawButtonState);
  71. ////////////////////////////////////////////////////////////////////////////////////////////
  72. // Variables
  73. AzFramework::SystemCursorState m_systemCursorState;
  74. AZ::Vector2 m_systemCursorPositionNormalized;
  75. RawButtonEventQueueByIdMap m_threadAwareRawButtonEventQueuesById;
  76. AZStd::mutex m_threadAwareRawButtonEventQueuesByIdMutex;
  77. RawMovementEventQueueByIdMap m_threadAwareRawMovementEventQueuesById;
  78. AZStd::mutex m_threadAwareRawMovementEventQueuesByIdMutex;
  79. AZ::Vector2 m_threadAwareSystemCursorPosition;
  80. AZStd::mutex m_threadAwareSystemCursorPositionMutex;
  81. };
  82. struct InputDeviceMouseBarrierImplFactory
  83. : public AzFramework::InputDeviceMouse::ImplementationFactory
  84. {
  85. AZStd::unique_ptr<AzFramework::InputDeviceMouse::Implementation> Create(AzFramework::InputDeviceMouse& inputDevice) override;
  86. };
  87. } // namespace BarrierInput