visual_shader_editor_plugin.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  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. #ifndef VISUAL_SHADER_EDITOR_PLUGIN_H
  31. #define VISUAL_SHADER_EDITOR_PLUGIN_H
  32. #include "editor/editor_plugin.h"
  33. #include "editor/editor_properties.h"
  34. #include "editor/plugins/editor_resource_conversion_plugin.h"
  35. #include "scene/resources/syntax_highlighter.h"
  36. #include "scene/resources/visual_shader.h"
  37. class CodeEdit;
  38. class ColorPicker;
  39. class CurveEditor;
  40. class GraphEdit;
  41. class GraphElement;
  42. class MenuButton;
  43. class PopupPanel;
  44. class RichTextLabel;
  45. class Tree;
  46. class VisualShaderEditor;
  47. class VisualShaderNodePlugin : public RefCounted {
  48. GDCLASS(VisualShaderNodePlugin, RefCounted);
  49. protected:
  50. VisualShaderEditor *vseditor = nullptr;
  51. protected:
  52. static void _bind_methods();
  53. GDVIRTUAL2RC(Object *, _create_editor, Ref<Resource>, Ref<VisualShaderNode>)
  54. public:
  55. void set_editor(VisualShaderEditor *p_editor);
  56. virtual Control *create_editor(const Ref<Resource> &p_parent_resource, const Ref<VisualShaderNode> &p_node);
  57. };
  58. class VisualShaderGraphPlugin : public RefCounted {
  59. GDCLASS(VisualShaderGraphPlugin, RefCounted);
  60. private:
  61. VisualShaderEditor *editor = nullptr;
  62. struct InputPort {
  63. Button *default_input_button = nullptr;
  64. };
  65. struct Port {
  66. TextureButton *preview_button = nullptr;
  67. };
  68. struct Link {
  69. VisualShader::Type type = VisualShader::Type::TYPE_MAX;
  70. VisualShaderNode *visual_node = nullptr;
  71. GraphElement *graph_element = nullptr;
  72. bool preview_visible = false;
  73. int preview_pos = 0;
  74. HashMap<int, InputPort> input_ports;
  75. HashMap<int, Port> output_ports;
  76. VBoxContainer *preview_box = nullptr;
  77. LineEdit *parameter_name = nullptr;
  78. CodeEdit *expression_edit = nullptr;
  79. CurveEditor *curve_editors[3] = { nullptr, nullptr, nullptr };
  80. };
  81. Ref<VisualShader> visual_shader;
  82. HashMap<int, Link> links;
  83. List<VisualShader::Connection> connections;
  84. Color vector_expanded_color[4];
  85. protected:
  86. static void _bind_methods();
  87. public:
  88. void set_editor(VisualShaderEditor *p_editor);
  89. void register_shader(VisualShader *p_visual_shader);
  90. void set_connections(const List<VisualShader::Connection> &p_connections);
  91. void register_link(VisualShader::Type p_type, int p_id, VisualShaderNode *p_visual_node, GraphElement *p_graph_element);
  92. void register_output_port(int p_id, int p_port, TextureButton *p_button);
  93. void register_parameter_name(int p_id, LineEdit *p_parameter_name);
  94. void register_default_input_button(int p_node_id, int p_port_id, Button *p_button);
  95. void register_expression_edit(int p_node_id, CodeEdit *p_expression_edit);
  96. void register_curve_editor(int p_node_id, int p_index, CurveEditor *p_curve_editor);
  97. void clear_links();
  98. void set_shader_type(VisualShader::Type p_type);
  99. bool is_preview_visible(int p_id) const;
  100. void update_node(VisualShader::Type p_type, int p_id);
  101. void update_node_deferred(VisualShader::Type p_type, int p_node_id);
  102. void add_node(VisualShader::Type p_type, int p_id, bool p_just_update);
  103. void remove_node(VisualShader::Type p_type, int p_id, bool p_just_update);
  104. void connect_nodes(VisualShader::Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port);
  105. void disconnect_nodes(VisualShader::Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port);
  106. void show_port_preview(VisualShader::Type p_type, int p_node_id, int p_port_id, bool p_is_valid);
  107. void set_node_position(VisualShader::Type p_type, int p_id, const Vector2 &p_position);
  108. void refresh_node_ports(VisualShader::Type p_type, int p_node);
  109. void set_input_port_default_value(VisualShader::Type p_type, int p_node_id, int p_port_id, Variant p_value);
  110. void update_parameter_refs();
  111. void set_parameter_name(VisualShader::Type p_type, int p_node_id, const String &p_name);
  112. void update_curve(int p_node_id);
  113. void update_curve_xyz(int p_node_id);
  114. void set_expression(VisualShader::Type p_type, int p_node_id, const String &p_expression);
  115. int get_constant_index(float p_constant) const;
  116. Ref<Script> get_node_script(int p_node_id) const;
  117. void update_node_size(int p_node_id);
  118. void update_theme();
  119. bool is_node_has_parameter_instances_relatively(VisualShader::Type p_type, int p_node) const;
  120. VisualShader::Type get_shader_type() const;
  121. VisualShaderGraphPlugin();
  122. ~VisualShaderGraphPlugin();
  123. };
  124. class VisualShaderEditedProperty : public RefCounted {
  125. GDCLASS(VisualShaderEditedProperty, RefCounted);
  126. private:
  127. Variant edited_property;
  128. protected:
  129. static void _bind_methods();
  130. public:
  131. void set_edited_property(Variant p_variant);
  132. Variant get_edited_property() const;
  133. VisualShaderEditedProperty() {}
  134. };
  135. class VisualShaderEditor : public VBoxContainer {
  136. GDCLASS(VisualShaderEditor, VBoxContainer);
  137. friend class VisualShaderGraphPlugin;
  138. PopupPanel *property_editor_popup = nullptr;
  139. EditorProperty *property_editor = nullptr;
  140. int editing_node = -1;
  141. int editing_port = -1;
  142. Ref<VisualShaderEditedProperty> edited_property_holder;
  143. Ref<VisualShader> visual_shader;
  144. GraphEdit *graph = nullptr;
  145. Button *add_node = nullptr;
  146. MenuButton *varying_button = nullptr;
  147. Button *preview_shader = nullptr;
  148. OptionButton *edit_type = nullptr;
  149. OptionButton *edit_type_standard = nullptr;
  150. OptionButton *edit_type_particles = nullptr;
  151. OptionButton *edit_type_sky = nullptr;
  152. OptionButton *edit_type_fog = nullptr;
  153. CheckBox *custom_mode_box = nullptr;
  154. bool custom_mode_enabled = false;
  155. bool pending_update_preview = false;
  156. bool shader_error = false;
  157. Window *preview_window = nullptr;
  158. VBoxContainer *preview_vbox = nullptr;
  159. CodeEdit *preview_text = nullptr;
  160. Ref<CodeHighlighter> syntax_highlighter = nullptr;
  161. PanelContainer *error_panel = nullptr;
  162. Label *error_label = nullptr;
  163. bool pending_custom_scripts_to_delete = false;
  164. List<Ref<Script>> custom_scripts_to_delete;
  165. bool _block_update_options_menu = false;
  166. bool _block_rebuild_shader = false;
  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. #ifdef MINGW_ENABLED
  218. #undef DELETE
  219. #endif
  220. enum NodeMenuOptions {
  221. ADD,
  222. SEPARATOR, // ignore
  223. CUT,
  224. COPY,
  225. PASTE,
  226. DELETE,
  227. DUPLICATE,
  228. CLEAR_COPY_BUFFER,
  229. SEPARATOR2, // ignore
  230. FLOAT_CONSTANTS,
  231. CONVERT_CONSTANTS_TO_PARAMETERS,
  232. CONVERT_PARAMETERS_TO_CONSTANTS,
  233. SEPARATOR3, // ignore
  234. SET_COMMENT_TITLE,
  235. SET_COMMENT_DESCRIPTION,
  236. };
  237. enum class VaryingMenuOptions {
  238. ADD,
  239. REMOVE,
  240. };
  241. Tree *members = nullptr;
  242. AcceptDialog *alert = nullptr;
  243. LineEdit *node_filter = nullptr;
  244. RichTextLabel *node_desc = nullptr;
  245. Label *highend_label = nullptr;
  246. void _tools_menu_option(int p_idx);
  247. 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);
  248. void _varying_menu_id_pressed(int p_idx);
  249. void _show_add_varying_dialog();
  250. void _show_remove_varying_dialog();
  251. void _update_nodes();
  252. void _update_graph();
  253. struct AddOption {
  254. String name;
  255. String category;
  256. String type;
  257. String description;
  258. Vector<Variant> ops;
  259. Ref<Script> script;
  260. int mode = 0;
  261. int return_type = 0;
  262. int func = 0;
  263. bool highend = false;
  264. bool is_custom = false;
  265. bool is_native = false;
  266. int temp_idx = 0;
  267. 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) {
  268. name = p_name;
  269. type = p_type;
  270. category = p_category;
  271. description = p_description;
  272. ops = p_ops;
  273. return_type = p_return_type;
  274. mode = p_mode;
  275. func = p_func;
  276. highend = p_highend;
  277. }
  278. };
  279. struct _OptionComparator {
  280. _FORCE_INLINE_ bool operator()(const AddOption &a, const AddOption &b) const {
  281. return a.category.count("/") > b.category.count("/") || (a.category + "/" + a.name).naturalnocasecmp_to(b.category + "/" + b.name) < 0;
  282. }
  283. };
  284. Vector<AddOption> add_options;
  285. int cubemap_node_option_idx;
  286. int texture2d_node_option_idx;
  287. int texture2d_array_node_option_idx;
  288. int texture3d_node_option_idx;
  289. int custom_node_option_idx;
  290. int curve_node_option_idx;
  291. int curve_xyz_node_option_idx;
  292. List<String> keyword_list;
  293. List<VisualShaderNodeParameterRef> uniform_refs;
  294. void _draw_color_over_button(Object *p_obj, Color p_color);
  295. void _setup_node(VisualShaderNode *p_node, const Vector<Variant> &p_ops);
  296. void _add_node(int p_idx, const Vector<Variant> &p_ops, String p_resource_path = "", int p_node_idx = -1);
  297. void _add_varying(const String &p_name, VisualShader::VaryingMode p_mode, VisualShader::VaryingType p_type);
  298. void _remove_varying(const String &p_name);
  299. void _update_options_menu();
  300. void _set_mode(int p_which);
  301. void _show_preview_text();
  302. void _preview_close_requested();
  303. void _preview_size_changed();
  304. void _update_preview();
  305. void _update_next_previews(int p_node_id);
  306. void _get_next_nodes_recursively(VisualShader::Type p_type, int p_node_id, LocalVector<int> &r_nodes) const;
  307. String _get_description(int p_idx);
  308. struct DragOp {
  309. VisualShader::Type type = VisualShader::Type::TYPE_MAX;
  310. int node = 0;
  311. Vector2 from;
  312. Vector2 to;
  313. };
  314. List<DragOp> drag_buffer;
  315. bool drag_dirty = false;
  316. void _node_dragged(const Vector2 &p_from, const Vector2 &p_to, int p_node);
  317. void _nodes_dragged();
  318. bool updating = false;
  319. void _connection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index);
  320. void _disconnection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index);
  321. void _scroll_changed(const Vector2 &p_scroll);
  322. void _node_selected(Object *p_node);
  323. void _delete_nodes(int p_type, const List<int> &p_nodes);
  324. void _delete_node_request(int p_type, int p_node);
  325. void _delete_nodes_request(const TypedArray<StringName> &p_nodes);
  326. void _node_changed(int p_id);
  327. void _edit_port_default_input(Object *p_button, int p_node, int p_port);
  328. void _port_edited(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing);
  329. int to_node = -1;
  330. int to_slot = -1;
  331. int from_node = -1;
  332. int from_slot = -1;
  333. HashSet<int> selected_constants;
  334. HashSet<int> selected_parameters;
  335. int selected_comment = -1;
  336. int selected_float_constant = -1;
  337. void _convert_constants_to_parameters(bool p_vice_versa);
  338. void _replace_node(VisualShader::Type p_type_id, int p_node_id, const StringName &p_from, const StringName &p_to);
  339. void _update_constant(VisualShader::Type p_type_id, int p_node_id, Variant p_var, int p_preview_port);
  340. void _update_parameter(VisualShader::Type p_type_id, int p_node_id, Variant p_var, int p_preview_port);
  341. void _connection_to_empty(const String &p_from, int p_from_slot, const Vector2 &p_release_position);
  342. void _connection_from_empty(const String &p_to, int p_to_slot, const Vector2 &p_release_position);
  343. void _comment_title_popup_show(const Point2 &p_position, int p_node_id);
  344. void _comment_title_popup_hide();
  345. void _comment_title_popup_focus_out();
  346. void _comment_title_text_changed(const String &p_new_text);
  347. void _comment_title_text_submitted(const String &p_new_text);
  348. void _comment_desc_popup_show(const Point2 &p_position, int p_node_id);
  349. void _comment_desc_popup_hide();
  350. void _comment_desc_confirm();
  351. void _comment_desc_text_changed();
  352. void _parameter_line_edit_changed(const String &p_text, int p_node_id);
  353. void _parameter_line_edit_focus_out(Object *p_line_edit, int p_node_id);
  354. void _port_name_focus_out(Object *p_line_edit, int p_node_id, int p_port_id, bool p_output);
  355. struct CopyItem {
  356. int id;
  357. Ref<VisualShaderNode> node;
  358. Vector2 position;
  359. Vector2 size;
  360. String group_inputs;
  361. String group_outputs;
  362. String expression;
  363. bool disabled = false;
  364. };
  365. void _dup_copy_nodes(int p_type, List<CopyItem> &r_nodes, List<VisualShader::Connection> &r_connections);
  366. void _dup_paste_nodes(int p_type, List<CopyItem> &r_items, const List<VisualShader::Connection> &p_connections, const Vector2 &p_offset, bool p_duplicate);
  367. void _duplicate_nodes();
  368. static Vector2 selection_center;
  369. static List<CopyItem> copy_items_buffer;
  370. static List<VisualShader::Connection> copy_connections_buffer;
  371. void _clear_copy_buffer();
  372. void _copy_nodes(bool p_cut);
  373. void _paste_nodes(bool p_use_custom_position = false, const Vector2 &p_custom_position = Vector2());
  374. Vector<Ref<VisualShaderNodePlugin>> plugins;
  375. Ref<VisualShaderGraphPlugin> graph_plugin;
  376. void _mode_selected(int p_id);
  377. void _custom_mode_toggled(bool p_enabled);
  378. void _input_select_item(Ref<VisualShaderNodeInput> p_input, String p_name);
  379. void _parameter_ref_select_item(Ref<VisualShaderNodeParameterRef> p_parameter_ref, String p_name);
  380. void _varying_select_item(Ref<VisualShaderNodeVarying> p_varying, String p_name);
  381. void _float_constant_selected(int p_which);
  382. VisualShader::Type get_current_shader_type() const;
  383. void _add_input_port(int p_node, int p_port, int p_port_type, const String &p_name);
  384. void _remove_input_port(int p_node, int p_port);
  385. void _change_input_port_type(int p_type, int p_node, int p_port);
  386. void _change_input_port_name(const String &p_text, Object *p_line_edit, int p_node, int p_port);
  387. void _add_output_port(int p_node, int p_port, int p_port_type, const String &p_name);
  388. void _remove_output_port(int p_node, int p_port);
  389. void _change_output_port_type(int p_type, int p_node, int p_port);
  390. void _change_output_port_name(const String &p_text, Object *p_line_edit, int p_node, int p_port);
  391. void _expand_output_port(int p_node, int p_port, bool p_expand);
  392. void _expression_focus_out(Object *p_code_edit, int p_node);
  393. void _set_node_size(int p_type, int p_node, const Size2 &p_size);
  394. void _node_resized(const Vector2 &p_new_size, int p_type, int p_node);
  395. void _preview_select_port(int p_node, int p_port);
  396. void _graph_gui_input(const Ref<InputEvent> &p_event);
  397. void _member_filter_changed(const String &p_text);
  398. void _sbox_input(const Ref<InputEvent> &p_ie);
  399. void _member_selected();
  400. void _member_unselected();
  401. void _member_create();
  402. void _member_cancel();
  403. void _varying_create();
  404. void _varying_name_changed(const String &p_text);
  405. void _varying_deleted();
  406. void _varying_selected();
  407. void _varying_unselected();
  408. void _update_varying_tree();
  409. void _set_custom_node_option(int p_index, int p_node, int p_op);
  410. Vector2 menu_point;
  411. void _node_menu_id_pressed(int p_idx);
  412. Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
  413. bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
  414. void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
  415. bool _is_available(int p_mode);
  416. void _update_parameters(bool p_update_refs);
  417. void _update_parameter_refs(HashSet<String> &p_names);
  418. void _update_varyings();
  419. void _update_options_menu_deferred();
  420. void _rebuild_shader_deferred();
  421. void _visibility_changed();
  422. void _get_current_mode_limits(int &r_begin_type, int &r_end_type) const;
  423. void _update_custom_script(const Ref<Script> &p_script);
  424. void _script_created(const Ref<Script> &p_script);
  425. void _resource_saved(const Ref<Resource> &p_resource);
  426. void _resource_removed(const Ref<Resource> &p_resource);
  427. void _resources_removed();
  428. protected:
  429. void _notification(int p_what);
  430. static void _bind_methods();
  431. public:
  432. void add_plugin(const Ref<VisualShaderNodePlugin> &p_plugin);
  433. void remove_plugin(const Ref<VisualShaderNodePlugin> &p_plugin);
  434. VisualShaderGraphPlugin *get_graph_plugin() { return graph_plugin.ptr(); }
  435. void clear_custom_types();
  436. 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);
  437. Dictionary get_custom_node_data(Ref<VisualShaderNodeCustom> &p_custom_node);
  438. void update_custom_type(const Ref<Resource> &p_resource);
  439. virtual Size2 get_minimum_size() const override;
  440. void edit(VisualShader *p_visual_shader);
  441. VisualShaderEditor();
  442. };
  443. class VisualShaderNodePluginDefault : public VisualShaderNodePlugin {
  444. GDCLASS(VisualShaderNodePluginDefault, VisualShaderNodePlugin);
  445. public:
  446. virtual Control *create_editor(const Ref<Resource> &p_parent_resource, const Ref<VisualShaderNode> &p_node) override;
  447. };
  448. class EditorPropertyVisualShaderMode : public EditorProperty {
  449. GDCLASS(EditorPropertyVisualShaderMode, EditorProperty);
  450. OptionButton *options = nullptr;
  451. void _option_selected(int p_which);
  452. protected:
  453. static void _bind_methods();
  454. public:
  455. void setup(const Vector<String> &p_options);
  456. virtual void update_property() override;
  457. void set_option_button_clip(bool p_enable);
  458. EditorPropertyVisualShaderMode();
  459. };
  460. class EditorInspectorVisualShaderModePlugin : public EditorInspectorPlugin {
  461. GDCLASS(EditorInspectorVisualShaderModePlugin, EditorInspectorPlugin);
  462. public:
  463. virtual bool can_handle(Object *p_object) override;
  464. 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;
  465. };
  466. class VisualShaderNodePortPreview : public Control {
  467. GDCLASS(VisualShaderNodePortPreview, Control);
  468. Ref<VisualShader> shader;
  469. VisualShader::Type type = VisualShader::Type::TYPE_MAX;
  470. int node = 0;
  471. int port = 0;
  472. bool is_valid = false;
  473. void _shader_changed(); //must regen
  474. protected:
  475. void _notification(int p_what);
  476. static void _bind_methods();
  477. public:
  478. virtual Size2 get_minimum_size() const override;
  479. void setup(const Ref<VisualShader> &p_shader, VisualShader::Type p_type, int p_node, int p_port, bool p_is_valid);
  480. };
  481. class VisualShaderConversionPlugin : public EditorResourceConversionPlugin {
  482. GDCLASS(VisualShaderConversionPlugin, EditorResourceConversionPlugin);
  483. public:
  484. virtual String converts_to() const override;
  485. virtual bool handles(const Ref<Resource> &p_resource) const override;
  486. virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
  487. };
  488. #endif // VISUAL_SHADER_EDITOR_PLUGIN_H