From 90f710b8c2564547293487a53af0b474572a8481 Mon Sep 17 00:00:00 2001 From: Michael Pollind Date: Sun, 31 Oct 2021 09:48:06 -0700 Subject: [PATCH 01/11] feat: add cursor wrapped mode Signed-off-by: Michael Pollind --- Code/Editor/EditorViewportSettings.cpp | 11 ++ Code/Editor/EditorViewportSettings.h | 3 + .../test_ModularViewportCameraController.cpp | 4 +- .../Input/QtEventToAzInputMapper.cpp | 109 ++++++++++++++---- .../Input/QtEventToAzInputMapper.h | 19 ++- .../Source/Viewport/RenderViewportWidget.cpp | 4 +- 6 files changed, 122 insertions(+), 28 deletions(-) diff --git a/Code/Editor/EditorViewportSettings.cpp b/Code/Editor/EditorViewportSettings.cpp index e06b9696e1..5711d1c3d3 100644 --- a/Code/Editor/EditorViewportSettings.cpp +++ b/Code/Editor/EditorViewportSettings.cpp @@ -23,6 +23,7 @@ namespace SandboxEditor constexpr AZStd::string_view AngleSizeSetting = "/Amazon/Preferences/Editor/AngleSize"; constexpr AZStd::string_view ShowGridSetting = "/Amazon/Preferences/Editor/ShowGrid"; constexpr AZStd::string_view StickySelectSetting = "/Amazon/Preferences/Editor/StickySelect"; + constexpr AZStd::string_view ManipulatorMouseWrapSetting = "/Amazon/Preferences/Editor/Manipulator/MouseWrapping"; constexpr AZStd::string_view ManipulatorLineBoundWidthSetting = "/Amazon/Preferences/Editor/Manipulator/LineBoundWidth"; constexpr AZStd::string_view ManipulatorCircleBoundWidthSetting = "/Amazon/Preferences/Editor/Manipulator/CircleBoundWidth"; constexpr AZStd::string_view CameraTranslateSpeedSetting = "/Amazon/Preferences/Editor/Camera/TranslateSpeed"; @@ -186,6 +187,16 @@ namespace SandboxEditor AzToolsFramework::SetRegistry(ManipulatorLineBoundWidthSetting, lineBoundWidth); } + bool ManipulatorMouseWrap() + { + return aznumeric_cast(GetRegistry(ManipulatorMouseWrapSetting, false)); + } + + void SetManipulatorMouseWrap(bool wrapping) + { + SetRegistry(ManipulatorMouseWrapSetting, wrapping); + } + float ManipulatorCircleBoundWidth() { return aznumeric_cast(AzToolsFramework::GetRegistry(ManipulatorCircleBoundWidthSetting, 0.1)); diff --git a/Code/Editor/EditorViewportSettings.h b/Code/Editor/EditorViewportSettings.h index fe1253ed0c..975feff307 100644 --- a/Code/Editor/EditorViewportSettings.h +++ b/Code/Editor/EditorViewportSettings.h @@ -57,6 +57,9 @@ namespace SandboxEditor SANDBOX_API float ManipulatorLineBoundWidth(); SANDBOX_API void SetManipulatorLineBoundWidth(float lineBoundWidth); + SANDBOX_API bool ManipulatorMouseWrap(); + SANDBOX_API void SetManipulatorMouseWrap(bool wrapping); + SANDBOX_API float ManipulatorCircleBoundWidth(); SANDBOX_API void SetManipulatorCircleBoundWidth(float circleBoundWidth); diff --git a/Code/Editor/Lib/Tests/test_ModularViewportCameraController.cpp b/Code/Editor/Lib/Tests/test_ModularViewportCameraController.cpp index 67d89ad967..f2ee3c79aa 100644 --- a/Code/Editor/Lib/Tests/test_ModularViewportCameraController.cpp +++ b/Code/Editor/Lib/Tests/test_ModularViewportCameraController.cpp @@ -47,12 +47,12 @@ namespace UnitTest void ViewportMouseCursorRequestImpl::BeginCursorCapture() { - m_inputChannelMapper->SetCursorCaptureEnabled(true); + m_inputChannelMapper->SetCursorMode(AzToolsFramework::QtEventToAzInputMapper::CURSOR_MODE_CAPTURED); } void ViewportMouseCursorRequestImpl::EndCursorCapture() { - m_inputChannelMapper->SetCursorCaptureEnabled(false); + m_inputChannelMapper->SetCursorMode(AzToolsFramework::QtEventToAzInputMapper::CURSOR_MODE_NONE); } bool ViewportMouseCursorRequestImpl::IsMouseOver() const diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Input/QtEventToAzInputMapper.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Input/QtEventToAzInputMapper.cpp index 066bdc1654..0b6df58c1a 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Input/QtEventToAzInputMapper.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Input/QtEventToAzInputMapper.cpp @@ -241,22 +241,39 @@ namespace AzToolsFramework } } + + void QtEventToAzInputMapper::SetCursorMode(QtEventToAzInputMapper::CursorInputMode mode) + { + if(mode != m_cursorMode) + { + m_cursorMode = mode; + switch(m_cursorMode) + { + case CURSOR_MODE_CAPTURED: + qApp->setOverrideCursor(Qt::BlankCursor); + m_mouseDevice->SetSystemCursorState(AzFramework::SystemCursorState::ConstrainedAndHidden); + break; + case CURSOR_MODE_WRAPPED: + qApp->restoreOverrideCursor(); + m_mouseDevice->SetSystemCursorState(AzFramework::SystemCursorState::UnconstrainedAndVisible); + break; + case CURSOR_MODE_NONE: + qApp->restoreOverrideCursor(); + m_mouseDevice->SetSystemCursorState(AzFramework::SystemCursorState::UnconstrainedAndVisible); + break; + } + } + } + void QtEventToAzInputMapper::SetCursorCaptureEnabled(bool enabled) { - if (m_capturingCursor != enabled) + if (enabled) { - m_capturingCursor = enabled; - - if (m_capturingCursor) - { - m_mouseDevice->SetSystemCursorState(AzFramework::SystemCursorState::ConstrainedAndHidden); - qApp->setOverrideCursor(Qt::BlankCursor); - } - else - { - m_mouseDevice->SetSystemCursorState(AzFramework::SystemCursorState::UnconstrainedAndVisible); - qApp->restoreOverrideCursor(); - } + SetCursorMode(CURSOR_MODE_CAPTURED); + } + else + { + SetCursorMode(CURSOR_MODE_NONE); } } @@ -436,25 +453,73 @@ namespace AzToolsFramework return QPoint{ denormalizedX, denormalizedY }; } + void wrapCursorX(const QRect& rect, QPoint& point) { + if (rect.left() < point.x()) + { + point.setX(rect.right() - 1); + } + else if (rect.right() > point.x()) + { + point.setX(rect.left() + 1); + } + } + + void wrapCursorY(const QRect& rect, QPoint& point) { + if (rect.top() < point.y()) + { + point.setY(rect.bottom() - 1); + } + else if (rect.bottom() > point.y()) + { + point.setY(rect.top() + 1); + } + } + + void QtEventToAzInputMapper::HandleMouseMoveEvent(const QPoint& globalCursorPosition) { const QPoint cursorDelta = globalCursorPosition - m_previousGlobalCursorPosition; + QScreen* screen = m_sourceWidget->screen(); + const QRect widgetRect(m_sourceWidget->mapToGlobal(QPoint(0,0)), m_sourceWidget->size()); m_mouseDevice->m_cursorPositionData2D->m_normalizedPosition = WidgetPositionToNormalizedPosition(m_sourceWidget->mapFromGlobal(globalCursorPosition)); m_mouseDevice->m_cursorPositionData2D->m_normalizedPositionDelta = WidgetPositionToNormalizedPosition(cursorDelta); - ProcessPendingMouseEvents(cursorDelta); + switch(m_cursorMode) + { + case CURSOR_MODE_CAPTURED: + AzQtComponents::SetCursorPos(m_previousGlobalCursorPosition); + break; + case CURSOR_MODE_WRAPPED_X: + QPoint screenPos(globalCursorPosition); + wrapCursorX(widgetRect, screenPos); + QCursor::setPos(screen, screenPos); + QPoint screenDelta = globalCursorPosition - screenPos; + m_previousGlobalCursorPosition = globalCursorPosition - screenDelta; + break; + case CURSOR_MODE_WRAPPED_Y: + QPoint screenPos(globalCursorPosition); + wrapCursorY(widgetRect, screenPos); + QCursor::setPos(screen, screenPos); + QPoint screenDelta = globalCursorPosition - screenPos; + m_previousGlobalCursorPosition = globalCursorPosition - screenDelta; + break; + case CURSOR_MODE_WRAPPED: + QPoint screenPos(globalCursorPosition); + wrapCursorX(widgetRect, screenPos); + wrapCursorY(widgetRect, screenPos); + QCursor::setPos(screen, screenPos); + QPoint screenDelta = globalCursorPosition - screenPos; + m_previousGlobalCursorPosition = globalCursorPosition - screenDelta; + break; + default: + m_previousGlobalCursorPosition = globalCursorPosition; + break; + - if (m_capturingCursor) - { - // Reset our cursor position to the previous point - AzQtComponents::SetCursorPos(m_previousGlobalCursorPosition); - } - else - { - m_previousGlobalCursorPosition = globalCursorPosition; } + ProcessPendingMouseEvents(cursorDelta); } void QtEventToAzInputMapper::HandleKeyEvent(QKeyEvent* keyEvent) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Input/QtEventToAzInputMapper.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Input/QtEventToAzInputMapper.h index 373945d445..7ba4e21bd4 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Input/QtEventToAzInputMapper.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Input/QtEventToAzInputMapper.h @@ -41,6 +41,17 @@ namespace AzToolsFramework Q_OBJECT public: + enum CursorInputMode { + CURSOR_MODE_NONE, + CURSOR_MODE_CAPTURED, //< Sets whether or not the cursor should be constrained to the source widget and invisible. + //< Internally, this will reset the cursor position after each move event to ensure movement + //< events don't allow the cursor to escape. This can be used for typical camera controls + //< like a dolly or rotation, where mouse movement is important but cursor location is not. + CURSOR_MODE_WRAPPED, //< Flags whether the curser is going to wrap around the soruce widget. + CURSOR_MODE_WRAPPED_X, + CURSOR_MODE_WRAPPED_Y + }; + QtEventToAzInputMapper(QWidget* sourceWidget, int syntheticDeviceId = 0); ~QtEventToAzInputMapper() = default; @@ -56,8 +67,12 @@ namespace AzToolsFramework //! Internally, this will reset the cursor position after each move event to ensure movement //! events don't allow the cursor to escape. This can be used for typical camera controls //! like a dolly or rotation, where mouse movement is important but cursor location is not. + //! @deprecated Use #SetCursorMode() void SetCursorCaptureEnabled(bool enabled); + //! Set the cursor mode. + void SetCursorMode(QtEventToAzInputMapper::CursorInputMode mode); + void SetOverrideCursor(ViewportInteraction::CursorStyleOverride cursorStyleOverride); void ClearOverrideCursor(); @@ -176,8 +191,8 @@ namespace AzToolsFramework QWidget* m_sourceWidget; // Flags whether or not Qt events should currently be processed. bool m_enabled = true; - // Flags whether or not the cursor is being constrained to the source widget (for invisible mouse movement). - bool m_capturingCursor = false; + // Controls the cursor behavior. + QtEventToAzInputMapper::CursorInputMode m_cursorMode = CURSOR_MODE_NONE; // Flags whether the cursor has been overridden. bool m_overrideCursor = false; diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Viewport/RenderViewportWidget.cpp b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Viewport/RenderViewportWidget.cpp index 505ff70122..cbede827e2 100644 --- a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Viewport/RenderViewportWidget.cpp +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Viewport/RenderViewportWidget.cpp @@ -331,12 +331,12 @@ namespace AtomToolsFramework void RenderViewportWidget::BeginCursorCapture() { - m_inputChannelMapper->SetCursorCaptureEnabled(true); + m_inputChannelMapper->SetCursorMode(AzToolsFramework::QtEventToAzInputMapper::CURSOR_MODE_CAPTURED); } void RenderViewportWidget::EndCursorCapture() { - m_inputChannelMapper->SetCursorCaptureEnabled(false); + m_inputChannelMapper->SetCursorMode(AzToolsFramework::QtEventToAzInputMapper::CURSOR_MODE_NONE); } void RenderViewportWidget::SetOverrideCursor(AzToolsFramework::ViewportInteraction::CursorStyleOverride cursorStyleOverride) From fa809a76ca3804e95377c0776a40cf4004da90c8 Mon Sep 17 00:00:00 2001 From: Michael Pollind Date: Mon, 13 Dec 2021 07:28:28 -0800 Subject: [PATCH 02/11] chore: address changes - updated checkstyle - update enum CursorInputMode - minor refeactor to QtEventToAzInputMapper Signed-off-by: Michael Pollind --- Code/Editor/EditorViewportSettings.cpp | 10 +- Code/Editor/EditorViewportSettings.h | 4 +- .../test_ModularViewportCameraController.cpp | 4 +- .../Input/QtEventToAzInputMapper.cpp | 116 +++++++++--------- .../Input/QtEventToAzInputMapper.h | 14 +-- .../Source/Viewport/RenderViewportWidget.cpp | 4 +- 6 files changed, 74 insertions(+), 78 deletions(-) diff --git a/Code/Editor/EditorViewportSettings.cpp b/Code/Editor/EditorViewportSettings.cpp index 5711d1c3d3..883eb91863 100644 --- a/Code/Editor/EditorViewportSettings.cpp +++ b/Code/Editor/EditorViewportSettings.cpp @@ -23,7 +23,7 @@ namespace SandboxEditor constexpr AZStd::string_view AngleSizeSetting = "/Amazon/Preferences/Editor/AngleSize"; constexpr AZStd::string_view ShowGridSetting = "/Amazon/Preferences/Editor/ShowGrid"; constexpr AZStd::string_view StickySelectSetting = "/Amazon/Preferences/Editor/StickySelect"; - constexpr AZStd::string_view ManipulatorMouseWrapSetting = "/Amazon/Preferences/Editor/Manipulator/MouseWrapping"; + constexpr AZStd::string_view ViewportMouseWrapSetting = "/Amazon/Preferences/Editor/Manipulator/MouseWrapping"; constexpr AZStd::string_view ManipulatorLineBoundWidthSetting = "/Amazon/Preferences/Editor/Manipulator/LineBoundWidth"; constexpr AZStd::string_view ManipulatorCircleBoundWidthSetting = "/Amazon/Preferences/Editor/Manipulator/CircleBoundWidth"; constexpr AZStd::string_view CameraTranslateSpeedSetting = "/Amazon/Preferences/Editor/Camera/TranslateSpeed"; @@ -187,14 +187,14 @@ namespace SandboxEditor AzToolsFramework::SetRegistry(ManipulatorLineBoundWidthSetting, lineBoundWidth); } - bool ManipulatorMouseWrap() + bool ViewportMouseWrapSetting() { - return aznumeric_cast(GetRegistry(ManipulatorMouseWrapSetting, false)); + return aznumeric_cast(GetRegistry(ViewportMouseWrapSetting, false)); } - void SetManipulatorMouseWrap(bool wrapping) + void SetViewportMouseWrapSetting(bool wrapping) { - SetRegistry(ManipulatorMouseWrapSetting, wrapping); + SetRegistry(ViewportMouseWrapSetting, wrapping); } float ManipulatorCircleBoundWidth() diff --git a/Code/Editor/EditorViewportSettings.h b/Code/Editor/EditorViewportSettings.h index 975feff307..a27187bc55 100644 --- a/Code/Editor/EditorViewportSettings.h +++ b/Code/Editor/EditorViewportSettings.h @@ -57,8 +57,8 @@ namespace SandboxEditor SANDBOX_API float ManipulatorLineBoundWidth(); SANDBOX_API void SetManipulatorLineBoundWidth(float lineBoundWidth); - SANDBOX_API bool ManipulatorMouseWrap(); - SANDBOX_API void SetManipulatorMouseWrap(bool wrapping); + SANDBOX_API bool ViewportMouseWrapSetting(); + SANDBOX_API void SetViewportMouseWrapSetting(bool wrapping); SANDBOX_API float ManipulatorCircleBoundWidth(); SANDBOX_API void SetManipulatorCircleBoundWidth(float circleBoundWidth); diff --git a/Code/Editor/Lib/Tests/test_ModularViewportCameraController.cpp b/Code/Editor/Lib/Tests/test_ModularViewportCameraController.cpp index f2ee3c79aa..9bfd9d396e 100644 --- a/Code/Editor/Lib/Tests/test_ModularViewportCameraController.cpp +++ b/Code/Editor/Lib/Tests/test_ModularViewportCameraController.cpp @@ -47,12 +47,12 @@ namespace UnitTest void ViewportMouseCursorRequestImpl::BeginCursorCapture() { - m_inputChannelMapper->SetCursorMode(AzToolsFramework::QtEventToAzInputMapper::CURSOR_MODE_CAPTURED); + m_inputChannelMapper->SetCursorMode(AzToolsFramework::QtEventToAzInputMapper::CursorModeCaptured); } void ViewportMouseCursorRequestImpl::EndCursorCapture() { - m_inputChannelMapper->SetCursorMode(AzToolsFramework::QtEventToAzInputMapper::CURSOR_MODE_NONE); + m_inputChannelMapper->SetCursorMode(AzToolsFramework::QtEventToAzInputMapper::CursorModeNone); } bool ViewportMouseCursorRequestImpl::IsMouseOver() const diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Input/QtEventToAzInputMapper.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Input/QtEventToAzInputMapper.cpp index 0b6df58c1a..77f297b98c 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Input/QtEventToAzInputMapper.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Input/QtEventToAzInputMapper.cpp @@ -241,40 +241,32 @@ namespace AzToolsFramework } } - - void QtEventToAzInputMapper::SetCursorMode(QtEventToAzInputMapper::CursorInputMode mode) + void QtEventToAzInputMapper::SetCursorMode(QtEventToAzInputMapper::CursorInputMode mode) { - if(mode != m_cursorMode) + if (mode != m_cursorMode) { m_cursorMode = mode; - switch(m_cursorMode) + switch (m_cursorMode) { - case CURSOR_MODE_CAPTURED: - qApp->setOverrideCursor(Qt::BlankCursor); - m_mouseDevice->SetSystemCursorState(AzFramework::SystemCursorState::ConstrainedAndHidden); - break; - case CURSOR_MODE_WRAPPED: - qApp->restoreOverrideCursor(); - m_mouseDevice->SetSystemCursorState(AzFramework::SystemCursorState::UnconstrainedAndVisible); - break; - case CURSOR_MODE_NONE: - qApp->restoreOverrideCursor(); - m_mouseDevice->SetSystemCursorState(AzFramework::SystemCursorState::UnconstrainedAndVisible); - break; + case CursorInputMode::CursorModeCaptured: + qApp->setOverrideCursor(Qt::BlankCursor); + m_mouseDevice->SetSystemCursorState(AzFramework::SystemCursorState::ConstrainedAndHidden); + break; + case CursorInputMode::CursorModeWrapped: + qApp->restoreOverrideCursor(); + m_mouseDevice->SetSystemCursorState(AzFramework::SystemCursorState::UnconstrainedAndVisible); + break; + case CursorInputMode::CursorModeNone: + qApp->restoreOverrideCursor(); + m_mouseDevice->SetSystemCursorState(AzFramework::SystemCursorState::UnconstrainedAndVisible); + break; } } } void QtEventToAzInputMapper::SetCursorCaptureEnabled(bool enabled) { - if (enabled) - { - SetCursorMode(CURSOR_MODE_CAPTURED); - } - else - { - SetCursorMode(CURSOR_MODE_NONE); - } + SetCursorMode(enabled ? CursorInputMode::CursorModeCaptured : CursorInputMode::CursorModeNone); } bool QtEventToAzInputMapper::eventFilter(QObject* object, QEvent* event) @@ -453,71 +445,75 @@ namespace AzToolsFramework return QPoint{ denormalizedX, denormalizedY }; } - void wrapCursorX(const QRect& rect, QPoint& point) { - if (rect.left() < point.x()) + void wrapCursorX(const QRect& rect, QPoint& point) + { + if (rect.left() < point.x()) { point.setX(rect.right() - 1); } - else if (rect.right() > point.x()) + else if (rect.right() > point.x()) { point.setX(rect.left() + 1); } } - void wrapCursorY(const QRect& rect, QPoint& point) { - if (rect.top() < point.y()) + void wrapCursorY(const QRect& rect, QPoint& point) + { + if (rect.top() < point.y()) { point.setY(rect.bottom() - 1); } - else if (rect.bottom() > point.y()) + else if (rect.bottom() > point.y()) { point.setY(rect.top() + 1); } } - void QtEventToAzInputMapper::HandleMouseMoveEvent(const QPoint& globalCursorPosition) { const QPoint cursorDelta = globalCursorPosition - m_previousGlobalCursorPosition; QScreen* screen = m_sourceWidget->screen(); - const QRect widgetRect(m_sourceWidget->mapToGlobal(QPoint(0,0)), m_sourceWidget->size()); + const QRect widgetRect(m_sourceWidget->mapToGlobal(QPoint(0, 0)), m_sourceWidget->size()); m_mouseDevice->m_cursorPositionData2D->m_normalizedPosition = WidgetPositionToNormalizedPosition(m_sourceWidget->mapFromGlobal(globalCursorPosition)); m_mouseDevice->m_cursorPositionData2D->m_normalizedPositionDelta = WidgetPositionToNormalizedPosition(cursorDelta); - switch(m_cursorMode) + switch (m_cursorMode) { - case CURSOR_MODE_CAPTURED: - AzQtComponents::SetCursorPos(m_previousGlobalCursorPosition); - break; - case CURSOR_MODE_WRAPPED_X: + case CursorInputMode::CursorModeCaptured: + AzQtComponents::SetCursorPos(m_previousGlobalCursorPosition); + break; + case CursorInputMode::CursorModeWrappedX: + case CursorInputMode::CursorModeWrappedY: + case CursorInputMode::CursorModeWrapped: + { QPoint screenPos(globalCursorPosition); - wrapCursorX(widgetRect, screenPos); + switch (m_cursorMode) + { + case CursorInputMode::CursorModeWrappedX: + wrapCursorX(widgetRect, screenPos); + break; + case CursorInputMode::CursorModeWrappedY: + wrapCursorY(widgetRect, screenPos); + break; + case CursorInputMode::CursorModeWrapped: + wrapCursorX(widgetRect, screenPos); + wrapCursorY(widgetRect, screenPos); + break; + default: + // this should never happen + AZ_Assert(false, "Invalid Curosr Mode: %i.", m_cursorMode); + break; + } QCursor::setPos(screen, screenPos); - QPoint screenDelta = globalCursorPosition - screenPos; + const QPoint screenDelta = globalCursorPosition - screenPos; m_previousGlobalCursorPosition = globalCursorPosition - screenDelta; - break; - case CURSOR_MODE_WRAPPED_Y: - QPoint screenPos(globalCursorPosition); - wrapCursorY(widgetRect, screenPos); - QCursor::setPos(screen, screenPos); - QPoint screenDelta = globalCursorPosition - screenPos; - m_previousGlobalCursorPosition = globalCursorPosition - screenDelta; - break; - case CURSOR_MODE_WRAPPED: - QPoint screenPos(globalCursorPosition); - wrapCursorX(widgetRect, screenPos); - wrapCursorY(widgetRect, screenPos); - QCursor::setPos(screen, screenPos); - QPoint screenDelta = globalCursorPosition - screenPos; - m_previousGlobalCursorPosition = globalCursorPosition - screenDelta; - break; - default: - m_previousGlobalCursorPosition = globalCursorPosition; - break; - - + } + break; + default: + AZ_Assert(false, "Invalid Curosr Mode: %i.", m_cursorMode); + break; } ProcessPendingMouseEvents(cursorDelta); } diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Input/QtEventToAzInputMapper.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Input/QtEventToAzInputMapper.h index 7ba4e21bd4..a6d9fdd753 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Input/QtEventToAzInputMapper.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Input/QtEventToAzInputMapper.h @@ -41,15 +41,15 @@ namespace AzToolsFramework Q_OBJECT public: - enum CursorInputMode { - CURSOR_MODE_NONE, - CURSOR_MODE_CAPTURED, //< Sets whether or not the cursor should be constrained to the source widget and invisible. + enum class CursorInputMode { + CursorModeNone, + CursorModeCaptured, //< Sets whether or not the cursor should be constrained to the source widget and invisible. //< Internally, this will reset the cursor position after each move event to ensure movement //< events don't allow the cursor to escape. This can be used for typical camera controls //< like a dolly or rotation, where mouse movement is important but cursor location is not. - CURSOR_MODE_WRAPPED, //< Flags whether the curser is going to wrap around the soruce widget. - CURSOR_MODE_WRAPPED_X, - CURSOR_MODE_WRAPPED_Y + CursorModeWrapped, //< Flags whether the curser is going to wrap around the soruce widget. + CursorModeWrappedX, + CursorModeWrappedY }; QtEventToAzInputMapper(QWidget* sourceWidget, int syntheticDeviceId = 0); @@ -192,7 +192,7 @@ namespace AzToolsFramework // Flags whether or not Qt events should currently be processed. bool m_enabled = true; // Controls the cursor behavior. - QtEventToAzInputMapper::CursorInputMode m_cursorMode = CURSOR_MODE_NONE; + QtEventToAzInputMapper::CursorInputMode m_cursorMode = CursorInputMode::CursorModeNone; // Flags whether the cursor has been overridden. bool m_overrideCursor = false; diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Viewport/RenderViewportWidget.cpp b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Viewport/RenderViewportWidget.cpp index cbede827e2..ef23560d57 100644 --- a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Viewport/RenderViewportWidget.cpp +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Viewport/RenderViewportWidget.cpp @@ -331,12 +331,12 @@ namespace AtomToolsFramework void RenderViewportWidget::BeginCursorCapture() { - m_inputChannelMapper->SetCursorMode(AzToolsFramework::QtEventToAzInputMapper::CURSOR_MODE_CAPTURED); + m_inputChannelMapper->SetCursorMode(AzToolsFramework::QtEventToAzInputMapper::CursorModeCaptured); } void RenderViewportWidget::EndCursorCapture() { - m_inputChannelMapper->SetCursorMode(AzToolsFramework::QtEventToAzInputMapper::CURSOR_MODE_NONE); + m_inputChannelMapper->SetCursorMode(AzToolsFramework::QtEventToAzInputMapper::CursorModeNone); } void RenderViewportWidget::SetOverrideCursor(AzToolsFramework::ViewportInteraction::CursorStyleOverride cursorStyleOverride) From 3a6f877a9f79157424d5a86d05f9f1b7a98d1585 Mon Sep 17 00:00:00 2001 From: Michael Pollind Date: Tue, 14 Dec 2021 23:05:13 -0800 Subject: [PATCH 03/11] chore: add first test Signed-off-by: Michael Pollind --- .../Input/QtEventToAzInputMapper.cpp | 8 ++--- .../Input/QtEventToAzInputMapperTests.cpp | 32 +++++++++++++++++++ 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Input/QtEventToAzInputMapper.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Input/QtEventToAzInputMapper.cpp index 77f297b98c..7852a4a5d5 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Input/QtEventToAzInputMapper.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Input/QtEventToAzInputMapper.cpp @@ -447,11 +447,11 @@ namespace AzToolsFramework void wrapCursorX(const QRect& rect, QPoint& point) { - if (rect.left() < point.x()) + if (point.x() < rect.left()) { point.setX(rect.right() - 1); } - else if (rect.right() > point.x()) + else if (point.x() > rect.right()) { point.setX(rect.left() + 1); } @@ -459,11 +459,11 @@ namespace AzToolsFramework void wrapCursorY(const QRect& rect, QPoint& point) { - if (rect.top() < point.y()) + if (point.y() < rect.top()) { point.setY(rect.bottom() - 1); } - else if (rect.bottom() > point.y()) + else if (point.y() > rect.bottom()) { point.setY(rect.top() + 1); } diff --git a/Code/Framework/AzToolsFramework/Tests/Input/QtEventToAzInputMapperTests.cpp b/Code/Framework/AzToolsFramework/Tests/Input/QtEventToAzInputMapperTests.cpp index 4c813a4bdd..e645c365e2 100644 --- a/Code/Framework/AzToolsFramework/Tests/Input/QtEventToAzInputMapperTests.cpp +++ b/Code/Framework/AzToolsFramework/Tests/Input/QtEventToAzInputMapperTests.cpp @@ -44,6 +44,10 @@ namespace UnitTest QObject::connect(m_inputChannelMapper.get(), &AzToolsFramework::QtEventToAzInputMapper::InputChannelUpdated, m_rootWidget.get(), [this]([[maybe_unused]] const AzFramework::InputChannel* inputChannel, QEvent* event) { + if(event == nullptr) { + return; + } + const QEvent::Type eventType = event->type(); if (eventType == QEvent::Type::MouseButtonPress || @@ -512,4 +516,32 @@ namespace UnitTest return info.param.m_az.GetName(); } ); + + TEST_F(QtEventToAzInputMapperFixture, MouseWrapMouseViewportQtEventToAzInputMapperFixture) + { + AzFramework::InputChannelNotificationBus::Handler::BusConnect(); + m_captureAzEvents = false; + + + const auto startPos = QPoint(WidgetSize.width() - 2, WidgetSize.height() / 2); + MouseMove(m_rootWidget.get(), startPos, QPoint(0,0)); + m_inputChannelMapper->SetCursorMode(AzToolsFramework::QtEventToAzInputMapper::CursorInputMode::CursorModeWrappedX); + + const auto deltaPos = QPoint(200.0f, 0); + const auto expectedPosition = m_rootWidget->mapToGlobal(QPoint(200, WidgetSize.height() / 2)); + const int iterations = 50; + + for(float i = 0; i < iterations; i++) { + MouseMove(m_rootWidget.get(), m_rootWidget->mapFromGlobal(QCursor::pos()), (deltaPos / iterations)); + } + + QPointF endPosition = QCursor::pos(); + EXPECT_NEAR(endPosition.x(), expectedPosition.x(), 5.0f); + EXPECT_NEAR(endPosition.y(), expectedPosition.y(), 5.0f); + + // cleanup + m_inputChannelMapper->SetCursorMode(AzToolsFramework::QtEventToAzInputMapper::CursorInputMode::CursorModeNone); + AzFramework::InputChannelNotificationBus::Handler::BusDisconnect(); + } + } // namespace UnitTest From 9e91c1872670c73cd1f3de98de616675ce9da8a5 Mon Sep 17 00:00:00 2001 From: Michael Pollind Date: Wed, 15 Dec 2021 13:32:24 -0800 Subject: [PATCH 04/11] chore: address changes add test cases Signed-off-by: Michael Pollind --- Code/Editor/EditorViewportSettings.cpp | 2 +- .../Input/QtEventToAzInputMapper.cpp | 14 +- .../Input/QtEventToAzInputMapper.h | 26 +-- .../Input/QtEventToAzInputMapperTests.cpp | 151 +++++++++++++++--- 4 files changed, 153 insertions(+), 40 deletions(-) diff --git a/Code/Editor/EditorViewportSettings.cpp b/Code/Editor/EditorViewportSettings.cpp index 883eb91863..7108beca5a 100644 --- a/Code/Editor/EditorViewportSettings.cpp +++ b/Code/Editor/EditorViewportSettings.cpp @@ -189,7 +189,7 @@ namespace SandboxEditor bool ViewportMouseWrapSetting() { - return aznumeric_cast(GetRegistry(ViewportMouseWrapSetting, false)); + return GetRegistry(ViewportMouseWrapSetting, false); } void SetViewportMouseWrapSetting(bool wrapping) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Input/QtEventToAzInputMapper.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Input/QtEventToAzInputMapper.cpp index 7852a4a5d5..edd45a7200 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Input/QtEventToAzInputMapper.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Input/QtEventToAzInputMapper.cpp @@ -241,7 +241,7 @@ namespace AzToolsFramework } } - void QtEventToAzInputMapper::SetCursorMode(QtEventToAzInputMapper::CursorInputMode mode) + void QtEventToAzInputMapper::SetCursorMode(AzToolsFramework::CursorInputMode mode) { if (mode != m_cursorMode) { @@ -445,7 +445,7 @@ namespace AzToolsFramework return QPoint{ denormalizedX, denormalizedY }; } - void wrapCursorX(const QRect& rect, QPoint& point) + void WrapCursorX(const QRect& rect, QPoint& point) { if (point.x() < rect.left()) { @@ -457,7 +457,7 @@ namespace AzToolsFramework } } - void wrapCursorY(const QRect& rect, QPoint& point) + void WrapCursorY(const QRect& rect, QPoint& point) { if (point.y() < rect.top()) { @@ -492,14 +492,14 @@ namespace AzToolsFramework switch (m_cursorMode) { case CursorInputMode::CursorModeWrappedX: - wrapCursorX(widgetRect, screenPos); + WrapCursorX(widgetRect, screenPos); break; case CursorInputMode::CursorModeWrappedY: - wrapCursorY(widgetRect, screenPos); + WrapCursorY(widgetRect, screenPos); break; case CursorInputMode::CursorModeWrapped: - wrapCursorX(widgetRect, screenPos); - wrapCursorY(widgetRect, screenPos); + WrapCursorX(widgetRect, screenPos); + WrapCursorY(widgetRect, screenPos); break; default: // this should never happen diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Input/QtEventToAzInputMapper.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Input/QtEventToAzInputMapper.h index a6d9fdd753..b84ac99c74 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Input/QtEventToAzInputMapper.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Input/QtEventToAzInputMapper.h @@ -32,6 +32,17 @@ class QWheelEvent; namespace AzToolsFramework { + enum class CursorInputMode { + CursorModeNone, + CursorModeCaptured, //!< Sets whether or not the cursor should be constrained to the source widget and invisible. + //!< Internally, this will reset the cursor position after each move event to ensure movement + //!< events don't allow the cursor to escape. This can be used for typical camera controls + //!< like a dolly or rotation, where mouse movement is important but cursor location is not. + CursorModeWrapped, //!< Flags whether the curser is going to wrap around the soruce widget. + CursorModeWrappedX, + CursorModeWrappedY + }; + //! Maps events from the Qt input system to synthetic InputChannels in AzFramework //! that can be used by AzFramework::ViewportControllers. class QtEventToAzInputMapper final @@ -41,17 +52,6 @@ namespace AzToolsFramework Q_OBJECT public: - enum class CursorInputMode { - CursorModeNone, - CursorModeCaptured, //< Sets whether or not the cursor should be constrained to the source widget and invisible. - //< Internally, this will reset the cursor position after each move event to ensure movement - //< events don't allow the cursor to escape. This can be used for typical camera controls - //< like a dolly or rotation, where mouse movement is important but cursor location is not. - CursorModeWrapped, //< Flags whether the curser is going to wrap around the soruce widget. - CursorModeWrappedX, - CursorModeWrappedY - }; - QtEventToAzInputMapper(QWidget* sourceWidget, int syntheticDeviceId = 0); ~QtEventToAzInputMapper() = default; @@ -71,7 +71,7 @@ namespace AzToolsFramework void SetCursorCaptureEnabled(bool enabled); //! Set the cursor mode. - void SetCursorMode(QtEventToAzInputMapper::CursorInputMode mode); + void SetCursorMode(AzToolsFramework::CursorInputMode mode); void SetOverrideCursor(ViewportInteraction::CursorStyleOverride cursorStyleOverride); void ClearOverrideCursor(); @@ -192,7 +192,7 @@ namespace AzToolsFramework // Flags whether or not Qt events should currently be processed. bool m_enabled = true; // Controls the cursor behavior. - QtEventToAzInputMapper::CursorInputMode m_cursorMode = CursorInputMode::CursorModeNone; + AzToolsFramework::CursorInputMode m_cursorMode = AzToolsFramework::CursorInputMode::CursorModeNone; // Flags whether the cursor has been overridden. bool m_overrideCursor = false; diff --git a/Code/Framework/AzToolsFramework/Tests/Input/QtEventToAzInputMapperTests.cpp b/Code/Framework/AzToolsFramework/Tests/Input/QtEventToAzInputMapperTests.cpp index e645c365e2..9af445850c 100644 --- a/Code/Framework/AzToolsFramework/Tests/Input/QtEventToAzInputMapperTests.cpp +++ b/Code/Framework/AzToolsFramework/Tests/Input/QtEventToAzInputMapperTests.cpp @@ -44,10 +44,10 @@ namespace UnitTest QObject::connect(m_inputChannelMapper.get(), &AzToolsFramework::QtEventToAzInputMapper::InputChannelUpdated, m_rootWidget.get(), [this]([[maybe_unused]] const AzFramework::InputChannel* inputChannel, QEvent* event) { - if(event == nullptr) { + if(event == nullptr) + { return; } - const QEvent::Type eventType = event->type(); if (eventType == QEvent::Type::MouseButtonPress || @@ -517,31 +517,144 @@ namespace UnitTest } ); - TEST_F(QtEventToAzInputMapperFixture, MouseWrapMouseViewportQtEventToAzInputMapperFixture) + struct MouseMoveParam { + AzToolsFramework::CursorInputMode mode; + int iterations; + QPoint startPos; + QPoint deltaPos; + QPoint expectedPos; + const char* name; + }; + + class MoveMoveWrapParamQtEventToAzInputMapperFixture + : public QtEventToAzInputMapperFixture + , public ::testing::WithParamInterface + { + }; + + TEST_P(MoveMoveWrapParamQtEventToAzInputMapperFixture, MouseMove_NoAzHandlers_VerifyMouseMovmentViewport) + { + // setup + const MouseMoveParam mouseMoveParam = GetParam(); + AzFramework::InputChannelNotificationBus::Handler::BusConnect(); m_captureAzEvents = false; + m_inputChannelMapper->SetCursorMode(mouseMoveParam.mode); + m_rootWidget->move(100, 100); - - const auto startPos = QPoint(WidgetSize.width() - 2, WidgetSize.height() / 2); - MouseMove(m_rootWidget.get(), startPos, QPoint(0,0)); - m_inputChannelMapper->SetCursorMode(AzToolsFramework::QtEventToAzInputMapper::CursorInputMode::CursorModeWrappedX); - const auto deltaPos = QPoint(200.0f, 0); - const auto expectedPosition = m_rootWidget->mapToGlobal(QPoint(200, WidgetSize.height() / 2)); - const int iterations = 50; - - for(float i = 0; i < iterations; i++) { - MouseMove(m_rootWidget.get(), m_rootWidget->mapFromGlobal(QCursor::pos()), (deltaPos / iterations)); + MouseMove(m_rootWidget.get(), mouseMoveParam.startPos, QPoint(0,0)); + for(float i = 0; i < mouseMoveParam.iterations; i++) { + MouseMove(m_rootWidget.get(), m_rootWidget->mapFromGlobal(QCursor::pos()), (mouseMoveParam.deltaPos / mouseMoveParam.iterations)); } - - QPointF endPosition = QCursor::pos(); - EXPECT_NEAR(endPosition.x(), expectedPosition.x(), 5.0f); - EXPECT_NEAR(endPosition.y(), expectedPosition.y(), 5.0f); - + + QPointF endPosition = m_rootWidget->mapFromGlobal(QCursor::pos()); + EXPECT_NEAR(endPosition.x(), mouseMoveParam.expectedPos.x(), 1.0f); + EXPECT_NEAR(endPosition.y(), mouseMoveParam.expectedPos.y(), 1.0f); + // cleanup - m_inputChannelMapper->SetCursorMode(AzToolsFramework::QtEventToAzInputMapper::CursorInputMode::CursorModeNone); + m_rootWidget->move(0, 0); + m_inputChannelMapper->SetCursorMode(AzToolsFramework::CursorInputMode::CursorModeNone); AzFramework::InputChannelNotificationBus::Handler::BusDisconnect(); } + INSTANTIATE_TEST_CASE_P(All, MoveMoveWrapParamQtEventToAzInputMapperFixture, + testing::Values( + // verify CursorModeWrappedX wrapping + MouseMoveParam {AzToolsFramework::CursorInputMode::CursorModeWrappedX, + 40, + QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() - 20, QtEventToAzInputMapperFixture::WidgetSize.height()/2.0f), + QPoint(40, 0), + QPoint(20, QtEventToAzInputMapperFixture::WidgetSize.height()/2.0f), + "CursorModeWrappedX_Test_Right" + }, + MouseMoveParam {AzToolsFramework::CursorInputMode::CursorModeWrappedX, + 40, + QPoint(20, QtEventToAzInputMapperFixture::WidgetSize.height()/2.0f), + QPoint(-40, 0), + QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() - 20, QtEventToAzInputMapperFixture::WidgetSize.height()/2.0f), + "CursorModeWrappedX_Test_Left" + }, + MouseMoveParam {AzToolsFramework::CursorInputMode::CursorModeWrappedX, + 40, + QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2.0f, 20.0f), + QPoint(0, -40), + QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2.0f, -20.0f), + "CursorModeWrappedX_Test_Top" + }, + MouseMoveParam {AzToolsFramework::CursorInputMode::CursorModeWrappedX, + 40, + QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2.0f, QtEventToAzInputMapperFixture::WidgetSize.height() - 20), + QPoint(0, 40), + QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2.0f, QtEventToAzInputMapperFixture::WidgetSize.height() + 20), + "CursorModeWrappedX_Test_Bottom" + }, + + // verify CursorModeWrappedY wrapping + MouseMoveParam {AzToolsFramework::CursorInputMode::CursorModeWrappedY, + 40, + QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() - 20, QtEventToAzInputMapperFixture::WidgetSize.height()/2.0f), + QPoint(40, 0), + QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() + 20, QtEventToAzInputMapperFixture::WidgetSize.height()/2.0f), + "CursorModeWrappedY_Test_Right" + }, + MouseMoveParam {AzToolsFramework::CursorInputMode::CursorModeWrappedY, + 40, + QPoint(20, QtEventToAzInputMapperFixture::WidgetSize.height()/2.0f), + QPoint(-40, 0), + QPoint(-20, QtEventToAzInputMapperFixture::WidgetSize.height()/2.0f), + "CursorModeWrappedY_Test_Left" + }, + MouseMoveParam {AzToolsFramework::CursorInputMode::CursorModeWrappedY, + 40, + QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2.0f, 20.0f), + QPoint(0, -40), + QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2.0f, QtEventToAzInputMapperFixture::WidgetSize.height() - 20.0f), + "CursorModeWrappedY_Test_Top" + }, + MouseMoveParam {AzToolsFramework::CursorInputMode::CursorModeWrappedY, + 40, + QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2.0f, QtEventToAzInputMapperFixture::WidgetSize.height() - 20), + QPoint(0, 40), + QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2.0f, 20), + "CursorModeWrappedY_Test_Bottom" + }, + + // verify CursorModeWrapped wrapping + MouseMoveParam {AzToolsFramework::CursorInputMode::CursorModeWrapped, + 40, + QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() - 20, QtEventToAzInputMapperFixture::WidgetSize.height()/2.0f), + QPoint(40, 0), + QPoint(20, QtEventToAzInputMapperFixture::WidgetSize.height()/2.0f), + "CursorModeWrapped_Test_Right" + }, + MouseMoveParam {AzToolsFramework::CursorInputMode::CursorModeWrapped, + 40, + QPoint(20, QtEventToAzInputMapperFixture::WidgetSize.height()/2.0f), + QPoint(-40, 0), + QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() - 20, QtEventToAzInputMapperFixture::WidgetSize.height()/2.0f), + "CursorModeWrapped_Test_Left" + }, + MouseMoveParam {AzToolsFramework::CursorInputMode::CursorModeWrapped, + 40, + QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2.0f, 20.0f), + QPoint(0, -40), + QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2.0f, QtEventToAzInputMapperFixture::WidgetSize.height() - 20.0f), + "CursorModeWrapped_Test_Top" + }, + MouseMoveParam {AzToolsFramework::CursorInputMode::CursorModeWrapped, + 40, + QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2.0f, QtEventToAzInputMapperFixture::WidgetSize.height() - 20), + QPoint(0, 40), + QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2.0f, 20), + "CursorModeWrapped_Test_Bottom" + } + ), + [](const ::testing::TestParamInfo& info) + { + return info.param.name; + } + ); + } // namespace UnitTest From 1654ff052041567778624fd7078164533bc37f42 Mon Sep 17 00:00:00 2001 From: Michael Pollind Date: Thu, 16 Dec 2021 22:37:31 -0800 Subject: [PATCH 05/11] chore: correct test case MouseMove_NoAzHandlers_VerifyMouseMovementViewport Signed-off-by: Michael Pollind --- .../Input/QtEventToAzInputMapper.cpp | 3 ++ .../Input/QtEventToAzInputMapper.h | 4 +- .../Input/QtEventToAzInputMapperTests.cpp | 43 ++++++++++++++++--- 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Input/QtEventToAzInputMapper.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Input/QtEventToAzInputMapper.cpp index edd45a7200..b660e87b56 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Input/QtEventToAzInputMapper.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Input/QtEventToAzInputMapper.cpp @@ -511,6 +511,9 @@ namespace AzToolsFramework m_previousGlobalCursorPosition = globalCursorPosition - screenDelta; } break; + case CursorInputMode::CursorModeNone: + m_previousGlobalCursorPosition = globalCursorPosition; + break; default: AZ_Assert(false, "Invalid Curosr Mode: %i.", m_cursorMode); break; diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Input/QtEventToAzInputMapper.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Input/QtEventToAzInputMapper.h index b84ac99c74..67ef195363 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Input/QtEventToAzInputMapper.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Input/QtEventToAzInputMapper.h @@ -39,8 +39,8 @@ namespace AzToolsFramework //!< events don't allow the cursor to escape. This can be used for typical camera controls //!< like a dolly or rotation, where mouse movement is important but cursor location is not. CursorModeWrapped, //!< Flags whether the curser is going to wrap around the soruce widget. - CursorModeWrappedX, - CursorModeWrappedY + CursorModeWrappedX, //!< Flags whether the curser is going to wrap around the soruce widget only on the left and right side. + CursorModeWrappedY //!< Flags whether the curser is going to wrap around the soruce widget only on the top and bottom side. }; //! Maps events from the Qt input system to synthetic InputChannels in AzFramework diff --git a/Code/Framework/AzToolsFramework/Tests/Input/QtEventToAzInputMapperTests.cpp b/Code/Framework/AzToolsFramework/Tests/Input/QtEventToAzInputMapperTests.cpp index 9af445850c..0282812be7 100644 --- a/Code/Framework/AzToolsFramework/Tests/Input/QtEventToAzInputMapperTests.cpp +++ b/Code/Framework/AzToolsFramework/Tests/Input/QtEventToAzInputMapperTests.cpp @@ -533,23 +533,38 @@ namespace UnitTest { }; - TEST_P(MoveMoveWrapParamQtEventToAzInputMapperFixture, MouseMove_NoAzHandlers_VerifyMouseMovmentViewport) + TEST_P(MoveMoveWrapParamQtEventToAzInputMapperFixture, MouseMove_NoAzHandlers_VerifyMouseMovementViewport) { + //TODO: mouseMove is bugged mapToGlobal is called twice + auto mouseMoveFix = [](QWidget* wid, QPoint globalPos, QPoint deltaPos) + { + QPoint globalPosition = globalPos + deltaPos; + QPoint localPosition = wid->mapFromGlobal(globalPosition); + QTest::mouseMove(wid, localPosition); + QMouseEvent mouseMoveEvent(QEvent::MouseMove, localPosition, globalPosition, Qt::NoButton, Qt::NoButton, Qt::NoModifier); + QApplication::sendEvent(wid, &mouseMoveEvent); + }; + // setup const MouseMoveParam mouseMoveParam = GetParam(); AzFramework::InputChannelNotificationBus::Handler::BusConnect(); m_captureAzEvents = false; - m_inputChannelMapper->SetCursorMode(mouseMoveParam.mode); + m_rootWidget->move(100, 100); + mouseMoveFix(m_rootWidget.get(), m_rootWidget->mapToGlobal(mouseMoveParam.startPos), QPoint(0, 0)); + // given + m_inputChannelMapper->SetCursorMode(mouseMoveParam.mode); - MouseMove(m_rootWidget.get(), mouseMoveParam.startPos, QPoint(0,0)); - for(float i = 0; i < mouseMoveParam.iterations; i++) { - MouseMove(m_rootWidget.get(), m_rootWidget->mapFromGlobal(QCursor::pos()), (mouseMoveParam.deltaPos / mouseMoveParam.iterations)); + mouseMoveFix(m_rootWidget.get(), m_rootWidget->mapToGlobal(mouseMoveParam.startPos), QPoint(0, 0)); + for (float i = 0; i < mouseMoveParam.iterations; i++) + { + mouseMoveFix(m_rootWidget.get(), QCursor::pos(), (mouseMoveParam.deltaPos / mouseMoveParam.iterations)); } - QPointF endPosition = m_rootWidget->mapFromGlobal(QCursor::pos()); + // validate + QPoint endPosition = m_rootWidget->mapFromGlobal(QCursor::pos()); EXPECT_NEAR(endPosition.x(), mouseMoveParam.expectedPos.x(), 1.0f); EXPECT_NEAR(endPosition.y(), mouseMoveParam.expectedPos.y(), 1.0f); @@ -649,6 +664,22 @@ namespace UnitTest QPoint(0, 40), QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2.0f, 20), "CursorModeWrapped_Test_Bottom" + }, + // verify CursorModeCaptured + MouseMoveParam {AzToolsFramework::CursorInputMode::CursorModeCaptured, + 40, + QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2.0f, QtEventToAzInputMapperFixture::WidgetSize.height() / 2.0f), + QPoint(0, 40), + QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2.0f, QtEventToAzInputMapperFixture::WidgetSize.height() / 2.0f), + "CursorModeCaptured" + }, + // verify CursorModeNone + MouseMoveParam {AzToolsFramework::CursorInputMode::CursorModeNone, + 40, + QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2.0f, QtEventToAzInputMapperFixture::WidgetSize.height() / 2.0f), + QPoint(40.0f, 0), + QPoint((QtEventToAzInputMapperFixture::WidgetSize.width() / 2.0f) + 40.0f, (QtEventToAzInputMapperFixture::WidgetSize.height() / 2.0f)), + "CursorModeNone" } ), [](const ::testing::TestParamInfo& info) From 95c0c83642b2496f96418745b6c245ee50cf87b9 Mon Sep 17 00:00:00 2001 From: Michael Pollind Date: Sat, 18 Dec 2021 18:29:39 -0800 Subject: [PATCH 06/11] chore: remove unused setting and fixed compiling errors Signed-off-by: Michael Pollind --- Code/Editor/EditorViewportSettings.cpp | 11 ----------- Code/Editor/EditorViewportSettings.h | 3 --- .../Tests/test_ModularViewportCameraController.cpp | 4 ++-- .../Code/Source/Viewport/RenderViewportWidget.cpp | 4 ++-- 4 files changed, 4 insertions(+), 18 deletions(-) diff --git a/Code/Editor/EditorViewportSettings.cpp b/Code/Editor/EditorViewportSettings.cpp index 7108beca5a..e06b9696e1 100644 --- a/Code/Editor/EditorViewportSettings.cpp +++ b/Code/Editor/EditorViewportSettings.cpp @@ -23,7 +23,6 @@ namespace SandboxEditor constexpr AZStd::string_view AngleSizeSetting = "/Amazon/Preferences/Editor/AngleSize"; constexpr AZStd::string_view ShowGridSetting = "/Amazon/Preferences/Editor/ShowGrid"; constexpr AZStd::string_view StickySelectSetting = "/Amazon/Preferences/Editor/StickySelect"; - constexpr AZStd::string_view ViewportMouseWrapSetting = "/Amazon/Preferences/Editor/Manipulator/MouseWrapping"; constexpr AZStd::string_view ManipulatorLineBoundWidthSetting = "/Amazon/Preferences/Editor/Manipulator/LineBoundWidth"; constexpr AZStd::string_view ManipulatorCircleBoundWidthSetting = "/Amazon/Preferences/Editor/Manipulator/CircleBoundWidth"; constexpr AZStd::string_view CameraTranslateSpeedSetting = "/Amazon/Preferences/Editor/Camera/TranslateSpeed"; @@ -187,16 +186,6 @@ namespace SandboxEditor AzToolsFramework::SetRegistry(ManipulatorLineBoundWidthSetting, lineBoundWidth); } - bool ViewportMouseWrapSetting() - { - return GetRegistry(ViewportMouseWrapSetting, false); - } - - void SetViewportMouseWrapSetting(bool wrapping) - { - SetRegistry(ViewportMouseWrapSetting, wrapping); - } - float ManipulatorCircleBoundWidth() { return aznumeric_cast(AzToolsFramework::GetRegistry(ManipulatorCircleBoundWidthSetting, 0.1)); diff --git a/Code/Editor/EditorViewportSettings.h b/Code/Editor/EditorViewportSettings.h index a27187bc55..fe1253ed0c 100644 --- a/Code/Editor/EditorViewportSettings.h +++ b/Code/Editor/EditorViewportSettings.h @@ -57,9 +57,6 @@ namespace SandboxEditor SANDBOX_API float ManipulatorLineBoundWidth(); SANDBOX_API void SetManipulatorLineBoundWidth(float lineBoundWidth); - SANDBOX_API bool ViewportMouseWrapSetting(); - SANDBOX_API void SetViewportMouseWrapSetting(bool wrapping); - SANDBOX_API float ManipulatorCircleBoundWidth(); SANDBOX_API void SetManipulatorCircleBoundWidth(float circleBoundWidth); diff --git a/Code/Editor/Lib/Tests/test_ModularViewportCameraController.cpp b/Code/Editor/Lib/Tests/test_ModularViewportCameraController.cpp index 9bfd9d396e..5009c626e2 100644 --- a/Code/Editor/Lib/Tests/test_ModularViewportCameraController.cpp +++ b/Code/Editor/Lib/Tests/test_ModularViewportCameraController.cpp @@ -47,12 +47,12 @@ namespace UnitTest void ViewportMouseCursorRequestImpl::BeginCursorCapture() { - m_inputChannelMapper->SetCursorMode(AzToolsFramework::QtEventToAzInputMapper::CursorModeCaptured); + m_inputChannelMapper->SetCursorMode(AzToolsFramework::CursorInputMode::CursorModeCaptured); } void ViewportMouseCursorRequestImpl::EndCursorCapture() { - m_inputChannelMapper->SetCursorMode(AzToolsFramework::QtEventToAzInputMapper::CursorModeNone); + m_inputChannelMapper->SetCursorMode(AzToolsFramework::CursorInputMode::CursorModeNone); } bool ViewportMouseCursorRequestImpl::IsMouseOver() const diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Viewport/RenderViewportWidget.cpp b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Viewport/RenderViewportWidget.cpp index ef23560d57..d6871a8795 100644 --- a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Viewport/RenderViewportWidget.cpp +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Viewport/RenderViewportWidget.cpp @@ -331,12 +331,12 @@ namespace AtomToolsFramework void RenderViewportWidget::BeginCursorCapture() { - m_inputChannelMapper->SetCursorMode(AzToolsFramework::QtEventToAzInputMapper::CursorModeCaptured); + m_inputChannelMapper->SetCursorMode(AzToolsFramework::CursorInputMode::CursorModeCaptured); } void RenderViewportWidget::EndCursorCapture() { - m_inputChannelMapper->SetCursorMode(AzToolsFramework::QtEventToAzInputMapper::CursorModeNone); + m_inputChannelMapper->SetCursorMode(AzToolsFramework::CursorInputMode::CursorModeNone); } void RenderViewportWidget::SetOverrideCursor(AzToolsFramework::ViewportInteraction::CursorStyleOverride cursorStyleOverride) From ed39c784c304c0cf9a374b297f3521f7f0787fc2 Mon Sep 17 00:00:00 2001 From: Michael Pollind Date: Sun, 19 Dec 2021 18:22:14 -0800 Subject: [PATCH 07/11] chore: add accumulated test for mouse position Signed-off-by: Michael Pollind --- .../Tests/Input/QtEventToAzInputMapperTests.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Code/Framework/AzToolsFramework/Tests/Input/QtEventToAzInputMapperTests.cpp b/Code/Framework/AzToolsFramework/Tests/Input/QtEventToAzInputMapperTests.cpp index 0282812be7..5047c19044 100644 --- a/Code/Framework/AzToolsFramework/Tests/Input/QtEventToAzInputMapperTests.cpp +++ b/Code/Framework/AzToolsFramework/Tests/Input/QtEventToAzInputMapperTests.cpp @@ -100,6 +100,11 @@ namespace UnitTest m_azChannelEvents.push_back(AzEventInfo(inputChannel)); hasBeenConsumed = m_captureAzEvents; } + else if (inputChannelId == AzFramework::InputDeviceMouse::SystemCursorPosition) + { + m_azCursorPositions.push_back(*inputChannel.GetCustomData()); + hasBeenConsumed = m_captureAzEvents; + } } else if (AzFramework::InputDeviceKeyboard::IsKeyboardDevice(inputDeviceId)) { @@ -165,6 +170,7 @@ namespace UnitTest AZStd::vector m_signalEvents; AZStd::vector m_azChannelEvents; AZStd::vector m_azTextEvents; + AZStd::vector m_azCursorPositions; bool m_captureAzEvents{ false }; bool m_captureTextEvents{ false }; @@ -549,13 +555,14 @@ namespace UnitTest const MouseMoveParam mouseMoveParam = GetParam(); AzFramework::InputChannelNotificationBus::Handler::BusConnect(); - m_captureAzEvents = false; + m_captureAzEvents = true; m_rootWidget->move(100, 100); mouseMoveFix(m_rootWidget.get(), m_rootWidget->mapToGlobal(mouseMoveParam.startPos), QPoint(0, 0)); // given m_inputChannelMapper->SetCursorMode(mouseMoveParam.mode); + m_azCursorPositions.clear(); mouseMoveFix(m_rootWidget.get(), m_rootWidget->mapToGlobal(mouseMoveParam.startPos), QPoint(0, 0)); for (float i = 0; i < mouseMoveParam.iterations; i++) @@ -563,11 +570,19 @@ namespace UnitTest mouseMoveFix(m_rootWidget.get(), QCursor::pos(), (mouseMoveParam.deltaPos / mouseMoveParam.iterations)); } + AZ::Vector2 accumalatedPosition(0.0f,0.0f); + for(const auto& pos: m_azCursorPositions) { + accumalatedPosition += (pos.m_normalizedPositionDelta * AZ::Vector2(WidgetSize.width(), WidgetSize.height())); + } + // validate QPoint endPosition = m_rootWidget->mapFromGlobal(QCursor::pos()); EXPECT_NEAR(endPosition.x(), mouseMoveParam.expectedPos.x(), 1.0f); EXPECT_NEAR(endPosition.y(), mouseMoveParam.expectedPos.y(), 1.0f); + EXPECT_NEAR(accumalatedPosition.GetX(), mouseMoveParam.deltaPos.x(), 1.0f); + EXPECT_NEAR(accumalatedPosition.GetY(), mouseMoveParam.deltaPos.y(), 1.0f); + // cleanup m_rootWidget->move(0, 0); m_inputChannelMapper->SetCursorMode(AzToolsFramework::CursorInputMode::CursorModeNone); From c65a903c7dc8ae5ce441df130f26e735534dd6bd Mon Sep 17 00:00:00 2001 From: Michael Pollind Date: Sat, 8 Jan 2022 21:01:29 -0800 Subject: [PATCH 08/11] chore: fix unit test Signed-off-by: Michael Pollind --- .../Input/QtEventToAzInputMapperTests.cpp | 26 ++++++------------- 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/Code/Framework/AzToolsFramework/Tests/Input/QtEventToAzInputMapperTests.cpp b/Code/Framework/AzToolsFramework/Tests/Input/QtEventToAzInputMapperTests.cpp index 5047c19044..d7ab896462 100644 --- a/Code/Framework/AzToolsFramework/Tests/Input/QtEventToAzInputMapperTests.cpp +++ b/Code/Framework/AzToolsFramework/Tests/Input/QtEventToAzInputMapperTests.cpp @@ -541,15 +541,6 @@ namespace UnitTest TEST_P(MoveMoveWrapParamQtEventToAzInputMapperFixture, MouseMove_NoAzHandlers_VerifyMouseMovementViewport) { - //TODO: mouseMove is bugged mapToGlobal is called twice - auto mouseMoveFix = [](QWidget* wid, QPoint globalPos, QPoint deltaPos) - { - QPoint globalPosition = globalPos + deltaPos; - QPoint localPosition = wid->mapFromGlobal(globalPosition); - QTest::mouseMove(wid, localPosition); - QMouseEvent mouseMoveEvent(QEvent::MouseMove, localPosition, globalPosition, Qt::NoButton, Qt::NoButton, Qt::NoModifier); - QApplication::sendEvent(wid, &mouseMoveEvent); - }; // setup const MouseMoveParam mouseMoveParam = GetParam(); @@ -558,30 +549,29 @@ namespace UnitTest m_captureAzEvents = true; m_rootWidget->move(100, 100); - mouseMoveFix(m_rootWidget.get(), m_rootWidget->mapToGlobal(mouseMoveParam.startPos), QPoint(0, 0)); + QScreen* screen = m_rootWidget->screen(); + MouseMove(m_rootWidget.get(), mouseMoveParam.startPos, QPoint(0, 0)); // given m_inputChannelMapper->SetCursorMode(mouseMoveParam.mode); m_azCursorPositions.clear(); - - mouseMoveFix(m_rootWidget.get(), m_rootWidget->mapToGlobal(mouseMoveParam.startPos), QPoint(0, 0)); for (float i = 0; i < mouseMoveParam.iterations; i++) { - mouseMoveFix(m_rootWidget.get(), QCursor::pos(), (mouseMoveParam.deltaPos / mouseMoveParam.iterations)); + MouseMove(m_rootWidget.get(), m_rootWidget->mapFromGlobal(QCursor::pos(screen)), (mouseMoveParam.deltaPos / mouseMoveParam.iterations)); } - AZ::Vector2 accumalatedPosition(0.0f,0.0f); + AZ::Vector2 accumulatedPosition(0.0f,0.0f); for(const auto& pos: m_azCursorPositions) { - accumalatedPosition += (pos.m_normalizedPositionDelta * AZ::Vector2(WidgetSize.width(), WidgetSize.height())); + accumulatedPosition += (pos.m_normalizedPositionDelta * AZ::Vector2(WidgetSize.width(), WidgetSize.height())); } // validate - QPoint endPosition = m_rootWidget->mapFromGlobal(QCursor::pos()); + const QPoint endPosition = m_rootWidget->mapFromGlobal(QCursor::pos(screen)); EXPECT_NEAR(endPosition.x(), mouseMoveParam.expectedPos.x(), 1.0f); EXPECT_NEAR(endPosition.y(), mouseMoveParam.expectedPos.y(), 1.0f); - EXPECT_NEAR(accumalatedPosition.GetX(), mouseMoveParam.deltaPos.x(), 1.0f); - EXPECT_NEAR(accumalatedPosition.GetY(), mouseMoveParam.deltaPos.y(), 1.0f); + EXPECT_NEAR(accumulatedPosition.GetX(), mouseMoveParam.deltaPos.x(), 1.0f); + EXPECT_NEAR(accumulatedPosition.GetY(), mouseMoveParam.deltaPos.y(), 1.0f); // cleanup m_rootWidget->move(0, 0); From fabb2b186c4d3f0b9cd2aa49a1233977fa796e12 Mon Sep 17 00:00:00 2001 From: Michael Pollind Date: Wed, 12 Jan 2022 20:52:57 -0800 Subject: [PATCH 09/11] chore: disable mouse move test Signed-off-by: Michael Pollind --- .../Tests/Input/QtEventToAzInputMapperTests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Code/Framework/AzToolsFramework/Tests/Input/QtEventToAzInputMapperTests.cpp b/Code/Framework/AzToolsFramework/Tests/Input/QtEventToAzInputMapperTests.cpp index d7ab896462..31193f6f05 100644 --- a/Code/Framework/AzToolsFramework/Tests/Input/QtEventToAzInputMapperTests.cpp +++ b/Code/Framework/AzToolsFramework/Tests/Input/QtEventToAzInputMapperTests.cpp @@ -539,7 +539,7 @@ namespace UnitTest { }; - TEST_P(MoveMoveWrapParamQtEventToAzInputMapperFixture, MouseMove_NoAzHandlers_VerifyMouseMovementViewport) + TEST_P(MoveMoveWrapParamQtEventToAzInputMapperFixture, DISABLED_MouseMove_NoAzHandlers_VerifyMouseMovementViewport) { // setup From 1643c68fa7f133ff68eb7405e43e5a22f2901de5 Mon Sep 17 00:00:00 2001 From: Michael Pollind Date: Sun, 23 Jan 2022 18:26:31 -0800 Subject: [PATCH 10/11] chore: fix compiling errors Signed-off-by: Michael Pollind --- .../Input/QtEventToAzInputMapperTests.cpp | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/Code/Framework/AzToolsFramework/Tests/Input/QtEventToAzInputMapperTests.cpp b/Code/Framework/AzToolsFramework/Tests/Input/QtEventToAzInputMapperTests.cpp index 31193f6f05..78a08af6cb 100644 --- a/Code/Framework/AzToolsFramework/Tests/Input/QtEventToAzInputMapperTests.cpp +++ b/Code/Framework/AzToolsFramework/Tests/Input/QtEventToAzInputMapperTests.cpp @@ -562,7 +562,7 @@ namespace UnitTest AZ::Vector2 accumulatedPosition(0.0f,0.0f); for(const auto& pos: m_azCursorPositions) { - accumulatedPosition += (pos.m_normalizedPositionDelta * AZ::Vector2(WidgetSize.width(), WidgetSize.height())); + accumulatedPosition += (pos.m_normalizedPositionDelta * AZ::Vector2((float)WidgetSize.width(), (float)WidgetSize.height())); } // validate @@ -584,106 +584,106 @@ namespace UnitTest // verify CursorModeWrappedX wrapping MouseMoveParam {AzToolsFramework::CursorInputMode::CursorModeWrappedX, 40, - QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() - 20, QtEventToAzInputMapperFixture::WidgetSize.height()/2.0f), + QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() - 20, QtEventToAzInputMapperFixture::WidgetSize.height() / 2), QPoint(40, 0), - QPoint(20, QtEventToAzInputMapperFixture::WidgetSize.height()/2.0f), + QPoint(20, QtEventToAzInputMapperFixture::WidgetSize.height() / 2), "CursorModeWrappedX_Test_Right" }, MouseMoveParam {AzToolsFramework::CursorInputMode::CursorModeWrappedX, 40, - QPoint(20, QtEventToAzInputMapperFixture::WidgetSize.height()/2.0f), + QPoint(20, QtEventToAzInputMapperFixture::WidgetSize.height() / 2), QPoint(-40, 0), - QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() - 20, QtEventToAzInputMapperFixture::WidgetSize.height()/2.0f), + QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() - 20, QtEventToAzInputMapperFixture::WidgetSize.height()/2), "CursorModeWrappedX_Test_Left" }, MouseMoveParam {AzToolsFramework::CursorInputMode::CursorModeWrappedX, 40, - QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2.0f, 20.0f), + QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2, 20), QPoint(0, -40), - QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2.0f, -20.0f), + QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2, -20), "CursorModeWrappedX_Test_Top" }, MouseMoveParam {AzToolsFramework::CursorInputMode::CursorModeWrappedX, 40, - QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2.0f, QtEventToAzInputMapperFixture::WidgetSize.height() - 20), + QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2, QtEventToAzInputMapperFixture::WidgetSize.height() - 20), QPoint(0, 40), - QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2.0f, QtEventToAzInputMapperFixture::WidgetSize.height() + 20), + QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2, QtEventToAzInputMapperFixture::WidgetSize.height() + 20), "CursorModeWrappedX_Test_Bottom" }, // verify CursorModeWrappedY wrapping MouseMoveParam {AzToolsFramework::CursorInputMode::CursorModeWrappedY, 40, - QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() - 20, QtEventToAzInputMapperFixture::WidgetSize.height()/2.0f), + QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() - 20, QtEventToAzInputMapperFixture::WidgetSize.height()/2), QPoint(40, 0), - QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() + 20, QtEventToAzInputMapperFixture::WidgetSize.height()/2.0f), + QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() + 20, QtEventToAzInputMapperFixture::WidgetSize.height()/2), "CursorModeWrappedY_Test_Right" }, MouseMoveParam {AzToolsFramework::CursorInputMode::CursorModeWrappedY, 40, - QPoint(20, QtEventToAzInputMapperFixture::WidgetSize.height()/2.0f), + QPoint(20, QtEventToAzInputMapperFixture::WidgetSize.height() / 2), QPoint(-40, 0), - QPoint(-20, QtEventToAzInputMapperFixture::WidgetSize.height()/2.0f), + QPoint(-20, QtEventToAzInputMapperFixture::WidgetSize.height() / 2), "CursorModeWrappedY_Test_Left" }, MouseMoveParam {AzToolsFramework::CursorInputMode::CursorModeWrappedY, 40, - QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2.0f, 20.0f), + QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2, 20), QPoint(0, -40), - QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2.0f, QtEventToAzInputMapperFixture::WidgetSize.height() - 20.0f), + QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2, QtEventToAzInputMapperFixture::WidgetSize.height() - 20), "CursorModeWrappedY_Test_Top" }, MouseMoveParam {AzToolsFramework::CursorInputMode::CursorModeWrappedY, 40, - QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2.0f, QtEventToAzInputMapperFixture::WidgetSize.height() - 20), + QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2, QtEventToAzInputMapperFixture::WidgetSize.height() - 20), QPoint(0, 40), - QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2.0f, 20), + QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2, 20), "CursorModeWrappedY_Test_Bottom" }, // verify CursorModeWrapped wrapping MouseMoveParam {AzToolsFramework::CursorInputMode::CursorModeWrapped, 40, - QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() - 20, QtEventToAzInputMapperFixture::WidgetSize.height()/2.0f), + QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() - 20, QtEventToAzInputMapperFixture::WidgetSize.height()/2), QPoint(40, 0), - QPoint(20, QtEventToAzInputMapperFixture::WidgetSize.height()/2.0f), + QPoint(20, QtEventToAzInputMapperFixture::WidgetSize.height()/2), "CursorModeWrapped_Test_Right" }, MouseMoveParam {AzToolsFramework::CursorInputMode::CursorModeWrapped, 40, - QPoint(20, QtEventToAzInputMapperFixture::WidgetSize.height()/2.0f), + QPoint(20, QtEventToAzInputMapperFixture::WidgetSize.height() / 2), QPoint(-40, 0), - QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() - 20, QtEventToAzInputMapperFixture::WidgetSize.height()/2.0f), + QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() - 20, QtEventToAzInputMapperFixture::WidgetSize.height()/2), "CursorModeWrapped_Test_Left" }, MouseMoveParam {AzToolsFramework::CursorInputMode::CursorModeWrapped, 40, - QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2.0f, 20.0f), + QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2, 20), QPoint(0, -40), - QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2.0f, QtEventToAzInputMapperFixture::WidgetSize.height() - 20.0f), + QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2, QtEventToAzInputMapperFixture::WidgetSize.height() - 20), "CursorModeWrapped_Test_Top" }, MouseMoveParam {AzToolsFramework::CursorInputMode::CursorModeWrapped, 40, - QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2.0f, QtEventToAzInputMapperFixture::WidgetSize.height() - 20), + QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2, QtEventToAzInputMapperFixture::WidgetSize.height() - 20), QPoint(0, 40), - QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2.0f, 20), + QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2, 20), "CursorModeWrapped_Test_Bottom" }, // verify CursorModeCaptured MouseMoveParam {AzToolsFramework::CursorInputMode::CursorModeCaptured, 40, - QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2.0f, QtEventToAzInputMapperFixture::WidgetSize.height() / 2.0f), + QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2, QtEventToAzInputMapperFixture::WidgetSize.height() / 2), QPoint(0, 40), - QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2.0f, QtEventToAzInputMapperFixture::WidgetSize.height() / 2.0f), + QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2, QtEventToAzInputMapperFixture::WidgetSize.height() / 2), "CursorModeCaptured" }, // verify CursorModeNone MouseMoveParam {AzToolsFramework::CursorInputMode::CursorModeNone, 40, - QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2.0f, QtEventToAzInputMapperFixture::WidgetSize.height() / 2.0f), - QPoint(40.0f, 0), - QPoint((QtEventToAzInputMapperFixture::WidgetSize.width() / 2.0f) + 40.0f, (QtEventToAzInputMapperFixture::WidgetSize.height() / 2.0f)), + QPoint(QtEventToAzInputMapperFixture::WidgetSize.width() / 2, QtEventToAzInputMapperFixture::WidgetSize.height() / 2), + QPoint(40, 0), + QPoint((QtEventToAzInputMapperFixture::WidgetSize.width() / 2) + 40, (QtEventToAzInputMapperFixture::WidgetSize.height() / 2)), "CursorModeNone" } ), From 7b649656bc870de433e0d6a8db6eb63b230a6cc5 Mon Sep 17 00:00:00 2001 From: Michael Pollind Date: Mon, 24 Jan 2022 07:30:39 -0800 Subject: [PATCH 11/11] chore: use numeric cast for QtEventTOAzInputMapperTest Signed-off-by: Michael Pollind --- .../Tests/Input/QtEventToAzInputMapperTests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Code/Framework/AzToolsFramework/Tests/Input/QtEventToAzInputMapperTests.cpp b/Code/Framework/AzToolsFramework/Tests/Input/QtEventToAzInputMapperTests.cpp index 78a08af6cb..8222a115f6 100644 --- a/Code/Framework/AzToolsFramework/Tests/Input/QtEventToAzInputMapperTests.cpp +++ b/Code/Framework/AzToolsFramework/Tests/Input/QtEventToAzInputMapperTests.cpp @@ -562,7 +562,7 @@ namespace UnitTest AZ::Vector2 accumulatedPosition(0.0f,0.0f); for(const auto& pos: m_azCursorPositions) { - accumulatedPosition += (pos.m_normalizedPositionDelta * AZ::Vector2((float)WidgetSize.width(), (float)WidgetSize.height())); + accumulatedPosition += (pos.m_normalizedPositionDelta * AZ::Vector2(aznumeric_cast(WidgetSize.width()), aznumeric_cast(WidgetSize.height()))); } // validate