Path: blob/master/editor/shader/text_shader_editor.h
10277 views
/**************************************************************************/1/* text_shader_editor.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "editor/gui/code_editor.h"33#include "editor/shader/shader_editor.h"34#include "scene/gui/menu_button.h"35#include "scene/gui/rich_text_label.h"36#include "servers/rendering/shader_warnings.h"3738class GDShaderSyntaxHighlighter : public CodeHighlighter {39GDCLASS(GDShaderSyntaxHighlighter, CodeHighlighter)4041private:42Vector<Point2i> disabled_branch_regions;43Color disabled_branch_color;4445public:46virtual Dictionary _get_line_syntax_highlighting_impl(int p_line) override;4748void add_disabled_branch_region(const Point2i &p_region);49void clear_disabled_branch_regions();50void set_disabled_branch_color(const Color &p_color);51};5253class ShaderTextEditor : public CodeTextEditor {54GDCLASS(ShaderTextEditor, CodeTextEditor);5556Color marked_line_color = Color(1, 1, 1);5758struct WarningsComparator {59_ALWAYS_INLINE_ bool operator()(const ShaderWarning &p_a, const ShaderWarning &p_b) const { return (p_a.get_line() < p_b.get_line()); }60};6162Ref<GDShaderSyntaxHighlighter> syntax_highlighter;63RichTextLabel *warnings_panel = nullptr;64Ref<Shader> shader;65Ref<ShaderInclude> shader_inc;66List<ShaderWarning> warnings;67Error last_compile_result = Error::OK;6869void _check_shader_mode();70void _update_warning_panel();7172bool block_shader_changed = false;73void _shader_changed();7475uint32_t dependencies_version = 0; // Incremented if deps changed7677protected:78void _notification(int p_what);79static void _bind_methods();80virtual void _load_theme_settings() override;8182virtual void _code_complete_script(const String &p_code, List<ScriptLanguage::CodeCompletionOption> *r_options) override;8384public:85void set_block_shader_changed(bool p_block) { block_shader_changed = p_block; }86uint32_t get_dependencies_version() const { return dependencies_version; }8788virtual void _validate_script() override;8990void reload_text();91void set_warnings_panel(RichTextLabel *p_warnings_panel);9293Ref<Shader> get_edited_shader() const;94Ref<ShaderInclude> get_edited_shader_include() const;9596void set_edited_shader(const Ref<Shader> &p_shader);97void set_edited_shader(const Ref<Shader> &p_shader, const String &p_code);98void set_edited_shader_include(const Ref<ShaderInclude> &p_include);99void set_edited_shader_include(const Ref<ShaderInclude> &p_include, const String &p_code);100void set_edited_code(const String &p_code);101102ShaderTextEditor();103};104105class TextShaderEditor : public ShaderEditor {106GDCLASS(TextShaderEditor, ShaderEditor);107108enum {109EDIT_UNDO,110EDIT_REDO,111EDIT_CUT,112EDIT_COPY,113EDIT_PASTE,114EDIT_SELECT_ALL,115EDIT_MOVE_LINE_UP,116EDIT_MOVE_LINE_DOWN,117EDIT_INDENT,118EDIT_UNINDENT,119EDIT_DELETE_LINE,120EDIT_DUPLICATE_SELECTION,121EDIT_DUPLICATE_LINES,122EDIT_TOGGLE_WORD_WRAP,123EDIT_TOGGLE_COMMENT,124EDIT_COMPLETE,125SEARCH_FIND,126SEARCH_FIND_NEXT,127SEARCH_FIND_PREV,128SEARCH_REPLACE,129SEARCH_GOTO_LINE,130BOOKMARK_TOGGLE,131BOOKMARK_GOTO_NEXT,132BOOKMARK_GOTO_PREV,133BOOKMARK_REMOVE_ALL,134HELP_DOCS,135EDIT_EMOJI_AND_SYMBOL,136};137138HBoxContainer *menu_bar_hbox = nullptr;139MenuButton *edit_menu = nullptr;140MenuButton *search_menu = nullptr;141PopupMenu *bookmarks_menu = nullptr;142Button *site_search = nullptr;143PopupMenu *context_menu = nullptr;144RichTextLabel *warnings_panel = nullptr;145uint64_t idle = 0;146147GotoLinePopup *goto_line_popup = nullptr;148ConfirmationDialog *erase_tab_confirm = nullptr;149ConfirmationDialog *disk_changed = nullptr;150151ShaderTextEditor *code_editor = nullptr;152bool compilation_success = true;153154void _menu_option(int p_option);155void _prepare_edit_menu();156mutable Ref<Shader> shader;157mutable Ref<ShaderInclude> shader_inc;158159void _editor_settings_changed();160void _apply_editor_settings();161void _project_settings_changed();162163void _check_for_external_edit();164void _reload_shader_from_disk();165void _reload_shader_include_from_disk();166void _reload();167void _show_warnings_panel(bool p_show);168void _warning_clicked(const Variant &p_line);169void _update_warnings(bool p_validate);170171void _script_validated(bool p_valid) {172compilation_success = p_valid;173emit_signal(SNAME("validation_changed"));174}175176uint32_t dependencies_version = 0xFFFFFFFF;177178bool trim_trailing_whitespace_on_save;179bool trim_final_newlines_on_save;180181protected:182void _notification(int p_what);183static void _bind_methods();184void _make_context_menu(bool p_selection, Vector2 p_position);185void _text_edit_gui_input(const Ref<InputEvent> &p_ev);186187void _update_bookmark_list();188void _bookmark_item_pressed(int p_idx);189190public:191virtual void edit_shader(const Ref<Shader> &p_shader) override;192virtual void edit_shader_include(const Ref<ShaderInclude> &p_shader_inc) override;193virtual void use_menu_bar_items(MenuButton *p_file_menu, Button *p_make_floating) override;194195virtual void apply_shaders() override;196virtual bool is_unsaved() const override;197virtual void save_external_data(const String &p_str = "") override;198virtual void validate_script() override;199200bool was_compilation_successful() const { return compilation_success; }201bool get_trim_trailing_whitespace_on_save() const { return trim_trailing_whitespace_on_save; }202bool get_trim_final_newlines_on_save() const { return trim_final_newlines_on_save; }203void ensure_select_current();204void goto_line_selection(int p_line, int p_begin, int p_end);205void trim_trailing_whitespace();206void trim_final_newlines();207void tag_saved_version();208ShaderTextEditor *get_code_editor() { return code_editor; }209210virtual Size2 get_minimum_size() const override { return Size2(0, 200); }211212TextShaderEditor();213};214215216