LUAEditorStyleMessages.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 "LUAEditorStyleMessages.h"
  9. #include <AzCore/Serialization/EditContext.h>
  10. #include "LUAEditorViewMessages.h"
  11. namespace LUAEditor
  12. {
  13. SyntaxStyleSettings::SyntaxStyleSettings()
  14. {
  15. m_font.setFamily(m_fontFamily.c_str());
  16. m_font.setFixedPitch(true);
  17. m_font.setStyleHint(QFont::Monospace);
  18. m_font.setPointSize(m_fontSize);
  19. m_font.setStyleStrategy(GetNoAntiAliasing() ? QFont::NoAntialias : QFont::PreferDefault);
  20. }
  21. void SyntaxStyleSettings::SetZoomPercent(float zoom)
  22. {
  23. m_zoomPercent = zoom;
  24. m_font.setPointSize(m_fontSize * (m_zoomPercent / 100.0f));
  25. }
  26. void SyntaxStyleSettings::Reflect(AZ::ReflectContext* reflection)
  27. {
  28. AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(reflection);
  29. if (serializeContext)
  30. {
  31. serializeContext->Class<SyntaxStyleSettings, AZ::UserSettings >()
  32. ->Version(7)
  33. ->EventHandler<SerializationEvents>()
  34. ->Field("m_fontFamily", &SyntaxStyleSettings::m_fontFamily)
  35. ->Field("m_fontSize", &SyntaxStyleSettings::m_fontSize)
  36. ->Field("m_noAntialiasing", &SyntaxStyleSettings::m_noAntialiasing)
  37. ->Field("m_tabSize", &SyntaxStyleSettings::m_tabSize)
  38. ->Field("m_useSpacesInsteadOfTabs", &SyntaxStyleSettings::m_useSpacesInsteadOfTabs)
  39. ->Field("m_textColor", &SyntaxStyleSettings::m_textColor)
  40. ->Field("m_lineNumberColor", &SyntaxStyleSettings::m_lineNumberColor)
  41. ->Field("m_textSelectedColor", &SyntaxStyleSettings::m_textSelectedColor)
  42. ->Field("m_textSelectedBackgroundColor", &SyntaxStyleSettings::m_textSelectedBackgroundColor)
  43. ->Field("m_textFocusedBackgroundColor", &SyntaxStyleSettings::m_textFocusedBackgroundColor)
  44. ->Field("m_textUnfocusedBackgroundColor", &SyntaxStyleSettings::m_textUnfocusedBackgroundColor)
  45. ->Field("m_textReadOnlyFocusedBackgroundColor", &SyntaxStyleSettings::m_textReadOnlyFocusedBackgroundColor)
  46. ->Field("m_textReadOnlyUnfocusedBackgroundColor", &SyntaxStyleSettings::m_textReadOnlyUnfocusedBackgroundColor)
  47. ->Field("m_textWhitespaceColor", &SyntaxStyleSettings::m_textWhitespaceColor)
  48. ->Field("m_breakpointFocusedBackgroundColor", &SyntaxStyleSettings::m_breakpointFocusedBackgroundColor)
  49. ->Field("m_breakpointUnocusedBackgroundColor", &SyntaxStyleSettings::m_breakpointUnfocusedBackgroundColor)
  50. ->Field("m_foldingFocusedBackgroundColor", &SyntaxStyleSettings::m_foldingFocusedBackgroundColor)
  51. ->Field("m_foldingUnfocusedBackgroundColor", &SyntaxStyleSettings::m_foldingUnfocusedBackgroundColor)
  52. ->Field("m_currentIdentifierColor", &SyntaxStyleSettings::m_currentIdentifierColor)
  53. ->Field("m_currentLineOutlineColor", &SyntaxStyleSettings::m_currentLineOutlineColor)
  54. ->Field("m_specialCharacterColor", &SyntaxStyleSettings::m_specialCharacterColor)
  55. ->Field("m_keywordColor", &SyntaxStyleSettings::m_keywordColor)
  56. ->Field("m_specialKeywordColor", &SyntaxStyleSettings::m_specialKeywordColor)
  57. ->Field("m_commentColor", &SyntaxStyleSettings::m_commentColor)
  58. ->Field("m_stringLiteralColor", &SyntaxStyleSettings::m_stringLiteralColor)
  59. ->Field("m_numberColor", &SyntaxStyleSettings::m_numberColor)
  60. ->Field("m_libraryColor", &SyntaxStyleSettings::m_libraryColor)
  61. ->Field("m_methodColor", &SyntaxStyleSettings::m_methodColor)
  62. ->Field("m_bracketColor", &SyntaxStyleSettings::m_bracketColor)
  63. ->Field("m_selectedBracketColor", &SyntaxStyleSettings::m_selectedBracketColor)
  64. ->Field("m_unmatchedBracketColor", &SyntaxStyleSettings::m_unmatchedBracketColor)
  65. ->Field("m_foldingColor", &SyntaxStyleSettings::m_foldingColor)
  66. ->Field("m_foldingCurrentColor", &SyntaxStyleSettings::m_foldingCurrentColor)
  67. ->Field("m_foldingLineColor", &SyntaxStyleSettings::m_foldingLineColor)
  68. ->Field("m_findResultsHeaderColor", &SyntaxStyleSettings::m_findResultsHeaderColor)
  69. ->Field("m_findResultsFileColor", &SyntaxStyleSettings::m_findResultsFileColor)
  70. ->Field("m_findResultsMatchColor", &SyntaxStyleSettings::m_findResultsMatchColor)
  71. ;
  72. AZ::EditContext* editContext = serializeContext->GetEditContext();
  73. if (editContext)
  74. {
  75. editContext->Class<SyntaxStyleSettings>("Syntax Colors", "Customize the Lua IDE syntax and interface colors.")
  76. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  77. ->ClassElement(AZ::Edit::ClassElements::Group, "Font")
  78. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  79. ->DataElement(AZ::Edit::UIHandlers::Default, &SyntaxStyleSettings::m_fontFamily, "Font", "")
  80. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &SyntaxStyleSettings::OnFontChange)
  81. ->DataElement(AZ::Edit::UIHandlers::Default, &SyntaxStyleSettings::m_fontSize, "Size", "")
  82. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &SyntaxStyleSettings::OnFontChange)
  83. ->DataElement(AZ::Edit::UIHandlers::Default, &SyntaxStyleSettings::m_noAntialiasing, "No Antialiasing", "")
  84. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &SyntaxStyleSettings::OnFontChange)
  85. ->DataElement(AZ::Edit::UIHandlers::Default, &SyntaxStyleSettings::m_tabSize, "Tab Size", "")
  86. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &SyntaxStyleSettings::OnFontChange)
  87. ->DataElement(AZ::Edit::UIHandlers::Default, &SyntaxStyleSettings::m_useSpacesInsteadOfTabs, "Use Spaces instead of Tabs", "")
  88. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &SyntaxStyleSettings::OnFontChange)
  89. ->ClassElement(AZ::Edit::ClassElements::Group, "Editing")
  90. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  91. ->ClassElement(AZ::Edit::ClassElements::Group, "Text")
  92. ->DataElement(AZ::Edit::UIHandlers::Color, &SyntaxStyleSettings::m_textColor, "Default", "Default text color")
  93. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &SyntaxStyleSettings::OnColorChange)
  94. ->DataElement(AZ::Edit::UIHandlers::Color, &SyntaxStyleSettings::m_lineNumberColor, "Line Number", "")
  95. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &SyntaxStyleSettings::OnColorChange)
  96. ->DataElement(AZ::Edit::UIHandlers::Color, &SyntaxStyleSettings::m_textSelectedColor, "Selected Text", "")
  97. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &SyntaxStyleSettings::OnColorChange)
  98. ->DataElement(AZ::Edit::UIHandlers::Color, &SyntaxStyleSettings::m_textSelectedBackgroundColor, "Selected Text Background", "")
  99. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &SyntaxStyleSettings::OnColorChange)
  100. ->DataElement(AZ::Edit::UIHandlers::Color, &SyntaxStyleSettings::m_textWhitespaceColor, "Whitespace Color", "")
  101. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &SyntaxStyleSettings::OnColorChange)
  102. ->ClassElement(AZ::Edit::ClassElements::Group, "LUA Syntax")
  103. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  104. ->DataElement(AZ::Edit::UIHandlers::Color, &SyntaxStyleSettings::m_currentIdentifierColor, "Current Identifier", "")
  105. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &SyntaxStyleSettings::OnColorChange)
  106. ->DataElement(AZ::Edit::UIHandlers::Color, &SyntaxStyleSettings::m_specialCharacterColor, "Special character", "")
  107. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &SyntaxStyleSettings::OnColorChange)
  108. ->DataElement(AZ::Edit::UIHandlers::Color, &SyntaxStyleSettings::m_keywordColor, "Keyword", "")
  109. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &SyntaxStyleSettings::OnColorChange)
  110. ->DataElement(AZ::Edit::UIHandlers::Color, &SyntaxStyleSettings::m_specialKeywordColor, "Special Keyword", "")
  111. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &SyntaxStyleSettings::OnColorChange)
  112. ->DataElement(AZ::Edit::UIHandlers::Color, &SyntaxStyleSettings::m_commentColor, "Comment", "")
  113. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &SyntaxStyleSettings::OnColorChange)
  114. ->DataElement(AZ::Edit::UIHandlers::Color, &SyntaxStyleSettings::m_stringLiteralColor, "String", "")
  115. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &SyntaxStyleSettings::OnColorChange)
  116. ->DataElement(AZ::Edit::UIHandlers::Color, &SyntaxStyleSettings::m_numberColor, "Number", "")
  117. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &SyntaxStyleSettings::OnColorChange)
  118. ->DataElement(AZ::Edit::UIHandlers::Color, &SyntaxStyleSettings::m_libraryColor, "Library", "")
  119. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &SyntaxStyleSettings::OnColorChange)
  120. ->DataElement(AZ::Edit::UIHandlers::Color, &SyntaxStyleSettings::m_methodColor, "Method", "")
  121. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &SyntaxStyleSettings::OnColorChange)
  122. ->DataElement(AZ::Edit::UIHandlers::Color, &SyntaxStyleSettings::m_bracketColor, "Bracket", "")
  123. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &SyntaxStyleSettings::OnColorChange)
  124. ->DataElement(AZ::Edit::UIHandlers::Color, &SyntaxStyleSettings::m_selectedBracketColor, "Selected Bracket", "")
  125. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &SyntaxStyleSettings::OnColorChange)
  126. ->DataElement(AZ::Edit::UIHandlers::Color, &SyntaxStyleSettings::m_unmatchedBracketColor, "Unmatched Bracket", "")
  127. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &SyntaxStyleSettings::OnColorChange)
  128. ->ClassElement(AZ::Edit::ClassElements::Group, "Interface")
  129. ->Attribute(AZ::Edit::Attributes::AutoExpand, false)
  130. ->DataElement(AZ::Edit::UIHandlers::Color, &SyntaxStyleSettings::m_breakpointFocusedBackgroundColor, "Focused Breakpoint Background", "")
  131. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &SyntaxStyleSettings::OnColorChange)
  132. ->DataElement(AZ::Edit::UIHandlers::Color, &SyntaxStyleSettings::m_breakpointUnfocusedBackgroundColor, "Non Focused Breakpoint Background", "")
  133. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &SyntaxStyleSettings::OnColorChange)
  134. ->DataElement(AZ::Edit::UIHandlers::Color, &SyntaxStyleSettings::m_foldingFocusedBackgroundColor, "Folding Focused Background", "")
  135. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &SyntaxStyleSettings::OnColorChange)
  136. ->DataElement(AZ::Edit::UIHandlers::Color, &SyntaxStyleSettings::m_foldingUnfocusedBackgroundColor, "Folding Non Focused Back", "")
  137. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &SyntaxStyleSettings::OnColorChange)
  138. ->DataElement(AZ::Edit::UIHandlers::Color, &SyntaxStyleSettings::m_currentLineOutlineColor, "Line Outline", "")
  139. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &SyntaxStyleSettings::OnColorChange)
  140. ->DataElement(AZ::Edit::UIHandlers::Color, &SyntaxStyleSettings::m_foldingColor, "Folding", "")
  141. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &SyntaxStyleSettings::OnColorChange)
  142. ->DataElement(AZ::Edit::UIHandlers::Color, &SyntaxStyleSettings::m_foldingCurrentColor, "Folding Current", "")
  143. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &SyntaxStyleSettings::OnColorChange)
  144. ->DataElement(AZ::Edit::UIHandlers::Color, &SyntaxStyleSettings::m_foldingLineColor, "Folding Line", "")
  145. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &SyntaxStyleSettings::OnColorChange)
  146. ->DataElement(AZ::Edit::UIHandlers::Color, &SyntaxStyleSettings::m_textFocusedBackgroundColor, "Focused Background Color", "")
  147. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &SyntaxStyleSettings::OnColorChange)
  148. ->DataElement(AZ::Edit::UIHandlers::Color, &SyntaxStyleSettings::m_textUnfocusedBackgroundColor, "Unfocused Background Color", "")
  149. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &SyntaxStyleSettings::OnColorChange)
  150. ->DataElement(AZ::Edit::UIHandlers::Color, &SyntaxStyleSettings::m_textReadOnlyFocusedBackgroundColor, "Read Only Focused Background", "")
  151. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &SyntaxStyleSettings::OnColorChange)
  152. ->DataElement(AZ::Edit::UIHandlers::Color, &SyntaxStyleSettings::m_textReadOnlyUnfocusedBackgroundColor, "Read Only Background", "")
  153. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &SyntaxStyleSettings::OnColorChange)
  154. ->ClassElement(AZ::Edit::ClassElements::Group, "Find Results")
  155. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  156. ->DataElement(AZ::Edit::UIHandlers::Color, &SyntaxStyleSettings::m_findResultsHeaderColor, "Header", "")
  157. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &SyntaxStyleSettings::OnColorChange)
  158. ->DataElement(AZ::Edit::UIHandlers::Color, &SyntaxStyleSettings::m_findResultsFileColor, "File", "")
  159. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &SyntaxStyleSettings::OnColorChange)
  160. ->DataElement(AZ::Edit::UIHandlers::Color, &SyntaxStyleSettings::m_findResultsMatchColor, "Match", "")
  161. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &SyntaxStyleSettings::OnColorChange)
  162. ;
  163. }
  164. }
  165. }
  166. void SyntaxStyleSettings::OnColorChange()
  167. {
  168. LUAEditorMainWindowMessages::Bus::Broadcast(&LUAEditorMainWindowMessages::Bus::Events::Repaint);
  169. }
  170. void SyntaxStyleSettings::OnFontChange()
  171. {
  172. m_font.setFamily(m_fontFamily.c_str());
  173. m_font.setPointSize(m_fontSize);
  174. m_font.setStyleStrategy(GetNoAntiAliasing() ? QFont::NoAntialias : QFont::PreferDefault);
  175. LUAEditorMainWindowMessages::Bus::Broadcast(&LUAEditorMainWindowMessages::Bus::Events::Repaint);
  176. }
  177. }