1 | /**************************************************************************/ |
2 | /* visual_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 VISUAL_SHADER_EDITOR_PLUGIN_H |
32 | #define VISUAL_SHADER_EDITOR_PLUGIN_H |
33 | |
34 | #include "editor/editor_plugin.h" |
35 | #include "editor/editor_properties.h" |
36 | #include "editor/plugins/editor_resource_conversion_plugin.h" |
37 | #include "scene/resources/syntax_highlighter.h" |
38 | #include "scene/resources/visual_shader.h" |
39 | |
40 | class CodeEdit; |
41 | class ColorPicker; |
42 | class CurveEditor; |
43 | class GraphEdit; |
44 | class GraphElement; |
45 | class ; |
46 | class ; |
47 | class RichTextLabel; |
48 | class Tree; |
49 | |
50 | class VisualShaderEditor; |
51 | |
52 | class VisualShaderNodePlugin : public RefCounted { |
53 | GDCLASS(VisualShaderNodePlugin, RefCounted); |
54 | |
55 | protected: |
56 | VisualShaderEditor *vseditor = nullptr; |
57 | |
58 | protected: |
59 | static void _bind_methods(); |
60 | |
61 | GDVIRTUAL2RC(Object *, _create_editor, Ref<Resource>, Ref<VisualShaderNode>) |
62 | |
63 | public: |
64 | void set_editor(VisualShaderEditor *p_editor); |
65 | virtual Control *create_editor(const Ref<Resource> &p_parent_resource, const Ref<VisualShaderNode> &p_node); |
66 | }; |
67 | |
68 | class VisualShaderGraphPlugin : public RefCounted { |
69 | GDCLASS(VisualShaderGraphPlugin, RefCounted); |
70 | |
71 | private: |
72 | VisualShaderEditor *editor = nullptr; |
73 | |
74 | struct InputPort { |
75 | Button *default_input_button = nullptr; |
76 | }; |
77 | |
78 | struct Port { |
79 | TextureButton *preview_button = nullptr; |
80 | }; |
81 | |
82 | struct Link { |
83 | VisualShader::Type type = VisualShader::Type::TYPE_MAX; |
84 | VisualShaderNode *visual_node = nullptr; |
85 | GraphElement *graph_element = nullptr; |
86 | bool preview_visible = false; |
87 | int preview_pos = 0; |
88 | HashMap<int, InputPort> input_ports; |
89 | HashMap<int, Port> output_ports; |
90 | VBoxContainer *preview_box = nullptr; |
91 | LineEdit *parameter_name = nullptr; |
92 | CodeEdit *expression_edit = nullptr; |
93 | CurveEditor *curve_editors[3] = { nullptr, nullptr, nullptr }; |
94 | }; |
95 | |
96 | Ref<VisualShader> visual_shader; |
97 | HashMap<int, Link> links; |
98 | List<VisualShader::Connection> connections; |
99 | |
100 | Color vector_expanded_color[4]; |
101 | |
102 | protected: |
103 | static void _bind_methods(); |
104 | |
105 | public: |
106 | void set_editor(VisualShaderEditor *p_editor); |
107 | void register_shader(VisualShader *p_visual_shader); |
108 | void set_connections(const List<VisualShader::Connection> &p_connections); |
109 | void register_link(VisualShader::Type p_type, int p_id, VisualShaderNode *p_visual_node, GraphElement *p_graph_element); |
110 | void register_output_port(int p_id, int p_port, TextureButton *p_button); |
111 | void register_parameter_name(int p_id, LineEdit *p_parameter_name); |
112 | void register_default_input_button(int p_node_id, int p_port_id, Button *p_button); |
113 | void register_expression_edit(int p_node_id, CodeEdit *p_expression_edit); |
114 | void register_curve_editor(int p_node_id, int p_index, CurveEditor *p_curve_editor); |
115 | void clear_links(); |
116 | void set_shader_type(VisualShader::Type p_type); |
117 | bool is_preview_visible(int p_id) const; |
118 | void update_node(VisualShader::Type p_type, int p_id); |
119 | void update_node_deferred(VisualShader::Type p_type, int p_node_id); |
120 | void add_node(VisualShader::Type p_type, int p_id, bool p_just_update); |
121 | void remove_node(VisualShader::Type p_type, int p_id, bool p_just_update); |
122 | void connect_nodes(VisualShader::Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port); |
123 | void disconnect_nodes(VisualShader::Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port); |
124 | void show_port_preview(VisualShader::Type p_type, int p_node_id, int p_port_id, bool p_is_valid); |
125 | void set_node_position(VisualShader::Type p_type, int p_id, const Vector2 &p_position); |
126 | void refresh_node_ports(VisualShader::Type p_type, int p_node); |
127 | void set_input_port_default_value(VisualShader::Type p_type, int p_node_id, int p_port_id, Variant p_value); |
128 | void update_parameter_refs(); |
129 | void set_parameter_name(VisualShader::Type p_type, int p_node_id, const String &p_name); |
130 | void update_curve(int p_node_id); |
131 | void update_curve_xyz(int p_node_id); |
132 | void set_expression(VisualShader::Type p_type, int p_node_id, const String &p_expression); |
133 | int get_constant_index(float p_constant) const; |
134 | Ref<Script> get_node_script(int p_node_id) const; |
135 | void update_node_size(int p_node_id); |
136 | void update_theme(); |
137 | bool is_node_has_parameter_instances_relatively(VisualShader::Type p_type, int p_node) const; |
138 | VisualShader::Type get_shader_type() const; |
139 | |
140 | VisualShaderGraphPlugin(); |
141 | ~VisualShaderGraphPlugin(); |
142 | }; |
143 | |
144 | class VisualShaderEditedProperty : public RefCounted { |
145 | GDCLASS(VisualShaderEditedProperty, RefCounted); |
146 | |
147 | private: |
148 | Variant edited_property; |
149 | |
150 | protected: |
151 | static void _bind_methods(); |
152 | |
153 | public: |
154 | void set_edited_property(Variant p_variant); |
155 | Variant get_edited_property() const; |
156 | |
157 | VisualShaderEditedProperty() {} |
158 | }; |
159 | |
160 | class VisualShaderEditor : public VBoxContainer { |
161 | GDCLASS(VisualShaderEditor, VBoxContainer); |
162 | friend class VisualShaderGraphPlugin; |
163 | |
164 | PopupPanel * = nullptr; |
165 | EditorProperty *property_editor = nullptr; |
166 | int editing_node = -1; |
167 | int editing_port = -1; |
168 | Ref<VisualShaderEditedProperty> edited_property_holder; |
169 | |
170 | Ref<VisualShader> visual_shader; |
171 | GraphEdit *graph = nullptr; |
172 | Button *add_node = nullptr; |
173 | MenuButton *varying_button = nullptr; |
174 | Button *preview_shader = nullptr; |
175 | |
176 | OptionButton *edit_type = nullptr; |
177 | OptionButton *edit_type_standard = nullptr; |
178 | OptionButton *edit_type_particles = nullptr; |
179 | OptionButton *edit_type_sky = nullptr; |
180 | OptionButton *edit_type_fog = nullptr; |
181 | CheckBox *custom_mode_box = nullptr; |
182 | bool custom_mode_enabled = false; |
183 | |
184 | bool pending_update_preview = false; |
185 | bool shader_error = false; |
186 | Window *preview_window = nullptr; |
187 | VBoxContainer *preview_vbox = nullptr; |
188 | CodeEdit *preview_text = nullptr; |
189 | Ref<CodeHighlighter> syntax_highlighter = nullptr; |
190 | PanelContainer *error_panel = nullptr; |
191 | Label *error_label = nullptr; |
192 | |
193 | bool pending_custom_scripts_to_delete = false; |
194 | List<Ref<Script>> custom_scripts_to_delete; |
195 | |
196 | bool = false; |
197 | bool _block_rebuild_shader = false; |
198 | |
199 | Point2 saved_node_pos; |
200 | bool saved_node_pos_dirty = false; |
201 | |
202 | ConfirmationDialog *members_dialog = nullptr; |
203 | VisualShaderNode::PortType members_input_port_type = VisualShaderNode::PORT_TYPE_MAX; |
204 | VisualShaderNode::PortType members_output_port_type = VisualShaderNode::PORT_TYPE_MAX; |
205 | PopupMenu * = nullptr; |
206 | PopupMenu * = nullptr; |
207 | MenuButton *tools = nullptr; |
208 | |
209 | ConfirmationDialog *add_varying_dialog = nullptr; |
210 | OptionButton *varying_type = nullptr; |
211 | LineEdit *varying_name = nullptr; |
212 | OptionButton *varying_mode = nullptr; |
213 | Label *varying_error_label = nullptr; |
214 | |
215 | ConfirmationDialog *remove_varying_dialog = nullptr; |
216 | Tree *varyings = nullptr; |
217 | |
218 | PopupPanel * = nullptr; |
219 | LineEdit * = nullptr; |
220 | |
221 | PopupPanel * = nullptr; |
222 | TextEdit * = nullptr; |
223 | |
224 | bool preview_first = true; |
225 | bool preview_showed = false; |
226 | |
227 | enum ShaderModeFlags { |
228 | MODE_FLAGS_SPATIAL_CANVASITEM = 1, |
229 | MODE_FLAGS_SKY = 2, |
230 | MODE_FLAGS_PARTICLES = 4, |
231 | MODE_FLAGS_FOG = 8, |
232 | }; |
233 | |
234 | int mode = MODE_FLAGS_SPATIAL_CANVASITEM; |
235 | |
236 | enum TypeFlags { |
237 | TYPE_FLAGS_VERTEX = 1, |
238 | TYPE_FLAGS_FRAGMENT = 2, |
239 | TYPE_FLAGS_LIGHT = 4, |
240 | }; |
241 | |
242 | enum ParticlesTypeFlags { |
243 | TYPE_FLAGS_EMIT = 1, |
244 | TYPE_FLAGS_PROCESS = 2, |
245 | TYPE_FLAGS_COLLIDE = 4, |
246 | TYPE_FLAGS_EMIT_CUSTOM = 8, |
247 | TYPE_FLAGS_PROCESS_CUSTOM = 16, |
248 | }; |
249 | |
250 | enum SkyTypeFlags { |
251 | TYPE_FLAGS_SKY = 1, |
252 | }; |
253 | |
254 | enum FogTypeFlags { |
255 | TYPE_FLAGS_FOG = 1, |
256 | }; |
257 | |
258 | enum { |
259 | EXPAND_ALL, |
260 | COLLAPSE_ALL |
261 | }; |
262 | |
263 | enum { |
264 | ADD, |
265 | SEPARATOR, // ignore |
266 | CUT, |
267 | COPY, |
268 | PASTE, |
269 | DELETE, |
270 | DUPLICATE, |
271 | CLEAR_COPY_BUFFER, |
272 | SEPARATOR2, // ignore |
273 | FLOAT_CONSTANTS, |
274 | CONVERT_CONSTANTS_TO_PARAMETERS, |
275 | CONVERT_PARAMETERS_TO_CONSTANTS, |
276 | SEPARATOR3, // ignore |
277 | , |
278 | , |
279 | }; |
280 | |
281 | enum class { |
282 | , |
283 | , |
284 | }; |
285 | |
286 | Tree *members = nullptr; |
287 | AcceptDialog *alert = nullptr; |
288 | LineEdit *node_filter = nullptr; |
289 | RichTextLabel *node_desc = nullptr; |
290 | Label *highend_label = nullptr; |
291 | |
292 | void (int p_idx); |
293 | void _show_members_dialog(bool at_mouse_pos, VisualShaderNode::PortType p_input_port_type = VisualShaderNode::PORT_TYPE_MAX, VisualShaderNode::PortType p_output_port_type = VisualShaderNode::PORT_TYPE_MAX); |
294 | |
295 | void (int p_idx); |
296 | void _show_add_varying_dialog(); |
297 | void _show_remove_varying_dialog(); |
298 | |
299 | void _update_nodes(); |
300 | void _update_graph(); |
301 | |
302 | struct AddOption { |
303 | String name; |
304 | String category; |
305 | String type; |
306 | String description; |
307 | Vector<Variant> ops; |
308 | Ref<Script> script; |
309 | int mode = 0; |
310 | int return_type = 0; |
311 | int func = 0; |
312 | bool highend = false; |
313 | bool is_custom = false; |
314 | bool is_native = false; |
315 | int temp_idx = 0; |
316 | |
317 | AddOption(const String &p_name = String(), const String &p_category = String(), const String &p_type = String(), const String &p_description = String(), const Vector<Variant> &p_ops = Vector<Variant>(), int p_return_type = -1, int p_mode = -1, int p_func = -1, bool p_highend = false) { |
318 | name = p_name; |
319 | type = p_type; |
320 | category = p_category; |
321 | description = p_description; |
322 | ops = p_ops; |
323 | return_type = p_return_type; |
324 | mode = p_mode; |
325 | func = p_func; |
326 | highend = p_highend; |
327 | } |
328 | }; |
329 | struct _OptionComparator { |
330 | _FORCE_INLINE_ bool operator()(const AddOption &a, const AddOption &b) const { |
331 | return a.category.count("/" ) > b.category.count("/" ) || (a.category + "/" + a.name).naturalnocasecmp_to(b.category + "/" + b.name) < 0; |
332 | } |
333 | }; |
334 | |
335 | Vector<AddOption> add_options; |
336 | int cubemap_node_option_idx; |
337 | int texture2d_node_option_idx; |
338 | int texture2d_array_node_option_idx; |
339 | int texture3d_node_option_idx; |
340 | int custom_node_option_idx; |
341 | int curve_node_option_idx; |
342 | int curve_xyz_node_option_idx; |
343 | List<String> keyword_list; |
344 | |
345 | List<VisualShaderNodeParameterRef> uniform_refs; |
346 | |
347 | void _draw_color_over_button(Object *p_obj, Color p_color); |
348 | |
349 | void _setup_node(VisualShaderNode *p_node, const Vector<Variant> &p_ops); |
350 | void _add_node(int p_idx, const Vector<Variant> &p_ops, String p_resource_path = "" , int p_node_idx = -1); |
351 | void _add_varying(const String &p_name, VisualShader::VaryingMode p_mode, VisualShader::VaryingType p_type); |
352 | void _remove_varying(const String &p_name); |
353 | void (); |
354 | void _set_mode(int p_which); |
355 | |
356 | void _show_preview_text(); |
357 | void _preview_close_requested(); |
358 | void _preview_size_changed(); |
359 | void _update_preview(); |
360 | void _update_next_previews(int p_node_id); |
361 | void _get_next_nodes_recursively(VisualShader::Type p_type, int p_node_id, LocalVector<int> &r_nodes) const; |
362 | String _get_description(int p_idx); |
363 | |
364 | struct DragOp { |
365 | VisualShader::Type type = VisualShader::Type::TYPE_MAX; |
366 | int node = 0; |
367 | Vector2 from; |
368 | Vector2 to; |
369 | }; |
370 | List<DragOp> drag_buffer; |
371 | bool drag_dirty = false; |
372 | void _node_dragged(const Vector2 &p_from, const Vector2 &p_to, int p_node); |
373 | void _nodes_dragged(); |
374 | bool updating = false; |
375 | |
376 | void _connection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index); |
377 | void _disconnection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index); |
378 | |
379 | void _scroll_changed(const Vector2 &p_scroll); |
380 | void _node_selected(Object *p_node); |
381 | |
382 | void _delete_nodes(int p_type, const List<int> &p_nodes); |
383 | void _close_node_request(int p_type, int p_node); |
384 | void _close_nodes_request(const TypedArray<StringName> &p_nodes); |
385 | |
386 | void _node_changed(int p_id); |
387 | |
388 | void _edit_port_default_input(Object *p_button, int p_node, int p_port); |
389 | void _port_edited(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing); |
390 | |
391 | int to_node = -1; |
392 | int to_slot = -1; |
393 | int from_node = -1; |
394 | int from_slot = -1; |
395 | |
396 | HashSet<int> selected_constants; |
397 | HashSet<int> selected_parameters; |
398 | int = -1; |
399 | int selected_float_constant = -1; |
400 | |
401 | void _convert_constants_to_parameters(bool p_vice_versa); |
402 | void _replace_node(VisualShader::Type p_type_id, int p_node_id, const StringName &p_from, const StringName &p_to); |
403 | void _update_constant(VisualShader::Type p_type_id, int p_node_id, Variant p_var, int p_preview_port); |
404 | void _update_parameter(VisualShader::Type p_type_id, int p_node_id, Variant p_var, int p_preview_port); |
405 | |
406 | void _connection_to_empty(const String &p_from, int p_from_slot, const Vector2 &p_release_position); |
407 | void _connection_from_empty(const String &p_to, int p_to_slot, const Vector2 &p_release_position); |
408 | |
409 | void (const Point2 &p_position, int p_node_id); |
410 | void (); |
411 | void (); |
412 | void (const String &p_new_text); |
413 | void (const String &p_new_text); |
414 | |
415 | void (const Point2 &p_position, int p_node_id); |
416 | void (); |
417 | void (); |
418 | void (); |
419 | |
420 | void _parameter_line_edit_changed(const String &p_text, int p_node_id); |
421 | void _parameter_line_edit_focus_out(Object *p_line_edit, int p_node_id); |
422 | |
423 | void _port_name_focus_out(Object *p_line_edit, int p_node_id, int p_port_id, bool p_output); |
424 | |
425 | struct CopyItem { |
426 | int id; |
427 | Ref<VisualShaderNode> node; |
428 | Vector2 position; |
429 | Vector2 size; |
430 | String group_inputs; |
431 | String group_outputs; |
432 | String expression; |
433 | bool disabled = false; |
434 | }; |
435 | |
436 | void _dup_copy_nodes(int p_type, List<CopyItem> &r_nodes, List<VisualShader::Connection> &r_connections); |
437 | void _dup_paste_nodes(int p_type, List<CopyItem> &r_items, const List<VisualShader::Connection> &p_connections, const Vector2 &p_offset, bool p_duplicate); |
438 | |
439 | void _duplicate_nodes(); |
440 | |
441 | static Vector2 selection_center; |
442 | static List<CopyItem> copy_items_buffer; |
443 | static List<VisualShader::Connection> copy_connections_buffer; |
444 | |
445 | void _clear_copy_buffer(); |
446 | void _copy_nodes(bool p_cut); |
447 | void _paste_nodes(bool p_use_custom_position = false, const Vector2 &p_custom_position = Vector2()); |
448 | |
449 | Vector<Ref<VisualShaderNodePlugin>> plugins; |
450 | Ref<VisualShaderGraphPlugin> graph_plugin; |
451 | |
452 | void _mode_selected(int p_id); |
453 | void _custom_mode_toggled(bool p_enabled); |
454 | |
455 | void _input_select_item(Ref<VisualShaderNodeInput> p_input, String p_name); |
456 | void _parameter_ref_select_item(Ref<VisualShaderNodeParameterRef> p_parameter_ref, String p_name); |
457 | void _varying_select_item(Ref<VisualShaderNodeVarying> p_varying, String p_name); |
458 | |
459 | void _float_constant_selected(int p_which); |
460 | |
461 | VisualShader::Type get_current_shader_type() const; |
462 | |
463 | void _add_input_port(int p_node, int p_port, int p_port_type, const String &p_name); |
464 | void _remove_input_port(int p_node, int p_port); |
465 | void _change_input_port_type(int p_type, int p_node, int p_port); |
466 | void _change_input_port_name(const String &p_text, Object *p_line_edit, int p_node, int p_port); |
467 | |
468 | void _add_output_port(int p_node, int p_port, int p_port_type, const String &p_name); |
469 | void _remove_output_port(int p_node, int p_port); |
470 | void _change_output_port_type(int p_type, int p_node, int p_port); |
471 | void _change_output_port_name(const String &p_text, Object *p_line_edit, int p_node, int p_port); |
472 | void _expand_output_port(int p_node, int p_port, bool p_expand); |
473 | |
474 | void _expression_focus_out(Object *p_code_edit, int p_node); |
475 | |
476 | void _set_node_size(int p_type, int p_node, const Size2 &p_size); |
477 | void _node_resized(const Vector2 &p_new_size, int p_type, int p_node); |
478 | |
479 | void _preview_select_port(int p_node, int p_port); |
480 | void _graph_gui_input(const Ref<InputEvent> &p_event); |
481 | |
482 | void _member_filter_changed(const String &p_text); |
483 | void _sbox_input(const Ref<InputEvent> &p_ie); |
484 | void _member_selected(); |
485 | void _member_unselected(); |
486 | void _member_create(); |
487 | void _member_cancel(); |
488 | |
489 | void _varying_create(); |
490 | void _varying_name_changed(const String &p_text); |
491 | void _varying_deleted(); |
492 | void _varying_selected(); |
493 | void _varying_unselected(); |
494 | void _update_varying_tree(); |
495 | |
496 | Vector2 ; |
497 | void (int p_idx); |
498 | |
499 | Variant get_drag_data_fw(const Point2 &p_point, Control *p_from); |
500 | bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const; |
501 | void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from); |
502 | |
503 | bool _is_available(int p_mode); |
504 | void _update_parameters(bool p_update_refs); |
505 | void _update_parameter_refs(HashSet<String> &p_names); |
506 | void _update_varyings(); |
507 | |
508 | void (); |
509 | void _rebuild_shader_deferred(); |
510 | |
511 | void _visibility_changed(); |
512 | |
513 | void _get_current_mode_limits(int &r_begin_type, int &r_end_type) const; |
514 | void _update_custom_script(const Ref<Script> &p_script); |
515 | void _script_created(const Ref<Script> &p_script); |
516 | void _resource_saved(const Ref<Resource> &p_resource); |
517 | void _resource_removed(const Ref<Resource> &p_resource); |
518 | void _resources_removed(); |
519 | |
520 | protected: |
521 | void _notification(int p_what); |
522 | static void _bind_methods(); |
523 | |
524 | public: |
525 | void add_plugin(const Ref<VisualShaderNodePlugin> &p_plugin); |
526 | void remove_plugin(const Ref<VisualShaderNodePlugin> &p_plugin); |
527 | |
528 | VisualShaderGraphPlugin *get_graph_plugin() { return graph_plugin.ptr(); } |
529 | |
530 | void clear_custom_types(); |
531 | void add_custom_type(const String &p_name, const String &p_type, const Ref<Script> &p_script, const String &p_description, int p_return_icon_type, const String &p_category, bool p_highend); |
532 | |
533 | Dictionary get_custom_node_data(Ref<VisualShaderNodeCustom> &p_custom_node); |
534 | void update_custom_type(const Ref<Resource> &p_resource); |
535 | |
536 | virtual Size2 get_minimum_size() const override; |
537 | void edit(VisualShader *p_visual_shader); |
538 | VisualShaderEditor(); |
539 | }; |
540 | |
541 | class VisualShaderNodePluginDefault : public VisualShaderNodePlugin { |
542 | GDCLASS(VisualShaderNodePluginDefault, VisualShaderNodePlugin); |
543 | |
544 | public: |
545 | virtual Control *create_editor(const Ref<Resource> &p_parent_resource, const Ref<VisualShaderNode> &p_node) override; |
546 | }; |
547 | |
548 | class EditorPropertyVisualShaderMode : public EditorProperty { |
549 | GDCLASS(EditorPropertyVisualShaderMode, EditorProperty); |
550 | OptionButton *options = nullptr; |
551 | |
552 | void _option_selected(int p_which); |
553 | |
554 | protected: |
555 | static void _bind_methods(); |
556 | |
557 | public: |
558 | void setup(const Vector<String> &p_options); |
559 | virtual void update_property() override; |
560 | void set_option_button_clip(bool p_enable); |
561 | EditorPropertyVisualShaderMode(); |
562 | }; |
563 | |
564 | class EditorInspectorVisualShaderModePlugin : public EditorInspectorPlugin { |
565 | GDCLASS(EditorInspectorVisualShaderModePlugin, EditorInspectorPlugin); |
566 | |
567 | public: |
568 | virtual bool can_handle(Object *p_object) override; |
569 | virtual bool parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const BitField<PropertyUsageFlags> p_usage, const bool p_wide = false) override; |
570 | }; |
571 | |
572 | class VisualShaderNodePortPreview : public Control { |
573 | GDCLASS(VisualShaderNodePortPreview, Control); |
574 | Ref<VisualShader> shader; |
575 | VisualShader::Type type = VisualShader::Type::TYPE_MAX; |
576 | int node = 0; |
577 | int port = 0; |
578 | bool is_valid = false; |
579 | void _shader_changed(); //must regen |
580 | protected: |
581 | void _notification(int p_what); |
582 | static void _bind_methods(); |
583 | |
584 | public: |
585 | virtual Size2 get_minimum_size() const override; |
586 | void setup(const Ref<VisualShader> &p_shader, VisualShader::Type p_type, int p_node, int p_port, bool p_is_valid); |
587 | }; |
588 | |
589 | class VisualShaderConversionPlugin : public EditorResourceConversionPlugin { |
590 | GDCLASS(VisualShaderConversionPlugin, EditorResourceConversionPlugin); |
591 | |
592 | public: |
593 | virtual String converts_to() const override; |
594 | virtual bool handles(const Ref<Resource> &p_resource) const override; |
595 | virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override; |
596 | }; |
597 | |
598 | #endif // VISUAL_SHADER_EDITOR_PLUGIN_H |
599 | |