chore: address changes add test cases
Signed-off-by: Michael Pollind <mpollind@gmail.com>
This commit is contained in:
@@ -189,7 +189,7 @@ namespace SandboxEditor
|
|||||||
|
|
||||||
bool ViewportMouseWrapSetting()
|
bool ViewportMouseWrapSetting()
|
||||||
{
|
{
|
||||||
return aznumeric_cast<bool>(GetRegistry(ViewportMouseWrapSetting, false));
|
return GetRegistry(ViewportMouseWrapSetting, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetViewportMouseWrapSetting(bool wrapping)
|
void SetViewportMouseWrapSetting(bool wrapping)
|
||||||
|
|||||||
@@ -241,7 +241,7 @@ namespace AzToolsFramework
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtEventToAzInputMapper::SetCursorMode(QtEventToAzInputMapper::CursorInputMode mode)
|
void QtEventToAzInputMapper::SetCursorMode(AzToolsFramework::CursorInputMode mode)
|
||||||
{
|
{
|
||||||
if (mode != m_cursorMode)
|
if (mode != m_cursorMode)
|
||||||
{
|
{
|
||||||
@@ -445,7 +445,7 @@ namespace AzToolsFramework
|
|||||||
return QPoint{ denormalizedX, denormalizedY };
|
return QPoint{ denormalizedX, denormalizedY };
|
||||||
}
|
}
|
||||||
|
|
||||||
void wrapCursorX(const QRect& rect, QPoint& point)
|
void WrapCursorX(const QRect& rect, QPoint& point)
|
||||||
{
|
{
|
||||||
if (point.x() < rect.left())
|
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())
|
if (point.y() < rect.top())
|
||||||
{
|
{
|
||||||
@@ -492,14 +492,14 @@ namespace AzToolsFramework
|
|||||||
switch (m_cursorMode)
|
switch (m_cursorMode)
|
||||||
{
|
{
|
||||||
case CursorInputMode::CursorModeWrappedX:
|
case CursorInputMode::CursorModeWrappedX:
|
||||||
wrapCursorX(widgetRect, screenPos);
|
WrapCursorX(widgetRect, screenPos);
|
||||||
break;
|
break;
|
||||||
case CursorInputMode::CursorModeWrappedY:
|
case CursorInputMode::CursorModeWrappedY:
|
||||||
wrapCursorY(widgetRect, screenPos);
|
WrapCursorY(widgetRect, screenPos);
|
||||||
break;
|
break;
|
||||||
case CursorInputMode::CursorModeWrapped:
|
case CursorInputMode::CursorModeWrapped:
|
||||||
wrapCursorX(widgetRect, screenPos);
|
WrapCursorX(widgetRect, screenPos);
|
||||||
wrapCursorY(widgetRect, screenPos);
|
WrapCursorY(widgetRect, screenPos);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// this should never happen
|
// this should never happen
|
||||||
|
|||||||
@@ -32,6 +32,17 @@ class QWheelEvent;
|
|||||||
|
|
||||||
namespace AzToolsFramework
|
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
|
//! Maps events from the Qt input system to synthetic InputChannels in AzFramework
|
||||||
//! that can be used by AzFramework::ViewportControllers.
|
//! that can be used by AzFramework::ViewportControllers.
|
||||||
class QtEventToAzInputMapper final
|
class QtEventToAzInputMapper final
|
||||||
@@ -41,17 +52,6 @@ namespace AzToolsFramework
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
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(QWidget* sourceWidget, int syntheticDeviceId = 0);
|
||||||
~QtEventToAzInputMapper() = default;
|
~QtEventToAzInputMapper() = default;
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ namespace AzToolsFramework
|
|||||||
void SetCursorCaptureEnabled(bool enabled);
|
void SetCursorCaptureEnabled(bool enabled);
|
||||||
|
|
||||||
//! Set the cursor mode.
|
//! Set the cursor mode.
|
||||||
void SetCursorMode(QtEventToAzInputMapper::CursorInputMode mode);
|
void SetCursorMode(AzToolsFramework::CursorInputMode mode);
|
||||||
|
|
||||||
void SetOverrideCursor(ViewportInteraction::CursorStyleOverride cursorStyleOverride);
|
void SetOverrideCursor(ViewportInteraction::CursorStyleOverride cursorStyleOverride);
|
||||||
void ClearOverrideCursor();
|
void ClearOverrideCursor();
|
||||||
@@ -192,7 +192,7 @@ namespace AzToolsFramework
|
|||||||
// Flags whether or not Qt events should currently be processed.
|
// Flags whether or not Qt events should currently be processed.
|
||||||
bool m_enabled = true;
|
bool m_enabled = true;
|
||||||
// Controls the cursor behavior.
|
// Controls the cursor behavior.
|
||||||
QtEventToAzInputMapper::CursorInputMode m_cursorMode = CursorInputMode::CursorModeNone;
|
AzToolsFramework::CursorInputMode m_cursorMode = AzToolsFramework::CursorInputMode::CursorModeNone;
|
||||||
// Flags whether the cursor has been overridden.
|
// Flags whether the cursor has been overridden.
|
||||||
bool m_overrideCursor = false;
|
bool m_overrideCursor = false;
|
||||||
|
|
||||||
|
|||||||
@@ -44,10 +44,10 @@ namespace UnitTest
|
|||||||
QObject::connect(m_inputChannelMapper.get(), &AzToolsFramework::QtEventToAzInputMapper::InputChannelUpdated, m_rootWidget.get(),
|
QObject::connect(m_inputChannelMapper.get(), &AzToolsFramework::QtEventToAzInputMapper::InputChannelUpdated, m_rootWidget.get(),
|
||||||
[this]([[maybe_unused]] const AzFramework::InputChannel* inputChannel, QEvent* event)
|
[this]([[maybe_unused]] const AzFramework::InputChannel* inputChannel, QEvent* event)
|
||||||
{
|
{
|
||||||
if(event == nullptr) {
|
if(event == nullptr)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QEvent::Type eventType = event->type();
|
const QEvent::Type eventType = event->type();
|
||||||
|
|
||||||
if (eventType == QEvent::Type::MouseButtonPress ||
|
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<MouseMoveParam>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST_P(MoveMoveWrapParamQtEventToAzInputMapperFixture, MouseMove_NoAzHandlers_VerifyMouseMovmentViewport)
|
||||||
|
{
|
||||||
|
// setup
|
||||||
|
const MouseMoveParam mouseMoveParam = GetParam();
|
||||||
|
|
||||||
AzFramework::InputChannelNotificationBus::Handler::BusConnect();
|
AzFramework::InputChannelNotificationBus::Handler::BusConnect();
|
||||||
m_captureAzEvents = false;
|
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);
|
MouseMove(m_rootWidget.get(), mouseMoveParam.startPos, QPoint(0,0));
|
||||||
const auto expectedPosition = m_rootWidget->mapToGlobal(QPoint(200, WidgetSize.height() / 2));
|
for(float i = 0; i < mouseMoveParam.iterations; i++) {
|
||||||
const int iterations = 50;
|
MouseMove(m_rootWidget.get(), m_rootWidget->mapFromGlobal(QCursor::pos()), (mouseMoveParam.deltaPos / mouseMoveParam.iterations));
|
||||||
|
|
||||||
for(float i = 0; i < iterations; i++) {
|
|
||||||
MouseMove(m_rootWidget.get(), m_rootWidget->mapFromGlobal(QCursor::pos()), (deltaPos / iterations));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QPointF endPosition = QCursor::pos();
|
QPointF endPosition = m_rootWidget->mapFromGlobal(QCursor::pos());
|
||||||
EXPECT_NEAR(endPosition.x(), expectedPosition.x(), 5.0f);
|
EXPECT_NEAR(endPosition.x(), mouseMoveParam.expectedPos.x(), 1.0f);
|
||||||
EXPECT_NEAR(endPosition.y(), expectedPosition.y(), 5.0f);
|
EXPECT_NEAR(endPosition.y(), mouseMoveParam.expectedPos.y(), 1.0f);
|
||||||
|
|
||||||
// cleanup
|
// cleanup
|
||||||
m_inputChannelMapper->SetCursorMode(AzToolsFramework::QtEventToAzInputMapper::CursorInputMode::CursorModeNone);
|
m_rootWidget->move(0, 0);
|
||||||
|
m_inputChannelMapper->SetCursorMode(AzToolsFramework::CursorInputMode::CursorModeNone);
|
||||||
AzFramework::InputChannelNotificationBus::Handler::BusDisconnect();
|
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<MouseMoveParam>& info)
|
||||||
|
{
|
||||||
|
return info.param.name;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
} // namespace UnitTest
|
} // namespace UnitTest
|
||||||
|
|||||||
Reference in New Issue
Block a user