/
redgpu
/
ezEngine
Обзор
Документация
Войти
/
redgpu
/
ezEngine
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
Code/Editor/EditorFramework/InputContexts/Implementation/OrthoGizmoContext.cpp
170 строк
5 KB
Jan Krassnigg
Adjusted modifiers for gizmos to prevent unwanted input (#1249)
04 апр 2024, 12:40
Не верифицирован
04 апр 2024, 12:40
f30a13b
Код
Авторство
О чём код?
#include <EditorFramework/EditorFrameworkPCH.h> #include <EditorFramework/Assets/AssetDocument.h> #include <EditorFramework/DocumentWindow/EngineDocumentWindow.moc.h> #include <EditorFramework/DocumentWindow/EngineViewWidget.moc.h> #include <EditorFramework/Gizmos/SnapProvider.h> #include <EditorFramework/InputContexts/OrthoGizmoContext.h> EZ_BEGIN_DYNAMIC_REFLECTED_TYPE(ezOrthoGizmoContext, 1, ezRTTINoAllocator) EZ_END_DYNAMIC_REFLECTED_TYPE; ezOrthoGizmoContext::ezOrthoGizmoContext(ezQtEngineDocumentWindow* pOwnerWindow, ezQtEngineViewWidget* pOwnerView, const ezCamera* pCamera) { m_pCamera = pCamera; m_bCanInteract = false; SetOwner(pOwnerWindow, pOwnerView); } void ezOrthoGizmoContext::FocusLost(bool bCancel) { ezGizmoEvent e; e.m_pGizmo = this; e.m_Type = bCancel ? ezGizmoEvent::Type::CancelInteractions : ezGizmoEvent::Type::EndInteractions; m_GizmoEvents.Broadcast(e); m_bCanInteract = false; SetActiveInputContext(nullptr); ezEditorInputContext::FocusLost(bCancel); } ezEditorInput ezOrthoGizmoContext::DoMousePressEvent(QMouseEvent* e) { if (!IsViewInOrthoMode()) return ezEditorInput::MayBeHandledByOthers; if (GetOwnerWindow()->GetDocument()->GetSelectionManager()->IsSelectionEmpty()) return ezEditorInput::MayBeHandledByOthers; if (e->button() == Qt::MouseButton::LeftButton) { m_bCanInteract = true; } return ezEditorInput::MayBeHandledByOthers; } ezEditorInput ezOrthoGizmoContext::DoMouseReleaseEvent(QMouseEvent* e) { if (!IsActiveInputContext()) { m_bCanInteract = false; return ezEditorInput::MayBeHandledByOthers; } if (e->button() == Qt::MouseButton::LeftButton) { FocusLost(false); return ezEditorInput::WasExclusivelyHandled; } return ezEditorInput::MayBeHandledByOthers; } ezEditorInput ezOrthoGizmoContext::DoMouseMoveEvent(QMouseEvent* e) { if (!e->buttons().testFlag(Qt::MouseButton::LeftButton)) { m_bCanInteract = false; return ezEditorInput::MayBeHandledByOthers; } if (IsActiveInputContext()) { float fDistPerPixel = 0; if (m_pCamera->GetCameraMode() == ezCameraMode::OrthoFixedHeight) fDistPerPixel = m_pCamera->GetFovOrDim() / (float)GetOwnerView()->size().height(); if (m_pCamera->GetCameraMode() == ezCameraMode::OrthoFixedWidth) fDistPerPixel = m_pCamera->GetFovOrDim() / (float)GetOwnerView()->size().width(); const ezVec3 vLastTranslationResult = m_vTranslationResult; const QPoint mousePosition = e->globalPosition().toPoint(); const ezVec2I32 diff = ezVec2I32(mousePosition.x(), mousePosition.y()) - m_vLastMousePos; m_vUnsnappedTranslationResult += m_pCamera->GetDirRight() * (float)diff.x * fDistPerPixel; m_vUnsnappedTranslationResult -= m_pCamera->GetDirUp() * (float)diff.y * fDistPerPixel; m_vTranslationResult = m_vUnsnappedTranslationResult; // disable snapping when SHIFT is pressed if (!e->modifiers().testFlag(Qt::ShiftModifier)) ezSnapProvider::SnapTranslation(m_vTranslationResult); m_vTranslationDiff = m_vTranslationResult - vLastTranslationResult; m_UnsnappedRotationResult += ezAngle::MakeFromDegree(-diff.x); ezAngle snappedRotation = m_UnsnappedRotationResult; // disable snapping when SHIFT is pressed if (!e->modifiers().testFlag(Qt::ShiftModifier)) ezSnapProvider::SnapRotation(snappedRotation); m_qRotationResult = ezQuat::MakeFromAxisAndAngle(m_pCamera->GetDirForwards(), snappedRotation); { m_fScaleMouseMove += diff.x; m_fUnsnappedScalingResult = 1.0f; const float fScaleSpeed = 0.01f; if (m_fScaleMouseMove > 0.0f) m_fUnsnappedScalingResult = 1.0f + m_fScaleMouseMove * fScaleSpeed; if (m_fScaleMouseMove < 0.0f) m_fUnsnappedScalingResult = 1.0f / (1.0f - m_fScaleMouseMove * fScaleSpeed); m_fScalingResult = m_fUnsnappedScalingResult; // disable snapping when SHIFT is pressed if (!e->modifiers().testFlag(Qt::ShiftModifier)) ezSnapProvider::SnapScale(m_fScalingResult); } m_vLastMousePos = UpdateMouseMode(e); ezGizmoEvent ev; ev.m_pGizmo = this; ev.m_Type = ezGizmoEvent::Type::Interaction; m_GizmoEvents.Broadcast(ev); return ezEditorInput::WasExclusivelyHandled; } if (m_bCanInteract) { m_vLastMousePos = SetMouseMode(ezEditorInputContext::MouseMode::WrapAtScreenBorders); m_vTranslationResult.SetZero(); m_vUnsnappedTranslationResult.SetZero(); m_qRotationResult.SetIdentity(); m_UnsnappedRotationResult = ezAngle::MakeFromRadian(0.0f); m_fScalingResult = 1.0f; m_fUnsnappedScalingResult = 1.0f; m_fScaleMouseMove = 0.0f; m_bCanInteract = false; SetActiveInputContext(this); ezGizmoEvent ev; ev.m_pGizmo = this; ev.m_Type = ezGizmoEvent::Type::BeginInteractions; m_GizmoEvents.Broadcast(ev); return ezEditorInput::WasExclusivelyHandled; } return ezEditorInput::MayBeHandledByOthers; } bool ezOrthoGizmoContext::IsViewInOrthoMode() const { return (GetOwnerView()->m_pViewConfig->m_Perspective != ezSceneViewPerspective::Perspective); }