shader_editor_plugin.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. #pragma once
  31. #include "editor/plugins/editor_plugin.h"
  32. class CodeTextEditor;
  33. class HSplitContainer;
  34. class ItemList;
  35. class MenuButton;
  36. class ShaderCreateDialog;
  37. class ShaderEditor;
  38. class TabContainer;
  39. class TextShaderEditor;
  40. class VBoxContainer;
  41. class HBoxContainer;
  42. class VisualShaderEditor;
  43. class WindowWrapper;
  44. class ShaderEditorPlugin : public EditorPlugin {
  45. GDCLASS(ShaderEditorPlugin, EditorPlugin);
  46. struct EditedShader {
  47. Ref<Shader> shader;
  48. Ref<ShaderInclude> shader_inc;
  49. ShaderEditor *shader_editor = nullptr;
  50. String path;
  51. String name;
  52. };
  53. LocalVector<EditedShader> edited_shaders;
  54. enum FileMenu {
  55. FILE_MENU_NEW,
  56. FILE_MENU_NEW_INCLUDE,
  57. FILE_MENU_OPEN,
  58. FILE_MENU_OPEN_INCLUDE,
  59. FILE_MENU_SAVE,
  60. FILE_MENU_SAVE_AS,
  61. FILE_MENU_INSPECT,
  62. FILE_MENU_INSPECT_NATIVE_SHADER_CODE,
  63. FILE_MENU_CLOSE,
  64. FILE_MENU_CLOSE_ALL,
  65. FILE_MENU_CLOSE_OTHER_TABS,
  66. FILE_MENU_SHOW_IN_FILE_SYSTEM,
  67. FILE_MENU_COPY_PATH,
  68. FILE_MENU_TOGGLE_FILES_PANEL,
  69. };
  70. enum PopupMenuType {
  71. FILE,
  72. CONTEXT,
  73. CONTEXT_VALID_ITEM,
  74. };
  75. VBoxContainer *main_container = nullptr;
  76. HSplitContainer *files_split = nullptr;
  77. HBoxContainer *menu_hb = nullptr;
  78. Control *menu_spacer = nullptr;
  79. ItemList *shader_list = nullptr;
  80. TabContainer *shader_tabs = nullptr;
  81. Button *button = nullptr;
  82. MenuButton *file_menu = nullptr;
  83. PopupMenu *context_menu = nullptr;
  84. WindowWrapper *window_wrapper = nullptr;
  85. Button *make_floating = nullptr;
  86. ShaderCreateDialog *shader_create_dialog = nullptr;
  87. float text_shader_zoom_factor = 1.0f;
  88. Ref<Resource> _get_current_shader();
  89. void _update_shader_list();
  90. void _shader_selected(int p_index, bool p_push_item = true);
  91. void _shader_list_clicked(int p_item, Vector2 p_local_mouse_pos, MouseButton p_mouse_button_index);
  92. void _setup_popup_menu(PopupMenuType p_type, PopupMenu *p_menu);
  93. void _make_script_list_context_menu();
  94. void _menu_item_pressed(int p_index);
  95. void _resource_saved(Object *obj);
  96. void _close_shader(int p_index);
  97. void _close_builtin_shaders_from_scene(const String &p_scene);
  98. void _file_removed(const String &p_removed_file);
  99. void _res_saved_callback(const Ref<Resource> &p_res);
  100. void _set_file_specific_items_disabled(bool p_disabled);
  101. void _shader_created(Ref<Shader> p_shader);
  102. void _shader_include_created(Ref<ShaderInclude> p_shader_inc);
  103. void _update_shader_list_status();
  104. void _move_shader_tab(int p_from, int p_to);
  105. Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
  106. bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
  107. void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
  108. void _window_changed(bool p_visible);
  109. void _set_text_shader_zoom_factor(float p_zoom_factor);
  110. void _update_shader_editor_zoom_factor(CodeTextEditor *p_shader_editor) const;
  111. void _switch_to_editor(ShaderEditor *p_editor);
  112. protected:
  113. void _notification(int p_what);
  114. public:
  115. virtual String get_plugin_name() const override { return "Shader"; }
  116. virtual void edit(Object *p_object) override;
  117. virtual bool handles(Object *p_object) const override;
  118. virtual void make_visible(bool p_visible) override;
  119. virtual void selected_notify() override;
  120. ShaderEditor *get_shader_editor(const Ref<Shader> &p_for_shader);
  121. virtual void set_window_layout(Ref<ConfigFile> p_layout) override;
  122. virtual void get_window_layout(Ref<ConfigFile> p_layout) override;
  123. virtual String get_unsaved_status(const String &p_for_scene) const override;
  124. virtual void save_external_data() override;
  125. virtual void apply_changes() override;
  126. ShaderEditorPlugin();
  127. };