EditorPreferencesPageViewportManipulator.cpp 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include "EditorDefs.h"
  9. #include "EditorPreferencesPageViewportManipulator.h"
  10. #include <AzCore/Serialization/EditContext.h>
  11. #include <AzToolsFramework/Viewport/ViewportSettings.h>
  12. // Editor
  13. #include "EditorViewportSettings.h"
  14. #include "Settings.h"
  15. void CEditorPreferencesPage_ViewportManipulator::Reflect(AZ::SerializeContext& serialize)
  16. {
  17. serialize.Class<Manipulators>()
  18. ->Version(1)
  19. ->Field("LineBoundWidth", &Manipulators::m_manipulatorLineBoundWidth)
  20. ->Field("CircleBoundWidth", &Manipulators::m_manipulatorCircleBoundWidth)
  21. ->Field("LinearManipulatorAxisLength", &Manipulators::m_linearManipulatorAxisLength)
  22. ->Field("PlanarManipulatorAxisLength", &Manipulators::m_planarManipulatorAxisLength)
  23. ->Field("SurfaceManipulatorRadius", &Manipulators::m_surfaceManipulatorRadius)
  24. ->Field("SurfaceManipulatorOpacity", &Manipulators::m_surfaceManipulatorOpacity)
  25. ->Field("LinearManipulatorConeLength", &Manipulators::m_linearManipulatorConeLength)
  26. ->Field("LinearManipulatorConeRadius", &Manipulators::m_linearManipulatorConeRadius)
  27. ->Field("ScaleManipulatorBoxHalfExtent", &Manipulators::m_scaleManipulatorBoxHalfExtent)
  28. ->Field("RotationManipulatorRadius", &Manipulators::m_rotationManipulatorRadius)
  29. ->Field("ManipulatorViewBaseScale", &Manipulators::m_manipulatorViewBaseScale)
  30. ->Field("FlipManipulatorAxesTowardsView", &Manipulators::m_flipManipulatorAxesTowardsView);
  31. serialize.Class<CEditorPreferencesPage_ViewportManipulator>()->Version(2)->Field(
  32. "Manipulators", &CEditorPreferencesPage_ViewportManipulator::m_manipulators);
  33. if (AZ::EditContext* editContext = serialize.GetEditContext())
  34. {
  35. editContext->Class<Manipulators>("Manipulators", "")
  36. ->DataElement(
  37. AZ::Edit::UIHandlers::SpinBox, &Manipulators::m_manipulatorLineBoundWidth, "Line Bound Width",
  38. "Manipulator Line Bound Width")
  39. ->Attribute(AZ::Edit::Attributes::Min, 0.001f)
  40. ->Attribute(AZ::Edit::Attributes::Max, 2.0f)
  41. ->DataElement(
  42. AZ::Edit::UIHandlers::SpinBox, &Manipulators::m_manipulatorCircleBoundWidth, "Circle Bound Width",
  43. "Manipulator Circle Bound Width")
  44. ->Attribute(AZ::Edit::Attributes::Min, 0.001f)
  45. ->Attribute(AZ::Edit::Attributes::Max, 2.0f)
  46. ->DataElement(
  47. AZ::Edit::UIHandlers::SpinBox, &Manipulators::m_linearManipulatorAxisLength, "Linear Manipulator Axis Length",
  48. "Length of default Linear Manipulator (for Translation and Scale Manipulators)")
  49. ->Attribute(AZ::Edit::Attributes::Min, 0.1f)
  50. ->Attribute(AZ::Edit::Attributes::Max, 5.0f)
  51. ->DataElement(
  52. AZ::Edit::UIHandlers::SpinBox, &Manipulators::m_planarManipulatorAxisLength, "Planar Manipulator Axis Length",
  53. "Length of default Planar Manipulator (for Translation Manipulators)")
  54. ->Attribute(AZ::Edit::Attributes::Min, 0.1f)
  55. ->Attribute(AZ::Edit::Attributes::Max, 5.0f)
  56. ->DataElement(
  57. AZ::Edit::UIHandlers::SpinBox, &Manipulators::m_surfaceManipulatorRadius, "Surface Manipulator Radius",
  58. "Radius of default Surface Manipulator (for Translation Manipulators)")
  59. ->Attribute(AZ::Edit::Attributes::Min, 0.05f)
  60. ->Attribute(AZ::Edit::Attributes::Max, 1.0f)
  61. ->DataElement(
  62. AZ::Edit::UIHandlers::SpinBox, &Manipulators::m_surfaceManipulatorOpacity, "Surface Manipulator Opacity",
  63. "Opacity of default Surface Manipulator (for Translation Manipulators)")
  64. ->Attribute(AZ::Edit::Attributes::Min, 0.01f)
  65. ->Attribute(AZ::Edit::Attributes::Max, 1.0f)
  66. ->DataElement(
  67. AZ::Edit::UIHandlers::SpinBox, &Manipulators::m_linearManipulatorConeLength, "Linear Manipulator Cone Length",
  68. "Length of cone for default Linear Manipulator (for Translation Manipulators)")
  69. ->Attribute(AZ::Edit::Attributes::Min, 0.05f)
  70. ->Attribute(AZ::Edit::Attributes::Max, 1.0f)
  71. ->DataElement(
  72. AZ::Edit::UIHandlers::SpinBox, &Manipulators::m_linearManipulatorConeRadius, "Linear Manipulator Cone Radius",
  73. "Radius of cone for default Linear Manipulator (for Translation Manipulators)")
  74. ->Attribute(AZ::Edit::Attributes::Min, 0.05f)
  75. ->Attribute(AZ::Edit::Attributes::Max, 0.5f)
  76. ->DataElement(
  77. AZ::Edit::UIHandlers::SpinBox, &Manipulators::m_scaleManipulatorBoxHalfExtent, "Scale Manipulator Box Half Extent",
  78. "Half extent of box for default Scale Manipulator")
  79. ->Attribute(AZ::Edit::Attributes::Min, 0.05f)
  80. ->Attribute(AZ::Edit::Attributes::Max, 1.0f)
  81. ->DataElement(
  82. AZ::Edit::UIHandlers::SpinBox, &Manipulators::m_rotationManipulatorRadius, "Rotation Manipulator Radius",
  83. "Radius of default Angular Manipulators (for Rotation Manipulators)")
  84. ->Attribute(AZ::Edit::Attributes::Min, 0.5f)
  85. ->Attribute(AZ::Edit::Attributes::Max, 5.0f)
  86. ->DataElement(
  87. AZ::Edit::UIHandlers::SpinBox, &Manipulators::m_manipulatorViewBaseScale, "Manipulator View Base Scale",
  88. "The base scale to apply to all Manipulator Views (default is 1.0)")
  89. ->Attribute(AZ::Edit::Attributes::Min, AzToolsFramework::MinManipulatorViewBaseScale)
  90. ->Attribute(AZ::Edit::Attributes::Max, AzToolsFramework::MaxManipulatorViewBaseScale)
  91. ->DataElement(
  92. AZ::Edit::UIHandlers::CheckBox, &Manipulators::m_flipManipulatorAxesTowardsView, "Flip Manipulator Axes Towards View",
  93. "Determines whether Planar and Linear Manipulators should switch to face the view (camera) in the Editor");
  94. editContext
  95. ->Class<CEditorPreferencesPage_ViewportManipulator>("Manipulator Viewport Preferences", "Manipulator Viewport Preferences")
  96. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  97. ->Attribute(AZ::Edit::Attributes::Visibility, AZ_CRC_CE("PropertyVisibility_ShowChildrenOnly"))
  98. ->DataElement(
  99. AZ::Edit::UIHandlers::Default, &CEditorPreferencesPage_ViewportManipulator::m_manipulators, "Manipulators", "Manipulators");
  100. }
  101. }
  102. CEditorPreferencesPage_ViewportManipulator::CEditorPreferencesPage_ViewportManipulator()
  103. {
  104. InitializeSettings();
  105. m_icon = QIcon(":/res/Gizmos.svg");
  106. }
  107. const char* CEditorPreferencesPage_ViewportManipulator::GetCategory()
  108. {
  109. return "Viewports";
  110. }
  111. const char* CEditorPreferencesPage_ViewportManipulator::GetTitle()
  112. {
  113. return "Manipulators";
  114. }
  115. QIcon& CEditorPreferencesPage_ViewportManipulator::GetIcon()
  116. {
  117. return m_icon;
  118. }
  119. void CEditorPreferencesPage_ViewportManipulator::OnCancel()
  120. {
  121. // noop
  122. }
  123. bool CEditorPreferencesPage_ViewportManipulator::OnQueryCancel()
  124. {
  125. return true;
  126. }
  127. void CEditorPreferencesPage_ViewportManipulator::OnApply()
  128. {
  129. SandboxEditor::SetManipulatorLineBoundWidth(m_manipulators.m_manipulatorLineBoundWidth);
  130. SandboxEditor::SetManipulatorCircleBoundWidth(m_manipulators.m_manipulatorCircleBoundWidth);
  131. AzToolsFramework::SetLinearManipulatorAxisLength(m_manipulators.m_linearManipulatorAxisLength);
  132. AzToolsFramework::SetPlanarManipulatorAxisLength(m_manipulators.m_planarManipulatorAxisLength);
  133. AzToolsFramework::SetSurfaceManipulatorRadius(m_manipulators.m_surfaceManipulatorRadius);
  134. AzToolsFramework::SetSurfaceManipulatorOpacity(m_manipulators.m_surfaceManipulatorOpacity);
  135. AzToolsFramework::SetLinearManipulatorConeLength(m_manipulators.m_linearManipulatorConeLength);
  136. AzToolsFramework::SetLinearManipulatorConeRadius(m_manipulators.m_linearManipulatorConeRadius);
  137. AzToolsFramework::SetScaleManipulatorBoxHalfExtent(m_manipulators.m_scaleManipulatorBoxHalfExtent);
  138. AzToolsFramework::SetRotationManipulatorRadius(m_manipulators.m_rotationManipulatorRadius);
  139. AzToolsFramework::SetFlipManipulatorAxesTowardsView(m_manipulators.m_flipManipulatorAxesTowardsView);
  140. AzToolsFramework::SetManipulatorViewBaseScale(m_manipulators.m_manipulatorViewBaseScale);
  141. }
  142. void CEditorPreferencesPage_ViewportManipulator::InitializeSettings()
  143. {
  144. m_manipulators.m_manipulatorLineBoundWidth = SandboxEditor::ManipulatorLineBoundWidth();
  145. m_manipulators.m_manipulatorCircleBoundWidth = SandboxEditor::ManipulatorCircleBoundWidth();
  146. m_manipulators.m_linearManipulatorAxisLength = AzToolsFramework::LinearManipulatorAxisLength();
  147. m_manipulators.m_planarManipulatorAxisLength = AzToolsFramework::PlanarManipulatorAxisLength();
  148. m_manipulators.m_surfaceManipulatorRadius = AzToolsFramework::SurfaceManipulatorRadius();
  149. m_manipulators.m_surfaceManipulatorOpacity = AzToolsFramework::SurfaceManipulatorOpacity();
  150. m_manipulators.m_linearManipulatorConeLength = AzToolsFramework::LinearManipulatorConeLength();
  151. m_manipulators.m_linearManipulatorConeRadius = AzToolsFramework::LinearManipulatorConeRadius();
  152. m_manipulators.m_scaleManipulatorBoxHalfExtent = AzToolsFramework::ScaleManipulatorBoxHalfExtent();
  153. m_manipulators.m_rotationManipulatorRadius = AzToolsFramework::RotationManipulatorRadius();
  154. m_manipulators.m_flipManipulatorAxesTowardsView = AzToolsFramework::FlipManipulatorAxesTowardsView();
  155. m_manipulators.m_manipulatorViewBaseScale = AzToolsFramework::ManipulatorViewBaseScale();
  156. }