shader_editor_plugin.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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. #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/menu_button.h"
  35. #include "scene/gui/panel_container.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<String> *r_options);
  49. public:
  50. virtual void _validate_script();
  51. Ref<Shader> get_edited_shader() const;
  52. void set_edited_shader(const Ref<Shader> &p_shader);
  53. ShaderTextEditor();
  54. };
  55. class ShaderEditor : public PanelContainer {
  56. GDCLASS(ShaderEditor, PanelContainer);
  57. enum {
  58. EDIT_UNDO,
  59. EDIT_REDO,
  60. EDIT_CUT,
  61. EDIT_COPY,
  62. EDIT_PASTE,
  63. EDIT_SELECT_ALL,
  64. EDIT_MOVE_LINE_UP,
  65. EDIT_MOVE_LINE_DOWN,
  66. EDIT_INDENT_LEFT,
  67. EDIT_INDENT_RIGHT,
  68. EDIT_DELETE_LINE,
  69. EDIT_CLONE_DOWN,
  70. EDIT_TOGGLE_COMMENT,
  71. EDIT_COMPLETE,
  72. SEARCH_FIND,
  73. SEARCH_FIND_NEXT,
  74. SEARCH_FIND_PREV,
  75. SEARCH_REPLACE,
  76. SEARCH_GOTO_LINE,
  77. };
  78. MenuButton *edit_menu;
  79. MenuButton *search_menu;
  80. MenuButton *settings_menu;
  81. PopupMenu *context_menu;
  82. uint64_t idle;
  83. GotoLineDialog *goto_line_dialog;
  84. ConfirmationDialog *erase_tab_confirm;
  85. ShaderTextEditor *shader_editor;
  86. void _menu_option(int p_option);
  87. void _params_changed();
  88. mutable Ref<Shader> shader;
  89. void _editor_settings_changed();
  90. protected:
  91. void _notification(int p_what);
  92. static void _bind_methods();
  93. void _make_context_menu(bool p_selection);
  94. void _text_edit_gui_input(const Ref<InputEvent> &ev);
  95. public:
  96. void apply_shaders();
  97. void ensure_select_current();
  98. void edit(const Ref<Shader> &p_shader);
  99. void goto_line_selection(int p_line, int p_begin, int p_end);
  100. virtual Size2 get_minimum_size() const { return Size2(0, 200); }
  101. void save_external_data();
  102. ShaderEditor(EditorNode *p_node);
  103. };
  104. class ShaderEditorPlugin : public EditorPlugin {
  105. GDCLASS(ShaderEditorPlugin, EditorPlugin);
  106. bool _2d;
  107. ShaderEditor *shader_editor;
  108. EditorNode *editor;
  109. Button *button;
  110. public:
  111. virtual String get_name() const { return "Shader"; }
  112. bool has_main_screen() const { return false; }
  113. virtual void edit(Object *p_object);
  114. virtual bool handles(Object *p_object) const;
  115. virtual void make_visible(bool p_visible);
  116. virtual void selected_notify();
  117. ShaderEditor *get_shader_editor() const { return shader_editor; }
  118. virtual void save_external_data();
  119. virtual void apply_changes();
  120. ShaderEditorPlugin(EditorNode *p_node);
  121. ~ShaderEditorPlugin();
  122. };
  123. #endif