Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/shader/shader_editor_plugin.h
21371 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
#include "scene/resources/shader.h"
35
36
class CodeTextEditor;
37
class EditorDock;
38
class HSplitContainer;
39
class ItemList;
40
class MenuButton;
41
class ShaderCreateDialog;
42
class ShaderEditor;
43
class TabContainer;
44
class VBoxContainer;
45
class HBoxContainer;
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
HSplitContainer *files_split = nullptr;
84
85
ItemList *shader_list = nullptr;
86
TabContainer *shader_tabs = nullptr;
87
88
MenuButton *file_menu = nullptr;
89
PopupMenu *context_menu = nullptr;
90
91
EditorDock *shader_dock = nullptr;
92
Ref<Shortcut> make_floating_shortcut;
93
94
ShaderCreateDialog *shader_create_dialog = nullptr;
95
96
float text_shader_zoom_factor = 1.0f;
97
bool restoring_layout = false;
98
99
Ref<Resource> _get_current_shader();
100
void _update_shader_list();
101
void _shader_selected(int p_index, bool p_push_item = true);
102
void _shader_list_clicked(int p_item, Vector2 p_local_mouse_pos, MouseButton p_mouse_button_index);
103
void _setup_popup_menu(PopupMenuType p_type, PopupMenu *p_menu);
104
void _make_script_list_context_menu();
105
void _menu_item_pressed(int p_index);
106
void _resource_saved(Object *obj);
107
void _close_shader(int p_index);
108
void _close_builtin_shaders_from_scene(const String &p_scene);
109
void _file_removed(const String &p_removed_file);
110
void _res_saved_callback(const Ref<Resource> &p_res);
111
void _set_file_specific_items_disabled(bool p_disabled);
112
113
void _shader_created(Ref<Shader> p_shader);
114
void _shader_include_created(Ref<ShaderInclude> p_shader_inc);
115
void _update_shader_list_status();
116
void _move_shader_tab(int p_from, int p_to);
117
118
Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
119
bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
120
void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
121
122
void _set_text_shader_zoom_factor(float p_zoom_factor);
123
void _update_shader_editor_zoom_factor(CodeTextEditor *p_shader_editor) const;
124
125
void _switch_to_editor(ShaderEditor *p_editor, bool p_focus = false);
126
127
protected:
128
void _notification(int p_what);
129
130
virtual void shortcut_input(const Ref<InputEvent> &p_event) override;
131
132
public:
133
virtual String get_plugin_name() const override { return "Shader"; }
134
virtual void edit(Object *p_object) override;
135
virtual bool handles(Object *p_object) const override;
136
virtual void make_visible(bool p_visible) override;
137
138
ShaderEditor *get_shader_editor(const Ref<Shader> &p_for_shader);
139
140
virtual void set_window_layout(Ref<ConfigFile> p_layout) override;
141
virtual void get_window_layout(Ref<ConfigFile> p_layout) override;
142
143
virtual String get_unsaved_status(const String &p_for_scene) const override;
144
virtual void save_external_data() override;
145
virtual void apply_changes() override;
146
147
ShaderEditorPlugin();
148
~ShaderEditorPlugin();
149
};
150
151