EditorPreferencesPageViewportGeneral.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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 "EditorPreferencesPageViewportGeneral.h"
  10. #include "EditorViewportSettings.h"
  11. #include <AzCore/Serialization/EditContext.h>
  12. #include <AzQtComponents/Components/StyleManager.h>
  13. // Editor
  14. #include "DisplaySettings.h"
  15. #include "Settings.h"
  16. void CEditorPreferencesPage_ViewportGeneral::Reflect(AZ::SerializeContext& serialize)
  17. {
  18. serialize.Class<General>()
  19. ->Version(1)
  20. ->Field("Sync2DViews", &General::m_sync2DViews)
  21. ->Field("DefaultFOV", &General::m_defaultFOV)
  22. ->Field("DefaultNearPlane", &General::m_defaultNearPlane)
  23. ->Field("DefaultFarPlane", &General::m_defaultFarPlane)
  24. ->Field("DefaultAspectRatio", &General::m_defaultAspectRatio)
  25. ->Field("EnableContextMenu", &General::m_contextMenuEnabled)
  26. ->Field("StickySelect", &General::m_stickySelectEnabled);
  27. serialize.Class<Display>()
  28. ->Version(1)
  29. ->Field("HighlightSelGeom", &Display::m_highlightSelGeom)
  30. ->Field("HighlightSelVegetation", &Display::m_highlightSelVegetation)
  31. ->Field("HighlightOnMouseOver", &Display::m_highlightOnMouseOver)
  32. ->Field("HideMouseCursorWhenCaptured", &Display::m_hideMouseCursorWhenCaptured)
  33. ->Field("DragSquareSize", &Display::m_dragSquareSize)
  34. ->Field("DisplayLinks", &Display::m_displayLinks)
  35. ->Field("DisplayTracks", &Display::m_displayTracks)
  36. ->Field("AlwaysShowRadii", &Display::m_alwaysShowRadii)
  37. ->Field("ShowBBoxes", &Display::m_showBBoxes)
  38. ->Field("DrawEntityLabels", &Display::m_drawEntityLabels)
  39. ->Field("ShowTriggerBounds", &Display::m_showTriggerBounds)
  40. ->Field("ShowFrozenHelpers", &Display::m_showFrozenHelpers)
  41. ->Field("FillSelectedShapes", &Display::m_fillSelectedShapes)
  42. ->Field("ShowGridGuide", &Display::m_showGridGuide)
  43. ->Field("DisplayDimensions", &Display::m_displayDimension);
  44. // clang-format off
  45. serialize.Class<MapViewport>()
  46. ->Version(1)
  47. ->Field("SwapXY", &MapViewport::m_swapXY)
  48. ->Field("Resolution", &MapViewport::m_resolution);
  49. // clang-format on
  50. serialize.Class<TextLabels>()
  51. ->Version(1)
  52. ->Field("LabelsOn", &TextLabels::m_labelsOn)
  53. ->Field("LabelsDistance", &TextLabels::m_labelsDistance);
  54. serialize.Class<SelectionPreviewColor>()
  55. ->Version(1)
  56. ->Field("ColorGroupBBox", &SelectionPreviewColor::m_colorGroupBBox)
  57. ->Field("ColorEntityBBox", &SelectionPreviewColor::m_colorEntityBBox)
  58. ->Field("BBoxAlpha", &SelectionPreviewColor::m_fBBoxAlpha)
  59. ->Field("GeometryHighlihgtColor", &SelectionPreviewColor::m_geometryHighlightColor)
  60. ->Field("SolidBrushGeometryColor", &SelectionPreviewColor::m_solidBrushGeometryColor)
  61. ->Field("GeomAlpha", &SelectionPreviewColor::m_fgeomAlpha)
  62. ->Field("ChildObjectGeomAlpha", &SelectionPreviewColor::m_childObjectGeomAlpha);
  63. serialize.Class<CEditorPreferencesPage_ViewportGeneral>()
  64. ->Version(1)
  65. ->Field("General Viewport Settings", &CEditorPreferencesPage_ViewportGeneral::m_general)
  66. ->Field("Viewport Displaying", &CEditorPreferencesPage_ViewportGeneral::m_display)
  67. ->Field("Map Viewport", &CEditorPreferencesPage_ViewportGeneral::m_map)
  68. ->Field("Test Labels", &CEditorPreferencesPage_ViewportGeneral::m_textLabels)
  69. ->Field("Selection Preview Color", &CEditorPreferencesPage_ViewportGeneral::m_selectionPreviewColor);
  70. AZ::EditContext* editContext = serialize.GetEditContext();
  71. if (editContext)
  72. {
  73. editContext->Class<General>("General Viewport Settings", "")
  74. ->DataElement(AZ::Edit::UIHandlers::CheckBox, &General::m_sync2DViews, "Synchronize 2D Viewports", "Synchronize 2D Viewports")
  75. ->DataElement(AZ::Edit::UIHandlers::SpinBox, &General::m_defaultFOV, "Perspective View FOV", "Perspective View FOV")
  76. ->Attribute(AZ::Edit::Attributes::Min, 1.0f)
  77. ->Attribute(AZ::Edit::Attributes::Max, 120.0f)
  78. ->DataElement(AZ::Edit::UIHandlers::SpinBox, &General::m_defaultNearPlane, "Perspective Near Plane", "Perspective Near Plane")
  79. ->DataElement(AZ::Edit::UIHandlers::SpinBox, &General::m_defaultFarPlane, "Perspective Far Plane", "Perspective Far Plane")
  80. ->DataElement(
  81. AZ::Edit::UIHandlers::SpinBox, &General::m_defaultAspectRatio, "Perspective View Aspect Ratio",
  82. "Perspective View Aspect Ratio")
  83. ->DataElement(
  84. AZ::Edit::UIHandlers::CheckBox, &General::m_contextMenuEnabled, "Enable Right-Click Context Menu",
  85. "Enable Right-Click Context Menu")
  86. ->DataElement(AZ::Edit::UIHandlers::CheckBox, &General::m_stickySelectEnabled, "Enable Sticky Select", "Enable Sticky Select");
  87. editContext->Class<Display>("Viewport Display Settings", "")
  88. ->DataElement(
  89. AZ::Edit::UIHandlers::CheckBox, &Display::m_highlightSelGeom, "Highlight Selected Geometry", "Highlight Selected Geometry")
  90. ->DataElement(
  91. AZ::Edit::UIHandlers::CheckBox, &Display::m_highlightSelVegetation, "Highlight Selected Vegetation",
  92. "Highlight Selected Vegetation")
  93. ->DataElement(
  94. AZ::Edit::UIHandlers::CheckBox, &Display::m_highlightOnMouseOver, "Highlight Geometry On Mouse Over",
  95. "Highlight Geometry On Mouse Over")
  96. ->DataElement(
  97. AZ::Edit::UIHandlers::CheckBox, &Display::m_hideMouseCursorWhenCaptured, "Hide Cursor When Captured",
  98. "Hide Mouse Cursor When Captured")
  99. ->DataElement(AZ::Edit::UIHandlers::SpinBox, &Display::m_dragSquareSize, "Drag Square Size", "Drag Square Size")
  100. ->DataElement(AZ::Edit::UIHandlers::CheckBox, &Display::m_displayLinks, "Display Object Links", "Display Object Links")
  101. ->DataElement(AZ::Edit::UIHandlers::CheckBox, &Display::m_displayTracks, "Display Animation Tracks", "Display Animation Tracks")
  102. ->DataElement(AZ::Edit::UIHandlers::CheckBox, &Display::m_alwaysShowRadii, "Always Show Radii", "Always Show Radii")
  103. ->DataElement(AZ::Edit::UIHandlers::CheckBox, &Display::m_showBBoxes, "Show Bounding Boxes", "Show Bounding Boxes")
  104. ->DataElement(
  105. AZ::Edit::UIHandlers::CheckBox, &Display::m_drawEntityLabels, "Always Draw Entity Labels", "Always Draw Entity Labels")
  106. ->DataElement(
  107. AZ::Edit::UIHandlers::CheckBox, &Display::m_showTriggerBounds, "Always Show Trigger Bounds", "Always Show Trigger Bounds")
  108. ->DataElement(
  109. AZ::Edit::UIHandlers::CheckBox, &Display::m_showFrozenHelpers, "Show Helpers of Frozen Objects",
  110. "Show Helpers of Frozen Objects")
  111. ->DataElement(AZ::Edit::UIHandlers::CheckBox, &Display::m_fillSelectedShapes, "Fill Selected Shapes", "Fill Selected Shapes")
  112. ->DataElement(AZ::Edit::UIHandlers::CheckBox, &Display::m_showGridGuide, "Show Snapping Grid Guide", "Show Snapping Grid Guide")
  113. ->DataElement(
  114. AZ::Edit::UIHandlers::CheckBox, &Display::m_displayDimension, "Display Dimension Figures", "Display Dimension Figures");
  115. editContext->Class<MapViewport>("Map Viewport Settings", "")
  116. ->DataElement(AZ::Edit::UIHandlers::CheckBox, &MapViewport::m_swapXY, "Swap X/Y Axis", "Swap X/Y Axis")
  117. ->DataElement(AZ::Edit::UIHandlers::SpinBox, &MapViewport::m_resolution, "Map Texture Resolution", "Map Texture Resolution");
  118. editContext->Class<TextLabels>("Text Label Settings", "")
  119. ->DataElement(AZ::Edit::UIHandlers::CheckBox, &TextLabels::m_labelsOn, "Enabled", "Enabled")
  120. ->DataElement(AZ::Edit::UIHandlers::CheckBox, &TextLabels::m_labelsDistance, "Distance", "Distance")
  121. ->Attribute(AZ::Edit::Attributes::Min, 0.f)
  122. ->Attribute(AZ::Edit::Attributes::Max, 100000.f);
  123. editContext->Class<SelectionPreviewColor>("Selection Preview Color Settings", "")
  124. ->DataElement(AZ::Edit::UIHandlers::Color, &SelectionPreviewColor::m_colorGroupBBox, "Group Bounding Box", "Group Bounding Box")
  125. ->DataElement(
  126. AZ::Edit::UIHandlers::Color, &SelectionPreviewColor::m_colorEntityBBox, "Entity Bounding Box", "Entity Bounding Box")
  127. ->DataElement(
  128. AZ::Edit::UIHandlers::SpinBox, &SelectionPreviewColor::m_fBBoxAlpha, "Bounding Box Highlight Alpha",
  129. "Bounding Box Highlight Alpha")
  130. ->Attribute(AZ::Edit::Attributes::Min, 0.0f)
  131. ->Attribute(AZ::Edit::Attributes::Max, 1.0f)
  132. ->DataElement(AZ::Edit::UIHandlers::Color, &SelectionPreviewColor::m_geometryHighlightColor, "Geometry Color", "Geometry Color")
  133. ->DataElement(
  134. AZ::Edit::UIHandlers::Color, &SelectionPreviewColor::m_solidBrushGeometryColor, "Solid Brush Geometry Color",
  135. "Solid Brush Geometry Color")
  136. ->DataElement(
  137. AZ::Edit::UIHandlers::SpinBox, &SelectionPreviewColor::m_fgeomAlpha, "Geometry Highlight Alpha", "Geometry Highlight Alpha")
  138. ->Attribute(AZ::Edit::Attributes::Min, 0.0f)
  139. ->Attribute(AZ::Edit::Attributes::Max, 1.0f)
  140. ->DataElement(
  141. AZ::Edit::UIHandlers::SpinBox, &SelectionPreviewColor::m_childObjectGeomAlpha, "Child Geometry Highlight Alpha",
  142. "Child Geometry Highlight Alpha")
  143. ->Attribute(AZ::Edit::Attributes::Min, 0.0f)
  144. ->Attribute(AZ::Edit::Attributes::Max, 1.0f);
  145. editContext->Class<CEditorPreferencesPage_ViewportGeneral>("General Viewport Preferences", "General Viewport Preferences")
  146. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  147. ->Attribute(AZ::Edit::Attributes::Visibility, AZ_CRC_CE("PropertyVisibility_ShowChildrenOnly"))
  148. ->DataElement(
  149. AZ::Edit::UIHandlers::Default, &CEditorPreferencesPage_ViewportGeneral::m_general, "General Viewport Settings",
  150. "General Viewport Settings")
  151. ->DataElement(
  152. AZ::Edit::UIHandlers::Default, &CEditorPreferencesPage_ViewportGeneral::m_display, "Viewport Display Settings",
  153. "Viewport Display Settings")
  154. ->DataElement(
  155. AZ::Edit::UIHandlers::Default, &CEditorPreferencesPage_ViewportGeneral::m_map, "Map Viewport Settings",
  156. "Map Viewport Settings")
  157. ->DataElement(
  158. AZ::Edit::UIHandlers::Default, &CEditorPreferencesPage_ViewportGeneral::m_textLabels, "Text Label Settings",
  159. "Text Label Settings")
  160. ->DataElement(
  161. AZ::Edit::UIHandlers::Default, &CEditorPreferencesPage_ViewportGeneral::m_selectionPreviewColor,
  162. "Selection Preview Color Settings", "Selection Preview Color Settings");
  163. }
  164. }
  165. CEditorPreferencesPage_ViewportGeneral::CEditorPreferencesPage_ViewportGeneral()
  166. {
  167. InitializeSettings();
  168. m_icon = QIcon(":/res/Viewport.svg");
  169. }
  170. const char* CEditorPreferencesPage_ViewportGeneral::GetCategory()
  171. {
  172. return "Viewports";
  173. }
  174. const char* CEditorPreferencesPage_ViewportGeneral::GetTitle()
  175. {
  176. return "Viewport";
  177. }
  178. QIcon& CEditorPreferencesPage_ViewportGeneral::GetIcon()
  179. {
  180. return m_icon;
  181. }
  182. void CEditorPreferencesPage_ViewportGeneral::OnCancel()
  183. {
  184. // noop
  185. }
  186. bool CEditorPreferencesPage_ViewportGeneral::OnQueryCancel()
  187. {
  188. return true;
  189. }
  190. void CEditorPreferencesPage_ViewportGeneral::OnApply()
  191. {
  192. CDisplaySettings* ds = GetIEditor()->GetDisplaySettings();
  193. gSettings.viewports.fDefaultAspectRatio = m_general.m_defaultAspectRatio;
  194. gSettings.viewports.bEnableContextMenu = m_general.m_contextMenuEnabled;
  195. gSettings.viewports.bSync2DViews = m_general.m_sync2DViews;
  196. SandboxEditor::SetStickySelectEnabled(m_general.m_stickySelectEnabled);
  197. SandboxEditor::SetCameraDefaultFovDegrees(m_general.m_defaultFOV);
  198. SandboxEditor::SetCameraDefaultNearPlaneDistance(m_general.m_defaultNearPlane);
  199. SandboxEditor::SetCameraDefaultFarPlaneDistance(m_general.m_defaultFarPlane);
  200. gSettings.viewports.bHighlightSelectedGeometry = m_display.m_highlightSelGeom;
  201. gSettings.viewports.bHighlightSelectedVegetation = m_display.m_highlightSelVegetation;
  202. gSettings.viewports.bHighlightMouseOverGeometry = m_display.m_highlightOnMouseOver;
  203. gSettings.viewports.bHideMouseCursorWhenCaptured = m_display.m_hideMouseCursorWhenCaptured;
  204. gSettings.viewports.nDragSquareSize = m_display.m_dragSquareSize;
  205. ds->DisplayLinks(m_display.m_displayLinks);
  206. ds->DisplayTracks(m_display.m_displayTracks);
  207. gSettings.viewports.bAlwaysShowRadiuses = m_display.m_alwaysShowRadii;
  208. if (m_display.m_showBBoxes)
  209. {
  210. ds->SetRenderFlags(ds->GetRenderFlags() | RENDER_FLAG_BBOX);
  211. }
  212. else
  213. {
  214. ds->SetRenderFlags(ds->GetRenderFlags() & (~RENDER_FLAG_BBOX));
  215. }
  216. gSettings.viewports.bDrawEntityLabels = m_display.m_drawEntityLabels;
  217. gSettings.viewports.bShowTriggerBounds = m_display.m_showTriggerBounds;
  218. gSettings.viewports.nShowFrozenHelpers = m_display.m_showFrozenHelpers;
  219. gSettings.viewports.bFillSelectedShapes = m_display.m_fillSelectedShapes;
  220. gSettings.viewports.bShowGridGuide = m_display.m_showGridGuide;
  221. ds->DisplayDimensionFigures(m_display.m_displayDimension);
  222. gSettings.viewports.nTopMapTextureResolution = m_map.m_resolution;
  223. gSettings.viewports.bTopMapSwapXY = m_map.m_swapXY;
  224. ds->DisplayLabels(m_textLabels.m_labelsOn);
  225. ds->SetLabelsDistance(m_textLabels.m_labelsDistance);
  226. gSettings.objectColorSettings.fChildGeomAlpha = m_selectionPreviewColor.m_childObjectGeomAlpha;
  227. gSettings.objectColorSettings.entityHighlight = QColor(
  228. static_cast<int>(m_selectionPreviewColor.m_colorEntityBBox.GetR() * 255.0f),
  229. static_cast<int>(m_selectionPreviewColor.m_colorEntityBBox.GetG() * 255.0f),
  230. static_cast<int>(m_selectionPreviewColor.m_colorEntityBBox.GetB() * 255.0f));
  231. gSettings.objectColorSettings.groupHighlight = QColor(
  232. static_cast<int>(m_selectionPreviewColor.m_colorGroupBBox.GetR() * 255.0f),
  233. static_cast<int>(m_selectionPreviewColor.m_colorGroupBBox.GetG() * 255.0f),
  234. static_cast<int>(m_selectionPreviewColor.m_colorGroupBBox.GetB() * 255.0f));
  235. gSettings.objectColorSettings.fBBoxAlpha = m_selectionPreviewColor.m_fBBoxAlpha;
  236. gSettings.objectColorSettings.fGeomAlpha = m_selectionPreviewColor.m_fgeomAlpha;
  237. gSettings.objectColorSettings.geometryHighlightColor = QColor(
  238. static_cast<int>(m_selectionPreviewColor.m_geometryHighlightColor.GetR() * 255.0f),
  239. static_cast<int>(m_selectionPreviewColor.m_geometryHighlightColor.GetG() * 255.0f),
  240. static_cast<int>(m_selectionPreviewColor.m_geometryHighlightColor.GetB() * 255.0f));
  241. gSettings.objectColorSettings.solidBrushGeometryColor = QColor(
  242. static_cast<int>(m_selectionPreviewColor.m_solidBrushGeometryColor.GetR() * 255.0f),
  243. static_cast<int>(m_selectionPreviewColor.m_solidBrushGeometryColor.GetG() * 255.0f),
  244. static_cast<int>(m_selectionPreviewColor.m_solidBrushGeometryColor.GetB() * 255.0f));
  245. }
  246. void CEditorPreferencesPage_ViewportGeneral::InitializeSettings()
  247. {
  248. CDisplaySettings* ds = GetIEditor()->GetDisplaySettings();
  249. m_general.m_defaultAspectRatio = gSettings.viewports.fDefaultAspectRatio;
  250. m_general.m_defaultNearPlane = SandboxEditor::CameraDefaultNearPlaneDistance();
  251. m_general.m_defaultFarPlane = SandboxEditor::CameraDefaultFarPlaneDistance();
  252. m_general.m_defaultFOV = SandboxEditor::CameraDefaultFovDegrees();
  253. m_general.m_contextMenuEnabled = gSettings.viewports.bEnableContextMenu;
  254. m_general.m_sync2DViews = gSettings.viewports.bSync2DViews;
  255. m_general.m_stickySelectEnabled = SandboxEditor::StickySelectEnabled();
  256. m_display.m_highlightSelGeom = gSettings.viewports.bHighlightSelectedGeometry;
  257. m_display.m_highlightSelVegetation = gSettings.viewports.bHighlightSelectedVegetation;
  258. m_display.m_highlightOnMouseOver = gSettings.viewports.bHighlightMouseOverGeometry;
  259. m_display.m_hideMouseCursorWhenCaptured = gSettings.viewports.bHideMouseCursorWhenCaptured;
  260. m_display.m_dragSquareSize = gSettings.viewports.nDragSquareSize;
  261. m_display.m_displayLinks = ds->IsDisplayLinks();
  262. m_display.m_displayTracks = ds->IsDisplayTracks();
  263. m_display.m_alwaysShowRadii = gSettings.viewports.bAlwaysShowRadiuses;
  264. m_display.m_showBBoxes = (ds->GetRenderFlags() & RENDER_FLAG_BBOX) == RENDER_FLAG_BBOX;
  265. m_display.m_drawEntityLabels = gSettings.viewports.bDrawEntityLabels;
  266. m_display.m_showTriggerBounds = gSettings.viewports.bShowTriggerBounds;
  267. m_display.m_showFrozenHelpers = gSettings.viewports.nShowFrozenHelpers;
  268. m_display.m_fillSelectedShapes = gSettings.viewports.bFillSelectedShapes;
  269. m_display.m_showGridGuide = gSettings.viewports.bShowGridGuide;
  270. m_display.m_displayDimension = ds->IsDisplayDimensionFigures();
  271. m_map.m_resolution = gSettings.viewports.nTopMapTextureResolution;
  272. m_map.m_swapXY = gSettings.viewports.bTopMapSwapXY;
  273. m_textLabels.m_labelsOn = ds->IsDisplayLabels();
  274. m_textLabels.m_labelsDistance = ds->GetLabelsDistance();
  275. m_selectionPreviewColor.m_childObjectGeomAlpha = gSettings.objectColorSettings.fChildGeomAlpha;
  276. m_selectionPreviewColor.m_colorEntityBBox.Set(
  277. static_cast<float>(gSettings.objectColorSettings.entityHighlight.redF()),
  278. static_cast<float>(gSettings.objectColorSettings.entityHighlight.greenF()),
  279. static_cast<float>(gSettings.objectColorSettings.entityHighlight.blueF()), 1.0f);
  280. m_selectionPreviewColor.m_colorGroupBBox.Set(
  281. static_cast<float>(gSettings.objectColorSettings.groupHighlight.redF()),
  282. static_cast<float>(gSettings.objectColorSettings.groupHighlight.greenF()),
  283. static_cast<float>(gSettings.objectColorSettings.groupHighlight.blueF()), 1.0f);
  284. m_selectionPreviewColor.m_fBBoxAlpha = gSettings.objectColorSettings.fBBoxAlpha;
  285. m_selectionPreviewColor.m_fgeomAlpha = gSettings.objectColorSettings.fGeomAlpha;
  286. m_selectionPreviewColor.m_geometryHighlightColor.Set(
  287. static_cast<float>(gSettings.objectColorSettings.geometryHighlightColor.redF()),
  288. static_cast<float>(gSettings.objectColorSettings.geometryHighlightColor.greenF()),
  289. static_cast<float>(gSettings.objectColorSettings.geometryHighlightColor.blueF()), 1.0f);
  290. m_selectionPreviewColor.m_solidBrushGeometryColor.Set(
  291. static_cast<float>(gSettings.objectColorSettings.solidBrushGeometryColor.redF()),
  292. static_cast<float>(gSettings.objectColorSettings.solidBrushGeometryColor.greenF()),
  293. static_cast<float>(gSettings.objectColorSettings.solidBrushGeometryColor.blueF()), 1.0f);
  294. }