| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "editor/gui/code_editor.h" |
| 34 |
#include "editor/shader/shader_editor.h" |
| 35 |
#include "scene/gui/menu_button.h" |
| 36 |
#include "scene/gui/rich_text_label.h" |
| 37 |
#include "servers/rendering/shader_warnings.h" |
| 38 |
|
| 39 |
class GDShaderSyntaxHighlighter : public CodeHighlighter { |
| 40 |
GDCLASS(GDShaderSyntaxHighlighter, CodeHighlighter) |
| 41 |
|
| 42 |
private: |
| 43 |
Vector<Point2i> disabled_branch_regions; |
| 44 |
Color disabled_branch_color; |
| 45 |
|
| 46 |
public: |
| 47 |
virtual Dictionary _get_line_syntax_highlighting_impl(int p_line) override; |
| 48 |
|
| 49 |
void add_disabled_branch_region(const Point2i &p_region); |
| 50 |
void clear_disabled_branch_regions(); |
| 51 |
void set_disabled_branch_color(const Color &p_color); |
| 52 |
}; |
| 53 |
|
| 54 |
class ShaderTextEditor : public CodeTextEditor { |
| 55 |
GDCLASS(ShaderTextEditor, CodeTextEditor); |
| 56 |
|
| 57 |
Color marked_line_color = Color(1, 1, 1); |
| 58 |
|
| 59 |
struct WarningsComparator { |
| 60 |
_ALWAYS_INLINE_ bool operator()(const ShaderWarning &p_a, const ShaderWarning &p_b) const { return (p_a.get_line() < p_b.get_line()); } |
| 61 |
}; |
| 62 |
|
| 63 |
Ref<GDShaderSyntaxHighlighter> syntax_highlighter; |
| 64 |
RichTextLabel *warnings_panel = nullptr; |
| 65 |
Ref<Shader> shader; |
| 66 |
Ref<ShaderInclude> shader_inc; |
| 67 |
List<ShaderWarning> warnings; |
| 68 |
Error last_compile_result = Error::OK; |
| 69 |
|
| 70 |
void _check_shader_mode(); |
| 71 |
void _update_warning_panel(); |
| 72 |
|
| 73 |
bool block_shader_changed = false; |
| 74 |
void _shader_changed(); |
| 75 |
|
| 76 |
uint32_t dependencies_version = 0; |
| 77 |
|
| 78 |
protected: |
| 79 |
void _notification(int p_what); |
| 80 |
static void _bind_methods(); |
| 81 |
virtual void _load_theme_settings() override; |
| 82 |
|
| 83 |
virtual void _code_complete_script(const String &p_code, List<ScriptLanguage::CodeCompletionOption> *r_options) override; |
| 84 |
|
| 85 |
public: |
| 86 |
void set_block_shader_changed(bool p_block) { block_shader_changed = p_block; } |
| 87 |
uint32_t get_dependencies_version() const { return dependencies_version; } |
| 88 |
|
| 89 |
virtual void _validate_script() override; |
| 90 |
|
| 91 |
void reload_text(); |
| 92 |
void set_warnings_panel(RichTextLabel *p_warnings_panel); |
| 93 |
|
| 94 |
Ref<Shader> get_edited_shader() const; |
| 95 |
Ref<ShaderInclude> get_edited_shader_include() const; |
| 96 |
|
| 97 |
void set_edited_shader(const Ref<Shader> &p_shader); |
| 98 |
void set_edited_shader(const Ref<Shader> &p_shader, const String &p_code); |
| 99 |
void set_edited_shader_include(const Ref<ShaderInclude> &p_include); |
| 100 |
void set_edited_shader_include(const Ref<ShaderInclude> &p_include, const String &p_code); |
| 101 |
void set_edited_code(const String &p_code); |
| 102 |
|
| 103 |
ShaderTextEditor(); |
| 104 |
}; |
| 105 |
|
| 106 |
class TextShaderEditor : public ShaderEditor { |
| 107 |
GDCLASS(TextShaderEditor, ShaderEditor); |
| 108 |
|
| 109 |
enum { |
| 110 |
EDIT_UNDO, |
| 111 |
EDIT_REDO, |
| 112 |
EDIT_CUT, |
| 113 |
EDIT_COPY, |
| 114 |
EDIT_PASTE, |
| 115 |
EDIT_SELECT_ALL, |
| 116 |
EDIT_MOVE_LINE_UP, |
| 117 |
EDIT_MOVE_LINE_DOWN, |
| 118 |
EDIT_INDENT, |
| 119 |
EDIT_UNINDENT, |
| 120 |
EDIT_DELETE_LINE, |
| 121 |
EDIT_DUPLICATE_SELECTION, |
| 122 |
EDIT_DUPLICATE_LINES, |
| 123 |
EDIT_TOGGLE_WORD_WRAP, |
| 124 |
EDIT_TOGGLE_COMMENT, |
| 125 |
EDIT_COMPLETE, |
| 126 |
SEARCH_FIND, |
| 127 |
SEARCH_FIND_NEXT, |
| 128 |
SEARCH_FIND_PREV, |
| 129 |
SEARCH_REPLACE, |
| 130 |
SEARCH_GOTO_LINE, |
| 131 |
BOOKMARK_TOGGLE, |
| 132 |
BOOKMARK_GOTO_NEXT, |
| 133 |
BOOKMARK_GOTO_PREV, |
| 134 |
BOOKMARK_REMOVE_ALL, |
| 135 |
HELP_DOCS, |
| 136 |
EDIT_EMOJI_AND_SYMBOL, |
| 137 |
}; |
| 138 |
|
| 139 |
HBoxContainer *menu_bar_hbox = nullptr; |
| 140 |
MenuButton *edit_menu = nullptr; |
| 141 |
MenuButton *search_menu = nullptr; |
| 142 |
PopupMenu *bookmarks_menu = nullptr; |
| 143 |
Button *site_search = nullptr; |
| 144 |
PopupMenu *context_menu = nullptr; |
| 145 |
RichTextLabel *warnings_panel = nullptr; |
| 146 |
|
| 147 |
GotoLinePopup *goto_line_popup = nullptr; |
| 148 |
ConfirmationDialog *disk_changed = nullptr; |
| 149 |
|
| 150 |
ShaderTextEditor *code_editor = nullptr; |
| 151 |
bool compilation_success = true; |
| 152 |
|
| 153 |
void _menu_option(int p_option); |
| 154 |
void _prepare_edit_menu(); |
| 155 |
mutable Ref<Shader> shader; |
| 156 |
mutable Ref<ShaderInclude> shader_inc; |
| 157 |
|
| 158 |
void _apply_editor_settings(); |
| 159 |
void _project_settings_changed(); |
| 160 |
|
| 161 |
void _check_for_external_edit(); |
| 162 |
void _reload_shader_from_disk(); |
| 163 |
void _reload_shader_include_from_disk(); |
| 164 |
void _reload(); |
| 165 |
void _show_warnings_panel(bool p_show); |
| 166 |
void _warning_clicked(const Variant &p_line); |
| 167 |
void _update_warnings(bool p_validate); |
| 168 |
|
| 169 |
void _script_validated(bool p_valid) { |
| 170 |
compilation_success = p_valid; |
| 171 |
emit_signal(SNAME("validation_changed")); |
| 172 |
} |
| 173 |
|
| 174 |
uint32_t dependencies_version = 0xFFFFFFFF; |
| 175 |
|
| 176 |
bool trim_trailing_whitespace_on_save = false; |
| 177 |
bool trim_final_newlines_on_save = false; |
| 178 |
|
| 179 |
protected: |
| 180 |
void _notification(int p_what); |
| 181 |
static void _bind_methods(); |
| 182 |
void _make_context_menu(bool p_selection, Vector2 p_position); |
| 183 |
void _text_edit_gui_input(const Ref<InputEvent> &p_ev); |
| 184 |
|
| 185 |
void _update_bookmark_list(); |
| 186 |
void _bookmark_item_pressed(int p_idx); |
| 187 |
|
| 188 |
public: |
| 189 |
virtual void edit_shader(const Ref<Shader> &p_shader) override; |
| 190 |
virtual void edit_shader_include(const Ref<ShaderInclude> &p_shader_inc) override; |
| 191 |
virtual void use_menu_bar(MenuButton *p_file_menu) override; |
| 192 |
|
| 193 |
virtual void apply_shaders() override; |
| 194 |
virtual bool is_unsaved() const override; |
| 195 |
virtual void save_external_data(const String &p_str = "") override; |
| 196 |
virtual void set_toggle_list_control(Control *p_toggle_list_control) override; |
| 197 |
virtual void update_toggle_files_button() override; |
| 198 |
virtual void validate_script() override; |
| 199 |
|
| 200 |
bool was_compilation_successful() const { return compilation_success; } |
| 201 |
bool get_trim_trailing_whitespace_on_save() const { return trim_trailing_whitespace_on_save; } |
| 202 |
bool get_trim_final_newlines_on_save() const { return trim_final_newlines_on_save; } |
| 203 |
void ensure_select_current(); |
| 204 |
void goto_line_selection(int p_line, int p_begin, int p_end); |
| 205 |
void trim_trailing_whitespace(); |
| 206 |
void trim_final_newlines(); |
| 207 |
void tag_saved_version(); |
| 208 |
ShaderTextEditor *get_code_editor() { return code_editor; } |
| 209 |
|
| 210 |
virtual Size2 get_minimum_size() const override { return Size2(0, 200); } |
| 211 |
|
| 212 |
TextShaderEditor(); |
| 213 |
}; |