/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ #include #include #include namespace AzManipulatorTestFramework { using MouseInteraction = AzToolsFramework::ViewportInteraction::MouseInteraction; using MouseInteractionEvent = AzToolsFramework::ViewportInteraction::MouseInteractionEvent; class CustomManipulatorManager : public AzToolsFramework::ManipulatorManager { using ManagerBase = AzToolsFramework::ManipulatorManager; public: using ManagerBase::ManagerBase; const AzToolsFramework::ManipulatorManagerId GetId() const; size_t GetRegisteredManipulatorCount() const; }; //! Implementation of the viewport interaction interface using direct access to the manipulator manager. class DirectCallViewportInteraction : public ViewportInteraction { public: DirectCallViewportInteraction(AzToolsFramework::ManipulatorManager* manipulatorManager); private: AzToolsFramework::ManipulatorManager* m_manipulatorManager; }; //! Implementation of the manipulator interface using direct access to the manipulator manager. class DirectCallManipulatorManager : public ManipulatorManagerInterface { public: DirectCallManipulatorManager( ViewportInteractionInterface* viewportInteraction, AZStd::shared_ptr manipulatorManager); // ManipulatorManagerInterface ... void ConsumeMouseInteractionEvent(const MouseInteractionEvent& event); AzToolsFramework::ManipulatorManagerId GetId() const override; bool ManipulatorBeingInteracted() const override; private: // Trigger the updating of manipulator bounds. void DrawManipulators(const MouseInteraction& mouseInteraction); ViewportInteractionInterface* m_viewportInteraction; AZStd::shared_ptr m_manipulatorManager; }; const AzToolsFramework::ManipulatorManagerId CustomManipulatorManager::GetId() const { return m_manipulatorManagerId; } size_t CustomManipulatorManager::GetRegisteredManipulatorCount() const { return m_manipulatorIdToPtrMap.size(); } DirectCallViewportInteraction::DirectCallViewportInteraction( AzToolsFramework::ManipulatorManager* manipulatorManager) : m_manipulatorManager(manipulatorManager) { } DirectCallManipulatorManager::DirectCallManipulatorManager( ViewportInteractionInterface* viewportInteraction, AZStd::shared_ptr manipulatorManager) : m_viewportInteraction(viewportInteraction) , m_manipulatorManager(AZStd::move(manipulatorManager)) { } void DirectCallManipulatorManager::ConsumeMouseInteractionEvent(const MouseInteractionEvent& event) { using namespace AzToolsFramework::ViewportInteraction; const auto& mouseInteraction = event.m_mouseInteraction; DrawManipulators(mouseInteraction); switch (event.m_mouseEvent) { case MouseEvent::Down: { m_manipulatorManager->ConsumeViewportMousePress(mouseInteraction); break; } case MouseEvent::DoubleClick: { break; } case MouseEvent::Move: { m_manipulatorManager->ConsumeViewportMouseMove(mouseInteraction); break; } case MouseEvent::Up: { m_manipulatorManager->ConsumeViewportMouseRelease(mouseInteraction); break; } case MouseEvent::Wheel: { m_manipulatorManager->ConsumeViewportMouseWheel(mouseInteraction); break; } default: break; } DrawManipulators(mouseInteraction); } void DirectCallManipulatorManager::DrawManipulators(const MouseInteraction& mouseInteraction) { m_manipulatorManager->DrawManipulators( m_viewportInteraction->GetDebugDisplay(), m_viewportInteraction->GetCameraState(), mouseInteraction); } AzToolsFramework::ManipulatorManagerId DirectCallManipulatorManager::GetId() const { return m_manipulatorManager->GetId(); } bool DirectCallManipulatorManager::ManipulatorBeingInteracted() const { return m_manipulatorManager->Interacting(); } DirectCallManipulatorViewportInteraction::DirectCallManipulatorViewportInteraction() : m_customManager( AZStd::make_unique( AzToolsFramework::ManipulatorManagerId(AZ::Crc32("TestManipulatorManagerId")))) , m_viewportInteraction(AZStd::make_unique(m_customManager.get())) , m_manipulatorManager( AZStd::make_unique(m_viewportInteraction.get(), m_customManager)) { } DirectCallManipulatorViewportInteraction::~DirectCallManipulatorViewportInteraction() = default; ViewportInteractionInterface& DirectCallManipulatorViewportInteraction::GetViewportInteraction() { return *m_viewportInteraction; } ManipulatorManagerInterface& DirectCallManipulatorViewportInteraction::GetManipulatorManager() { return *m_manipulatorManager; } } // namespace AzManipulatorTestFramework