DisplaySettings.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. // Description : Display Settings implementation.
  9. #include "EditorDefs.h"
  10. #include "DisplaySettings.h"
  11. // Qt
  12. #include <QSettings>
  13. // Editor
  14. #include "Settings.h"
  15. //////////////////////////////////////////////////////////////////////////
  16. CDisplaySettings::CDisplaySettings()
  17. {
  18. m_flags = SETTINGS_NOLABELS | SETTINGS_NOCOLLISION;
  19. m_objectHideMask = 0;
  20. // All flags besides GI enabled by default
  21. m_renderFlags = RENDER_FLAG_LAST_ONE - 1;
  22. m_renderFlags &= ~(RENDER_FLAG_BBOX);
  23. m_renderFlags &= ~(RENDER_FLAG_GI);
  24. m_debugFlags = 0;
  25. m_labelsDistance = 100;
  26. }
  27. //////////////////////////////////////////////////////////////////////////
  28. CDisplaySettings::~CDisplaySettings()
  29. {
  30. }
  31. void CDisplaySettings::SaveRegistry()
  32. {
  33. SaveValue("Settings", "ObjectHideMask", m_objectHideMask);
  34. SaveValue("Settings", "RenderFlags", m_renderFlags);
  35. SaveValue("Settings", "DisplayFlags", m_flags & SETTINGS_SERIALIZABLE_FLAGS_MASK);
  36. SaveValue("Settings", "DebugFlags", m_debugFlags);
  37. SaveValue("Settings", "LabelsDistance", static_cast<int>(m_labelsDistance));
  38. }
  39. void CDisplaySettings::LoadRegistry()
  40. {
  41. LoadValue("Settings", "ObjectHideMask", m_objectHideMask);
  42. LoadValue("Settings", "RenderFlags", m_renderFlags);
  43. LoadValue("Settings", "DisplayFlags", m_flags);
  44. m_flags &= SETTINGS_SERIALIZABLE_FLAGS_MASK;
  45. LoadValue("Settings", "DebugFlags", m_debugFlags);
  46. int temp = static_cast<int>(m_labelsDistance);
  47. LoadValue("Settings", "LabelsDistance", temp);
  48. m_labelsDistance = static_cast<float>(temp);
  49. gSettings.objectHideMask = m_objectHideMask;
  50. }
  51. void CDisplaySettings::SetObjectHideMask(int hideMask)
  52. {
  53. m_objectHideMask = hideMask;
  54. gSettings.objectHideMask = m_objectHideMask;
  55. };
  56. //////////////////////////////////////////////////////////////////////////
  57. void CDisplaySettings::PostInitApply()
  58. {
  59. SetRenderFlags(m_renderFlags);
  60. SetDebugFlags(m_debugFlags);
  61. }
  62. //////////////////////////////////////////////////////////////////////////
  63. void CDisplaySettings::SetRenderFlags(int flags)
  64. {
  65. m_renderFlags = flags;
  66. }
  67. //////////////////////////////////////////////////////////////////////////
  68. void CDisplaySettings::SetDebugFlags(int flags)
  69. {
  70. m_debugFlags = flags;
  71. //
  72. //SetCVar( "ai_DebugDraw",m_debugFlags&DBG_AI_DEBUGDRAW );
  73. //SetCVarInt( "r_TexLog",(m_debugFlags&DBG_TEXTURE_MEMINFO) ? 2:0 );
  74. //SetCVarInt( "MemStats",(m_debugFlags&DBG_MEMSTATS) ? 1000:0 );
  75. //SetCVarInt( "p_draw_helpers",(m_debugFlags&DBG_PHYSICS_DEBUGDRAW) ? 5634:0 );
  76. //SetCVar( "r_ProfileShaders",(m_debugFlags&DBG_RENDERER_PROFILESHADERS) );
  77. SetCVarInt("r_MeasureOverdraw", (m_debugFlags & DBG_RENDERER_OVERDRAW) ? 1 : 0); //Eric@conffx display Overdraw in Particle editor preview window
  78. //SetCVarInt( "r_Stats",(m_debugFlags&DBG_RENDERER_RESOURCES) ? 4:0 );
  79. //SetCVarInt( "sys_enable_budgetmonitoring",(m_debugFlags&DBG_BUDGET_MONITORING) ? 4:0 );
  80. //SetCVarInt( "Profile",(m_debugFlags&DBG_FRAMEPROFILE) ? 1:0 );
  81. }
  82. //////////////////////////////////////////////////////////////////////////
  83. void CDisplaySettings::SetCVar(const char* cvar, bool value)
  84. {
  85. ICVar* var = GetIEditor()->GetSystem()->GetIConsole()->GetCVar(cvar);
  86. if (var)
  87. {
  88. var->Set((value) ? 1 : 0);
  89. }
  90. else
  91. {
  92. CLogFile::FormatLine("Console Variable %s not declared", cvar);
  93. }
  94. }
  95. //////////////////////////////////////////////////////////////////////////
  96. void CDisplaySettings::SetCVarInt(const char* cvar, int value)
  97. {
  98. ICVar* var = GetIEditor()->GetSystem()->GetIConsole()->GetCVar(cvar);
  99. if (var)
  100. {
  101. var->Set(value);
  102. }
  103. else
  104. {
  105. CLogFile::FormatLine("Console Variable %s not declared", cvar);
  106. }
  107. }
  108. //////////////////////////////////////////////////////////////////////////
  109. void CDisplaySettings::DisplayLabels(bool bEnable)
  110. {
  111. if (bEnable)
  112. {
  113. m_flags &= ~SETTINGS_NOLABELS;
  114. }
  115. else
  116. {
  117. m_flags |= SETTINGS_NOLABELS;
  118. }
  119. }
  120. //////////////////////////////////////////////////////////////////////////
  121. void CDisplaySettings::DisplayTracks(bool bEnable)
  122. {
  123. if (bEnable)
  124. {
  125. m_flags &= ~SETTINGS_HIDE_TRACKS;
  126. }
  127. else
  128. {
  129. m_flags |= SETTINGS_HIDE_TRACKS;
  130. }
  131. }
  132. //////////////////////////////////////////////////////////////////////////
  133. void CDisplaySettings::DisplayLinks(bool bEnable)
  134. {
  135. if (bEnable)
  136. {
  137. m_flags &= ~SETTINGS_HIDE_LINKS;
  138. }
  139. else
  140. {
  141. m_flags |= SETTINGS_HIDE_LINKS;
  142. }
  143. }
  144. //////////////////////////////////////////////////////////////////////////
  145. void CDisplaySettings::DisplayHelpers(bool bEnable)
  146. {
  147. if (bEnable)
  148. {
  149. m_flags &= ~SETTINGS_HIDE_HELPERS;
  150. }
  151. else
  152. {
  153. m_flags |= SETTINGS_HIDE_HELPERS;
  154. }
  155. }
  156. //////////////////////////////////////////////////////////////////////////
  157. void CDisplaySettings::DisplayDimensionFigures(bool bEnable)
  158. {
  159. if (bEnable)
  160. {
  161. m_flags |= SETTINGS_SHOW_DIMENSIONFIGURES;
  162. }
  163. else
  164. {
  165. m_flags &= ~SETTINGS_SHOW_DIMENSIONFIGURES;
  166. }
  167. }
  168. //////////////////////////////////////////////////////////////////////////
  169. void CDisplaySettings::SetHighlightBreakable(bool bHighlight)
  170. {
  171. if (bHighlight)
  172. {
  173. m_debugFlags |= DBG_HIGHLIGHT_BREAKABLE;
  174. }
  175. else
  176. {
  177. m_debugFlags &= ~DBG_HIGHLIGHT_BREAKABLE;
  178. }
  179. }
  180. //////////////////////////////////////////////////////////////////////////
  181. void CDisplaySettings::SetHighlightMissingSurfaceType(bool bHighlight)
  182. {
  183. if (bHighlight)
  184. {
  185. m_debugFlags |= DBG_HIGHLIGHT_MISSING_SURFACE_TYPE;
  186. }
  187. else
  188. {
  189. m_debugFlags &= ~DBG_HIGHLIGHT_MISSING_SURFACE_TYPE;
  190. }
  191. }
  192. //////////////////////////////////////////////////////////////////////////
  193. void CDisplaySettings::SaveValue(const char* sSection, const char* sKey, int value)
  194. {
  195. QSettings settings;
  196. settings.setValue(QStringLiteral("%1/%2").arg(sSection, sKey), value);
  197. }
  198. //////////////////////////////////////////////////////////////////////////
  199. void CDisplaySettings::LoadValue(const char* sSection, const char* sKey, int& value)
  200. {
  201. QSettings settings;
  202. value = settings.value(QStringLiteral("%1/%2").arg(sSection, sKey), value).toInt();
  203. }
  204. //////////////////////////////////////////////////////////////////////////
  205. void CDisplaySettings::LoadValue(const char* sSection, const char* sKey, bool& value)
  206. {
  207. QSettings settings;
  208. value = settings.value(QStringLiteral("%1/%2").arg(sSection, sKey), value).toInt();
  209. }