3737#include " scene/gui/text_edit.h"
3838#include " servers/rendering/shader_language.h"
3939
40+ void EditorNativeShaderSourceVisualizer::_load_theme_settings () {
41+ syntax_highlighter->set_number_color (EDITOR_GET (" text_editor/theme/highlighting/number_color" ));
42+ syntax_highlighter->set_symbol_color (EDITOR_GET (" text_editor/theme/highlighting/symbol_color" ));
43+ syntax_highlighter->set_function_color (EDITOR_GET (" text_editor/theme/highlighting/function_color" ));
44+ syntax_highlighter->set_member_variable_color (EDITOR_GET (" text_editor/theme/highlighting/member_variable_color" ));
45+
46+ syntax_highlighter->clear_keyword_colors ();
47+
48+ List<String> keywords;
49+ ShaderLanguage::get_keyword_list (&keywords);
50+ const Color keyword_color = EDITOR_GET (" text_editor/theme/highlighting/keyword_color" );
51+ const Color control_flow_keyword_color = EDITOR_GET (" text_editor/theme/highlighting/control_flow_keyword_color" );
52+
53+ for (const String &keyword : keywords) {
54+ if (ShaderLanguage::is_control_flow_keyword (keyword)) {
55+ syntax_highlighter->add_keyword_color (keyword, control_flow_keyword_color);
56+ } else {
57+ syntax_highlighter->add_keyword_color (keyword, keyword_color);
58+ }
59+ }
60+
61+ // Colorize comments.
62+ const Color comment_color = EDITOR_GET (" text_editor/theme/highlighting/comment_color" );
63+ syntax_highlighter->clear_color_regions ();
64+ syntax_highlighter->add_color_region (" /*" , " */" , comment_color, false );
65+ syntax_highlighter->add_color_region (" //" , " " , comment_color, true );
66+
67+ // Colorize preprocessor statements.
68+ const Color user_type_color = EDITOR_GET (" text_editor/theme/highlighting/user_type_color" );
69+ syntax_highlighter->add_color_region (" #" , " " , user_type_color, true );
70+
71+ syntax_highlighter->set_uint_suffix_enabled (true );
72+ }
73+
4074void EditorNativeShaderSourceVisualizer::_inspect_shader (RID p_shader) {
4175 if (versions) {
4276 memdelete (versions);
@@ -45,10 +79,7 @@ void EditorNativeShaderSourceVisualizer::_inspect_shader(RID p_shader) {
4579
4680 RS::ShaderNativeSourceCode nsc = RS::get_singleton ()->shader_get_native_source_code (p_shader);
4781
48- List<String> keywords;
49- ShaderLanguage::get_keyword_list (&keywords);
50- Ref<EditorJsonVisualizerSyntaxHighlighter> syntax_highlighter;
51- syntax_highlighter.instantiate (keywords);
82+ _load_theme_settings ();
5283
5384 versions = memnew (TabContainer);
5485 versions->set_tab_alignment (TabBar::ALIGNMENT_CENTER);
@@ -62,8 +93,50 @@ void EditorNativeShaderSourceVisualizer::_inspect_shader(RID p_shader) {
6293 vtab->set_h_size_flags (Control::SIZE_EXPAND_FILL);
6394 versions->add_child (vtab);
6495 for (int j = 0 ; j < nsc.versions [i].stages .size (); j++) {
65- EditorJsonVisualizer *code_edit = memnew (EditorJsonVisualizer);
66- code_edit->load_theme (syntax_highlighter);
96+ CodeEdit *code_edit = memnew (CodeEdit);
97+ code_edit->set_editable (false );
98+ code_edit->set_syntax_highlighter (syntax_highlighter);
99+ code_edit->add_theme_font_override (SceneStringName (font), get_theme_font (" source" , EditorStringName (EditorFonts)));
100+ code_edit->add_theme_font_size_override (SceneStringName (font_size), get_theme_font_size (" source_size" , EditorStringName (EditorFonts)));
101+ code_edit->add_theme_constant_override (" line_spacing" , EDITOR_GET (" text_editor/appearance/whitespace/line_spacing" ));
102+
103+ // Appearance: Caret
104+ code_edit->set_caret_type ((TextEdit::CaretType)EDITOR_GET (" text_editor/appearance/caret/type" ).operator int ());
105+ code_edit->set_caret_blink_enabled (EDITOR_GET (" text_editor/appearance/caret/caret_blink" ));
106+ code_edit->set_caret_blink_interval (EDITOR_GET (" text_editor/appearance/caret/caret_blink_interval" ));
107+ code_edit->set_highlight_current_line (EDITOR_GET (" text_editor/appearance/caret/highlight_current_line" ));
108+ code_edit->set_highlight_all_occurrences (EDITOR_GET (" text_editor/appearance/caret/highlight_all_occurrences" ));
109+
110+ // Appearance: Gutters
111+ code_edit->set_draw_line_numbers (EDITOR_GET (" text_editor/appearance/gutters/show_line_numbers" ));
112+ code_edit->set_line_numbers_zero_padded (EDITOR_GET (" text_editor/appearance/gutters/line_numbers_zero_padded" ));
113+
114+ // Appearance: Minimap
115+ code_edit->set_draw_minimap (EDITOR_GET (" text_editor/appearance/minimap/show_minimap" ));
116+ code_edit->set_minimap_width ((int )EDITOR_GET (" text_editor/appearance/minimap/minimap_width" ) * EDSCALE);
117+
118+ // Appearance: Lines
119+ code_edit->set_line_folding_enabled (EDITOR_GET (" text_editor/appearance/lines/code_folding" ));
120+ code_edit->set_draw_fold_gutter (EDITOR_GET (" text_editor/appearance/lines/code_folding" ));
121+ code_edit->set_line_wrapping_mode ((TextEdit::LineWrappingMode)EDITOR_GET (" text_editor/appearance/lines/word_wrap" ).operator int ());
122+ code_edit->set_autowrap_mode ((TextServer::AutowrapMode)EDITOR_GET (" text_editor/appearance/lines/autowrap_mode" ).operator int ());
123+
124+ // Appearance: Whitespace
125+ code_edit->set_draw_tabs (EDITOR_GET (" text_editor/appearance/whitespace/draw_tabs" ));
126+ code_edit->set_draw_spaces (EDITOR_GET (" text_editor/appearance/whitespace/draw_spaces" ));
127+ code_edit->add_theme_constant_override (" line_spacing" , EDITOR_GET (" text_editor/appearance/whitespace/line_spacing" ));
128+
129+ // Behavior: Navigation
130+ code_edit->set_scroll_past_end_of_file_enabled (EDITOR_GET (" text_editor/behavior/navigation/scroll_past_end_of_file" ));
131+ code_edit->set_smooth_scroll_enabled (EDITOR_GET (" text_editor/behavior/navigation/smooth_scrolling" ));
132+ code_edit->set_v_scroll_speed (EDITOR_GET (" text_editor/behavior/navigation/v_scroll_speed" ));
133+ code_edit->set_drag_and_drop_selection_enabled (EDITOR_GET (" text_editor/behavior/navigation/drag_and_drop_selection" ));
134+
135+ // Behavior: Indent
136+ code_edit->set_indent_size (EDITOR_GET (" text_editor/behavior/indent/size" ));
137+ code_edit->set_auto_indent_enabled (EDITOR_GET (" text_editor/behavior/indent/auto_indent" ));
138+ code_edit->set_indent_wrapped_lines (EDITOR_GET (" text_editor/behavior/indent/indent_wrapped_lines" ));
139+
67140 code_edit->set_name (nsc.versions [i].stages [j].name );
68141 code_edit->set_text (nsc.versions [i].stages [j].code );
69142 code_edit->set_v_size_flags (Control::SIZE_EXPAND_FILL);
@@ -80,6 +153,8 @@ void EditorNativeShaderSourceVisualizer::_bind_methods() {
80153}
81154
82155EditorNativeShaderSourceVisualizer::EditorNativeShaderSourceVisualizer () {
156+ syntax_highlighter.instantiate ();
157+
83158 add_to_group (" _native_shader_source_visualizer" );
84159 set_title (TTR (" Native Shader Source Inspector" ));
85160}
0 commit comments