editor_json_visualizer.cpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /**************************************************************************/
  2. /* editor_json_visualizer.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "editor_json_visualizer.h"
  31. #include "editor/editor_settings.h"
  32. #include "editor/editor_string_names.h"
  33. #include "editor/themes/editor_scale.h"
  34. #include "scene/gui/text_edit.h"
  35. #include "servers/rendering/shader_language.h"
  36. EditorJsonVisualizerSyntaxHighlighter::EditorJsonVisualizerSyntaxHighlighter(const List<String> &p_keywords) {
  37. set_number_color(EDITOR_GET("text_editor/theme/highlighting/number_color"));
  38. set_symbol_color(EDITOR_GET("text_editor/theme/highlighting/symbol_color"));
  39. set_function_color(EDITOR_GET("text_editor/theme/highlighting/function_color"));
  40. set_member_variable_color(EDITOR_GET("text_editor/theme/highlighting/member_variable_color"));
  41. clear_keyword_colors();
  42. const Color keyword_color = EDITOR_GET("text_editor/theme/highlighting/keyword_color");
  43. const Color control_flow_keyword_color = EDITOR_GET("text_editor/theme/highlighting/control_flow_keyword_color");
  44. for (const String &keyword : p_keywords) {
  45. if (ShaderLanguage::is_control_flow_keyword(keyword)) {
  46. add_keyword_color(keyword, control_flow_keyword_color);
  47. } else {
  48. add_keyword_color(keyword, keyword_color);
  49. }
  50. }
  51. // Colorize comments.
  52. const Color comment_color = EDITOR_GET("text_editor/theme/highlighting/comment_color");
  53. clear_color_regions();
  54. add_color_region("/*", "*/", comment_color, false);
  55. add_color_region("//", "", comment_color, true);
  56. // Colorize preprocessor statements.
  57. const Color user_type_color = EDITOR_GET("text_editor/theme/highlighting/user_type_color");
  58. add_color_region("#", "", user_type_color, true);
  59. set_uint_suffix_enabled(true);
  60. }
  61. void EditorJsonVisualizer::load_theme(Ref<EditorJsonVisualizerSyntaxHighlighter> p_syntax_highlighter) {
  62. set_editable(false);
  63. set_syntax_highlighter(p_syntax_highlighter);
  64. add_theme_font_override(SceneStringName(font), get_theme_font("source", EditorStringName(EditorFonts)));
  65. add_theme_font_size_override(SceneStringName(font_size), get_theme_font_size("source_size", EditorStringName(EditorFonts)));
  66. add_theme_constant_override("line_spacing", EDITOR_GET("text_editor/appearance/whitespace/line_spacing"));
  67. // Appearance: Caret
  68. set_caret_type((TextEdit::CaretType)EDITOR_GET("text_editor/appearance/caret/type").operator int());
  69. set_caret_blink_enabled(EDITOR_GET("text_editor/appearance/caret/caret_blink"));
  70. set_caret_blink_interval(EDITOR_GET("text_editor/appearance/caret/caret_blink_interval"));
  71. set_highlight_current_line(EDITOR_GET("text_editor/appearance/caret/highlight_current_line"));
  72. set_highlight_all_occurrences(EDITOR_GET("text_editor/appearance/caret/highlight_all_occurrences"));
  73. // Appearance: Gutters
  74. set_draw_line_numbers(EDITOR_GET("text_editor/appearance/gutters/show_line_numbers"));
  75. set_line_numbers_zero_padded(EDITOR_GET("text_editor/appearance/gutters/line_numbers_zero_padded"));
  76. // Appearance: Minimap
  77. set_draw_minimap(EDITOR_GET("text_editor/appearance/minimap/show_minimap"));
  78. set_minimap_width((int)EDITOR_GET("text_editor/appearance/minimap/minimap_width") * EDSCALE);
  79. // Appearance: Lines
  80. set_line_folding_enabled(EDITOR_GET("text_editor/appearance/lines/code_folding"));
  81. set_draw_fold_gutter(EDITOR_GET("text_editor/appearance/lines/code_folding"));
  82. set_line_wrapping_mode((TextEdit::LineWrappingMode)EDITOR_GET("text_editor/appearance/lines/word_wrap").operator int());
  83. set_autowrap_mode((TextServer::AutowrapMode)EDITOR_GET("text_editor/appearance/lines/autowrap_mode").operator int());
  84. // Appearance: Whitespace
  85. set_draw_tabs(EDITOR_GET("text_editor/appearance/whitespace/draw_tabs"));
  86. set_draw_spaces(EDITOR_GET("text_editor/appearance/whitespace/draw_spaces"));
  87. add_theme_constant_override("line_spacing", EDITOR_GET("text_editor/appearance/whitespace/line_spacing"));
  88. // Behavior: Navigation
  89. set_scroll_past_end_of_file_enabled(EDITOR_GET("text_editor/behavior/navigation/scroll_past_end_of_file"));
  90. set_smooth_scroll_enabled(EDITOR_GET("text_editor/behavior/navigation/smooth_scrolling"));
  91. set_v_scroll_speed(EDITOR_GET("text_editor/behavior/navigation/v_scroll_speed"));
  92. set_drag_and_drop_selection_enabled(EDITOR_GET("text_editor/behavior/navigation/drag_and_drop_selection"));
  93. // Behavior: Indent
  94. set_indent_size(EDITOR_GET("text_editor/behavior/indent/size"));
  95. set_auto_indent_enabled(EDITOR_GET("text_editor/behavior/indent/auto_indent"));
  96. set_indent_wrapped_lines(EDITOR_GET("text_editor/behavior/indent/indent_wrapped_lines"));
  97. }
  98. void EditorJsonVisualizer::_notification(int p_what) {
  99. if (p_what == NOTIFICATION_THEME_CHANGED) {
  100. Ref<Font> source_font = get_theme_font("source", EditorStringName(EditorFonts));
  101. int source_font_size = get_theme_font_size("source_size", EditorStringName(EditorFonts));
  102. int line_spacing = EDITOR_GET("text_editor/theme/line_spacing");
  103. if (get_theme_font(SceneStringName(font)) != source_font) {
  104. add_theme_font_override(SceneStringName(font), source_font);
  105. }
  106. if (get_theme_font_size(SceneStringName(font_size)) != source_font_size) {
  107. add_theme_font_size_override(SceneStringName(font_size), source_font_size);
  108. }
  109. if (get_theme_constant("line_spacing") != line_spacing) {
  110. add_theme_constant_override("line_spacing", line_spacing);
  111. }
  112. }
  113. }