shader_editor_plugin.h 5.5 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. #ifndef SHADER_EDITOR_PLUGIN_H
  31. #define SHADER_EDITOR_PLUGIN_H
  32. #include "editor/plugins/editor_plugin.h"
  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 VisualShaderEditor;
  42. class WindowWrapper;
  43. #ifdef MINGW_ENABLED
  44. #undef FILE_OPEN
  45. #endif
  46. class ShaderEditorPlugin : public EditorPlugin {
  47. GDCLASS(ShaderEditorPlugin, EditorPlugin);
  48. struct EditedShader {
  49. Ref<Shader> shader;
  50. Ref<ShaderInclude> shader_inc;
  51. ShaderEditor *shader_editor = nullptr;
  52. String path;
  53. String name;
  54. };
  55. LocalVector<EditedShader> edited_shaders;
  56. enum {
  57. FILE_NEW,
  58. FILE_NEW_INCLUDE,
  59. FILE_OPEN,
  60. FILE_OPEN_INCLUDE,
  61. FILE_SAVE,
  62. FILE_SAVE_AS,
  63. FILE_INSPECT,
  64. FILE_INSPECT_NATIVE_SHADER_CODE,
  65. FILE_CLOSE,
  66. CLOSE_ALL,
  67. CLOSE_OTHER_TABS,
  68. SHOW_IN_FILE_SYSTEM,
  69. COPY_PATH,
  70. };
  71. enum PopupMenuType {
  72. FILE,
  73. CONTEXT,
  74. CONTEXT_VALID_ITEM,
  75. };
  76. HSplitContainer *main_split = nullptr;
  77. VBoxContainer *left_panel = nullptr;
  78. ItemList *shader_list = nullptr;
  79. TabContainer *shader_tabs = nullptr;
  80. Button *button = nullptr;
  81. MenuButton *file_menu = nullptr;
  82. PopupMenu *context_menu = nullptr;
  83. WindowWrapper *window_wrapper = nullptr;
  84. Button *make_floating = nullptr;
  85. ShaderCreateDialog *shader_create_dialog = nullptr;
  86. float text_shader_zoom_factor = 1.0f;
  87. Ref<Resource> _get_current_shader();
  88. void _update_shader_list();
  89. void _shader_selected(int p_index);
  90. void _shader_list_clicked(int p_item, Vector2 p_local_mouse_pos, MouseButton p_mouse_button_index);
  91. void _setup_popup_menu(PopupMenuType p_type, PopupMenu *p_menu);
  92. void _make_script_list_context_menu();
  93. void _menu_item_pressed(int p_index);
  94. void _resource_saved(Object *obj);
  95. void _close_shader(int p_index);
  96. void _close_builtin_shaders_from_scene(const String &p_scene);
  97. void _file_removed(const String &p_removed_file);
  98. void _res_saved_callback(const Ref<Resource> &p_res);
  99. void _set_file_specific_items_disabled(bool p_disabled);
  100. void _shader_created(Ref<Shader> p_shader);
  101. void _shader_include_created(Ref<ShaderInclude> p_shader_inc);
  102. void _update_shader_list_status();
  103. void _move_shader_tab(int p_from, int p_to);
  104. Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
  105. bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
  106. void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
  107. void _window_changed(bool p_visible);
  108. void _set_text_shader_zoom_factor(float p_zoom_factor);
  109. protected:
  110. void _notification(int p_what);
  111. public:
  112. virtual String get_plugin_name() const override { return "Shader"; }
  113. virtual void edit(Object *p_object) override;
  114. virtual bool handles(Object *p_object) const override;
  115. virtual void make_visible(bool p_visible) override;
  116. virtual void selected_notify() override;
  117. ShaderEditor *get_shader_editor(const Ref<Shader> &p_for_shader);
  118. virtual void set_window_layout(Ref<ConfigFile> p_layout) override;
  119. virtual void get_window_layout(Ref<ConfigFile> p_layout) override;
  120. virtual String get_unsaved_status(const String &p_for_scene) const override;
  121. virtual void save_external_data() override;
  122. virtual void apply_changes() override;
  123. ShaderEditorPlugin();
  124. ~ShaderEditorPlugin();
  125. };
  126. #endif // SHADER_EDITOR_PLUGIN_H