Update snapping settings to be stored in the Settings Registry (#646)

* add overload to ActionManager to support capturing an AZStd::function

* move snapping settings to new settings registry

* remove unneeded reference in ViewportSettings

* move viewport setting function implementations to .cpp file

* add more sensible default values for snapping

* fix variable name for angle snapping

* remove const from function prototype value parameters

* add import/export api for free functions

* change from std::bind to a lambda

* remove redundant const for constexpr string_view

* add AZStd alias for std::abs
This commit is contained in:
Tom Hulton-Harrop
2021-05-10 18:40:32 +01:00
committed by GitHub
parent bdaa7eb3c1
commit b2523217c3
15 changed files with 242 additions and 81 deletions
+16 -3
View File
@@ -169,6 +169,13 @@ public:
return *this;
}
template<typename Fn>
ActionWrapper& RegisterUpdateCallback(Fn&& fn)
{
m_actionManager->RegisterUpdateCallback(m_action->data().toInt(), AZStd::forward<Fn>(fn));
return *this;
}
private:
friend ActionManager;
friend DynamicMenu;
@@ -315,11 +322,17 @@ public:
void DetachOverride() override;
template<typename T>
void RegisterUpdateCallback(int id, T* object, void (T::* method)(QAction*))
void RegisterUpdateCallback(int id, T* object, void (T::*method)(QAction*))
{
Q_ASSERT(m_actions.contains(id));
auto f = std::bind(method, object, m_actions.value(id));
m_updateCallbacks[id] = f;
m_updateCallbacks[id] = [action = m_actions.value(id), object, method] { AZStd::invoke(method, object, action); };
}
template<typename Fn>
void RegisterUpdateCallback(int id, Fn&& fn)
{
Q_ASSERT(m_actions.contains(id));
m_updateCallbacks[id] = [action = m_actions.value(id), fn] { fn(action); };
}
template<typename T>
-24
View File
@@ -398,8 +398,6 @@ void CCryEditApp::RegisterActionHandlers()
ON_COMMAND(ID_GAME_SYNCPLAYER, OnSyncPlayer)
ON_COMMAND(ID_RESOURCES_REDUCEWORKINGSET, OnResourcesReduceworkingset)
ON_COMMAND(ID_SNAP_TO_GRID, OnSnap)
ON_COMMAND(ID_WIREFRAME, OnWireframe)
ON_COMMAND(ID_VIEW_GRIDSETTINGS, OnViewGridsettings)
@@ -442,7 +440,6 @@ void CCryEditApp::RegisterActionHandlers()
ON_COMMAND(ID_VIEW_CYCLE2DVIEWPORT, OnViewCycle2dviewport)
#endif
ON_COMMAND(ID_DISPLAY_GOTOPOSITION, OnDisplayGotoPosition)
ON_COMMAND(ID_SNAPANGLE, OnSnapangle)
ON_COMMAND(ID_CHANGEMOVESPEED_INCREASE, OnChangemovespeedIncrease)
ON_COMMAND(ID_CHANGEMOVESPEED_DECREASE, OnChangemovespeedDecrease)
ON_COMMAND(ID_CHANGEMOVESPEED_CHANGESTEP, OnChangemovespeedChangestep)
@@ -3423,14 +3420,6 @@ void CCryEditApp::OnResourcesReduceworkingset()
#endif
}
//////////////////////////////////////////////////////////////////////////
void CCryEditApp::OnSnap()
{
// Switch current snap to grid state.
bool bGridEnabled = gSettings.pGrid->IsEnabled();
gSettings.pGrid->Enable(!bGridEnabled);
}
void CCryEditApp::OnWireframe()
{
int nWireframe(R_SOLID_MODE);
@@ -3679,19 +3668,6 @@ void CCryEditApp::OnDisplayGotoPosition()
dlg.exec();
}
//////////////////////////////////////////////////////////////////////////
void CCryEditApp::OnSnapangle()
{
gSettings.pGrid->EnableAngleSnap(!gSettings.pGrid->IsAngleSnapEnabled());
}
//////////////////////////////////////////////////////////////////////////
void CCryEditApp::OnUpdateSnapangle(QAction* action)
{
Q_ASSERT(action->isCheckable());
action->setChecked(gSettings.pGrid->IsAngleSnapEnabled());
}
//////////////////////////////////////////////////////////////////////////
void CCryEditApp::OnChangemovespeedIncrease()
{
-3
View File
@@ -364,7 +364,6 @@ private:
AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING
friend struct PythonTestOutputHandler;
void OnSnap();
void OnWireframe();
void OnUpdateWireframe(QAction* action);
void OnViewGridsettings();
@@ -402,8 +401,6 @@ private:
void OnToolsScriptHelp();
void OnViewCycle2dviewport();
void OnDisplayGotoPosition();
void OnSnapangle();
void OnUpdateSnapangle(QAction* action);
void OnChangemovespeedIncrease();
void OnChangemovespeedDecrease();
void OnChangemovespeedChangestep();
@@ -0,0 +1,116 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <EditorViewportSettings.h>
#include <AzCore/Casting/numeric_cast.h>
#include <AzCore/Settings/SettingsRegistry.h>
#include <AzCore/std/string/string_view.h>
namespace Editor
{
constexpr AZStd::string_view GridSnappingSetting = "/Amazon/Preferences/Editor/GridSnapping";
constexpr AZStd::string_view GridSizeSetting = "/Amazon/Preferences/Editor/GridSize";
constexpr AZStd::string_view AngleSnappingSetting = "/Amazon/Preferences/Editor/AngleSnapping";
constexpr AZStd::string_view AngleSizeSetting = "/Amazon/Preferences/Editor/AngleSize";
constexpr AZStd::string_view ShowGridSetting = "/Amazon/Preferences/Editor/ShowGrid";
bool GridSnappingEnabled()
{
bool enabled = false;
if (auto* registry = AZ::SettingsRegistry::Get())
{
registry->Get(enabled, GridSnappingSetting);
}
return enabled;
}
float GridSnappingSize()
{
double gridSize = 0.1;
if (auto* registry = AZ::SettingsRegistry::Get())
{
registry->Get(gridSize, GridSizeSetting);
}
return aznumeric_cast<float>(gridSize);
}
bool AngleSnappingEnabled()
{
bool enabled = false;
if (auto* registry = AZ::SettingsRegistry::Get())
{
registry->Get(enabled, AngleSnappingSetting);
}
return enabled;
}
float AngleSnappingSize()
{
double angleSize = 5.0;
if (auto* registry = AZ::SettingsRegistry::Get())
{
registry->Get(angleSize, AngleSizeSetting);
}
return aznumeric_cast<float>(angleSize);
}
bool ShowingGrid()
{
bool enabled = false;
if (auto* registry = AZ::SettingsRegistry::Get())
{
registry->Get(enabled, ShowGridSetting);
}
return enabled;
}
void SetGridSnapping(const bool enabled)
{
if (auto* registry = AZ::SettingsRegistry::Get())
{
registry->Set(GridSnappingSetting, enabled);
}
}
void SetGridSnappingSize(const float size)
{
if (auto* registry = AZ::SettingsRegistry::Get())
{
registry->Set(GridSizeSetting, size);
}
}
void SetAngleSnapping(const bool enabled)
{
if (auto* registry = AZ::SettingsRegistry::Get())
{
registry->Set(AngleSnappingSetting, enabled);
}
}
void SetAngleSnappingSize(const float size)
{
if (auto* registry = AZ::SettingsRegistry::Get())
{
registry->Set(AngleSizeSetting, size);
}
}
void SetShowingGrid(const bool showing)
{
if (auto* registry = AZ::SettingsRegistry::Get())
{
registry->Set(ShowGridSetting, showing);
}
}
} // namespace Editor
@@ -0,0 +1,38 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <EditorCoreAPI.h>
namespace Editor
{
EDITOR_CORE_API bool GridSnappingEnabled();
EDITOR_CORE_API float GridSnappingSize();
EDITOR_CORE_API bool AngleSnappingEnabled();
EDITOR_CORE_API float AngleSnappingSize();
EDITOR_CORE_API bool ShowingGrid();
EDITOR_CORE_API void SetGridSnapping(bool enabled);
EDITOR_CORE_API void SetGridSnappingSize(float size);
EDITOR_CORE_API void SetAngleSnapping(bool enabled);
EDITOR_CORE_API void SetAngleSnappingSize(float size);
EDITOR_CORE_API void SetShowingGrid(bool showing);
} // namespace Editor
+19 -13
View File
@@ -75,6 +75,7 @@
#include "ViewportManipulatorController.h"
#include "LegacyViewportCameraController.h"
#include "ModernViewportCameraController.h"
#include "EditorViewportSettings.h"
#include "ViewPane.h"
#include "CustomResolutionDlg.h"
@@ -127,6 +128,18 @@ AZ_CVAR(
bool, ed_useNewCameraSystem, false, nullptr, AZ::ConsoleFunctorFlags::Null,
"Use the new Editor camera system (the Atom-native Editor viewport (experimental) must also be enabled)");
//! Viewport settings for the EditorViewportWidget
struct EditorViewportSettings : public AzToolsFramework::ViewportInteraction::ViewportSettings
{
bool GridSnappingEnabled() const override;
float GridSize() const override;
bool ShowGrid() const override;
bool AngleSnappingEnabled() const override;
float AngleStep() const override;
};
static const EditorViewportSettings g_EditorViewportSettings;
namespace AZ::ViewportHelpers
{
static const char TextCantCreateCameraNoLevel[] = "Cannot create camera when no level is loaded.";
@@ -170,7 +183,6 @@ EditorViewportWidget::EditorViewportWidget(const QString& name, QWidget* parent)
, m_camFOV(gSettings.viewports.fDefaultFov)
, m_defaultViewName(name)
, m_renderViewport(nullptr) //m_renderViewport is initialized later, in SetViewportId
, m_editorViewportSettings(this)
{
// need this to be set in order to allow for language switching on Windows
setAttribute(Qt::WA_InputMethodEnabled);
@@ -1246,7 +1258,7 @@ void EditorViewportWidget::SetViewportId(int id)
m_renderViewport->GetControllerList()->Add(AZStd::make_shared<SandboxEditor::LegacyViewportCameraController>());
}
m_renderViewport->SetViewportSettings(&m_editorViewportSettings);
m_renderViewport->SetViewportSettings(&g_EditorViewportSettings);
UpdateScene();
@@ -2867,35 +2879,29 @@ void EditorViewportWidget::SetAsActiveViewport()
}
}
EditorViewportSettings::EditorViewportSettings(const EditorViewportWidget* editorViewportWidget)
: m_editorViewportWidget(editorViewportWidget)
{
}
bool EditorViewportSettings::GridSnappingEnabled() const
{
return m_editorViewportWidget->GetViewManager()->GetGrid()->IsEnabled();
return Editor::GridSnappingEnabled();
}
float EditorViewportSettings::GridSize() const
{
const CGrid* grid = m_editorViewportWidget->GetViewManager()->GetGrid();
return grid->scale * grid->size;
return Editor::GridSnappingSize();
}
bool EditorViewportSettings::ShowGrid() const
{
return gSettings.viewports.bShowGridGuide;
return Editor::ShowingGrid();
}
bool EditorViewportSettings::AngleSnappingEnabled() const
{
return m_editorViewportWidget->GetViewManager()->GetGrid()->IsAngleSnapEnabled();
return Editor::AngleSnappingEnabled();
}
float EditorViewportSettings::AngleStep() const
{
return m_editorViewportWidget->GetViewManager()->GetGrid()->GetAngleSnap();
return Editor::AngleSnappingSize();
}
#include <moc_EditorViewportWidget.cpp>
@@ -65,23 +65,6 @@ namespace AzToolsFramework
class ManipulatorManager;
}
class EditorViewportWidget;
//! Viewport settings for the EditorViewportWidget
struct EditorViewportSettings : public AzToolsFramework::ViewportInteraction::ViewportSettings
{
explicit EditorViewportSettings(const EditorViewportWidget* editorViewportWidget);
bool GridSnappingEnabled() const override;
float GridSize() const override;
bool ShowGrid() const override;
bool AngleSnappingEnabled() const override;
float AngleStep() const override;
private:
const EditorViewportWidget* m_editorViewportWidget = nullptr;
};
// EditorViewportWidget window
AZ_PUSH_DISABLE_DLL_EXPORT_BASECLASS_WARNING
AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING
@@ -607,7 +590,5 @@ private:
AZ::Name m_defaultViewportContextName;
EditorViewportSettings m_editorViewportSettings;
AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING
};
+16 -6
View File
@@ -78,6 +78,7 @@ AZ_POP_DISABLE_WARNING
#include "Core/QtEditorApplication.h"
#include "UndoDropDown.h"
#include "CVarMenu.h"
#include "EditorViewportSettings.h"
#include "KeyboardCustomizationSettings.h"
#include "CustomizeKeyboardDialog.h"
@@ -915,13 +916,22 @@ void MainWindow::InitActions()
.SetToolTip(tr("Snap to grid (G)"))
.SetStatusTip(tr("Toggles snap to grid"))
.SetCheckable(true)
.RegisterUpdateCallback(this, &MainWindow::OnUpdateSnapToGrid);
.RegisterUpdateCallback([](QAction* action) {
Q_ASSERT(action->isCheckable());
action->setChecked(Editor::GridSnappingEnabled());
})
.Connect(&QAction::triggered, []() { Editor::SetGridSnapping(!Editor::GridSnappingEnabled()); });
am->AddAction(ID_SNAPANGLE, tr("Snap angle"))
.SetIcon(Style::icon("Angle"))
.SetApplyHoverEffect()
.SetStatusTip(tr("Snap angle"))
.SetCheckable(true)
.RegisterUpdateCallback(cryEdit, &CCryEditApp::OnUpdateSnapangle);
.RegisterUpdateCallback([](QAction* action) {
Q_ASSERT(action->isCheckable());
action->setChecked(Editor::AngleSnappingEnabled());
})
.Connect(&QAction::triggered, []() { Editor::SetAngleSnapping(!Editor::AngleSnappingEnabled()); });
// Display actions
am->AddAction(ID_WIREFRAME, tr("&Wireframe"))
@@ -1432,12 +1442,12 @@ QWidget* MainWindow::CreateSnapToGridWidget()
{
SnapToWidget::SetValueCallback setCallback = [](double snapStep)
{
GetIEditor()->GetViewManager()->GetGrid()->size = snapStep;
Editor::SetGridSnappingSize(snapStep);
};
SnapToWidget::GetValueCallback getCallback = []()
{
return GetIEditor()->GetViewManager()->GetGrid()->size;
return Editor::GridSnappingSize();
};
return new SnapToWidget(m_actionManager->GetAction(ID_SNAP_TO_GRID), setCallback, getCallback);
@@ -1447,12 +1457,12 @@ QWidget* MainWindow::CreateSnapToAngleWidget()
{
SnapToWidget::SetValueCallback setCallback = [](double snapAngle)
{
GetIEditor()->GetViewManager()->GetGrid()->angleSnap = snapAngle;
Editor::SetAngleSnappingSize(snapAngle);
};
SnapToWidget::GetValueCallback getCallback = []()
{
return GetIEditor()->GetViewManager()->GetGrid()->angleSnap;
return Editor::AngleSnappingSize();
};
return new SnapToWidget(m_actionManager->GetAction(ID_SNAPANGLE), setCallback, getCallback);
@@ -22,6 +22,8 @@ set(FILES
Include/IEditorMaterial.h
Include/IEditorMaterialManager.h
Include/IImageUtil.h
EditorViewportSettings.cpp
EditorViewportSettings.h
Controls/ReflectedPropertyControl/ReflectedPropertyCtrl.qrc
Controls/ReflectedPropertyControl/ReflectedPropertyCtrl.cpp
Controls/ReflectedPropertyControl/ReflectedPropertyCtrl.h