visual_shader_editor_plugin.h 20 KB

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