1 /*************************************************************************/ 2 /* shader_editor_plugin.h */ 3 /*************************************************************************/ 4 /* This file is part of: */ 5 /* GODOT ENGINE */ 6 /* https://godotengine.org */ 7 /*************************************************************************/ 8 /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ 9 /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ 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 #ifndef SHADER_EDITOR_PLUGIN_H 32 #define SHADER_EDITOR_PLUGIN_H 33 34 #include "editor/code_editor.h" 35 #include "editor/editor_plugin.h" 36 #include "scene/gui/menu_button.h" 37 #include "scene/gui/panel_container.h" 38 #include "scene/gui/tab_container.h" 39 #include "scene/gui/text_edit.h" 40 #include "scene/main/timer.h" 41 #include "scene/resources/shader.h" 42 #include "servers/visual/shader_language.h" 43 44 class ShaderTextEditor : public CodeTextEditor { 45 46 GDCLASS(ShaderTextEditor, CodeTextEditor); 47 48 Ref<Shader> shader; 49 50 void _check_shader_mode(); 51 52 protected: 53 static void _bind_methods(); 54 virtual void _load_theme_settings(); 55 56 virtual void _code_complete_script(const String &p_code, List<ScriptCodeCompletionOption> *r_options); 57 58 public: 59 virtual void _validate_script(); 60 61 void reload_text(); 62 63 Ref<Shader> get_edited_shader() const; 64 void set_edited_shader(const Ref<Shader> &p_shader); 65 ShaderTextEditor(); 66 }; 67 68 class ShaderEditor : public PanelContainer { 69 70 GDCLASS(ShaderEditor, PanelContainer); 71 72 enum { 73 74 EDIT_UNDO, 75 EDIT_REDO, 76 EDIT_CUT, 77 EDIT_COPY, 78 EDIT_PASTE, 79 EDIT_SELECT_ALL, 80 EDIT_MOVE_LINE_UP, 81 EDIT_MOVE_LINE_DOWN, 82 EDIT_INDENT_LEFT, 83 EDIT_INDENT_RIGHT, 84 EDIT_DELETE_LINE, 85 EDIT_CLONE_DOWN, 86 EDIT_TOGGLE_COMMENT, 87 EDIT_COMPLETE, 88 SEARCH_FIND, 89 SEARCH_FIND_NEXT, 90 SEARCH_FIND_PREV, 91 SEARCH_REPLACE, 92 SEARCH_GOTO_LINE, 93 BOOKMARK_TOGGLE, 94 BOOKMARK_GOTO_NEXT, 95 BOOKMARK_GOTO_PREV, 96 BOOKMARK_REMOVE_ALL, 97 HELP_DOCS, 98 }; 99 100 MenuButton *edit_menu; 101 MenuButton *search_menu; 102 PopupMenu *bookmarks_menu; 103 MenuButton *help_menu; 104 PopupMenu *context_menu; 105 uint64_t idle; 106 107 GotoLineDialog *goto_line_dialog; 108 ConfirmationDialog *erase_tab_confirm; 109 ConfirmationDialog *disk_changed; 110 111 ShaderTextEditor *shader_editor; 112 113 void _menu_option(int p_option); 114 void _params_changed(); 115 mutable Ref<Shader> shader; 116 117 void _editor_settings_changed(); 118 119 void _check_for_external_edit(); 120 void _reload_shader_from_disk(); 121 122 protected: 123 void _notification(int p_what); 124 static void _bind_methods(); 125 void _make_context_menu(bool p_selection, Vector2 p_position); 126 void _text_edit_gui_input(const Ref<InputEvent> &ev); 127 128 void _update_bookmark_list(); 129 void _bookmark_item_pressed(int p_idx); 130 131 public: 132 void apply_shaders(); 133 134 void ensure_select_current(); 135 void edit(const Ref<Shader> &p_shader); 136 137 void goto_line_selection(int p_line, int p_begin, int p_end); 138 get_minimum_size()139 virtual Size2 get_minimum_size() const { return Size2(0, 200); } 140 void save_external_data(const String &p_str = ""); 141 142 ShaderEditor(EditorNode *p_node); 143 }; 144 145 class ShaderEditorPlugin : public EditorPlugin { 146 147 GDCLASS(ShaderEditorPlugin, EditorPlugin); 148 149 bool _2d; 150 ShaderEditor *shader_editor; 151 EditorNode *editor; 152 Button *button; 153 154 public: get_name()155 virtual String get_name() const { return "Shader"; } has_main_screen()156 bool has_main_screen() const { return false; } 157 virtual void edit(Object *p_object); 158 virtual bool handles(Object *p_object) const; 159 virtual void make_visible(bool p_visible); 160 virtual void selected_notify(); 161 get_shader_editor()162 ShaderEditor *get_shader_editor() const { return shader_editor; } 163 164 virtual void save_external_data(); 165 virtual void apply_changes(); 166 167 ShaderEditorPlugin(EditorNode *p_node); 168 ~ShaderEditorPlugin(); 169 }; 170 171 #endif 172