visual_shader_editor_plugin.h 21 KB

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