Debian Codegraph @

editor/shader/shader_editor_plugin.h

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