Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,101 @@
/*
* 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 <AzManipulatorTestFramework/AzManipulatorTestFrameworkFixture.h>
#include <AzToolsFramework/ViewportSelection/EditorInteractionSystemViewportSelectionRequestBus.h>
namespace UnitTest
{
using MouseInteraction = AzToolsFramework::ViewportInteraction::MouseInteraction;
using MouseInteractionEvent = AzToolsFramework::ViewportInteraction::MouseInteractionEvent;
using MouseButton = AzToolsFramework::ViewportInteraction::MouseButton;
using MouseEvent = AzToolsFramework::ViewportInteraction::MouseEvent;
using MousePick = AzToolsFramework::ViewportInteraction::MousePick;
AZStd::shared_ptr<AzToolsFramework::LinearManipulator> CreateLinearManipulator(
const AzToolsFramework::ManipulatorManagerId manipulatorManagerId)
{
auto manipulator = AzToolsFramework::LinearManipulator::MakeShared(AZ::Transform::CreateIdentity());
// unit sphere view
auto sphereView = AzToolsFramework::CreateManipulatorViewSphere(
AZ::Colors::Red, 1.0f,
[](const MouseInteraction& /*mouseInteraction*/, const bool /*mouseOver*/,
const AZ::Color& defaultColor)
{
return defaultColor;
}, true);
// unit sphere bound
AzToolsFramework::Picking::BoundShapeSphere sphereBound;
sphereBound.m_center = AZ::Vector3::CreateZero();
sphereBound.m_radius = 1.0f;
// we need the view to construct the manipulator bounds after the manipulator has been registered
auto view = sphereView.get();
// construct view and register with manager
AzToolsFramework::ManipulatorViews views;
views.emplace_back(AZStd::move(sphereView));
manipulator->SetViews(AZStd::move(views));
manipulator->Register(manipulatorManagerId);
// this would occur internally when the manipulator is drawn but we must do manually here
view->RefreshBound(manipulatorManagerId, manipulator->GetManipulatorId(), sphereBound);
return manipulator;
}
MousePick CreateWorldSpaceMousePickRay(const AZ::Vector3& origin, const AZ::Vector3& direction)
{
MousePick mousePick;
mousePick.m_rayOrigin = origin;
mousePick.m_rayDirection = direction;
return mousePick;
}
MouseInteraction CreateMouseInteraction(const MousePick& worldSpaceRay, MouseButton button)
{
AzToolsFramework::ViewportInteraction::MouseInteraction interaction;
interaction.m_mousePick = worldSpaceRay;
interaction.m_mouseButtons.m_mouseButtons = static_cast<AZ::u32>(button);
return interaction;
}
MouseInteractionEvent CreateMouseInteractionEvent(
const MousePick& worldSpaceRay, MouseButton button, MouseEvent event)
{
return MouseInteractionEvent(CreateMouseInteraction(worldSpaceRay, button), event);
}
void DispatchMouseInteractionEvent(const MouseInteractionEvent& event)
{
AzToolsFramework::EditorInteractionSystemViewportSelectionRequestBus::Event(
AzToolsFramework::GetEntityContextId(),
&AzToolsFramework::ViewportInteraction::InternalMouseViewportRequests::InternalHandleAllMouseInteractions,
event);
}
AzFramework::CameraState SetCameraStatePosition(const AZ::Vector3& position, AzFramework::CameraState& cameraState)
{
cameraState.m_position = position;
return cameraState;
}
AzFramework::CameraState SetCameraStateDirection(const AZ::Vector3& direction, AzFramework::CameraState& cameraState)
{
const auto transform = AZ::Transform::CreateLookAt(cameraState.m_position, cameraState.m_position + direction);
AzFramework::SetCameraTransform(cameraState, transform);
return cameraState;
}
} // namespace UnitTest
@@ -0,0 +1,141 @@
/*
* 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 <AzCore/Component/TransformBus.h>
#include <AzFramework/Viewport/ViewportScreen.h>
#include <AzManipulatorTestFramework/AzManipulatorTestFrameworkUtils.h>
#include <AzToolsFramework/ViewportSelection/EditorInteractionSystemViewportSelectionRequestBus.h>
#include <AzToolsFramework/ViewportSelection/EditorInteractionSystemViewportSelectionRequestBus.h>
#include <AzToolsFramework/ViewportSelection/EditorTransformComponentSelectionRequestBus.h>
namespace AzManipulatorTestFramework
{
using InteractionId = AzToolsFramework::ViewportInteraction::InteractionId;
using KeyboardModifiers = AzToolsFramework::ViewportInteraction::KeyboardModifiers;
using MouseInteraction = AzToolsFramework::ViewportInteraction::MouseInteraction;
using MouseInteractionEvent = AzToolsFramework::ViewportInteraction::MouseInteractionEvent;
using MouseButton = AzToolsFramework::ViewportInteraction::MouseButton;
using MouseButtons = AzToolsFramework::ViewportInteraction::MouseButtons;
using MouseEvent = AzToolsFramework::ViewportInteraction::MouseEvent;
using MousePick = AzToolsFramework::ViewportInteraction::MousePick;
AZStd::shared_ptr<AzToolsFramework::LinearManipulator> CreateLinearManipulator(
const AzToolsFramework::ManipulatorManagerId manipulatorManagerId,
const AZ::Vector3& position,
const float radius)
{
auto manipulator = AzToolsFramework::LinearManipulator::MakeShared(AZ::Transform::CreateIdentity());
manipulator->SetLocalPosition(position);
// unit sphere view
auto sphereView = AzToolsFramework::CreateManipulatorViewSphere(
AZ::Colors::Red, radius,
[](const MouseInteraction& /*mouseInteraction*/, const bool /*mouseOver*/,
const AZ::Color& defaultColor)
{
return defaultColor;
}, true);
// unit sphere bound
AzToolsFramework::Picking::BoundShapeSphere sphereBound;
sphereBound.m_center = position;
sphereBound.m_radius = radius;
// we need the view to construct the manipulator bounds after the manipulator has been registered
auto view = sphereView.get();
// construct view and register with manager
AzToolsFramework::ManipulatorViews views;
views.emplace_back(AZStd::move(sphereView));
manipulator->SetViews(AZStd::move(views));
manipulator->Register(manipulatorManagerId);
// this would occur internally when the manipulator is drawn but we must do manually here to ensure that the
// bounds will always be valid upon instantiation
view->RefreshBound(manipulatorManagerId, manipulator->GetManipulatorId(), sphereBound);
return manipulator;
}
AzToolsFramework::ViewportInteraction::MousePick CreateMousePick(
const AZ::Vector3& origin, const AZ::Vector3& direction, const AzFramework::ScreenPoint& screenPoint)
{
return { origin, direction, screenPoint };
}
AzToolsFramework::ViewportInteraction::MousePick BuildMousePick(
const AzFramework::ScreenPoint& screenPoint, const AzFramework::CameraState& cameraState)
{
const auto screenToWorld = AzFramework::ScreenToWorld(screenPoint, cameraState);
AzToolsFramework::ViewportInteraction::MousePick mousePick;
mousePick.m_screenCoordinates = screenPoint;
mousePick.m_rayOrigin = screenToWorld;
mousePick.m_rayDirection = (screenToWorld - cameraState.m_position).GetNormalized();
return mousePick;
}
MouseInteraction CreateMouseInteraction(
const MousePick& mousePick, MouseButtons buttons, InteractionId interactionId, KeyboardModifiers modifiers)
{
AzToolsFramework::ViewportInteraction::MouseInteraction interaction;
interaction.m_mousePick = mousePick;
interaction.m_mouseButtons = buttons;
interaction.m_interactionId = interactionId;
interaction.m_keyboardModifiers = modifiers;
return interaction;
}
MouseButtons CreateMouseButtons(MouseButton button)
{
MouseButtons buttons;
buttons.m_mouseButtons = static_cast<AZ::u32>(button);
return buttons;
}
MouseInteractionEvent CreateMouseInteractionEvent(
const MouseInteraction& mouseInteraction, MouseEvent event)
{
return MouseInteractionEvent(mouseInteraction, event);
}
void DispatchMouseInteractionEvent(const MouseInteractionEvent& event)
{
AzToolsFramework::EditorInteractionSystemViewportSelectionRequestBus::Event(
AzToolsFramework::GetEntityContextId(),
&AzToolsFramework::ViewportInteraction::InternalMouseViewportRequests::InternalHandleAllMouseInteractions,
event);
}
AzFramework::CameraState SetCameraStatePosition(const AZ::Vector3& position, AzFramework::CameraState& cameraState)
{
cameraState.m_position = position;
return cameraState;
}
AzFramework::CameraState SetCameraStateDirection(const AZ::Vector3& direction, AzFramework::CameraState& cameraState)
{
const auto transform = AZ::Transform::CreateLookAt(cameraState.m_position, cameraState.m_position + direction);
AzFramework::SetCameraTransform(cameraState, transform);
return cameraState;
}
AzFramework::ScreenPoint GetCameraStateViewportCenter(const AzFramework::CameraState& cameraState)
{
return {
aznumeric_cast<int>(cameraState.m_viewportSize.GetX() / 2.f),
aznumeric_cast<int>(cameraState.m_viewportSize.GetY() / 2.f)
};
}
} // namespace UnitTest
@@ -0,0 +1,148 @@
/*
* 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 <AzManipulatorTestFramework/DirectManipulatorViewportInteraction.h>
#include <AzManipulatorTestFramework/ViewportInteraction.h>
#include <AzToolsFramework/Manipulators/ManipulatorManager.h>
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 manipulator interface using direct access to the manipulator manager.
class DirectCallManipulatorManager
: public ManipulatorManagerInterface
{
public:
DirectCallManipulatorManager(
ViewportInteractionInterface* viewportInteraction,
AZStd::shared_ptr<CustomManipulatorManager> 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<CustomManipulatorManager> m_manipulatorManager;
};
const AzToolsFramework::ManipulatorManagerId CustomManipulatorManager::GetId() const
{
return m_manipulatorManagerId;
}
size_t CustomManipulatorManager::GetRegisteredManipulatorCount() const
{
return m_manipulatorIdToPtrMap.size();
}
DirectCallManipulatorManager::DirectCallManipulatorManager(
ViewportInteractionInterface* viewportInteraction,
AZStd::shared_ptr<CustomManipulatorManager> 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<CustomManipulatorManager>(
AzToolsFramework::ManipulatorManagerId(AZ::Crc32("TestManipulatorManagerId"))))
, m_viewportInteraction(AZStd::make_unique<ViewportInteraction>())
, m_manipulatorManager(
AZStd::make_unique<DirectCallManipulatorManager>(m_viewportInteraction.get(), m_customManager))
{
}
DirectCallManipulatorViewportInteraction::~DirectCallManipulatorViewportInteraction() = default;
const ViewportInteractionInterface& DirectCallManipulatorViewportInteraction::GetViewportInteraction() const
{
return *m_viewportInteraction;
}
const ManipulatorManagerInterface& DirectCallManipulatorViewportInteraction::GetManipulatorManager() const
{
return *m_manipulatorManager;
}
} // namespace AzManipulatorTestFramework
@@ -0,0 +1,195 @@
/*
* 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 <AzManipulatorTestFramework/ImmediateModeActionDispatcher.h>
#include <AzManipulatorTestFramework/AzManipulatorTestFrameworkUtils.h>
#include <AzToolsFramework/ComponentMode/EditorComponentModeBus.h>
#include <AzToolsFramework/Entity/EditorEntityHelpers.h>
namespace AzManipulatorTestFramework
{
template<typename FieldT, typename FlagT>
void ToggleOn(FieldT& field, FlagT flag)
{
field |= static_cast<FieldT>(flag);
}
template<typename FieldT, typename FlagT>
void ToggleOff(FieldT& field, FlagT flag)
{
field &= ~static_cast<FieldT>(flag);
}
using MouseButton = AzToolsFramework::ViewportInteraction::MouseButton;
using KeyboardModifier = AzToolsFramework::ViewportInteraction::KeyboardModifier;
using MouseInteractionEvent = AzToolsFramework::ViewportInteraction::MouseInteractionEvent;
ImmediateModeActionDispatcher::ImmediateModeActionDispatcher(
ManipulatorViewportInteraction& viewportManipulatorInteraction)
: m_viewportManipulatorInteraction(viewportManipulatorInteraction)
{
}
ImmediateModeActionDispatcher::~ImmediateModeActionDispatcher() = default;
void ImmediateModeActionDispatcher::MouseMoveAfterButton()
{
// the editor application generates a mouse move event with a zero delta after every
// mouse down and mouse up event, to match the editor behavior we insert this event
// to ensure the tests are simulating the same environment as the editor
GetMouseInteractionEvent()->m_mouseEvent = AzToolsFramework::ViewportInteraction::MouseEvent::Move;
m_viewportManipulatorInteraction.GetManipulatorManager().ConsumeMouseInteractionEvent(*m_event);
}
void ImmediateModeActionDispatcher::EnableSnapToGridImpl()
{
m_viewportManipulatorInteraction.GetViewportInteraction().EnableGridSnaping();
}
void ImmediateModeActionDispatcher::DisableSnapToGridImpl()
{
m_viewportManipulatorInteraction.GetViewportInteraction().DisableGridSnaping();
}
void ImmediateModeActionDispatcher::GridSizeImpl(float size)
{
m_viewportManipulatorInteraction.GetViewportInteraction().SetGridSize(size);
}
void ImmediateModeActionDispatcher::CameraStateImpl(const AzFramework::CameraState& cameraState)
{
m_viewportManipulatorInteraction.GetViewportInteraction().SetCameraState(cameraState);
GetMouseInteractionEvent()->m_mouseInteraction.m_mousePick.m_rayOrigin = cameraState.m_position;
GetMouseInteractionEvent()->m_mouseInteraction.m_mousePick.m_rayDirection = cameraState.m_forward;
}
void ImmediateModeActionDispatcher::MouseLButtonDownImpl()
{
ToggleOn(GetMouseInteractionEvent()->m_mouseInteraction.m_mouseButtons.m_mouseButtons, MouseButton::Left);
GetMouseInteractionEvent()->m_mouseEvent = AzToolsFramework::ViewportInteraction::MouseEvent::Down;
m_viewportManipulatorInteraction.GetManipulatorManager().ConsumeMouseInteractionEvent(*m_event);
// the mouse position will be the same as the previous event, thus the delta will be 0
MouseMoveAfterButton();
}
void ImmediateModeActionDispatcher::MouseLButtonUpImpl()
{
GetMouseInteractionEvent()->m_mouseEvent = AzToolsFramework::ViewportInteraction::MouseEvent::Up;
m_viewportManipulatorInteraction.GetManipulatorManager().ConsumeMouseInteractionEvent(*GetMouseInteractionEvent());
ToggleOff(GetMouseInteractionEvent()->m_mouseInteraction.m_mouseButtons.m_mouseButtons, MouseButton::Left);
// the mouse position will be the same as the previous event, thus the delta will be 0
MouseMoveAfterButton();
}
void ImmediateModeActionDispatcher::MousePositionImpl(const AzFramework::ScreenPoint& position)
{
const auto cameraState = m_viewportManipulatorInteraction.GetViewportInteraction().GetCameraState();
GetMouseInteractionEvent()->m_mouseInteraction.m_mousePick = BuildMousePick(position, cameraState);
GetMouseInteractionEvent()->m_mouseEvent = AzToolsFramework::ViewportInteraction::MouseEvent::Move;
m_viewportManipulatorInteraction.GetManipulatorManager().ConsumeMouseInteractionEvent(*m_event);
}
void ImmediateModeActionDispatcher::KeyboardModifierDownImpl(const KeyboardModifier& keyModifier)
{
ToggleOn(GetMouseInteractionEvent()->m_mouseInteraction.m_keyboardModifiers.m_keyModifiers, keyModifier);
}
void ImmediateModeActionDispatcher::KeyboardModifierUpImpl(const KeyboardModifier& keyModifier)
{
ToggleOff(GetMouseInteractionEvent()->m_mouseInteraction.m_keyboardModifiers.m_keyModifiers, keyModifier);
}
void ImmediateModeActionDispatcher::SetEntityWorldTransformImpl(AZ::EntityId entityId, const AZ::Transform& transform)
{
AzToolsFramework::SetWorldTransform(entityId, transform);
}
void ImmediateModeActionDispatcher::SetSelectedEntityImpl(AZ::EntityId entity)
{
AzToolsFramework::SelectEntity(entity);
}
void ImmediateModeActionDispatcher::SetSelectedEntitiesImpl(const AzToolsFramework::EntityIdList& entities)
{
AzToolsFramework::SelectEntities(entities);
}
void ImmediateModeActionDispatcher::EnterComponentModeImpl(const AZ::Uuid& uuid)
{
using AzToolsFramework::ComponentModeFramework::ComponentModeSystemRequestBus;
ComponentModeSystemRequestBus::Broadcast(
&ComponentModeSystemRequestBus::Events::AddSelectedComponentModesOfType, uuid);
}
const AzToolsFramework::ViewportInteraction::MouseInteractionEvent* ImmediateModeActionDispatcher::GetMouseInteractionEvent() const
{
if (!m_event)
{
m_event = AZStd::unique_ptr<MouseInteractionEvent>(AZStd::make_unique<MouseInteractionEvent>());
m_event->m_mouseInteraction.m_interactionId.m_viewportId =
m_viewportManipulatorInteraction.GetViewportInteraction().GetViewportId();
}
return m_event.get();
}
AzToolsFramework::ViewportInteraction::MouseInteractionEvent* ImmediateModeActionDispatcher::GetMouseInteractionEvent()
{
return const_cast<MouseInteractionEvent*>(
static_cast<const ImmediateModeActionDispatcher*>(this)->GetMouseInteractionEvent());
}
ImmediateModeActionDispatcher* ImmediateModeActionDispatcher::ExpectTrue(bool result)
{
Log("Expecting true");
EXPECT_TRUE(result);
return this;
}
ImmediateModeActionDispatcher* ImmediateModeActionDispatcher::ExpectFalse(bool result)
{
Log("Expecting false");
EXPECT_FALSE(result);
return this;
}
ImmediateModeActionDispatcher* ImmediateModeActionDispatcher::GetEntityWorldTransform(
AZ::EntityId entityId, AZ::Transform& transform)
{
Log("Getting entity world transform");
transform = AzToolsFramework::GetWorldTransform(entityId);
return this;
}
void ImmediateModeActionDispatcher::ExpectManipulatorBeingInteractedImpl()
{
EXPECT_TRUE(m_viewportManipulatorInteraction.GetManipulatorManager().ManipulatorBeingInteracted());
}
void ImmediateModeActionDispatcher::ExpectManipulatorNotBeingInteractedImpl()
{
EXPECT_FALSE(m_viewportManipulatorInteraction.GetManipulatorManager().ManipulatorBeingInteracted());
}
ImmediateModeActionDispatcher* ImmediateModeActionDispatcher::ResetEvent()
{
Log("Resetting the event state");
m_event.reset();
return this;
}
ImmediateModeActionDispatcher* ImmediateModeActionDispatcher::ExecuteBlock(const AZStd::function<void()>& blockFn)
{
blockFn();
return this;
}
} // namespace AzManipulatorTestFramework
@@ -0,0 +1,93 @@
/*
* 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 <AzManipulatorTestFramework/IndirectManipulatorViewportInteraction.h>
#include <AzManipulatorTestFramework/ViewportInteraction.h>
#include <AzToolsFramework/Manipulators/ManipulatorManager.h>
namespace AzManipulatorTestFramework
{
using MouseInteraction = AzToolsFramework::ViewportInteraction::MouseInteraction;
using MouseInteractionEvent = AzToolsFramework::ViewportInteraction::MouseInteractionEvent;
//! Implementation of the manipulator interface using bus calls to access to the manipulator manager.
class IndirectCallManipulatorManager
: public ManipulatorManagerInterface
{
public:
IndirectCallManipulatorManager(ViewportInteractionInterface& viewportInteraction);
// ManipulatorManagerInterface ...
void ConsumeMouseInteractionEvent(const MouseInteractionEvent& event) override;
AzToolsFramework::ManipulatorManagerId GetId() const override;
bool ManipulatorBeingInteracted() const override;
private:
// trigger the updating of manipulator bounds.
void DrawManipulators();
ViewportInteractionInterface& m_viewportInteraction;
};
IndirectCallManipulatorManager::IndirectCallManipulatorManager(ViewportInteractionInterface& viewportInteraction)
: m_viewportInteraction(viewportInteraction)
{
}
void IndirectCallManipulatorManager::ConsumeMouseInteractionEvent(const MouseInteractionEvent& event)
{
DrawManipulators();
AzToolsFramework::EditorInteractionSystemViewportSelectionRequestBus::Event(
AzToolsFramework::GetEntityContextId(),
&AzToolsFramework::ViewportInteraction::InternalMouseViewportRequests::InternalHandleAllMouseInteractions,
event);
DrawManipulators();
}
void IndirectCallManipulatorManager::DrawManipulators()
{
AzFramework::ViewportDebugDisplayEventBus::Event(
AzToolsFramework::GetEntityContextId(), &AzFramework::ViewportDebugDisplayEvents::DisplayViewport,
AzFramework::ViewportInfo{ m_viewportInteraction.GetViewportId() }, m_viewportInteraction.GetDebugDisplay());
}
AzToolsFramework::ManipulatorManagerId IndirectCallManipulatorManager::GetId() const
{
return AzToolsFramework::g_mainManipulatorManagerId;
}
bool IndirectCallManipulatorManager::ManipulatorBeingInteracted() const
{
bool manipulatorInteracting;
AzToolsFramework::ManipulatorManagerRequestBus::EventResult(
manipulatorInteracting, AzToolsFramework::g_mainManipulatorManagerId,
&AzToolsFramework::ManipulatorManagerRequestBus::Events::Interacting);
return manipulatorInteracting;
}
IndirectCallManipulatorViewportInteraction::IndirectCallManipulatorViewportInteraction()
: m_viewportInteraction(AZStd::make_unique<ViewportInteraction>())
, m_manipulatorManager(AZStd::make_unique<IndirectCallManipulatorManager>(*m_viewportInteraction))
{
}
IndirectCallManipulatorViewportInteraction::~IndirectCallManipulatorViewportInteraction() = default;
const ViewportInteractionInterface& IndirectCallManipulatorViewportInteraction::GetViewportInteraction() const
{
return *m_viewportInteraction;
}
const ManipulatorManagerInterface& IndirectCallManipulatorViewportInteraction::GetManipulatorManager() const
{
return *m_manipulatorManager;
}
} // namespace AzManipulatorTestFramework
@@ -0,0 +1,133 @@
/*
* 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 <AzManipulatorTestFramework/RetainedModeActionDispatcher.h>
namespace AzManipulatorTestFramework
{
using KeyboardModifier = AzToolsFramework::ViewportInteraction::KeyboardModifier;
RetainedModeActionDispatcher::RetainedModeActionDispatcher(
ManipulatorViewportInteraction& viewportManipulatorInteraction)
: m_dispatcher(viewportManipulatorInteraction)
{
}
void RetainedModeActionDispatcher::AddActionToSequence(Action&& action)
{
if (m_locked)
{
const char* error = "Couldn't add action to sequence, dispatcher is locked (you must call ResetSequence() \
before adding actions to this dispatcher)";
Log(error);
AZ_Assert(false, "Error: %s", error);
}
m_actions.emplace_back(action);
}
void RetainedModeActionDispatcher::EnableSnapToGridImpl()
{
AddActionToSequence([=]() { m_dispatcher.EnableSnapToGrid(); });
}
void RetainedModeActionDispatcher::DisableSnapToGridImpl()
{
AddActionToSequence([=]() { m_dispatcher.DisableSnapToGrid(); });
}
void RetainedModeActionDispatcher::GridSizeImpl(float size)
{
AddActionToSequence([=]() { m_dispatcher.GridSize(size); });
}
void RetainedModeActionDispatcher::CameraStateImpl(const AzFramework::CameraState& cameraState)
{
AddActionToSequence([=]() { m_dispatcher.CameraState(cameraState); });
}
void RetainedModeActionDispatcher::MouseLButtonDownImpl()
{
AddActionToSequence([=]() { m_dispatcher.MouseLButtonDown(); });
}
void RetainedModeActionDispatcher::MouseLButtonUpImpl()
{
AddActionToSequence([=]() { m_dispatcher.MouseLButtonUp(); });
}
void RetainedModeActionDispatcher::MousePositionImpl(const AzFramework::ScreenPoint& position)
{
AddActionToSequence([=]() { m_dispatcher.MousePosition(position); });
}
void RetainedModeActionDispatcher::KeyboardModifierDownImpl(const KeyboardModifier& keyModifier)
{
AddActionToSequence([=]() { m_dispatcher.KeyboardModifierDown(keyModifier); });
}
void RetainedModeActionDispatcher::KeyboardModifierUpImpl(const KeyboardModifier& keyModifier)
{
AddActionToSequence([=]() { m_dispatcher.KeyboardModifierUp(keyModifier); });
}
void RetainedModeActionDispatcher::ExpectManipulatorBeingInteractedImpl()
{
AddActionToSequence([=]() { m_dispatcher.ExpectManipulatorBeingInteracted(); });
}
void RetainedModeActionDispatcher::ExpectManipulatorNotBeingInteractedImpl()
{
AddActionToSequence([=]() { m_dispatcher.ExpectManipulatorNotBeingInteracted(); });
}
void RetainedModeActionDispatcher::SetEntityWorldTransformImpl(AZ::EntityId entityId, const AZ::Transform& transform)
{
AddActionToSequence([=]() { m_dispatcher.SetEntityWorldTransform(entityId, transform); });
}
void RetainedModeActionDispatcher::SetSelectedEntityImpl(AZ::EntityId entity)
{
AddActionToSequence([=]() { m_dispatcher.SetSelectedEntity(entity); });
}
void RetainedModeActionDispatcher::SetSelectedEntitiesImpl(const AzToolsFramework::EntityIdList& entities)
{
AddActionToSequence([=]() { m_dispatcher.SetSelectedEntities(entities); });
}
void RetainedModeActionDispatcher::EnterComponentModeImpl(const AZ::Uuid& uuid)
{
AddActionToSequence([=]() { m_dispatcher.EnterComponentMode(uuid); });
}
RetainedModeActionDispatcher* RetainedModeActionDispatcher::ResetSequence()
{
Log("Resetting the action sequence");
m_actions.clear();
m_dispatcher.ResetEvent();
m_locked = false;
return this;
}
RetainedModeActionDispatcher* RetainedModeActionDispatcher::Execute()
{
Log("Executing %u actions", m_actions.size());
for (auto& action : m_actions)
{
action();
}
m_dispatcher.ResetEvent();
m_locked = true;
return this;
}
} // namespace AzManipulatorTestFramework
@@ -0,0 +1,134 @@
/*
* 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 <AzManipulatorTestFramework/ViewportInteraction.h>
#include <AzFramework/Viewport/ViewportScreen.h>
#include <AzFramework/Viewport/CameraState.h>
#include <AzToolsFramework/Manipulators/ManipulatorBus.h>
namespace AzManipulatorTestFramework
{
// Null debug display for dummy draw calls
class NullDebugDisplayRequests
: public AzFramework::DebugDisplayRequests
{
public:
virtual ~NullDebugDisplayRequests() = default;
};
ViewportInteraction::ViewportInteraction()
: m_nullDebugDisplayRequests(AZStd::make_unique<NullDebugDisplayRequests>())
{
AzToolsFramework::ViewportInteraction::ViewportInteractionRequestBus::Handler::BusConnect(m_viewportId);
}
ViewportInteraction::~ViewportInteraction()
{
AzToolsFramework::ViewportInteraction::ViewportInteractionRequestBus::Handler::BusDisconnect();
}
AzFramework::CameraState ViewportInteraction::GetCameraState()
{
return m_cameraState;
}
bool ViewportInteraction::GridSnappingEnabled()
{
return m_gridSnapping;
}
float ViewportInteraction::GridSize()
{
return m_gridSize;
}
bool ViewportInteraction::ShowGrid()
{
return false;
}
bool ViewportInteraction::AngleSnappingEnabled()
{
return m_angularSnapping;
}
float ViewportInteraction::AngleStep()
{
return m_angularStep;
}
QPoint ViewportInteraction::ViewportWorldToScreen(const AZ::Vector3& worldPosition)
{
auto pos = AzFramework::WorldToScreen(worldPosition, m_cameraState);
return QPoint(pos.m_x, pos.m_y);
}
void ViewportInteraction::SetCameraState(const AzFramework::CameraState& cameraState)
{
m_cameraState = cameraState;
}
AzFramework::DebugDisplayRequests& ViewportInteraction::GetDebugDisplay()
{
return *m_nullDebugDisplayRequests;
}
void ViewportInteraction::EnableGridSnaping()
{
m_gridSnapping = true;
}
void ViewportInteraction::DisableGridSnaping()
{
m_gridSnapping = false;
}
void ViewportInteraction::EnableAngularSnaping()
{
m_angularSnapping = true;
}
void ViewportInteraction::DisableAngularSnaping()
{
m_angularSnapping = false;
}
void ViewportInteraction::SetGridSize(float size)
{
m_gridSize = size;
}
void ViewportInteraction::SetAngularStep(float step)
{
m_angularStep = step;
}
int ViewportInteraction::GetViewportId() const
{
return m_viewportId;
}
AZStd::optional<AZ::Vector3> ViewportInteraction::ViewportScreenToWorld([[maybe_unused]]const QPoint& screenPosition, [[maybe_unused]]float depth)
{
return {};
}
AZStd::optional<AzToolsFramework::ViewportInteraction::ProjectedViewportRay> ViewportInteraction::ViewportScreenToWorldRay([[maybe_unused]]const QPoint& screenPosition)
{
return {};
}
QPoint ViewportInteraction::ViewportCursorScreenPosition()
{
return QPoint();
}
} // namespace AzManipulatorTestFramework