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
31#ifndef SHADER_EDITOR_PLUGIN_H
32#define SHADER_EDITOR_PLUGIN_H
33
34#include "editor/editor_plugin.h"
35
36class HSplitContainer;
37class ItemList;
38class MenuButton;
39class ShaderCreateDialog;
40class TabContainer;
41class TextShaderEditor;
42class VisualShaderEditor;
43class WindowWrapper;
44
45class ShaderEditorPlugin : public EditorPlugin {
46 GDCLASS(ShaderEditorPlugin, EditorPlugin);
47
48 struct EditedShader {
49 Ref<Shader> shader;
50 Ref<ShaderInclude> shader_inc;
51 TextShaderEditor *shader_editor = nullptr;
52 VisualShaderEditor *visual_shader_editor = nullptr;
53 };
54
55 LocalVector<EditedShader> edited_shaders;
56
57 // Always valid operations come first in the enum, file-specific ones
58 // should go after FILE_SAVE which is used to build the menu accordingly.
59 enum {
60 FILE_NEW,
61 FILE_NEW_INCLUDE,
62 FILE_OPEN,
63 FILE_OPEN_INCLUDE,
64 FILE_SAVE,
65 FILE_SAVE_AS,
66 FILE_INSPECT,
67 FILE_CLOSE,
68 FILE_MAX
69 };
70
71 HSplitContainer *main_split = nullptr;
72 ItemList *shader_list = nullptr;
73 TabContainer *shader_tabs = nullptr;
74
75 Button *button = nullptr;
76 MenuButton *file_menu = nullptr;
77
78 WindowWrapper *window_wrapper = nullptr;
79 Button *make_floating = nullptr;
80
81 ShaderCreateDialog *shader_create_dialog = nullptr;
82
83 void _update_shader_list();
84 void _shader_selected(int p_index);
85 void _shader_list_clicked(int p_item, Vector2 p_local_mouse_pos, MouseButton p_mouse_button_index);
86 void _menu_item_pressed(int p_index);
87 void _resource_saved(Object *obj);
88 void _close_shader(int p_index);
89 void _close_builtin_shaders_from_scene(const String &p_scene);
90
91 void _shader_created(Ref<Shader> p_shader);
92 void _shader_include_created(Ref<ShaderInclude> p_shader_inc);
93 void _update_shader_list_status();
94 void _move_shader_tab(int p_from, int p_to);
95
96 Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
97 bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
98 void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
99
100 void _window_changed(bool p_visible);
101
102protected:
103 void _notification(int p_what);
104
105public:
106 virtual String get_name() const override { return "Shader"; }
107 virtual void edit(Object *p_object) override;
108 virtual bool handles(Object *p_object) const override;
109 virtual void make_visible(bool p_visible) override;
110 virtual void selected_notify() override;
111
112 TextShaderEditor *get_shader_editor(const Ref<Shader> &p_for_shader);
113 VisualShaderEditor *get_visual_shader_editor(const Ref<Shader> &p_for_shader);
114
115 virtual void set_window_layout(Ref<ConfigFile> p_layout) override;
116 virtual void get_window_layout(Ref<ConfigFile> p_layout) override;
117
118 virtual String get_unsaved_status(const String &p_for_scene) const override;
119 virtual void save_external_data() override;
120 virtual void apply_changes() override;
121
122 ShaderEditorPlugin();
123 ~ShaderEditorPlugin();
124};
125
126#endif // SHADER_EDITOR_PLUGIN_H
127