IndirectManipulatorViewportInteraction.cpp 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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/IndirectManipulatorViewportInteraction.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. //! Implementation of the manipulator interface using bus calls to access to the manipulator manager.
  16. class IndirectCallManipulatorManager : public ManipulatorManagerInterface
  17. {
  18. public:
  19. IndirectCallManipulatorManager(ViewportInteractionInterface& viewportInteraction);
  20. // ManipulatorManagerInterface overrides ...
  21. void ConsumeMouseInteractionEvent(const MouseInteractionEvent& event) override;
  22. AzToolsFramework::ManipulatorManagerId GetId() const override;
  23. bool ManipulatorBeingInteracted() const override;
  24. private:
  25. // trigger the updating of manipulator bounds.
  26. void DrawManipulators();
  27. ViewportInteractionInterface& m_viewportInteraction;
  28. };
  29. IndirectCallManipulatorManager::IndirectCallManipulatorManager(ViewportInteractionInterface& viewportInteraction)
  30. : m_viewportInteraction(viewportInteraction)
  31. {
  32. }
  33. void IndirectCallManipulatorManager::ConsumeMouseInteractionEvent(const MouseInteractionEvent& event)
  34. {
  35. m_viewportInteraction.UpdateVisibility();
  36. // ensure we call display viewport 2d to simulate this update step (some state may be
  37. // updated here, e.g. box select)
  38. AzFramework::ViewportDebugDisplayEventBus::Event(
  39. AzToolsFramework::GetEntityContextId(), &AzFramework::ViewportDebugDisplayEvents::DisplayViewport2d,
  40. AzFramework::ViewportInfo{ m_viewportInteraction.GetViewportId() }, m_viewportInteraction.GetDebugDisplay());
  41. DrawManipulators();
  42. AzToolsFramework::EditorInteractionSystemViewportSelectionRequestBus::Event(
  43. AzToolsFramework::GetEntityContextId(),
  44. &AzToolsFramework::ViewportInteraction::InternalMouseViewportRequests::InternalHandleAllMouseInteractions, event);
  45. DrawManipulators();
  46. }
  47. void IndirectCallManipulatorManager::DrawManipulators()
  48. {
  49. AzFramework::ViewportDebugDisplayEventBus::Event(
  50. AzToolsFramework::GetEntityContextId(), &AzFramework::ViewportDebugDisplayEvents::DisplayViewport,
  51. AzFramework::ViewportInfo{ m_viewportInteraction.GetViewportId() }, m_viewportInteraction.GetDebugDisplay());
  52. }
  53. AzToolsFramework::ManipulatorManagerId IndirectCallManipulatorManager::GetId() const
  54. {
  55. return AzToolsFramework::g_mainManipulatorManagerId;
  56. }
  57. bool IndirectCallManipulatorManager::ManipulatorBeingInteracted() const
  58. {
  59. bool manipulatorInteracting;
  60. AzToolsFramework::ManipulatorManagerRequestBus::EventResult(
  61. manipulatorInteracting, AzToolsFramework::g_mainManipulatorManagerId,
  62. &AzToolsFramework::ManipulatorManagerRequestBus::Events::Interacting);
  63. return manipulatorInteracting;
  64. }
  65. IndirectCallManipulatorViewportInteraction::IndirectCallManipulatorViewportInteraction(
  66. AZStd::shared_ptr<AzFramework::DebugDisplayRequests> debugDisplayRequests)
  67. : m_viewportInteraction(AZStd::make_unique<ViewportInteraction>(AZStd::move(debugDisplayRequests)))
  68. , m_manipulatorManager(AZStd::make_unique<IndirectCallManipulatorManager>(*m_viewportInteraction))
  69. {
  70. }
  71. IndirectCallManipulatorViewportInteraction::~IndirectCallManipulatorViewportInteraction() = default;
  72. const ViewportInteractionInterface& IndirectCallManipulatorViewportInteraction::GetViewportInteraction() const
  73. {
  74. return *m_viewportInteraction;
  75. }
  76. const ManipulatorManagerInterface& IndirectCallManipulatorViewportInteraction::GetManipulatorManager() const
  77. {
  78. return *m_manipulatorManager;
  79. }
  80. } // namespace AzManipulatorTestFramework