DirectManipulatorViewportInteraction.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. #include <AzManipulatorTestFramework/DirectManipulatorViewportInteraction.h>
  9. #include <AzManipulatorTestFramework/ViewportInteraction.h>
  10. #include <AzToolsFramework/Manipulators/ManipulatorManager.h>
  11. namespace AzManipulatorTestFramework
  12. {
  13. using MouseInteraction = AzToolsFramework::ViewportInteraction::MouseInteraction;
  14. using MouseInteractionEvent = AzToolsFramework::ViewportInteraction::MouseInteractionEvent;
  15. class CustomManipulatorManager : public AzToolsFramework::ManipulatorManager
  16. {
  17. using ManagerBase = AzToolsFramework::ManipulatorManager;
  18. public:
  19. using ManagerBase::ManagerBase;
  20. const AzToolsFramework::ManipulatorManagerId GetId() const;
  21. size_t GetRegisteredManipulatorCount() const;
  22. };
  23. //! Implementation of the manipulator interface using direct access to the manipulator manager.
  24. class DirectCallManipulatorManager : public ManipulatorManagerInterface
  25. {
  26. public:
  27. DirectCallManipulatorManager(
  28. ViewportInteractionInterface* viewportInteraction, AZStd::shared_ptr<CustomManipulatorManager> manipulatorManager);
  29. // ManipulatorManagerInterface ...
  30. void ConsumeMouseInteractionEvent(const MouseInteractionEvent& event) override;
  31. AzToolsFramework::ManipulatorManagerId GetId() const override;
  32. bool ManipulatorBeingInteracted() const override;
  33. private:
  34. // Trigger the updating of manipulator bounds.
  35. void DrawManipulators(const MouseInteraction& mouseInteraction);
  36. ViewportInteractionInterface* m_viewportInteraction;
  37. AZStd::shared_ptr<CustomManipulatorManager> m_manipulatorManager;
  38. };
  39. const AzToolsFramework::ManipulatorManagerId CustomManipulatorManager::GetId() const
  40. {
  41. return m_manipulatorManagerId;
  42. }
  43. size_t CustomManipulatorManager::GetRegisteredManipulatorCount() const
  44. {
  45. return m_manipulatorIdToPtrMap.size();
  46. }
  47. DirectCallManipulatorManager::DirectCallManipulatorManager(
  48. ViewportInteractionInterface* viewportInteraction, AZStd::shared_ptr<CustomManipulatorManager> manipulatorManager)
  49. : m_viewportInteraction(viewportInteraction)
  50. , m_manipulatorManager(AZStd::move(manipulatorManager))
  51. {
  52. }
  53. void DirectCallManipulatorManager::ConsumeMouseInteractionEvent(const MouseInteractionEvent& event)
  54. {
  55. using namespace AzToolsFramework::ViewportInteraction;
  56. const auto& mouseInteraction = event.m_mouseInteraction;
  57. DrawManipulators(mouseInteraction);
  58. switch (event.m_mouseEvent)
  59. {
  60. case MouseEvent::Down:
  61. {
  62. m_manipulatorManager->ConsumeViewportMousePress(mouseInteraction);
  63. break;
  64. }
  65. case MouseEvent::DoubleClick:
  66. {
  67. break;
  68. }
  69. case MouseEvent::Move:
  70. {
  71. m_manipulatorManager->ConsumeViewportMouseMove(mouseInteraction);
  72. break;
  73. }
  74. case MouseEvent::Up:
  75. {
  76. m_manipulatorManager->ConsumeViewportMouseRelease(mouseInteraction);
  77. break;
  78. }
  79. case MouseEvent::Wheel:
  80. {
  81. m_manipulatorManager->ConsumeViewportMouseWheel(mouseInteraction);
  82. break;
  83. }
  84. default:
  85. break;
  86. }
  87. DrawManipulators(mouseInteraction);
  88. }
  89. void DirectCallManipulatorManager::DrawManipulators(const MouseInteraction& mouseInteraction)
  90. {
  91. m_manipulatorManager->DrawManipulators(
  92. m_viewportInteraction->GetDebugDisplay(), m_viewportInteraction->GetCameraState(), mouseInteraction);
  93. }
  94. AzToolsFramework::ManipulatorManagerId DirectCallManipulatorManager::GetId() const
  95. {
  96. return m_manipulatorManager->GetId();
  97. }
  98. bool DirectCallManipulatorManager::ManipulatorBeingInteracted() const
  99. {
  100. return m_manipulatorManager->Interacting();
  101. }
  102. DirectCallManipulatorViewportInteraction::DirectCallManipulatorViewportInteraction(
  103. AZStd::shared_ptr<AzFramework::DebugDisplayRequests> debugDisplayRequests)
  104. : m_customManager(
  105. AZStd::make_unique<CustomManipulatorManager>(AzToolsFramework::ManipulatorManagerId(AZ::Crc32("TestManipulatorManagerId"))))
  106. , m_viewportInteraction(AZStd::make_unique<ViewportInteraction>(AZStd::move(debugDisplayRequests)))
  107. , m_manipulatorManager(AZStd::make_unique<DirectCallManipulatorManager>(m_viewportInteraction.get(), m_customManager))
  108. {
  109. }
  110. DirectCallManipulatorViewportInteraction::~DirectCallManipulatorViewportInteraction() = default;
  111. const ViewportInteractionInterface& DirectCallManipulatorViewportInteraction::GetViewportInteraction() const
  112. {
  113. return *m_viewportInteraction;
  114. }
  115. const ManipulatorManagerInterface& DirectCallManipulatorViewportInteraction::GetManipulatorManager() const
  116. {
  117. return *m_manipulatorManager;
  118. }
  119. } // namespace AzManipulatorTestFramework