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