|
@@ -97,20 +97,20 @@ namespace UnitTest
|
|
|
{
|
|
|
LeakDetectionFixture::SetUp();
|
|
|
|
|
|
- m_rootWidget = AZStd::make_unique<QWidget>();
|
|
|
+ m_rootWidget = new QWidget();
|
|
|
// set root widget to the the active window to ensure focus in/out events are fired
|
|
|
- QApplication::setActiveWindow(m_rootWidget.get());
|
|
|
+ QApplication::setActiveWindow(m_rootWidget);
|
|
|
m_rootWidget->setFixedSize(WidgetSize);
|
|
|
m_rootWidget->move(0, 0); // explicitly set the widget to be in the upper left corner
|
|
|
|
|
|
- m_otherWidget = AZStd::make_unique<QWidget>();
|
|
|
+ m_otherWidget = new QWidget(m_rootWidget);
|
|
|
m_otherWidget->setFixedSize(WidgetSize / 2);
|
|
|
m_otherWidget->move(WidgetSize.width(), 0); // move widget to right of root widget
|
|
|
|
|
|
m_controllerList = AZStd::make_shared<AzFramework::ViewportControllerList>();
|
|
|
m_controllerList->RegisterViewportContext(TestViewportId);
|
|
|
|
|
|
- m_inputChannelMapper = AZStd::make_unique<AzToolsFramework::QtEventToAzInputMapper>(m_rootWidget.get(), TestViewportId);
|
|
|
+ m_inputChannelMapper = AZStd::make_unique<AzToolsFramework::QtEventToAzInputMapper>(m_rootWidget, TestViewportId);
|
|
|
|
|
|
m_settingsRegistry = AZStd::make_unique<AZ::SettingsRegistryImpl>();
|
|
|
AZ::SettingsRegistry::Register(m_settingsRegistry.get());
|
|
@@ -127,8 +127,7 @@ namespace UnitTest
|
|
|
m_controllerList.reset();
|
|
|
|
|
|
QApplication::setActiveWindow(nullptr);
|
|
|
- m_otherWidget.reset();
|
|
|
- m_rootWidget.reset();
|
|
|
+ delete m_rootWidget;
|
|
|
|
|
|
LeakDetectionFixture::TearDown();
|
|
|
}
|
|
@@ -141,7 +140,7 @@ namespace UnitTest
|
|
|
QObject::connect(
|
|
|
m_inputChannelMapper.get(),
|
|
|
&AzToolsFramework::QtEventToAzInputMapper::InputChannelUpdated,
|
|
|
- m_rootWidget.get(),
|
|
|
+ m_rootWidget,
|
|
|
[this, nativeWindowHandle](const AzFramework::InputChannel* inputChannel, [[maybe_unused]] QEvent* event)
|
|
|
{
|
|
|
m_controllerList->HandleInputChannelEvent(
|
|
@@ -214,7 +213,7 @@ namespace UnitTest
|
|
|
{
|
|
|
// move to the center of the screen
|
|
|
const auto start = QPoint(WidgetSize.width() / 2, WidgetSize.height() / 2);
|
|
|
- MouseMove(m_rootWidget.get(), start, QPoint(0, 0));
|
|
|
+ MouseMove(m_rootWidget, start, QPoint(0, 0));
|
|
|
m_controllerList->UpdateViewport({ TestViewportId, AzFramework::FloatSeconds(deltaTimeFn()), AZ::ScriptTimePoint() });
|
|
|
|
|
|
// move mouse diagonally to top right, then to bottom left and back repeatedly
|
|
@@ -225,7 +224,7 @@ namespace UnitTest
|
|
|
{
|
|
|
for (int i = 0; i < iterationsPerDiagonal; ++i)
|
|
|
{
|
|
|
- MousePressAndMove(m_rootWidget.get(), current, halfDelta / iterationsPerDiagonal, Qt::MouseButton::RightButton);
|
|
|
+ MousePressAndMove(m_rootWidget, current, halfDelta / iterationsPerDiagonal, Qt::MouseButton::RightButton);
|
|
|
m_controllerList->UpdateViewport({ TestViewportId, AzFramework::FloatSeconds(deltaTimeFn()), AZ::ScriptTimePoint() });
|
|
|
current += halfDelta / iterationsPerDiagonal;
|
|
|
}
|
|
@@ -237,13 +236,13 @@ namespace UnitTest
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- QTest::mouseRelease(m_rootWidget.get(), Qt::MouseButton::RightButton, Qt::KeyboardModifier::NoModifier, current);
|
|
|
+ QTest::mouseRelease(m_rootWidget, Qt::MouseButton::RightButton, Qt::KeyboardModifier::NoModifier, current);
|
|
|
m_controllerList->UpdateViewport({ TestViewportId, AzFramework::FloatSeconds(deltaTimeFn()), AZ::ScriptTimePoint() });
|
|
|
}
|
|
|
|
|
|
::testing::NiceMock<MockViewportInteractionRequests> m_mockViewportInteractionRequests;
|
|
|
- AZStd::unique_ptr<QWidget> m_rootWidget;
|
|
|
- AZStd::unique_ptr<QWidget> m_otherWidget;
|
|
|
+ QWidget* m_rootWidget = nullptr;
|
|
|
+ QWidget* m_otherWidget = nullptr;;
|
|
|
AzFramework::ViewportControllerListPtr m_controllerList;
|
|
|
AZStd::unique_ptr<AzToolsFramework::QtEventToAzInputMapper> m_inputChannelMapper;
|
|
|
::testing::NiceMock<MockWindowRequests> m_mockWindowRequests;
|
|
@@ -323,30 +322,30 @@ namespace UnitTest
|
|
|
// When
|
|
|
// move to the center of the screen
|
|
|
auto start = QPoint(WidgetSize.width() / 2, WidgetSize.height() / 2);
|
|
|
- MouseMove(m_rootWidget.get(), start, QPoint(0, 0));
|
|
|
+ MouseMove(m_rootWidget, start, QPoint(0, 0));
|
|
|
m_controllerList->UpdateViewport({ TestViewportId, AzFramework::FloatSeconds(DeltaTime), AZ::ScriptTimePoint() });
|
|
|
|
|
|
const auto mouseDelta = QPoint(5, 0);
|
|
|
|
|
|
// initial movement to begin the camera behavior
|
|
|
- MousePressAndMove(m_rootWidget.get(), start, mouseDelta, Qt::MouseButton::RightButton);
|
|
|
+ MousePressAndMove(m_rootWidget, start, mouseDelta, Qt::MouseButton::RightButton);
|
|
|
m_controllerList->UpdateViewport({ TestViewportId, AzFramework::FloatSeconds(DeltaTime), AZ::ScriptTimePoint() });
|
|
|
|
|
|
// move the cursor right
|
|
|
for (int i = 0; i < 50; ++i)
|
|
|
{
|
|
|
- MousePressAndMove(m_rootWidget.get(), start + mouseDelta, mouseDelta, Qt::MouseButton::RightButton);
|
|
|
+ MousePressAndMove(m_rootWidget, start + mouseDelta, mouseDelta, Qt::MouseButton::RightButton);
|
|
|
m_controllerList->UpdateViewport({ TestViewportId, AzFramework::FloatSeconds(DeltaTime), AZ::ScriptTimePoint() });
|
|
|
}
|
|
|
|
|
|
// move the cursor left (do an extra iteration moving left to account for the initial dead-zone)
|
|
|
for (int i = 0; i < 51; ++i)
|
|
|
{
|
|
|
- MousePressAndMove(m_rootWidget.get(), start + mouseDelta, -mouseDelta, Qt::MouseButton::RightButton);
|
|
|
+ MousePressAndMove(m_rootWidget, start + mouseDelta, -mouseDelta, Qt::MouseButton::RightButton);
|
|
|
m_controllerList->UpdateViewport({ TestViewportId, AzFramework::FloatSeconds(DeltaTime), AZ::ScriptTimePoint() });
|
|
|
}
|
|
|
|
|
|
- QTest::mouseRelease(m_rootWidget.get(), Qt::MouseButton::RightButton, Qt::KeyboardModifier::NoModifier, start + mouseDelta);
|
|
|
+ QTest::mouseRelease(m_rootWidget, Qt::MouseButton::RightButton, Qt::KeyboardModifier::NoModifier, start + mouseDelta);
|
|
|
m_controllerList->UpdateViewport({ TestViewportId, AzFramework::FloatSeconds(DeltaTime), AZ::ScriptTimePoint() });
|
|
|
|
|
|
// Then
|
|
@@ -371,12 +370,12 @@ namespace UnitTest
|
|
|
// When
|
|
|
// move to the center of the screen
|
|
|
auto start = QPoint(WidgetSize.width() / 2, WidgetSize.height() / 2);
|
|
|
- MouseMove(m_rootWidget.get(), start, QPoint(0, 0));
|
|
|
+ MouseMove(m_rootWidget, start, QPoint(0, 0));
|
|
|
m_controllerList->UpdateViewport({ TestViewportId, AzFramework::FloatSeconds(DeltaTime), AZ::ScriptTimePoint() });
|
|
|
|
|
|
// will move a small amount initially
|
|
|
const auto mouseDelta = QPoint(5, 0);
|
|
|
- MousePressAndMove(m_rootWidget.get(), start, mouseDelta, Qt::MouseButton::RightButton);
|
|
|
+ MousePressAndMove(m_rootWidget, start, mouseDelta, Qt::MouseButton::RightButton);
|
|
|
|
|
|
// ensure further updates to not continue to rotate
|
|
|
for (int i = 0; i < 50; ++i)
|
|
@@ -407,15 +406,15 @@ namespace UnitTest
|
|
|
// When
|
|
|
// move cursor to the center of the screen
|
|
|
auto start = QPoint(WidgetSize.width() / 2, WidgetSize.height() / 2);
|
|
|
- MouseMove(m_rootWidget.get(), start, QPoint(0, 0));
|
|
|
+ MouseMove(m_rootWidget, start, QPoint(0, 0));
|
|
|
m_controllerList->UpdateViewport({ TestViewportId, AzFramework::FloatSeconds(DeltaTime), AZ::ScriptTimePoint() });
|
|
|
|
|
|
// move camera right
|
|
|
const auto mouseDelta = QPoint(200, 0);
|
|
|
- MousePressAndMove(m_rootWidget.get(), start, mouseDelta, Qt::MouseButton::RightButton);
|
|
|
+ MousePressAndMove(m_rootWidget, start, mouseDelta, Qt::MouseButton::RightButton);
|
|
|
m_controllerList->UpdateViewport({ TestViewportId, AzFramework::FloatSeconds(DeltaTime), AZ::ScriptTimePoint() });
|
|
|
|
|
|
- QTest::mouseRelease(m_rootWidget.get(), Qt::MouseButton::RightButton, Qt::NoModifier, start + mouseDelta);
|
|
|
+ QTest::mouseRelease(m_rootWidget, Qt::MouseButton::RightButton, Qt::NoModifier, start + mouseDelta);
|
|
|
m_controllerList->UpdateViewport({ TestViewportId, AzFramework::FloatSeconds(DeltaTime), AZ::ScriptTimePoint() });
|
|
|
|
|
|
// update the position of the widget
|
|
@@ -423,11 +422,11 @@ namespace UnitTest
|
|
|
m_rootWidget->move(offset);
|
|
|
|
|
|
// move cursor back to widget center
|
|
|
- MouseMove(m_rootWidget.get(), start, QPoint(0, 0));
|
|
|
+ MouseMove(m_rootWidget, start, QPoint(0, 0));
|
|
|
m_controllerList->UpdateViewport({ TestViewportId, AzFramework::FloatSeconds(DeltaTime), AZ::ScriptTimePoint() });
|
|
|
|
|
|
// move camera left
|
|
|
- MousePressAndMove(m_rootWidget.get(), start, -mouseDelta, Qt::MouseButton::RightButton);
|
|
|
+ MousePressAndMove(m_rootWidget, start, -mouseDelta, Qt::MouseButton::RightButton);
|
|
|
m_controllerList->UpdateViewport({ TestViewportId, AzFramework::FloatSeconds(DeltaTime), AZ::ScriptTimePoint() });
|
|
|
|
|
|
// Then
|
|
@@ -463,7 +462,7 @@ namespace UnitTest
|
|
|
// When
|
|
|
// press alt without main viewport in focus
|
|
|
m_otherWidget->setFocus();
|
|
|
- QTest::keyPress(m_otherWidget.get(), Qt::Key::Key_Alt);
|
|
|
+ QTest::keyPress(m_otherWidget, Qt::Key::Key_Alt);
|
|
|
m_controllerList->UpdateViewport({ TestViewportId, AzFramework::FloatSeconds(DeltaTime), AZ::ScriptTimePoint() });
|
|
|
|
|
|
// change focus
|
|
@@ -471,19 +470,19 @@ namespace UnitTest
|
|
|
|
|
|
// move cursor to the center of the screen
|
|
|
auto start = QPoint(WidgetSize.width() / 2, WidgetSize.height() / 2);
|
|
|
- MouseMove(m_rootWidget.get(), start, QPoint(0, 0));
|
|
|
+ MouseMove(m_rootWidget, start, QPoint(0, 0));
|
|
|
m_controllerList->UpdateViewport({ TestViewportId, AzFramework::FloatSeconds(DeltaTime), AZ::ScriptTimePoint() });
|
|
|
|
|
|
// update starting position of mouse cursor request (if needed later)
|
|
|
m_viewportMouseCursorRequests.m_mousePosition = AzToolsFramework::ViewportInteraction::ScreenPointFromQPoint(start);
|
|
|
|
|
|
// start a mouse press and update the viewport
|
|
|
- QTest::mousePress(m_rootWidget.get(), Qt::MouseButton::LeftButton, Qt::NoModifier, start);
|
|
|
+ QTest::mousePress(m_rootWidget, Qt::MouseButton::LeftButton, Qt::NoModifier, start);
|
|
|
m_controllerList->UpdateViewport({ TestViewportId, AzFramework::FloatSeconds(DeltaTime), AZ::ScriptTimePoint() });
|
|
|
|
|
|
// move mouse right and perform a camera orbit (with left mouse button held from before)
|
|
|
const auto mouseDelta = QPoint(200, 0);
|
|
|
- MouseMove(m_rootWidget.get(), start, mouseDelta);
|
|
|
+ MouseMove(m_rootWidget, start, mouseDelta);
|
|
|
m_controllerList->UpdateViewport({ TestViewportId, AzFramework::FloatSeconds(DeltaTime), AZ::ScriptTimePoint() });
|
|
|
|
|
|
// Then
|
|
@@ -494,4 +493,43 @@ namespace UnitTest
|
|
|
// Clean-up
|
|
|
HaltCollaborators();
|
|
|
}
|
|
|
+
|
|
|
+ TEST_F(ModularViewportCameraControllerFixture, CameraSystemStopsMovingWhenViewportLosesFocus)
|
|
|
+ {
|
|
|
+ SandboxEditor::SetCameraCaptureCursorForLook(false);
|
|
|
+
|
|
|
+ // Given
|
|
|
+ PrepareCollaborators();
|
|
|
+
|
|
|
+ // ensure widgets are showing to make sure focus in/out events are fired correctly
|
|
|
+ m_rootWidget->setVisible(true);
|
|
|
+ m_otherWidget->setVisible(true);
|
|
|
+
|
|
|
+ // store initial camera translation and rotation
|
|
|
+ const AZ::Vector3 cameraTranslation = m_cameraViewportContextView->GetCameraTransform().GetTranslation();
|
|
|
+
|
|
|
+ // change focus to main widget
|
|
|
+ m_rootWidget->setFocus();
|
|
|
+
|
|
|
+ // start moving the camera left
|
|
|
+ QTest::keyPress(m_rootWidget, Qt::Key::Key_A);
|
|
|
+ // update the viewport
|
|
|
+ m_controllerList->UpdateViewport({ TestViewportId, AzFramework::FloatSeconds(1.0f), AZ::ScriptTimePoint() });
|
|
|
+
|
|
|
+ // ensure the camera moved from its initial position
|
|
|
+ const AZ::Vector3 nextCameraTranslation = m_cameraViewportContextView->GetCameraTransform().GetTranslation();
|
|
|
+ EXPECT_THAT(nextCameraTranslation, ::testing::Not(IsClose(cameraTranslation)));
|
|
|
+
|
|
|
+ // move focus to the other widget
|
|
|
+ m_otherWidget->setFocus();
|
|
|
+ // update the viewport
|
|
|
+ m_controllerList->UpdateViewport({ TestViewportId, AzFramework::FloatSeconds(1.0f), AZ::ScriptTimePoint() });
|
|
|
+
|
|
|
+ // ensure the camera did not move from its last position
|
|
|
+ const AZ::Vector3 lastCameraTranslation = m_cameraViewportContextView->GetCameraTransform().GetTranslation();
|
|
|
+ EXPECT_THAT(lastCameraTranslation, IsClose(nextCameraTranslation));
|
|
|
+
|
|
|
+ // Clean-up
|
|
|
+ HaltCollaborators();
|
|
|
+ }
|
|
|
} // namespace UnitTest
|