|
| 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 | + |
| 31 | +#include "editor_json_visualizer.h" |
| 32 | + |
| 33 | +#include "editor/editor_settings.h" |
| 34 | +#include "editor/editor_string_names.h" |
| 35 | +#include "editor/themes/editor_scale.h" |
| 36 | +#include "scene/gui/text_edit.h" |
| 37 | +#include "servers/rendering/shader_language.h" |
| 38 | + |
| 39 | +EditorJsonVisualizerSyntaxHighlighter::EditorJsonVisualizerSyntaxHighlighter(const List<String> &p_keywords) { |
| 40 | + set_number_color(EDITOR_GET("text_editor/theme/highlighting/number_color")); |
| 41 | + set_symbol_color(EDITOR_GET("text_editor/theme/highlighting/symbol_color")); |
| 42 | + set_function_color(EDITOR_GET("text_editor/theme/highlighting/function_color")); |
| 43 | + set_member_variable_color(EDITOR_GET("text_editor/theme/highlighting/member_variable_color")); |
| 44 | + |
| 45 | + clear_keyword_colors(); |
| 46 | + const Color keyword_color = EDITOR_GET("text_editor/theme/highlighting/keyword_color"); |
| 47 | + const Color control_flow_keyword_color = EDITOR_GET("text_editor/theme/highlighting/control_flow_keyword_color"); |
| 48 | + |
| 49 | + for (const String &keyword : p_keywords) { |
| 50 | + if (ShaderLanguage::is_control_flow_keyword(keyword)) { |
| 51 | + add_keyword_color(keyword, control_flow_keyword_color); |
| 52 | + } else { |
| 53 | + add_keyword_color(keyword, keyword_color); |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + // Colorize comments. |
| 58 | + const Color comment_color = EDITOR_GET("text_editor/theme/highlighting/comment_color"); |
| 59 | + clear_color_regions(); |
| 60 | + add_color_region("/*", "*/", comment_color, false); |
| 61 | + add_color_region("//", "", comment_color, true); |
| 62 | + |
| 63 | + // Colorize preprocessor statements. |
| 64 | + const Color user_type_color = EDITOR_GET("text_editor/theme/highlighting/user_type_color"); |
| 65 | + add_color_region("#", "", user_type_color, true); |
| 66 | + |
| 67 | + set_uint_suffix_enabled(true); |
| 68 | +} |
| 69 | + |
| 70 | +void EditorJsonVisualizer::load_theme(Ref<EditorJsonVisualizerSyntaxHighlighter> p_syntax_highlighter) { |
| 71 | + set_editable(false); |
| 72 | + set_syntax_highlighter(p_syntax_highlighter); |
| 73 | + add_theme_font_override(SceneStringName(font), get_theme_font("source", EditorStringName(EditorFonts))); |
| 74 | + add_theme_font_size_override(SceneStringName(font_size), get_theme_font_size("source_size", EditorStringName(EditorFonts))); |
| 75 | + add_theme_constant_override("line_spacing", EDITOR_GET("text_editor/appearance/whitespace/line_spacing")); |
| 76 | + |
| 77 | + // Appearance: Caret |
| 78 | + set_caret_type((TextEdit::CaretType)EDITOR_GET("text_editor/appearance/caret/type").operator int()); |
| 79 | + set_caret_blink_enabled(EDITOR_GET("text_editor/appearance/caret/caret_blink")); |
| 80 | + set_caret_blink_interval(EDITOR_GET("text_editor/appearance/caret/caret_blink_interval")); |
| 81 | + set_highlight_current_line(EDITOR_GET("text_editor/appearance/caret/highlight_current_line")); |
| 82 | + set_highlight_all_occurrences(EDITOR_GET("text_editor/appearance/caret/highlight_all_occurrences")); |
| 83 | + |
| 84 | + // Appearance: Gutters |
| 85 | + set_draw_line_numbers(EDITOR_GET("text_editor/appearance/gutters/show_line_numbers")); |
| 86 | + set_line_numbers_zero_padded(EDITOR_GET("text_editor/appearance/gutters/line_numbers_zero_padded")); |
| 87 | + |
| 88 | + // Appearance: Minimap |
| 89 | + set_draw_minimap(EDITOR_GET("text_editor/appearance/minimap/show_minimap")); |
| 90 | + set_minimap_width((int)EDITOR_GET("text_editor/appearance/minimap/minimap_width") * EDSCALE); |
| 91 | + |
| 92 | + // Appearance: Lines |
| 93 | + set_line_folding_enabled(EDITOR_GET("text_editor/appearance/lines/code_folding")); |
| 94 | + set_draw_fold_gutter(EDITOR_GET("text_editor/appearance/lines/code_folding")); |
| 95 | + set_line_wrapping_mode((TextEdit::LineWrappingMode)EDITOR_GET("text_editor/appearance/lines/word_wrap").operator int()); |
| 96 | + set_autowrap_mode((TextServer::AutowrapMode)EDITOR_GET("text_editor/appearance/lines/autowrap_mode").operator int()); |
| 97 | + |
| 98 | + // Appearance: Whitespace |
| 99 | + set_draw_tabs(EDITOR_GET("text_editor/appearance/whitespace/draw_tabs")); |
| 100 | + set_draw_spaces(EDITOR_GET("text_editor/appearance/whitespace/draw_spaces")); |
| 101 | + add_theme_constant_override("line_spacing", EDITOR_GET("text_editor/appearance/whitespace/line_spacing")); |
| 102 | + |
| 103 | + // Behavior: Navigation |
| 104 | + set_scroll_past_end_of_file_enabled(EDITOR_GET("text_editor/behavior/navigation/scroll_past_end_of_file")); |
| 105 | + set_smooth_scroll_enabled(EDITOR_GET("text_editor/behavior/navigation/smooth_scrolling")); |
| 106 | + set_v_scroll_speed(EDITOR_GET("text_editor/behavior/navigation/v_scroll_speed")); |
| 107 | + set_drag_and_drop_selection_enabled(EDITOR_GET("text_editor/behavior/navigation/drag_and_drop_selection")); |
| 108 | + |
| 109 | + // Behavior: Indent |
| 110 | + set_indent_size(EDITOR_GET("text_editor/behavior/indent/size")); |
| 111 | + set_auto_indent_enabled(EDITOR_GET("text_editor/behavior/indent/auto_indent")); |
| 112 | + set_indent_wrapped_lines(EDITOR_GET("text_editor/behavior/indent/indent_wrapped_lines")); |
| 113 | +} |
| 114 | + |
| 115 | +void EditorJsonVisualizer::_notification(int p_what) { |
| 116 | + if (p_what == NOTIFICATION_THEME_CHANGED) { |
| 117 | + Ref<Font> source_font = get_theme_font("source", EditorStringName(EditorFonts)); |
| 118 | + int source_font_size = get_theme_font_size("source_size", EditorStringName(EditorFonts)); |
| 119 | + int line_spacing = EDITOR_GET("text_editor/theme/line_spacing"); |
| 120 | + if (get_theme_font(SceneStringName(font)) != source_font) { |
| 121 | + add_theme_font_override(SceneStringName(font), source_font); |
| 122 | + } |
| 123 | + if (get_theme_font_size(SceneStringName(font_size)) != source_font_size) { |
| 124 | + add_theme_font_size_override(SceneStringName(font_size), source_font_size); |
| 125 | + } |
| 126 | + if (get_theme_constant("line_spacing") != line_spacing) { |
| 127 | + add_theme_constant_override("line_spacing", line_spacing); |
| 128 | + } |
| 129 | + } |
| 130 | +} |
0 commit comments