LUAEditorStyleMessages.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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 <AzCore/base.h>
  9. #include <AzCore/EBus/EBus.h>
  10. #include <AzCore/std/containers/unordered_set.h>
  11. #include <AzCore/UserSettings/UserSettings.h>
  12. #include <AzCore/Math/Vector3.h>
  13. #include <AzCore/Memory/SystemAllocator.h>
  14. #include <AzCore/Serialization/SerializeContext.h>
  15. #include <QColor>
  16. #include <QFont>
  17. #pragma once
  18. namespace AZ { class ReflectContext; }
  19. namespace LUAEditor
  20. {
  21. class SyntaxStyleSettings
  22. : public AZ::UserSettings
  23. {
  24. public:
  25. AZ_RTTI(SyntaxStyleSettings, "{9C5A2A16-1855-4074-AA06-FC58A6A789D7}", AZ::UserSettings);
  26. AZ_CLASS_ALLOCATOR(SyntaxStyleSettings, AZ::SystemAllocator);
  27. SyntaxStyleSettings();
  28. QColor ToQColor(const AZ::Vector3& color) const
  29. {
  30. return QColor::fromRgbF(color.GetX(), color.GetY(), color.GetZ());
  31. }
  32. QColor GetTextColor() const { return ToQColor(m_textColor); }
  33. QColor GetLineNumberColor() const { return ToQColor(m_lineNumberColor); }
  34. QColor GetTextFocusedBackgroundColor() const { return ToQColor(m_textFocusedBackgroundColor); }
  35. QColor GetTextUnfocusedBackgroundColor() const { return ToQColor(m_textUnfocusedBackgroundColor); }
  36. QColor GetTextReadOnlyFocusedBackgroundColor() const { return ToQColor(m_textReadOnlyFocusedBackgroundColor); }
  37. QColor GetTextReadOnlyUnfocusedBackgroundColor() const { return ToQColor(m_textReadOnlyUnfocusedBackgroundColor); }
  38. QColor GetTextSelectedColor() const { return ToQColor(m_textSelectedColor); }
  39. QColor GetTextSelectedBackgroundColor() const { return ToQColor(m_textSelectedBackgroundColor); }
  40. QColor GetTextWhitespaceColor() const { return ToQColor(m_textWhitespaceColor); }
  41. QColor GetBreakpointFocusedBackgroundColor() const { return ToQColor(m_breakpointFocusedBackgroundColor); }
  42. QColor GetBreakpointUnfocusedBackgroundColor() const { return ToQColor(m_breakpointUnfocusedBackgroundColor); }
  43. QColor GetFoldingFocusedBackgroundColor() const { return ToQColor(m_foldingFocusedBackgroundColor); }
  44. QColor GetFoldingUnfocusedBackgroundColor() const { return ToQColor(m_foldingUnfocusedBackgroundColor); }
  45. QColor GetCurrentIdentifierColor() const { return ToQColor(m_currentIdentifierColor); }
  46. QColor GetCurrentLineOutlineColor() const { return ToQColor(m_currentLineOutlineColor); }
  47. QColor GetSpecialCharacterColor() const { return ToQColor(m_specialCharacterColor); }
  48. QColor GetKeywordColor() const { return ToQColor(m_keywordColor); }
  49. QColor GetSpecialKeywordColor() const { return ToQColor(m_specialKeywordColor); }
  50. QColor GetCommentColor() const { return ToQColor(m_commentColor); }
  51. QColor GetStringLiteralColor() const { return ToQColor(m_stringLiteralColor); }
  52. QColor GetNumberColor() const { return ToQColor(m_numberColor); }
  53. QColor GetLibraryColor() const { return ToQColor(m_libraryColor); }
  54. QColor GetMethodColor() const { return ToQColor(m_methodColor); }
  55. QColor GetBracketColor() const { return ToQColor(m_bracketColor); }
  56. QColor GetSelectedBracketColor() const { return ToQColor(m_selectedBracketColor); }
  57. QColor GetUnmatchedBracketColor() const { return ToQColor(m_unmatchedBracketColor); }
  58. QColor GetFoldingColor() const { return ToQColor(m_foldingColor); }
  59. QColor GetFoldingSelectedColor() const { return ToQColor(m_foldingCurrentColor); }
  60. QColor GetFoldingLineColor() const { return ToQColor(m_foldingLineColor); }
  61. QColor GetFindResultsHeaderColor() const { return ToQColor(m_findResultsHeaderColor); }
  62. QColor GetFindResultsFileColor() const { return ToQColor(m_findResultsFileColor); }
  63. QColor GetFindResultsMatchColor() const { return ToQColor(m_findResultsMatchColor); }
  64. QColor GetFindResultsLineHighlightColor() const { return ToQColor(m_findResultsLineHighlightColor); }
  65. const QFont& GetFont() const { return m_font; }
  66. bool GetNoAntiAliasing() const { return m_noAntialiasing; }
  67. int GetTabSize() const { return m_tabSize; }
  68. bool UseSpacesInsteadOfTabs() const { return m_useSpacesInsteadOfTabs; }
  69. void SetZoomPercent(float zoom);
  70. static void Reflect(AZ::ReflectContext* reflection);
  71. private:
  72. AZ::Vector3 m_textColor {
  73. 156.0f / 255.0f, 220.0f / 255.0f, 254.0f / 255.0f
  74. };
  75. AZ::Vector3 m_lineNumberColor {
  76. 200.0f / 255.0f, 200.0f / 255.0f, 200.0f / 255.0f
  77. };
  78. AZ::Vector3 m_textFocusedBackgroundColor {
  79. 31.0f / 255.0f, 31.0f / 255.0f, 31.0f / 255.0f
  80. };
  81. AZ::Vector3 m_textUnfocusedBackgroundColor {
  82. 31.0f / 255.0f, 31.0f / 255.0f, 31.0f / 255.0f
  83. };
  84. AZ::Vector3 m_textReadOnlyFocusedBackgroundColor {
  85. 60.0f / 255.0f, 60.0f / 255.0f, 60.0f / 255.0f
  86. };
  87. AZ::Vector3 m_textReadOnlyUnfocusedBackgroundColor {
  88. 60.0f / 255.0f, 60.0f / 255.0f, 60.0f / 255.0f
  89. };
  90. AZ::Vector3 m_textSelectedColor {
  91. 225.0f / 255.0f, 225.0f / 255.0f, 225.0f / 255.0f
  92. };
  93. AZ::Vector3 m_textSelectedBackgroundColor {
  94. 55.0f / 255.0f, 90.0f / 255.0f, 125.0f / 255.0f
  95. };
  96. AZ::Vector3 m_textWhitespaceColor{
  97. 100.0f / 255.0f, 100.0f / 255.0f, 100.0f / 255.0f
  98. };
  99. AZ::Vector3 m_breakpointFocusedBackgroundColor {
  100. 80.0f / 255.0f, 80.0f / 255.0f, 80.0f / 255.0f
  101. };
  102. AZ::Vector3 m_breakpointUnfocusedBackgroundColor {
  103. 80.0f / 255.0f, 80.0f / 255.0f, 80.0f / 255.0f
  104. };
  105. AZ::Vector3 m_foldingFocusedBackgroundColor {
  106. 70.0f / 255.0f, 70.0f / 255.0f, 70.0f / 255.0f
  107. };
  108. AZ::Vector3 m_foldingUnfocusedBackgroundColor {
  109. 70.0f / 255.0f, 70.0f / 255.0f, 70.0f / 255.0f
  110. };
  111. AZ::Vector3 m_currentIdentifierColor {
  112. 68.0f / 255.0f, 68.0f / 255.0f, 68.0f / 255.0f
  113. };
  114. AZ::Vector3 m_currentLineOutlineColor {
  115. 61.0f / 255.0f, 61.0f / 255.0f, 61.0f / 255.0f
  116. };
  117. AZ::Vector3 m_specialCharacterColor {
  118. 204.0f / 255.0f, 204.0f / 255.0f, 204.0f / 255.0f
  119. };
  120. AZ::Vector3 m_keywordColor {
  121. 213.0f / 255.0f, 134.0f / 255.0f, 192.0f / 255.0f
  122. };
  123. AZ::Vector3 m_specialKeywordColor {
  124. 63.0f / 255.0f, 156.0f / 255.0f, 214.0f / 255.0f
  125. };
  126. AZ::Vector3 m_commentColor {
  127. 106.0f / 255.0f, 153.0f / 255.0f, 85.0f / 255.0f
  128. };
  129. AZ::Vector3 m_stringLiteralColor {
  130. 206.0f / 255.0f, 145.0f / 255.0f, 117.0f / 255.0f
  131. };
  132. AZ::Vector3 m_numberColor {
  133. 181.0f / 255.0f, 203.0f / 255.0f, 164.0f / 255.0f
  134. };
  135. AZ::Vector3 m_libraryColor {
  136. 78.0f / 255.0f, 201.0f / 255.0f, 176.0f / 255.0f
  137. };
  138. AZ::Vector3 m_methodColor {
  139. 220.0f / 255.0f, 220.0f / 255.0f, 170.0f / 255.0f
  140. };
  141. AZ::Vector3 m_bracketColor {
  142. 255.0f / 255.0f, 215.0f / 255.0f, 0.0f / 255.0f
  143. };
  144. AZ::Vector3 m_selectedBracketColor {
  145. 219.0f / 255.0f, 29.0f / 255.0f, 133.0f / 255.0f
  146. };
  147. AZ::Vector3 m_unmatchedBracketColor {
  148. 219.0f / 255.0f, 29.0f / 255.0f, 133.0f / 255.0f
  149. };
  150. AZ::Vector3 m_foldingColor {
  151. 150.0f / 255.0f, 150.0f / 255.0f, 150.0f / 255.0f
  152. };
  153. AZ::Vector3 m_foldingCurrentColor {
  154. 240.0f / 255.0f, 240.0f / 255.0f, 240.0f / 255.0f
  155. };
  156. AZ::Vector3 m_foldingLineColor {
  157. 150.0f / 255.0f, 150.0f / 255.0f, 150.0f / 255.0f
  158. };
  159. AZ::Vector3 m_findResultsHeaderColor {
  160. 255.0f / 255.0f, 220.0f / 255.0f, 20.0f / 255.0f
  161. };
  162. AZ::Vector3 m_findResultsFileColor {
  163. 105.0f / 255.0f, 220.0f / 255.0f, 53.0f / 255.0f
  164. };
  165. AZ::Vector3 m_findResultsMatchColor {
  166. 255.0f / 255.0f, 220.0f / 255.0f, 20.0f / 255.0f
  167. };
  168. AZ::Vector3 m_findResultsLineHighlightColor {
  169. 160.0f / 255.0f, 160.0f / 255.0f, 164.0f / 255.0f
  170. };
  171. QFont m_font;
  172. AZStd::string m_fontFamily { "Consolas" };
  173. int m_fontSize {
  174. 14
  175. };
  176. bool m_noAntialiasing {
  177. false
  178. };
  179. // Number of spaces to make a tab
  180. int m_tabSize {
  181. 4
  182. };
  183. float m_zoomPercent = 100.f;
  184. bool m_useSpacesInsteadOfTabs = false;
  185. void OnColorChange();
  186. void OnFontChange();
  187. // We use this class to ensure that the font is updated when the instance of it got de-serialized.
  188. class SerializationEvents : public AZ::SerializeContext::IEventHandler
  189. {
  190. void OnReadEnd(void* classPtr) override
  191. {
  192. if(auto* settings = static_cast<SyntaxStyleSettings*>(classPtr))
  193. {
  194. settings->OnFontChange();
  195. }
  196. }
  197. };
  198. };
  199. class HighlightedWords
  200. : public AZ::EBusTraits
  201. {
  202. public:
  203. static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
  204. static const AZ::EBusHandlerPolicy HandlerPolicy = AZ:: EBusHandlerPolicy::Single;
  205. typedef AZ::EBus<HighlightedWords> Bus;
  206. typedef Bus::Handler Handler;
  207. typedef AZStd::unordered_set<AZStd::string> LUAKeywordsType;
  208. virtual const LUAKeywordsType* GetLUAKeywords() = 0;
  209. virtual const LUAKeywordsType* GetLUALibraryFunctions() = 0;
  210. };
  211. class HighlightedWordNotifications
  212. : public AZ::EBusTraits
  213. {
  214. public:
  215. static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
  216. typedef AZ::EBus<HighlightedWordNotifications> Bus;
  217. typedef Bus::Handler Handler;
  218. virtual void LUALibraryFunctionsUpdated() = 0;
  219. };
  220. }