shader_editor_plugin.h 5.3 KB

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