chore: address changes

- updated checkstyle
- update enum CursorInputMode
- minor refeactor to QtEventToAzInputMapper

Signed-off-by: Michael Pollind <mpollind@gmail.com>
monroegm-disable-blank-issue-2
Michael Pollind 4 years ago
parent 90f710b8c2
commit fa809a76ca

@ -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<float>(GetRegistry(ManipulatorMouseWrapSetting, false));
return aznumeric_cast<bool>(GetRegistry(ViewportMouseWrapSetting, false));
}
void SetManipulatorMouseWrap(bool wrapping)
void SetViewportMouseWrapSetting(bool wrapping)
{
SetRegistry(ManipulatorMouseWrapSetting, wrapping);
SetRegistry(ViewportMouseWrapSetting, wrapping);
}
float ManipulatorCircleBoundWidth()

@ -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);

@ -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

@ -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:
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:
case CursorInputMode::CursorModeCaptured:
AzQtComponents::SetCursorPos(m_previousGlobalCursorPosition);
break;
case CursorInputMode::CursorModeWrappedX:
case CursorInputMode::CursorModeWrappedY:
case CursorInputMode::CursorModeWrapped:
{
QPoint screenPos(globalCursorPosition);
wrapCursorX(widgetRect, screenPos);
wrapCursorY(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;
default:
m_previousGlobalCursorPosition = globalCursorPosition;
break;
}
break;
default:
AZ_Assert(false, "Invalid Curosr Mode: %i.", m_cursorMode);
break;
}
ProcessPendingMouseEvents(cursorDelta);
}

@ -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;

@ -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)

Loading…
Cancel
Save