/**************************************************************************/ /* visual_shader_editor_plugin.h */ /**************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ /* https://godotengine.org */ /**************************************************************************/ /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ /* "Software"), to deal in the Software without restriction, including */ /* without limitation the rights to use, copy, modify, merge, publish, */ /* distribute, sublicense, and/or sell copies of the Software, and to */ /* permit persons to whom the Software is furnished to do so, subject to */ /* the following conditions: */ /* */ /* The above copyright notice and this permission notice shall be */ /* included in all copies or substantial portions of the Software. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /**************************************************************************/ #ifndef VISUAL_SHADER_EDITOR_PLUGIN_H #define VISUAL_SHADER_EDITOR_PLUGIN_H #include "editor/editor_properties.h" #include "editor/plugins/editor_plugin.h" #include "editor/plugins/editor_resource_conversion_plugin.h" #include "scene/gui/graph_edit.h" #include "scene/resources/syntax_highlighter.h" #include "scene/resources/visual_shader.h" class CodeEdit; class ColorPicker; class CurveEditor; class GraphElement; class GraphFrame; class MenuButton; class PopupPanel; class RichTextLabel; class Tree; class VisualShaderEditor; class VisualShaderNodePlugin : public RefCounted { GDCLASS(VisualShaderNodePlugin, RefCounted); protected: VisualShaderEditor *vseditor = nullptr; protected: static void _bind_methods(); GDVIRTUAL2RC(Object *, _create_editor, Ref, Ref) public: void set_editor(VisualShaderEditor *p_editor); virtual Control *create_editor(const Ref &p_parent_resource, const Ref &p_node); }; class VisualShaderGraphPlugin : public RefCounted { GDCLASS(VisualShaderGraphPlugin, RefCounted); private: VisualShaderEditor *editor = nullptr; struct InputPort { Button *default_input_button = nullptr; }; struct Port { TextureButton *preview_button = nullptr; }; struct Link { VisualShader::Type type = VisualShader::Type::TYPE_MAX; VisualShaderNode *visual_node = nullptr; GraphElement *graph_element = nullptr; bool preview_visible = false; int preview_pos = 0; HashMap input_ports; HashMap output_ports; VBoxContainer *preview_box = nullptr; LineEdit *parameter_name = nullptr; CodeEdit *expression_edit = nullptr; CurveEditor *curve_editors[3] = { nullptr, nullptr, nullptr }; }; Ref visual_shader; HashMap links; List connections; Color vector_expanded_color[4]; // Visual shader specific theme for using MSDF fonts (on GraphNodes) which reduce aliasing at higher zoom levels. Ref vs_msdf_fonts_theme; protected: static void _bind_methods(); public: void set_editor(VisualShaderEditor *p_editor); void register_shader(VisualShader *p_visual_shader); void set_connections(const List &p_connections); void register_link(VisualShader::Type p_type, int p_id, VisualShaderNode *p_visual_node, GraphElement *p_graph_element); void register_output_port(int p_id, int p_port, TextureButton *p_button); void register_parameter_name(int p_id, LineEdit *p_parameter_name); void register_default_input_button(int p_node_id, int p_port_id, Button *p_button); void register_expression_edit(int p_node_id, CodeEdit *p_expression_edit); void register_curve_editor(int p_node_id, int p_index, CurveEditor *p_curve_editor); void clear_links(); void set_shader_type(VisualShader::Type p_type); bool is_preview_visible(int p_id) const; void update_node(VisualShader::Type p_type, int p_id); void update_node_deferred(VisualShader::Type p_type, int p_node_id); void add_node(VisualShader::Type p_type, int p_id, bool p_just_update, bool p_update_frames); void remove_node(VisualShader::Type p_type, int p_id, bool p_just_update); void connect_nodes(VisualShader::Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port); void disconnect_nodes(VisualShader::Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port); void show_port_preview(VisualShader::Type p_type, int p_node_id, int p_port_id, bool p_is_valid); void update_frames(VisualShader::Type p_type, int p_node); void set_node_position(VisualShader::Type p_type, int p_id, const Vector2 &p_position); void refresh_node_ports(VisualShader::Type p_type, int p_node); void set_input_port_default_value(VisualShader::Type p_type, int p_node_id, int p_port_id, const Variant &p_value); void update_parameter_refs(); void set_parameter_name(VisualShader::Type p_type, int p_node_id, const String &p_name); void update_curve(int p_node_id); void update_curve_xyz(int p_node_id); void set_expression(VisualShader::Type p_type, int p_node_id, const String &p_expression); void attach_node_to_frame(VisualShader::Type p_type, int p_node_id, int p_frame_id); void detach_node_from_frame(VisualShader::Type p_type, int p_node_id); void set_frame_color_enabled(VisualShader::Type p_type, int p_node_id, bool p_enable); void set_frame_color(VisualShader::Type p_type, int p_node_id, const Color &p_color); void set_frame_autoshrink_enabled(VisualShader::Type p_type, int p_node_id, bool p_enable); int get_constant_index(float p_constant) const; Ref