Path: blob/master/editor/shader/text_shader_editor.h
21217 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;145146GotoLinePopup *goto_line_popup = nullptr;147ConfirmationDialog *disk_changed = nullptr;148149ShaderTextEditor *code_editor = nullptr;150bool compilation_success = true;151152void _menu_option(int p_option);153void _prepare_edit_menu();154mutable Ref<Shader> shader;155mutable Ref<ShaderInclude> shader_inc;156157void _apply_editor_settings();158void _project_settings_changed();159160void _check_for_external_edit();161void _reload_shader_from_disk();162void _reload_shader_include_from_disk();163void _reload();164void _show_warnings_panel(bool p_show);165void _warning_clicked(const Variant &p_line);166void _update_warnings(bool p_validate);167168void _script_validated(bool p_valid) {169compilation_success = p_valid;170emit_signal(SNAME("validation_changed"));171}172173uint32_t dependencies_version = 0xFFFFFFFF;174175bool trim_trailing_whitespace_on_save = false;176bool trim_final_newlines_on_save = false;177178protected:179void _notification(int p_what);180static void _bind_methods();181void _make_context_menu(bool p_selection, Vector2 p_position);182void _text_edit_gui_input(const Ref<InputEvent> &p_ev);183184void _update_bookmark_list();185void _bookmark_item_pressed(int p_idx);186187public:188virtual void edit_shader(const Ref<Shader> &p_shader) override;189virtual void edit_shader_include(const Ref<ShaderInclude> &p_shader_inc) override;190virtual void use_menu_bar(MenuButton *p_file_menu) override;191192virtual void apply_shaders() override;193virtual bool is_unsaved() const override;194virtual void save_external_data(const String &p_str = "") override;195virtual void set_toggle_list_control(Control *p_toggle_list_control) override;196virtual void update_toggle_files_button() override;197virtual void validate_script() override;198199bool was_compilation_successful() const { return compilation_success; }200bool get_trim_trailing_whitespace_on_save() const { return trim_trailing_whitespace_on_save; }201bool get_trim_final_newlines_on_save() const { return trim_final_newlines_on_save; }202void ensure_select_current();203void goto_line_selection(int p_line, int p_begin, int p_end);204void trim_trailing_whitespace();205void trim_final_newlines();206void tag_saved_version();207ShaderTextEditor *get_code_editor() { return code_editor; }208209virtual Size2 get_minimum_size() const override { return Size2(0, 200); }210211TextShaderEditor();212};213214215