visual_shader_editor_plugin.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  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) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  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. #ifndef VISUAL_SHADER_EDITOR_PLUGIN_H
  31. #define VISUAL_SHADER_EDITOR_PLUGIN_H
  32. #include "editor/editor_plugin.h"
  33. #include "editor/plugins/curve_editor_plugin.h"
  34. #include "editor/property_editor.h"
  35. #include "scene/gui/button.h"
  36. #include "scene/gui/code_edit.h"
  37. #include "scene/gui/graph_edit.h"
  38. #include "scene/gui/popup.h"
  39. #include "scene/gui/rich_text_label.h"
  40. #include "scene/gui/tree.h"
  41. #include "scene/resources/visual_shader.h"
  42. class VisualShaderNodePlugin : public RefCounted {
  43. GDCLASS(VisualShaderNodePlugin, RefCounted);
  44. protected:
  45. static void _bind_methods();
  46. GDVIRTUAL2RC(Object *, _create_editor, RES, Ref<VisualShaderNode>)
  47. public:
  48. virtual Control *create_editor(const Ref<Resource> &p_parent_resource, const Ref<VisualShaderNode> &p_node);
  49. };
  50. class VisualShaderGraphPlugin : public RefCounted {
  51. GDCLASS(VisualShaderGraphPlugin, RefCounted);
  52. private:
  53. struct InputPort {
  54. Button *default_input_button = nullptr;
  55. };
  56. struct Port {
  57. TextureButton *preview_button = nullptr;
  58. };
  59. struct Link {
  60. VisualShader::Type type = VisualShader::Type::TYPE_MAX;
  61. VisualShaderNode *visual_node = nullptr;
  62. GraphNode *graph_node = nullptr;
  63. bool preview_visible = false;
  64. int preview_pos = 0;
  65. Map<int, InputPort> input_ports;
  66. Map<int, Port> output_ports;
  67. VBoxContainer *preview_box = nullptr;
  68. LineEdit *uniform_name = nullptr;
  69. CodeEdit *expression_edit = nullptr;
  70. CurveEditor *curve_editors[3] = { nullptr, nullptr, nullptr };
  71. };
  72. Ref<VisualShader> visual_shader;
  73. Map<int, Link> links;
  74. List<VisualShader::Connection> connections;
  75. bool dirty = false;
  76. Color vector_expanded_color[4];
  77. protected:
  78. static void _bind_methods();
  79. public:
  80. void register_shader(VisualShader *p_visual_shader);
  81. void set_connections(List<VisualShader::Connection> &p_connections);
  82. void register_link(VisualShader::Type p_type, int p_id, VisualShaderNode *p_visual_node, GraphNode *p_graph_node);
  83. void register_output_port(int p_id, int p_port, TextureButton *p_button);
  84. void register_uniform_name(int p_id, LineEdit *p_uniform_name);
  85. void register_default_input_button(int p_node_id, int p_port_id, Button *p_button);
  86. void register_expression_edit(int p_node_id, CodeEdit *p_expression_edit);
  87. void register_curve_editor(int p_node_id, int p_index, CurveEditor *p_curve_editor);
  88. void clear_links();
  89. void set_shader_type(VisualShader::Type p_type);
  90. bool is_preview_visible(int p_id) const;
  91. bool is_dirty() const;
  92. void make_dirty(bool p_enabled);
  93. void update_node(VisualShader::Type p_type, int p_id);
  94. void update_node_deferred(VisualShader::Type p_type, int p_node_id);
  95. void add_node(VisualShader::Type p_type, int p_id);
  96. void remove_node(VisualShader::Type p_type, int p_id);
  97. void connect_nodes(VisualShader::Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port);
  98. void disconnect_nodes(VisualShader::Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port);
  99. void show_port_preview(VisualShader::Type p_type, int p_node_id, int p_port_id);
  100. void set_node_position(VisualShader::Type p_type, int p_id, const Vector2 &p_position);
  101. void refresh_node_ports(VisualShader::Type p_type, int p_node);
  102. void set_input_port_default_value(VisualShader::Type p_type, int p_node_id, int p_port_id, Variant p_value);
  103. void update_uniform_refs();
  104. void set_uniform_name(VisualShader::Type p_type, int p_node_id, const String &p_name);
  105. void update_curve(int p_node_id);
  106. void update_curve_xyz(int p_node_id);
  107. void set_expression(VisualShader::Type p_type, int p_node_id, const String &p_expression);
  108. int get_constant_index(float p_constant) const;
  109. void update_node_size(int p_node_id);
  110. void update_theme();
  111. VisualShader::Type get_shader_type() const;
  112. VisualShaderGraphPlugin();
  113. ~VisualShaderGraphPlugin();
  114. };
  115. class VisualShaderEditor : public VBoxContainer {
  116. GDCLASS(VisualShaderEditor, VBoxContainer);
  117. friend class VisualShaderGraphPlugin;
  118. CustomPropertyEditor *property_editor = nullptr;
  119. int editing_node = -1;
  120. int editing_port = -1;
  121. Ref<VisualShader> visual_shader;
  122. GraphEdit *graph = nullptr;
  123. Button *add_node = nullptr;
  124. Button *varying_button = nullptr;
  125. PopupMenu *varying_options = nullptr;
  126. Button *preview_shader = nullptr;
  127. OptionButton *edit_type = nullptr;
  128. OptionButton *edit_type_standard = nullptr;
  129. OptionButton *edit_type_particles = nullptr;
  130. OptionButton *edit_type_sky = nullptr;
  131. OptionButton *edit_type_fog = nullptr;
  132. CheckBox *custom_mode_box = nullptr;
  133. bool custom_mode_enabled = false;
  134. bool pending_update_preview = false;
  135. bool shader_error = false;
  136. Window *preview_window = nullptr;
  137. VBoxContainer *preview_vbox = nullptr;
  138. CodeEdit *preview_text = nullptr;
  139. Ref<CodeHighlighter> syntax_highlighter = nullptr;
  140. PanelContainer *error_panel = nullptr;
  141. Label *error_label = nullptr;
  142. UndoRedo *undo_redo = nullptr;
  143. Point2 saved_node_pos;
  144. bool saved_node_pos_dirty = false;
  145. ConfirmationDialog *members_dialog = nullptr;
  146. VisualShaderNode::PortType members_input_port_type = VisualShaderNode::PORT_TYPE_MAX;
  147. VisualShaderNode::PortType members_output_port_type = VisualShaderNode::PORT_TYPE_MAX;
  148. PopupMenu *popup_menu = nullptr;
  149. PopupMenu *constants_submenu = nullptr;
  150. MenuButton *tools = nullptr;
  151. ConfirmationDialog *add_varying_dialog = nullptr;
  152. OptionButton *varying_type = nullptr;
  153. LineEdit *varying_name = nullptr;
  154. OptionButton *varying_mode = nullptr;
  155. Label *varying_error_label = nullptr;
  156. ConfirmationDialog *remove_varying_dialog = nullptr;
  157. Tree *varyings = nullptr;
  158. PopupPanel *comment_title_change_popup = nullptr;
  159. LineEdit *comment_title_change_edit = nullptr;
  160. PopupPanel *comment_desc_change_popup = nullptr;
  161. TextEdit *comment_desc_change_edit = nullptr;
  162. bool preview_first = true;
  163. bool preview_showed = false;
  164. enum ShaderModeFlags {
  165. MODE_FLAGS_SPATIAL_CANVASITEM = 1,
  166. MODE_FLAGS_SKY = 2,
  167. MODE_FLAGS_PARTICLES = 4,
  168. MODE_FLAGS_FOG = 8,
  169. };
  170. int mode = MODE_FLAGS_SPATIAL_CANVASITEM;
  171. enum TypeFlags {
  172. TYPE_FLAGS_VERTEX = 1,
  173. TYPE_FLAGS_FRAGMENT = 2,
  174. TYPE_FLAGS_LIGHT = 4,
  175. };
  176. enum ParticlesTypeFlags {
  177. TYPE_FLAGS_EMIT = 1,
  178. TYPE_FLAGS_PROCESS = 2,
  179. TYPE_FLAGS_COLLIDE = 4,
  180. TYPE_FLAGS_EMIT_CUSTOM = 8,
  181. TYPE_FLAGS_PROCESS_CUSTOM = 16,
  182. };
  183. enum SkyTypeFlags {
  184. TYPE_FLAGS_SKY = 1,
  185. };
  186. enum FogTypeFlags {
  187. TYPE_FLAGS_FOG = 1,
  188. };
  189. enum ToolsMenuOptions {
  190. EXPAND_ALL,
  191. COLLAPSE_ALL
  192. };
  193. enum NodeMenuOptions {
  194. ADD,
  195. SEPARATOR, // ignore
  196. CUT,
  197. COPY,
  198. PASTE,
  199. DELETE,
  200. DUPLICATE,
  201. CLEAR_COPY_BUFFER,
  202. SEPARATOR2, // ignore
  203. FLOAT_CONSTANTS,
  204. CONVERT_CONSTANTS_TO_UNIFORMS,
  205. CONVERT_UNIFORMS_TO_CONSTANTS,
  206. SEPARATOR3, // ignore
  207. SET_COMMENT_TITLE,
  208. SET_COMMENT_DESCRIPTION,
  209. };
  210. enum class VaryingMenuOptions {
  211. ADD,
  212. REMOVE,
  213. };
  214. Tree *members = nullptr;
  215. AcceptDialog *alert = nullptr;
  216. LineEdit *node_filter = nullptr;
  217. RichTextLabel *node_desc = nullptr;
  218. Label *highend_label = nullptr;
  219. void _tools_menu_option(int p_idx);
  220. 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);
  221. void _show_varying_menu();
  222. void _varying_menu_id_pressed(int p_idx);
  223. void _show_add_varying_dialog();
  224. void _show_remove_varying_dialog();
  225. void _update_nodes();
  226. void _update_graph();
  227. struct AddOption {
  228. String name;
  229. String category;
  230. String type;
  231. String description;
  232. Vector<Variant> ops;
  233. Ref<Script> script;
  234. int mode = 0;
  235. int return_type = 0;
  236. int func = 0;
  237. bool highend = false;
  238. bool is_custom = false;
  239. int temp_idx = 0;
  240. AddOption(const String &p_name = String(), const String &p_category = String(), const String &p_sub_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) {
  241. name = p_name;
  242. type = p_type;
  243. category = p_category + "/" + p_sub_category;
  244. description = p_description;
  245. ops = p_ops;
  246. return_type = p_return_type;
  247. mode = p_mode;
  248. func = p_func;
  249. highend = p_highend;
  250. }
  251. };
  252. struct _OptionComparator {
  253. _FORCE_INLINE_ bool operator()(const AddOption &a, const AddOption &b) const {
  254. return a.category.count("/") > b.category.count("/") || (a.category + "/" + a.name).naturalnocasecmp_to(b.category + "/" + b.name) < 0;
  255. }
  256. };
  257. Vector<AddOption> add_options;
  258. int cubemap_node_option_idx;
  259. int texture2d_node_option_idx;
  260. int texture2d_array_node_option_idx;
  261. int texture3d_node_option_idx;
  262. int custom_node_option_idx;
  263. int curve_node_option_idx;
  264. int curve_xyz_node_option_idx;
  265. List<String> keyword_list;
  266. List<VisualShaderNodeUniformRef> uniform_refs;
  267. void _draw_color_over_button(Object *obj, Color p_color);
  268. void _setup_node(VisualShaderNode *p_node, const Vector<Variant> &p_ops);
  269. void _add_node(int p_idx, const Vector<Variant> &p_ops, String p_resource_path = "", int p_node_idx = -1);
  270. void _add_varying(const String &p_name, VisualShader::VaryingMode p_mode, VisualShader::VaryingType p_type);
  271. void _remove_varying(const String &p_name);
  272. void _update_options_menu();
  273. void _set_mode(int p_which);
  274. void _show_preview_text();
  275. void _preview_close_requested();
  276. void _preview_size_changed();
  277. void _update_preview();
  278. String _get_description(int p_idx);
  279. static VisualShaderEditor *singleton;
  280. struct DragOp {
  281. VisualShader::Type type = VisualShader::Type::TYPE_MAX;
  282. int node = 0;
  283. Vector2 from;
  284. Vector2 to;
  285. };
  286. List<DragOp> drag_buffer;
  287. bool drag_dirty = false;
  288. void _node_dragged(const Vector2 &p_from, const Vector2 &p_to, int p_node);
  289. void _nodes_dragged();
  290. bool updating = false;
  291. void _connection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index);
  292. void _disconnection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index);
  293. void _scroll_changed(const Vector2 &p_scroll);
  294. void _node_selected(Object *p_node);
  295. void _delete_nodes(int p_type, const List<int> &p_nodes);
  296. void _delete_node_request(int p_type, int p_node);
  297. void _delete_nodes_request();
  298. void _node_changed(int p_id);
  299. void _edit_port_default_input(Object *p_button, int p_node, int p_port);
  300. void _port_edited();
  301. int to_node = -1;
  302. int to_slot = -1;
  303. int from_node = -1;
  304. int from_slot = -1;
  305. Set<int> selected_constants;
  306. Set<int> selected_uniforms;
  307. int selected_comment = -1;
  308. int selected_float_constant = -1;
  309. void _convert_constants_to_uniforms(bool p_vice_versa);
  310. void _replace_node(VisualShader::Type p_type_id, int p_node_id, const StringName &p_from, const StringName &p_to);
  311. void _update_constant(VisualShader::Type p_type_id, int p_node_id, Variant p_var, int p_preview_port);
  312. void _update_uniform(VisualShader::Type p_type_id, int p_node_id, Variant p_var, int p_preview_port);
  313. void _connection_to_empty(const String &p_from, int p_from_slot, const Vector2 &p_release_position);
  314. void _connection_from_empty(const String &p_to, int p_to_slot, const Vector2 &p_release_position);
  315. void _comment_title_popup_show(const Point2 &p_position, int p_node_id);
  316. void _comment_title_popup_hide();
  317. void _comment_title_popup_focus_out();
  318. void _comment_title_text_changed(const String &p_new_text);
  319. void _comment_title_text_submitted(const String &p_new_text);
  320. void _comment_desc_popup_show(const Point2 &p_position, int p_node_id);
  321. void _comment_desc_popup_hide();
  322. void _comment_desc_confirm();
  323. void _comment_desc_text_changed();
  324. void _uniform_line_edit_changed(const String &p_text, int p_node_id);
  325. void _uniform_line_edit_focus_out(Object *line_edit, int p_node_id);
  326. void _port_name_focus_out(Object *line_edit, int p_node_id, int p_port_id, bool p_output);
  327. struct CopyItem {
  328. int id;
  329. Ref<VisualShaderNode> node;
  330. Vector2 position;
  331. Vector2 size;
  332. String group_inputs;
  333. String group_outputs;
  334. String expression;
  335. bool disabled = false;
  336. };
  337. void _dup_copy_nodes(int p_type, List<CopyItem> &r_nodes, List<VisualShader::Connection> &r_connections);
  338. void _dup_paste_nodes(int p_type, List<CopyItem> &r_items, const List<VisualShader::Connection> &p_connections, const Vector2 &p_offset, bool p_duplicate);
  339. void _duplicate_nodes();
  340. Vector2 selection_center;
  341. List<CopyItem> copy_items_buffer;
  342. List<VisualShader::Connection> copy_connections_buffer;
  343. void _clear_copy_buffer();
  344. void _copy_nodes(bool p_cut);
  345. void _paste_nodes(bool p_use_custom_position = false, const Vector2 &p_custom_position = Vector2());
  346. Vector<Ref<VisualShaderNodePlugin>> plugins;
  347. Ref<VisualShaderGraphPlugin> graph_plugin;
  348. void _mode_selected(int p_id);
  349. void _custom_mode_toggled(bool p_enabled);
  350. void _input_select_item(Ref<VisualShaderNodeInput> input, String name);
  351. void _uniform_select_item(Ref<VisualShaderNodeUniformRef> p_uniform, String p_name);
  352. void _varying_select_item(Ref<VisualShaderNodeVarying> p_varying, String p_name);
  353. void _float_constant_selected(int p_which);
  354. VisualShader::Type get_current_shader_type() const;
  355. void _add_input_port(int p_node, int p_port, int p_port_type, const String &p_name);
  356. void _remove_input_port(int p_node, int p_port);
  357. void _change_input_port_type(int p_type, int p_node, int p_port);
  358. void _change_input_port_name(const String &p_text, Object *p_line_edit, int p_node, int p_port);
  359. void _add_output_port(int p_node, int p_port, int p_port_type, const String &p_name);
  360. void _remove_output_port(int p_node, int p_port);
  361. void _change_output_port_type(int p_type, int p_node, int p_port);
  362. void _change_output_port_name(const String &p_text, Object *p_line_edit, int p_node, int p_port);
  363. void _expand_output_port(int p_node, int p_port, bool p_expand);
  364. void _expression_focus_out(Object *code_edit, int p_node);
  365. void _set_node_size(int p_type, int p_node, const Size2 &p_size);
  366. void _node_resized(const Vector2 &p_new_size, int p_type, int p_node);
  367. void _preview_select_port(int p_node, int p_port);
  368. void _graph_gui_input(const Ref<InputEvent> &p_event);
  369. void _member_filter_changed(const String &p_text);
  370. void _sbox_input(const Ref<InputEvent> &p_ie);
  371. void _member_selected();
  372. void _member_unselected();
  373. void _member_create();
  374. void _member_cancel();
  375. void _varying_create();
  376. void _varying_name_changed(const String &p_text);
  377. void _varying_deleted();
  378. void _varying_selected();
  379. void _varying_unselected();
  380. void _update_varying_tree();
  381. Vector2 menu_point;
  382. void _node_menu_id_pressed(int p_idx);
  383. Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
  384. bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
  385. void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
  386. bool _is_available(int p_mode);
  387. void _update_created_node(GraphNode *node);
  388. void _update_uniforms(bool p_update_refs);
  389. void _update_uniform_refs(Set<String> &p_names);
  390. void _update_varyings();
  391. void _visibility_changed();
  392. protected:
  393. void _notification(int p_what);
  394. static void _bind_methods();
  395. public:
  396. void update_nodes();
  397. void add_plugin(const Ref<VisualShaderNodePlugin> &p_plugin);
  398. void remove_plugin(const Ref<VisualShaderNodePlugin> &p_plugin);
  399. static VisualShaderEditor *get_singleton() { return singleton; }
  400. VisualShaderGraphPlugin *get_graph_plugin() { return graph_plugin.ptr(); }
  401. void clear_custom_types();
  402. void add_custom_type(const String &p_name, const Ref<Script> &p_script, const String &p_description, int p_return_icon_type, const String &p_category, bool p_highend);
  403. virtual Size2 get_minimum_size() const override;
  404. void edit(VisualShader *p_visual_shader);
  405. VisualShaderEditor();
  406. };
  407. class VisualShaderEditorPlugin : public EditorPlugin {
  408. GDCLASS(VisualShaderEditorPlugin, EditorPlugin);
  409. VisualShaderEditor *visual_shader_editor = nullptr;
  410. Button *button = nullptr;
  411. public:
  412. virtual String get_name() const override { return "VisualShader"; }
  413. bool has_main_screen() const override { return false; }
  414. virtual void edit(Object *p_object) override;
  415. virtual bool handles(Object *p_object) const override;
  416. virtual void make_visible(bool p_visible) override;
  417. VisualShaderEditorPlugin();
  418. ~VisualShaderEditorPlugin();
  419. };
  420. class VisualShaderNodePluginDefault : public VisualShaderNodePlugin {
  421. GDCLASS(VisualShaderNodePluginDefault, VisualShaderNodePlugin);
  422. public:
  423. virtual Control *create_editor(const Ref<Resource> &p_parent_resource, const Ref<VisualShaderNode> &p_node) override;
  424. };
  425. class EditorPropertyShaderMode : public EditorProperty {
  426. GDCLASS(EditorPropertyShaderMode, EditorProperty);
  427. OptionButton *options = nullptr;
  428. void _option_selected(int p_which);
  429. protected:
  430. static void _bind_methods();
  431. public:
  432. void setup(const Vector<String> &p_options);
  433. virtual void update_property() override;
  434. void set_option_button_clip(bool p_enable);
  435. EditorPropertyShaderMode();
  436. };
  437. class EditorInspectorShaderModePlugin : public EditorInspectorPlugin {
  438. GDCLASS(EditorInspectorShaderModePlugin, EditorInspectorPlugin);
  439. public:
  440. virtual bool can_handle(Object *p_object) override;
  441. 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 uint32_t p_usage, const bool p_wide = false) override;
  442. };
  443. class VisualShaderNodePortPreview : public Control {
  444. GDCLASS(VisualShaderNodePortPreview, Control);
  445. Ref<VisualShader> shader;
  446. VisualShader::Type type = VisualShader::Type::TYPE_MAX;
  447. int node = 0;
  448. int port = 0;
  449. void _shader_changed(); //must regen
  450. protected:
  451. void _notification(int p_what);
  452. static void _bind_methods();
  453. public:
  454. virtual Size2 get_minimum_size() const override;
  455. void setup(const Ref<VisualShader> &p_shader, VisualShader::Type p_type, int p_node, int p_port);
  456. };
  457. class VisualShaderConversionPlugin : public EditorResourceConversionPlugin {
  458. GDCLASS(VisualShaderConversionPlugin, EditorResourceConversionPlugin);
  459. public:
  460. virtual String converts_to() const override;
  461. virtual bool handles(const Ref<Resource> &p_resource) const override;
  462. virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
  463. };
  464. #endif // VISUAL_SHADER_EDITOR_PLUGIN_H