From 5b71fc45b703d2ea44cc1aa99830ec3e0966b3e6 Mon Sep 17 00:00:00 2001 From: Mariano Javier Suligoy Date: Thu, 16 Jul 2015 22:38:12 -0300 Subject: [PATCH 01/11] Use popup menu to add new nodes to the shader graph editor in the last clicked location. --- scene/gui/graph_edit.cpp | 14 +++++-- .../plugins/shader_graph_editor_plugin.cpp | 37 ++++++++++++------- .../plugins/shader_graph_editor_plugin.h | 6 ++- 3 files changed, 38 insertions(+), 19 deletions(-) diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index 3cd0dd3d16c1..d0ff4e48d34b 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -499,7 +499,15 @@ void GraphEdit::_input_event(const InputEvent& p_ev) { if (p_ev.type==InputEvent::MOUSE_MOTION && (p_ev.mouse_motion.button_mask&BUTTON_MASK_MIDDLE || (p_ev.mouse_motion.button_mask&BUTTON_MASK_LEFT && Input::get_singleton()->is_key_pressed(KEY_SPACE)))) { h_scroll->set_val( h_scroll->get_val() - p_ev.mouse_motion.relative_x ); v_scroll->set_val( v_scroll->get_val() - p_ev.mouse_motion.relative_y ); - } + } else if (p_ev.type== InputEvent::MOUSE_BUTTON) { + + const InputEventMouseButton &b=p_ev.mouse_button; + + if (b.button_index==2 && b.pressed) + { + emit_signal("popup_request", Vector2(b.global_x, b.global_y)); + } + } } void GraphEdit::clear_connections() { @@ -554,8 +562,8 @@ void GraphEdit::_bind_methods() { ObjectTypeDB::bind_method(_MD("_input_event"),&GraphEdit::_input_event); ADD_SIGNAL(MethodInfo("connection_request",PropertyInfo(Variant::STRING,"from"),PropertyInfo(Variant::INT,"from_slot"),PropertyInfo(Variant::STRING,"to"),PropertyInfo(Variant::INT,"to_slot"))); - ADD_SIGNAL(MethodInfo("disconnection_request",PropertyInfo(Variant::STRING,"from"),PropertyInfo(Variant::INT,"from_slot"),PropertyInfo(Variant::STRING,"to"),PropertyInfo(Variant::INT,"to_slot"))); - + ADD_SIGNAL(MethodInfo("disconnection_request",PropertyInfo(Variant::STRING,"from"),PropertyInfo(Variant::INT,"from_slot"),PropertyInfo(Variant::STRING,"to"),PropertyInfo(Variant::INT,"to_slot"))); + ADD_SIGNAL(MethodInfo("popup_request", PropertyInfo(Variant::VECTOR2,"p_position"))); } diff --git a/tools/editor/plugins/shader_graph_editor_plugin.cpp b/tools/editor/plugins/shader_graph_editor_plugin.cpp index 03fcbffa24d1..b4fb14dbbc71 100644 --- a/tools/editor/plugins/shader_graph_editor_plugin.cpp +++ b/tools/editor/plugins/shader_graph_editor_plugin.cpp @@ -2114,7 +2114,7 @@ void ShaderGraphView::_notification(int p_what) { } } -void ShaderGraphView::add_node(int p_type) { +void ShaderGraphView::add_node(int p_type, const Vector2 &location) { List existing; graph->get_node_list(type,&existing); @@ -2127,7 +2127,7 @@ void ShaderGraphView::add_node(int p_type) { } } - Vector2 init_ofs(20,20); + Vector2 init_ofs = location; while(true) { bool valid=true; for(List::Element *E=existing.front();E;E=E->next()) { @@ -2222,7 +2222,17 @@ void ShaderGraphEditor::_add_node(int p_type) { ShaderGraph::ShaderType shader_type=ShaderGraph::ShaderType(tabs->get_current_tab()); - graph_edits[shader_type]->add_node(p_type); + graph_edits[shader_type]->add_node(p_type, next_location); +} + +void ShaderGraphEditor::_popup_requested(const Vector2 &p_position) +{ + next_location = get_local_mouse_pos(); + popup->set_global_pos(p_position); + popup->set_size( Size2( 200, 0) ); + popup->popup(); + popup->call_deferred("grab_click_focus"); + popup->set_invalidate_click_until_motion(); } @@ -2243,11 +2253,11 @@ void ShaderGraphEditor::_notification(int p_what) { if (nn.ends_with(":")) { addsep=true; } - menu->get_popup()->add_icon_item(get_icon(ic,"EditorIcons"),v,i); + popup->add_icon_item(get_icon(ic,"EditorIcons"),v,i); if (addsep) - menu->get_popup()->add_separator(); + popup->add_separator(); } - menu->get_popup()->connect("item_pressed",this,"_add_node"); + popup->connect("item_pressed",this,"_add_node"); } @@ -2256,7 +2266,7 @@ void ShaderGraphEditor::_notification(int p_what) { void ShaderGraphEditor::_bind_methods() { ObjectTypeDB::bind_method("_add_node",&ShaderGraphEditor::_add_node); - + ObjectTypeDB::bind_method("_popup_requested",&ShaderGraphEditor::_popup_requested); } @@ -2302,11 +2312,10 @@ const char* ShaderGraphEditor::node_names[ShaderGraph::NODE_TYPE_MAX]={ ShaderGraphEditor::ShaderGraphEditor(bool p_2d) { _2d=p_2d; - HBoxContainer *hbc = memnew( HBoxContainer ); - menu = memnew( MenuButton ); - menu->set_text("Add Node.."); - hbc->add_child(menu); - add_child(hbc); + HBoxContainer *hbc = memnew( HBoxContainer ); + popup = memnew( PopupMenu ); + hbc->add_child(popup); + add_child(hbc); tabs = memnew(TabContainer); @@ -2325,8 +2334,8 @@ ShaderGraphEditor::ShaderGraphEditor(bool p_2d) { tabs->add_child(graph_edits[i]->get_graph_edit()); graph_edits[i]->get_graph_edit()->connect("connection_request",graph_edits[i],"_connection_request"); graph_edits[i]->get_graph_edit()->connect("disconnection_request",graph_edits[i],"_disconnection_request"); - graph_edits[i]->get_graph_edit()->set_right_disconnects(true); - + graph_edits[i]->get_graph_edit()->connect("popup_request",this,"_popup_requested"); + graph_edits[i]->get_graph_edit()->set_right_disconnects(true); } tabs->set_current_tab(1); diff --git a/tools/editor/plugins/shader_graph_editor_plugin.h b/tools/editor/plugins/shader_graph_editor_plugin.h index 0051fbfd7494..c41ec68360c3 100644 --- a/tools/editor/plugins/shader_graph_editor_plugin.h +++ b/tools/editor/plugins/shader_graph_editor_plugin.h @@ -175,7 +175,7 @@ class ShaderGraphView : public Node { static void _bind_methods(); public: - void add_node(int p_type); + void add_node(int p_type, const Vector2 &location); GraphEdit *get_graph_edit() { return graph_edit; } void set_graph(Ref p_graph); @@ -186,13 +186,15 @@ class ShaderGraphEditor : public VBoxContainer { OBJ_TYPE(ShaderGraphEditor,VBoxContainer); - MenuButton *menu; + PopupMenu *popup; TabContainer *tabs; ShaderGraphView *graph_edits[ShaderGraph::SHADER_TYPE_MAX]; static const char* node_names[ShaderGraph::NODE_TYPE_MAX]; + Vector2 next_location; bool _2d; void _add_node(int p_type); + void _popup_requested(const Vector2 &p_position); protected: void _notification(int p_what); static void _bind_methods(); From bdd12744fe340152cef5bf88de9e2d183bff1790 Mon Sep 17 00:00:00 2001 From: Mariano Javier Suligoy Date: Sun, 19 Jul 2015 01:48:46 -0300 Subject: [PATCH 02/11] Select and move multiple nodes at once --- scene/gui/graph_edit.cpp | 861 ++-- scene/gui/graph_edit.h | 106 +- scene/gui/graph_node.cpp | 686 +-- scene/gui/graph_node.h | 125 +- .../resources/default_theme/default_theme.cpp | 2 + .../default_theme/graph_node_selected.png | Bin 0 -> 738 bytes scene/resources/default_theme/theme_data.h | 5 + .../plugins/shader_graph_editor_plugin.cpp | 3779 +++++++++-------- .../plugins/shader_graph_editor_plugin.h | 244 +- 9 files changed, 2966 insertions(+), 2842 deletions(-) create mode 100644 scene/resources/default_theme/graph_node_selected.png diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index d0ff4e48d34b..4569c71d0b68 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -3,388 +3,385 @@ #include "os/keyboard.h" bool GraphEditFilter::has_point(const Point2& p_point) const { - return ge->_filter_input(p_point); + return ge->_filter_input(p_point); } GraphEditFilter::GraphEditFilter(GraphEdit *p_edit) { - ge=p_edit; + ge=p_edit; } Error GraphEdit::connect_node(const StringName& p_from, int p_from_port,const StringName& p_to,int p_to_port) { - if (is_node_connected(p_from,p_from_port,p_to,p_to_port)) - return OK; - Connection c; - c.from=p_from; - c.from_port=p_from_port; - c.to=p_to; - c.to_port=p_to_port; - connections.push_back(c); - top_layer->update(); - - return OK; + if (is_node_connected(p_from,p_from_port,p_to,p_to_port)) + return OK; + Connection c; + c.from=p_from; + c.from_port=p_from_port; + c.to=p_to; + c.to_port=p_to_port; + connections.push_back(c); + top_layer->update(); + + return OK; } bool GraphEdit::is_node_connected(const StringName& p_from, int p_from_port,const StringName& p_to,int p_to_port) { - for(List::Element *E=connections.front();E;E=E->next()) { + for(List::Element *E=connections.front();E;E=E->next()) { - if (E->get().from==p_from && E->get().from_port==p_from_port && E->get().to==p_to && E->get().to_port==p_to_port) - return true; - } + if (E->get().from==p_from && E->get().from_port==p_from_port && E->get().to==p_to && E->get().to_port==p_to_port) + return true; + } - return false; + return false; } void GraphEdit::disconnect_node(const StringName& p_from, int p_from_port,const StringName& p_to,int p_to_port){ - for(List::Element *E=connections.front();E;E=E->next()) { + for(List::Element *E=connections.front();E;E=E->next()) { - if (E->get().from==p_from && E->get().from_port==p_from_port && E->get().to==p_to && E->get().to_port==p_to_port) { + if (E->get().from==p_from && E->get().from_port==p_from_port && E->get().to==p_to && E->get().to_port==p_to_port) { - connections.erase(E); - top_layer->update(); - return; - } - } + connections.erase(E); + top_layer->update(); + return; + } + } } void GraphEdit::get_connection_list(List *r_connections) const { - *r_connections=connections; + *r_connections=connections; } void GraphEdit::_scroll_moved(double) { - _update_scroll_offset(); - top_layer->update(); + _update_scroll_offset(); + top_layer->update(); } void GraphEdit::_update_scroll_offset() { - for(int i=0;icast_to(); - if (!gn) - continue; + GraphNode *gn=get_child(i)->cast_to(); + if (!gn) + continue; - Point2 pos=gn->get_offset(); - pos-=Point2(h_scroll->get_val(),v_scroll->get_val()); - gn->set_pos(pos); - } + Point2 pos=gn->get_offset(); + pos-=Point2(h_scroll->get_val(),v_scroll->get_val()); + gn->set_pos(pos); + } } void GraphEdit::_update_scroll() { - if (updating) - return; + if (updating) + return; - updating=true; - Rect2 screen; - for(int i=0;icast_to(); - if (!gn) - continue; + GraphNode *gn=get_child(i)->cast_to(); + if (!gn) + continue; - Rect2 r; - r.pos=gn->get_offset(); - r.size=gn->get_size(); - screen = screen.merge(r); - } + Rect2 r; + r.pos=gn->get_offset(); + r.size=gn->get_size(); + screen = screen.merge(r); + } - screen.pos-=get_size(); - screen.size+=get_size()*2.0; + screen.pos-=get_size(); + screen.size+=get_size()*2.0; - h_scroll->set_min(screen.pos.x); - h_scroll->set_max(screen.pos.x+screen.size.x); - h_scroll->set_page(get_size().x); - if (h_scroll->get_max() - h_scroll->get_min() <= h_scroll->get_page()) - h_scroll->hide(); - else - h_scroll->show(); + h_scroll->set_min(screen.pos.x); + h_scroll->set_max(screen.pos.x+screen.size.x); + h_scroll->set_page(get_size().x); + if (h_scroll->get_max() - h_scroll->get_min() <= h_scroll->get_page()) + h_scroll->hide(); + else + h_scroll->show(); - v_scroll->set_min(screen.pos.y); - v_scroll->set_max(screen.pos.y+screen.size.y); - v_scroll->set_page(get_size().y); + v_scroll->set_min(screen.pos.y); + v_scroll->set_max(screen.pos.y+screen.size.y); + v_scroll->set_page(get_size().y); - if (v_scroll->get_max() - v_scroll->get_min() <= v_scroll->get_page()) - v_scroll->hide(); - else - v_scroll->show(); + if (v_scroll->get_max() - v_scroll->get_min() <= v_scroll->get_page()) + v_scroll->hide(); + else + v_scroll->show(); - _update_scroll_offset(); - updating=false; + _update_scroll_offset(); + updating=false; } void GraphEdit::_graph_node_raised(Node* p_gn) { - GraphNode *gn=p_gn->cast_to(); - ERR_FAIL_COND(!gn); - gn->raise(); - top_layer->raise(); + GraphNode *gn=p_gn->cast_to(); + ERR_FAIL_COND(!gn); + gn->raise(); + top_layer->raise(); } void GraphEdit::_graph_node_moved(Node *p_gn) { - GraphNode *gn=p_gn->cast_to(); - ERR_FAIL_COND(!gn); - - //gn->set_pos(gn->get_offset()+scroll_offset); - - top_layer->update(); + GraphNode *gn=p_gn->cast_to(); + ERR_FAIL_COND(!gn); + top_layer->update(); } void GraphEdit::add_child_notify(Node *p_child) { - top_layer->call_deferred("raise"); //top layer always on top! - GraphNode *gn = p_child->cast_to(); - if (gn) { - gn->connect("offset_changed",this,"_graph_node_moved",varray(gn)); - gn->connect("raise_request",this,"_graph_node_raised",varray(gn)); - _graph_node_moved(gn); - gn->set_stop_mouse(false); - } + top_layer->call_deferred("raise"); //top layer always on top! + GraphNode *gn = p_child->cast_to(); + if (gn) { + gn->connect("offset_changed",this,"_graph_node_moved",varray(gn)); + gn->connect("raise_request",this,"_graph_node_raised",varray(gn)); + _graph_node_moved(gn); + gn->set_stop_mouse(false); + } } void GraphEdit::remove_child_notify(Node *p_child) { - top_layer->call_deferred("raise"); //top layer always on top! - GraphNode *gn = p_child->cast_to(); - if (gn) { - gn->disconnect("offset_changed",this,"_graph_node_moved"); - gn->disconnect("raise_request",this,"_graph_node_raised"); - } + top_layer->call_deferred("raise"); //top layer always on top! + GraphNode *gn = p_child->cast_to(); + if (gn) { + gn->disconnect("offset_changed",this,"_graph_node_moved"); + gn->disconnect("raise_request",this,"_graph_node_raised"); + } } void GraphEdit::_notification(int p_what) { - if (p_what==NOTIFICATION_READY) { - Size2 size = top_layer->get_size(); - Size2 hmin = h_scroll->get_combined_minimum_size(); - Size2 vmin = v_scroll->get_combined_minimum_size(); + if (p_what==NOTIFICATION_READY) { + Size2 size = top_layer->get_size(); + Size2 hmin = h_scroll->get_combined_minimum_size(); + Size2 vmin = v_scroll->get_combined_minimum_size(); - v_scroll->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_END,vmin.width); - v_scroll->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,0); - v_scroll->set_anchor_and_margin(MARGIN_TOP,ANCHOR_BEGIN,0); - v_scroll->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END,0); + v_scroll->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_END,vmin.width); + v_scroll->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,0); + v_scroll->set_anchor_and_margin(MARGIN_TOP,ANCHOR_BEGIN,0); + v_scroll->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END,0); - h_scroll->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_BEGIN,0); - h_scroll->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,0); - h_scroll->set_anchor_and_margin(MARGIN_TOP,ANCHOR_END,hmin.height); - h_scroll->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END,0); + h_scroll->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_BEGIN,0); + h_scroll->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,0); + h_scroll->set_anchor_and_margin(MARGIN_TOP,ANCHOR_END,hmin.height); + h_scroll->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END,0); - } - if (p_what==NOTIFICATION_DRAW) { - VS::get_singleton()->canvas_item_set_clip(get_canvas_item(),true); + } + if (p_what==NOTIFICATION_DRAW) { + VS::get_singleton()->canvas_item_set_clip(get_canvas_item(),true); - } + } - if (p_what==NOTIFICATION_RESIZED) { - _update_scroll(); - top_layer->update(); - } + if (p_what==NOTIFICATION_RESIZED) { + _update_scroll(); + top_layer->update(); + } } bool GraphEdit::_filter_input(const Point2& p_point) { - Ref port =get_icon("port","GraphNode"); + Ref port =get_icon("port","GraphNode"); - float grab_r=port->get_width()*0.5; - for(int i=get_child_count()-1;i>=0;i--) { + float grab_r=port->get_width()*0.5; + for(int i=get_child_count()-1;i>=0;i--) { - GraphNode *gn=get_child(i)->cast_to(); - if (!gn) - continue; + GraphNode *gn=get_child(i)->cast_to(); + if (!gn) + continue; - for(int j=0;jget_connection_output_count();j++) { + for(int j=0;jget_connection_output_count();j++) { - Vector2 pos = gn->get_connection_output_pos(j)+gn->get_pos(); - if (pos.distance_to(p_point)get_connection_output_pos(j)+gn->get_pos(); + if (pos.distance_to(p_point)get_connection_input_count();j++) { + for(int j=0;jget_connection_input_count();j++) { - Vector2 pos = gn->get_connection_input_pos(j)+gn->get_pos(); - if (pos.distance_to(p_point)get_connection_input_pos(j)+gn->get_pos(); + if (pos.distance_to(p_point) port =get_icon("port","GraphNode"); - Vector2 mpos(p_ev.mouse_button.x,p_ev.mouse_button.y); - float grab_r=port->get_width()*0.5; - for(int i=get_child_count()-1;i>=0;i--) { + Ref port =get_icon("port","GraphNode"); + Vector2 mpos(p_ev.mouse_button.x,p_ev.mouse_button.y); + float grab_r=port->get_width()*0.5; + for(int i=get_child_count()-1;i>=0;i--) { - GraphNode *gn=get_child(i)->cast_to(); - if (!gn) - continue; + GraphNode *gn=get_child(i)->cast_to(); + if (!gn) + continue; - for(int j=0;jget_connection_output_count();j++) { + for(int j=0;jget_connection_output_count();j++) { - Vector2 pos = gn->get_connection_output_pos(j)+gn->get_pos(); - if (pos.distance_to(mpos)get_connection_output_pos(j)+gn->get_pos(); + if (pos.distance_to(mpos)get_name(); - connecting_index=j; - connecting_out=true; - connecting_type=gn->get_connection_output_type(j); - connecting_color=gn->get_connection_output_color(j); - connecting_target=false; - connecting_to=pos; - return; - } + connecting=true; + connecting_from=gn->get_name(); + connecting_index=j; + connecting_out=true; + connecting_type=gn->get_connection_output_type(j); + connecting_color=gn->get_connection_output_color(j); + connecting_target=false; + connecting_to=pos; + return; + } - } + } - for(int j=0;jget_connection_input_count();j++) { + for(int j=0;jget_connection_input_count();j++) { - Vector2 pos = gn->get_connection_input_pos(j)+gn->get_pos(); + Vector2 pos = gn->get_connection_input_pos(j)+gn->get_pos(); - if (pos.distance_to(mpos)::Element*E=connections.front();E;E=E->next()) { + if (right_disconnects) { + //check disconnect + for (List::Element*E=connections.front();E;E=E->next()) { - if (E->get().to==gn->get_name() && E->get().to_port==j) { + if (E->get().to==gn->get_name() && E->get().to_port==j) { - Node*fr = get_node(String(E->get().from)); - if (fr && fr->cast_to()) { + Node*fr = get_node(String(E->get().from)); + if (fr && fr->cast_to()) { - connecting_from=E->get().from; - connecting_index=E->get().from_port; - connecting_out=true; - connecting_type=fr->cast_to()->get_connection_output_type(E->get().from_port); - connecting_color=fr->cast_to()->get_connection_output_color(E->get().from_port); - connecting_target=false; - connecting_to=pos; + connecting_from=E->get().from; + connecting_index=E->get().from_port; + connecting_out=true; + connecting_type=fr->cast_to()->get_connection_output_type(E->get().from_port); + connecting_color=fr->cast_to()->get_connection_output_color(E->get().from_port); + connecting_target=false; + connecting_to=pos; - emit_signal("disconnection_request",E->get().from,E->get().from_port,E->get().to,E->get().to_port); - fr = get_node(String(connecting_from)); //maybe it was erased - if (fr && fr->cast_to()) { - connecting=true; - } - return; - } + emit_signal("disconnection_request",E->get().from,E->get().from_port,E->get().to,E->get().to_port); + fr = get_node(String(connecting_from)); //maybe it was erased + if (fr && fr->cast_to()) { + connecting=true; + } + return; + } - } - } - } + } + } + } - connecting=true; - connecting_from=gn->get_name(); - connecting_index=j; - connecting_out=false; - connecting_type=gn->get_connection_input_type(j); - connecting_color=gn->get_connection_input_color(j); - connecting_target=false; - connecting_to=pos; - return; - } + connecting=true; + connecting_from=gn->get_name(); + connecting_index=j; + connecting_out=false; + connecting_type=gn->get_connection_input_type(j); + connecting_color=gn->get_connection_input_color(j); + connecting_target=false; + connecting_to=pos; + return; + } - } - } - } + } + } + } - if (p_ev.type==InputEvent::MOUSE_MOTION && connecting) { + if (p_ev.type==InputEvent::MOUSE_MOTION && connecting) { - connecting_to=Vector2(p_ev.mouse_motion.x,p_ev.mouse_motion.y); - connecting_target=false; - top_layer->update(); + connecting_to=Vector2(p_ev.mouse_motion.x,p_ev.mouse_motion.y); + connecting_target=false; + top_layer->update(); - Ref port =get_icon("port","GraphNode"); - Vector2 mpos(p_ev.mouse_button.x,p_ev.mouse_button.y); - float grab_r=port->get_width()*0.5; - for(int i=get_child_count()-1;i>=0;i--) { + Ref port =get_icon("port","GraphNode"); + Vector2 mpos(p_ev.mouse_button.x,p_ev.mouse_button.y); + float grab_r=port->get_width()*0.5; + for(int i=get_child_count()-1;i>=0;i--) { - GraphNode *gn=get_child(i)->cast_to(); - if (!gn) - continue; + GraphNode *gn=get_child(i)->cast_to(); + if (!gn) + continue; - if (!connecting_out) { - for(int j=0;jget_connection_output_count();j++) { + if (!connecting_out) { + for(int j=0;jget_connection_output_count();j++) { - Vector2 pos = gn->get_connection_output_pos(j)+gn->get_pos(); - int type =gn->get_connection_output_type(j); - if (type==connecting_type && pos.distance_to(mpos)get_connection_output_pos(j)+gn->get_pos(); + int type =gn->get_connection_output_type(j); + if (type==connecting_type && pos.distance_to(mpos)get_name(); - connecting_target_index=j; - return; - } + connecting_target=true; + connecting_to=pos; + connecting_target_to=gn->get_name(); + connecting_target_index=j; + return; + } - } - } else { + } + } else { - for(int j=0;jget_connection_input_count();j++) { + for(int j=0;jget_connection_input_count();j++) { - Vector2 pos = gn->get_connection_input_pos(j)+gn->get_pos(); - int type =gn->get_connection_input_type(j); - if (type==connecting_type && pos.distance_to(mpos)get_name(); - connecting_target_index=j; - return; - } - } - } - } - } + Vector2 pos = gn->get_connection_input_pos(j)+gn->get_pos(); + int type =gn->get_connection_input_type(j); + if (type==connecting_type && pos.distance_to(mpos)get_name(); + connecting_target_index=j; + return; + } + } + } + } + } - if (p_ev.type==InputEvent::MOUSE_BUTTON && p_ev.mouse_button.button_index==BUTTON_LEFT && !p_ev.mouse_button.pressed) { + if (p_ev.type==InputEvent::MOUSE_BUTTON && p_ev.mouse_button.button_index==BUTTON_LEFT && !p_ev.mouse_button.pressed) { - if (connecting && connecting_target) { + if (connecting && connecting_target) { - String from = connecting_from; - int from_slot = connecting_index; - String to =connecting_target_to; - int to_slot = connecting_target_index; + String from = connecting_from; + int from_slot = connecting_index; + String to =connecting_target_to; + int to_slot = connecting_target_index; - if (!connecting_out) { - SWAP(from,to); - SWAP(from_slot,to_slot); - } - emit_signal("connection_request",from,from_slot,to,to_slot); - - } - connecting=false; - top_layer->update(); + if (!connecting_out) { + SWAP(from,to); + SWAP(from_slot,to_slot); + } + emit_signal("connection_request",from,from_slot,to,to_slot); - } + } + connecting=false; + top_layer->update(); + + } @@ -392,203 +389,295 @@ void GraphEdit::_top_layer_input(const InputEvent& p_ev) { void GraphEdit::_draw_cos_line(const Vector2& p_from, const Vector2& p_to,const Color& p_color) { - static const int steps = 20; + static const int steps = 20; - Rect2 r; - r.pos=p_from; - r.expand_to(p_to); - Vector2 sign=Vector2((p_from.x < p_to.x) ? 1 : -1,(p_from.y < p_to.y) ? 1 : -1); - bool flip = sign.x * sign.y < 0; + Rect2 r; + r.pos=p_from; + r.expand_to(p_to); + Vector2 sign=Vector2((p_from.x < p_to.x) ? 1 : -1,(p_from.y < p_to.y) ? 1 : -1); + bool flip = sign.x * sign.y < 0; - Vector2 prev; - for(int i=0;i<=steps;i++) { + Vector2 prev; + for(int i=0;i<=steps;i++) { - float d = i/float(steps); - float c=-Math::cos(d*Math_PI) * 0.5+0.5; - if (flip) - c=1.0-c; - Vector2 p = r.pos+Vector2(d*r.size.width,c*r.size.height); + float d = i/float(steps); + float c=-Math::cos(d*Math_PI) * 0.5+0.5; + if (flip) + c=1.0-c; + Vector2 p = r.pos+Vector2(d*r.size.width,c*r.size.height); - if (i>0) { + if (i>0) { - top_layer->draw_line(prev,p,p_color,2); - } + top_layer->draw_line(prev,p,p_color,2); + } - prev=p; - } + prev=p; + } } void GraphEdit::_top_layer_draw() { - _update_scroll(); - - if (connecting) { - - Node *fromn = get_node(connecting_from); - ERR_FAIL_COND(!fromn); - GraphNode *from = fromn->cast_to(); - ERR_FAIL_COND(!from); - Vector2 pos; - if (connecting_out) - pos=from->get_connection_output_pos(connecting_index); - else - pos=from->get_connection_input_pos(connecting_index); - pos+=from->get_pos(); - - Vector2 topos; - topos=connecting_to; - - Color col=connecting_color; - - if (connecting_target) { - col.r+=0.4; - col.g+=0.4; - col.b+=0.4; - } - _draw_cos_line(pos,topos,col); - } - - List::Element* > to_erase; - for(List::Element *E=connections.front();E;E=E->next()) { - - NodePath fromnp(E->get().from); - - Node * from = get_node(fromnp); - if (!from) { - to_erase.push_back(E); - continue; - } - - GraphNode *gfrom = from->cast_to(); - - if (!gfrom) { - to_erase.push_back(E); - continue; - } - - NodePath tonp(E->get().to); - Node * to = get_node(tonp); - if (!to) { - to_erase.push_back(E); - continue; - } - - GraphNode *gto = to->cast_to(); - - if (!gto) { - to_erase.push_back(E); - continue; - } - - Vector2 frompos=gfrom->get_connection_output_pos(E->get().from_port)+gfrom->get_pos(); - Color color = gfrom->get_connection_output_color(E->get().from_port); - Vector2 topos=gto->get_connection_input_pos(E->get().to_port)+gto->get_pos(); - _draw_cos_line(frompos,topos,color); - - } - - while(to_erase.size()) { - connections.erase(to_erase.front()->get()); - to_erase.pop_front(); - } - //draw connections + _update_scroll(); + + if (connecting) { + + Node *fromn = get_node(connecting_from); + ERR_FAIL_COND(!fromn); + GraphNode *from = fromn->cast_to(); + ERR_FAIL_COND(!from); + Vector2 pos; + if (connecting_out) + pos=from->get_connection_output_pos(connecting_index); + else + pos=from->get_connection_input_pos(connecting_index); + pos+=from->get_pos(); + + Vector2 topos; + topos=connecting_to; + + Color col=connecting_color; + + if (connecting_target) { + col.r+=0.4; + col.g+=0.4; + col.b+=0.4; + } + _draw_cos_line(pos,topos,col); + } + + List::Element* > to_erase; + for(List::Element *E=connections.front();E;E=E->next()) { + + NodePath fromnp(E->get().from); + + Node * from = get_node(fromnp); + if (!from) { + to_erase.push_back(E); + continue; + } + + GraphNode *gfrom = from->cast_to(); + + if (!gfrom) { + to_erase.push_back(E); + continue; + } + + NodePath tonp(E->get().to); + Node * to = get_node(tonp); + if (!to) { + to_erase.push_back(E); + continue; + } + + GraphNode *gto = to->cast_to(); + + if (!gto) { + to_erase.push_back(E); + continue; + } + + Vector2 frompos=gfrom->get_connection_output_pos(E->get().from_port)+gfrom->get_pos(); + Color color = gfrom->get_connection_output_color(E->get().from_port); + Vector2 topos=gto->get_connection_input_pos(E->get().to_port)+gto->get_pos(); + _draw_cos_line(frompos,topos,color); + + } + + while(to_erase.size()) { + connections.erase(to_erase.front()->get()); + to_erase.pop_front(); + } + //draw connections } void GraphEdit::_input_event(const InputEvent& p_ev) { - if (p_ev.type==InputEvent::MOUSE_MOTION && (p_ev.mouse_motion.button_mask&BUTTON_MASK_MIDDLE || (p_ev.mouse_motion.button_mask&BUTTON_MASK_LEFT && Input::get_singleton()->is_key_pressed(KEY_SPACE)))) { - h_scroll->set_val( h_scroll->get_val() - p_ev.mouse_motion.relative_x ); - v_scroll->set_val( v_scroll->get_val() - p_ev.mouse_motion.relative_y ); - } else if (p_ev.type== InputEvent::MOUSE_BUTTON) { + if (p_ev.type==InputEvent::MOUSE_MOTION && (p_ev.mouse_motion.button_mask&BUTTON_MASK_MIDDLE || (p_ev.mouse_motion.button_mask&BUTTON_MASK_LEFT && Input::get_singleton()->is_key_pressed(KEY_SPACE)))) { + h_scroll->set_val( h_scroll->get_val() - p_ev.mouse_motion.relative_x ); + v_scroll->set_val( v_scroll->get_val() - p_ev.mouse_motion.relative_y ); + } + + if (p_ev.type==InputEvent::MOUSE_MOTION && dragging) { + + just_selected=true; + drag_accum+=Vector2(p_ev.mouse_motion.relative_x,p_ev.mouse_motion.relative_y); + for(int i=get_child_count()-1;i>=0;i--) { + GraphNode *gn=get_child(i)->cast_to(); + if (gn && gn->is_selected()) + gn->set_offset(gn->get_drag_from()+drag_accum); + } + } + + if (p_ev.type== InputEvent::MOUSE_BUTTON) { const InputEventMouseButton &b=p_ev.mouse_button; - if (b.button_index==2 && b.pressed) + if (b.button_index==BUTTON_RIGHT && b.pressed) { emit_signal("popup_request", Vector2(b.global_x, b.global_y)); } + + if (b.button_index==BUTTON_LEFT && !b.pressed && dragging) { + if (!just_selected && drag_accum==Vector2() && Input::get_singleton()->is_key_pressed(KEY_CONTROL)) { + //deselect current node + for(int i=get_child_count()-1;i>=0;i--) { + GraphNode *gn=get_child(i)->cast_to(); + + if (gn && gn->get_rect().has_point(get_local_mouse_pos())) + gn->set_selected(false); + } + } + + if (drag_accum!=Vector2()) { + + emit_signal("_begin_node_move"); + + for(int i=get_child_count()-1;i>=0;i--) { + GraphNode *gn=get_child(i)->cast_to(); + if (gn && gn->is_selected()) + gn->set_drag(false); + } + + emit_signal("_end_node_move"); + } + + dragging = false; + + top_layer->update(); + } + + if (b.button_index==BUTTON_LEFT && b.pressed) { + + GraphNode *gn; + for(int i=get_child_count()-1;i>=0;i--) { + + gn=get_child(i)->cast_to(); + + if (gn && gn->get_rect().has_point(get_local_mouse_pos())) + break; + } + + if (gn) { + + if (_filter_input(Vector2(b.x,b.y))) + return; + + dragging = true; + drag_accum = Vector2(); + just_selected = !gn->is_selected(); + if(!gn->is_selected() && !Input::get_singleton()->is_key_pressed(KEY_CONTROL)) { + for (int i = 0; i < get_child_count(); i++) { + GraphNode *o_gn = get_child(i)->cast_to(); + if (o_gn) + o_gn->set_selected(o_gn == gn); + } + } + + gn->set_selected(true); + for (int i = 0; i < get_child_count(); i++) { + GraphNode *o_gn = get_child(i)->cast_to(); + if (!o_gn) + continue; + if (o_gn->is_selected()) + o_gn->set_drag(true); + } + + } else { + for(int i=get_child_count()-1;i>=0;i--) { + + GraphNode *gn=get_child(i)->cast_to(); + if (!gn) + continue; + + gn->set_selected(false); + } + } + } } } void GraphEdit::clear_connections() { - connections.clear(); - update(); + connections.clear(); + update(); } void GraphEdit::set_right_disconnects(bool p_enable) { - right_disconnects=p_enable; + right_disconnects=p_enable; } bool GraphEdit::is_right_disconnects_enabled() const{ - return right_disconnects; + return right_disconnects; } Array GraphEdit::_get_connection_list() const { - List conns; - get_connection_list(&conns); - Array arr; - for(List::Element *E=conns.front();E;E=E->next()) { - Dictionary d; - d["from"]=E->get().from; - d["from_port"]=E->get().from_port; - d["to"]=E->get().to; - d["to_port"]=E->get().to_port; - arr.push_back(d); - } - return arr; + List conns; + get_connection_list(&conns); + Array arr; + for(List::Element *E=conns.front();E;E=E->next()) { + Dictionary d; + d["from"]=E->get().from; + d["from_port"]=E->get().from_port; + d["to"]=E->get().to; + d["to_port"]=E->get().to_port; + arr.push_back(d); + } + return arr; } void GraphEdit::_bind_methods() { - ObjectTypeDB::bind_method(_MD("connect_node:Error","from","from_port","to","to_port"),&GraphEdit::connect_node); - ObjectTypeDB::bind_method(_MD("is_node_connected","from","from_port","to","to_port"),&GraphEdit::is_node_connected); - ObjectTypeDB::bind_method(_MD("disconnect_node","from","from_port","to","to_port"),&GraphEdit::disconnect_node); - ObjectTypeDB::bind_method(_MD("get_connection_list"),&GraphEdit::_get_connection_list); + ObjectTypeDB::bind_method(_MD("connect_node:Error","from","from_port","to","to_port"),&GraphEdit::connect_node); + ObjectTypeDB::bind_method(_MD("is_node_connected","from","from_port","to","to_port"),&GraphEdit::is_node_connected); + ObjectTypeDB::bind_method(_MD("disconnect_node","from","from_port","to","to_port"),&GraphEdit::disconnect_node); + ObjectTypeDB::bind_method(_MD("get_connection_list"),&GraphEdit::_get_connection_list); - ObjectTypeDB::bind_method(_MD("set_right_disconnects","enable"),&GraphEdit::set_right_disconnects); - ObjectTypeDB::bind_method(_MD("is_right_disconnects_enabled"),&GraphEdit::is_right_disconnects_enabled); + ObjectTypeDB::bind_method(_MD("set_right_disconnects","enable"),&GraphEdit::set_right_disconnects); + ObjectTypeDB::bind_method(_MD("is_right_disconnects_enabled"),&GraphEdit::is_right_disconnects_enabled); - ObjectTypeDB::bind_method(_MD("_graph_node_moved"),&GraphEdit::_graph_node_moved); - ObjectTypeDB::bind_method(_MD("_graph_node_raised"),&GraphEdit::_graph_node_raised); + ObjectTypeDB::bind_method(_MD("_graph_node_moved"),&GraphEdit::_graph_node_moved); + ObjectTypeDB::bind_method(_MD("_graph_node_raised"),&GraphEdit::_graph_node_raised); - ObjectTypeDB::bind_method(_MD("_top_layer_input"),&GraphEdit::_top_layer_input); - ObjectTypeDB::bind_method(_MD("_top_layer_draw"),&GraphEdit::_top_layer_draw); - ObjectTypeDB::bind_method(_MD("_scroll_moved"),&GraphEdit::_scroll_moved); + ObjectTypeDB::bind_method(_MD("_top_layer_input"),&GraphEdit::_top_layer_input); + ObjectTypeDB::bind_method(_MD("_top_layer_draw"),&GraphEdit::_top_layer_draw); + ObjectTypeDB::bind_method(_MD("_scroll_moved"),&GraphEdit::_scroll_moved); - ObjectTypeDB::bind_method(_MD("_input_event"),&GraphEdit::_input_event); + ObjectTypeDB::bind_method(_MD("_input_event"),&GraphEdit::_input_event); - ADD_SIGNAL(MethodInfo("connection_request",PropertyInfo(Variant::STRING,"from"),PropertyInfo(Variant::INT,"from_slot"),PropertyInfo(Variant::STRING,"to"),PropertyInfo(Variant::INT,"to_slot"))); + ADD_SIGNAL(MethodInfo("connection_request",PropertyInfo(Variant::STRING,"from"),PropertyInfo(Variant::INT,"from_slot"),PropertyInfo(Variant::STRING,"to"),PropertyInfo(Variant::INT,"to_slot"))); ADD_SIGNAL(MethodInfo("disconnection_request",PropertyInfo(Variant::STRING,"from"),PropertyInfo(Variant::INT,"from_slot"),PropertyInfo(Variant::STRING,"to"),PropertyInfo(Variant::INT,"to_slot"))); ADD_SIGNAL(MethodInfo("popup_request", PropertyInfo(Variant::VECTOR2,"p_position"))); + ADD_SIGNAL(MethodInfo("_begin_node_move")); + ADD_SIGNAL(MethodInfo("_end_node_move")); } GraphEdit::GraphEdit() { - top_layer=NULL; - top_layer=memnew(GraphEditFilter(this)); - add_child(top_layer); - top_layer->set_stop_mouse(false); - top_layer->set_area_as_parent_rect(); - top_layer->connect("draw",this,"_top_layer_draw"); + top_layer=NULL; + top_layer=memnew(GraphEditFilter(this)); + add_child(top_layer); + top_layer->set_stop_mouse(false); + top_layer->set_area_as_parent_rect(); + top_layer->connect("draw",this,"_top_layer_draw"); top_layer->set_stop_mouse(false); - top_layer->connect("input_event",this,"_top_layer_input"); + top_layer->connect("input_event",this,"_top_layer_input"); - h_scroll = memnew(HScrollBar); - h_scroll->set_name("_h_scroll"); - top_layer->add_child(h_scroll); + h_scroll = memnew(HScrollBar); + h_scroll->set_name("_h_scroll"); + top_layer->add_child(h_scroll); - v_scroll = memnew(VScrollBar); - v_scroll->set_name("_v_scroll"); - top_layer->add_child(v_scroll); - updating=false; - connecting=false; - right_disconnects=false; + v_scroll = memnew(VScrollBar); + v_scroll->set_name("_v_scroll"); + top_layer->add_child(v_scroll); + updating=false; + connecting=false; + right_disconnects=false; - h_scroll->connect("value_changed", this,"_scroll_moved"); - v_scroll->connect("value_changed", this,"_scroll_moved"); + h_scroll->connect("value_changed", this,"_scroll_moved"); + v_scroll->connect("value_changed", this,"_scroll_moved"); } diff --git a/scene/gui/graph_edit.h b/scene/gui/graph_edit.h index 0a9da73ab695..2f9a5fc954ea 100644 --- a/scene/gui/graph_edit.h +++ b/scene/gui/graph_edit.h @@ -8,93 +8,95 @@ class GraphEdit; class GraphEditFilter : public Control { - OBJ_TYPE(GraphEditFilter,Control); + OBJ_TYPE(GraphEditFilter,Control); friend class GraphEdit; - GraphEdit *ge; - virtual bool has_point(const Point2& p_point) const; + GraphEdit *ge; + virtual bool has_point(const Point2& p_point) const; public: - GraphEditFilter(GraphEdit *p_edit); + GraphEditFilter(GraphEdit *p_edit); }; class GraphEdit : public Control { - OBJ_TYPE(GraphEdit,Control); + OBJ_TYPE(GraphEdit,Control); public: - struct Connection { - StringName from; - StringName to; - int from_port; - int to_port; + struct Connection { + StringName from; + StringName to; + int from_port; + int to_port; - }; + }; private: - HScrollBar* h_scroll; - VScrollBar* v_scroll; + HScrollBar* h_scroll; + VScrollBar* v_scroll; - bool connecting; - String connecting_from; - bool connecting_out; - int connecting_index; - int connecting_type; - Color connecting_color; - bool connecting_target; - Vector2 connecting_to; - String connecting_target_to; - int connecting_target_index; + bool connecting; + String connecting_from; + bool connecting_out; + int connecting_index; + int connecting_type; + Color connecting_color; + bool connecting_target; + Vector2 connecting_to; + String connecting_target_to; + int connecting_target_index; + bool dragging; + bool just_selected; + Vector2 drag_accum; + bool right_disconnects; + bool updating; + List connections; - bool right_disconnects; - bool updating; - List connections; + void _draw_cos_line(const Vector2& p_from, const Vector2& p_to,const Color& p_color); - void _draw_cos_line(const Vector2& p_from, const Vector2& p_to,const Color& p_color); + void _graph_node_raised(Node* p_gn); + void _graph_node_moved(Node *p_gn); - void _graph_node_raised(Node* p_gn); - void _graph_node_moved(Node *p_gn); + void _update_scroll(); + void _scroll_moved(double); + void _input_event(const InputEvent& p_ev); - void _update_scroll(); - void _scroll_moved(double); - void _input_event(const InputEvent& p_ev); + GraphEditFilter *top_layer; + void _top_layer_input(const InputEvent& p_ev); + void _top_layer_draw(); + void _update_scroll_offset(); - GraphEditFilter *top_layer; - void _top_layer_input(const InputEvent& p_ev); - void _top_layer_draw(); - void _update_scroll_offset(); - - Array _get_connection_list() const; + Array _get_connection_list() const; friend class GraphEditFilter; - bool _filter_input(const Point2& p_point); + bool _filter_input(const Point2& p_point); protected: - static void _bind_methods(); - virtual void add_child_notify(Node *p_child); - virtual void remove_child_notify(Node *p_child); - void _notification(int p_what); + static void _bind_methods(); + virtual void add_child_notify(Node *p_child); + virtual void remove_child_notify(Node *p_child); + void _notification(int p_what); public: - Error connect_node(const StringName& p_from, int p_from_port,const StringName& p_to,int p_to_port); - bool is_node_connected(const StringName& p_from, int p_from_port,const StringName& p_to,int p_to_port); - void disconnect_node(const StringName& p_from, int p_from_port,const StringName& p_to,int p_to_port); - void clear_connections(); + Error connect_node(const StringName& p_from, int p_from_port,const StringName& p_to,int p_to_port); + bool is_node_connected(const StringName& p_from, int p_from_port,const StringName& p_to,int p_to_port); + void disconnect_node(const StringName& p_from, int p_from_port,const StringName& p_to,int p_to_port); + void clear_connections(); - GraphEditFilter *get_top_layer() const { return top_layer; } - void get_connection_list(List *r_connections) const; + GraphEditFilter *get_top_layer() const { return top_layer; } + void get_connection_list(List *r_connections) const; - void set_right_disconnects(bool p_enable); - bool is_right_disconnects_enabled() const; + void set_right_disconnects(bool p_enable); + bool is_right_disconnects_enabled() const; - GraphEdit(); + GraphEdit(); }; #endif // GRAPHEdit_H diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp index 444b37855f31..760eb6ceede7 100644 --- a/scene/gui/graph_node.cpp +++ b/scene/gui/graph_node.cpp @@ -4,91 +4,91 @@ bool GraphNode::_set(const StringName& p_name, const Variant& p_value) { - if (!p_name.operator String().begins_with("slot/")) - return false; + if (!p_name.operator String().begins_with("slot/")) + return false; - int idx=p_name.operator String().get_slice("/",1).to_int(); - String what = p_name.operator String().get_slice("/",2); + int idx=p_name.operator String().get_slice("/",1).to_int(); + String what = p_name.operator String().get_slice("/",2); - Slot si; - if (slot_info.has(idx)) - si=slot_info[idx]; + Slot si; + if (slot_info.has(idx)) + si=slot_info[idx]; - if (what=="left_enabled") - si.enable_left=p_value; - else if (what=="left_type") - si.type_left=p_value; - else if (what=="left_color") - si.color_left=p_value; - else if (what=="right_enabled") - si.enable_right=p_value; - else if (what=="right_type") - si.type_right=p_value; - else if (what=="right_color") - si.color_right=p_value; - else - return false; + if (what=="left_enabled") + si.enable_left=p_value; + else if (what=="left_type") + si.type_left=p_value; + else if (what=="left_color") + si.color_left=p_value; + else if (what=="right_enabled") + si.enable_right=p_value; + else if (what=="right_type") + si.type_right=p_value; + else if (what=="right_color") + si.color_right=p_value; + else + return false; - set_slot(idx,si.enable_left,si.type_left,si.color_left,si.enable_right,si.type_right,si.color_right); - update(); - return true; + set_slot(idx,si.enable_left,si.type_left,si.color_left,si.enable_right,si.type_right,si.color_right); + update(); + return true; } bool GraphNode::_get(const StringName& p_name,Variant &r_ret) const{ - if (!p_name.operator String().begins_with("slot/")) { - return false; - } + if (!p_name.operator String().begins_with("slot/")) { + return false; + } - int idx=p_name.operator String().get_slice("/",1).to_int(); - String what = p_name.operator String().get_slice("/",2); + int idx=p_name.operator String().get_slice("/",1).to_int(); + String what = p_name.operator String().get_slice("/",2); - Slot si; - if (slot_info.has(idx)) - si=slot_info[idx]; + Slot si; + if (slot_info.has(idx)) + si=slot_info[idx]; - if (what=="left_enabled") - r_ret=si.enable_left; - else if (what=="left_type") - r_ret=si.type_left; - else if (what=="left_color") - r_ret=si.color_left; - else if (what=="right_enabled") - r_ret=si.enable_right; - else if (what=="right_type") - r_ret=si.type_right; - else if (what=="right_color") - r_ret=si.color_right; - else - return false; + if (what=="left_enabled") + r_ret=si.enable_left; + else if (what=="left_type") + r_ret=si.type_left; + else if (what=="left_color") + r_ret=si.color_left; + else if (what=="right_enabled") + r_ret=si.enable_right; + else if (what=="right_type") + r_ret=si.type_right; + else if (what=="right_color") + r_ret=si.color_right; + else + return false; - return true; + return true; } void GraphNode::_get_property_list( List *p_list) const{ - int idx=0; - for(int i=0;icast_to(); - if (!c || c->is_set_as_toplevel() ) - continue; + int idx=0; + for(int i=0;icast_to(); + if (!c || c->is_set_as_toplevel() ) + continue; - String base="slot/"+itos(idx)+"/"; + String base="slot/"+itos(idx)+"/"; - p_list->push_back(PropertyInfo(Variant::BOOL,base+"left_enabled")); - p_list->push_back(PropertyInfo(Variant::INT,base+"left_type")); - p_list->push_back(PropertyInfo(Variant::COLOR,base+"left_color")); - p_list->push_back(PropertyInfo(Variant::BOOL,base+"right_enabled")); - p_list->push_back(PropertyInfo(Variant::INT,base+"right_type")); - p_list->push_back(PropertyInfo(Variant::COLOR,base+"right_color")); + p_list->push_back(PropertyInfo(Variant::BOOL,base+"left_enabled")); + p_list->push_back(PropertyInfo(Variant::INT,base+"left_type")); + p_list->push_back(PropertyInfo(Variant::COLOR,base+"left_color")); + p_list->push_back(PropertyInfo(Variant::BOOL,base+"right_enabled")); + p_list->push_back(PropertyInfo(Variant::INT,base+"right_type")); + p_list->push_back(PropertyInfo(Variant::COLOR,base+"right_color")); - idx++; - } + idx++; + } } @@ -96,61 +96,61 @@ void GraphNode::_resort() { - int sep=get_constant("separation"); - Ref sb=get_stylebox("frame"); - bool first=true; + int sep=get_constant("separation"); + Ref sb=get_stylebox("frame"); + bool first=true; - Size2 minsize; + Size2 minsize; - for(int i=0;icast_to(); - if (!c) - continue; - if (c->is_set_as_toplevel()) - continue; + for(int i=0;icast_to(); + if (!c) + continue; + if (c->is_set_as_toplevel()) + continue; - Size2i size=c->get_combined_minimum_size(); + Size2i size=c->get_combined_minimum_size(); - minsize.y+=size.y; - minsize.x=MAX(minsize.x,size.x); + minsize.y+=size.y; + minsize.x=MAX(minsize.x,size.x); - if (first) - first=false; - else - minsize.y+=sep; + if (first) + first=false; + else + minsize.y+=sep; - } + } - int vofs=0; - int w = get_size().x - sb->get_minimum_size().x; + int vofs=0; + int w = get_size().x - sb->get_minimum_size().x; - cache_y.clear(); - for(int i=0;icast_to(); - if (!c) - continue; - if (c->is_set_as_toplevel()) - continue; + cache_y.clear(); + for(int i=0;icast_to(); + if (!c) + continue; + if (c->is_set_as_toplevel()) + continue; - Size2i size=c->get_combined_minimum_size(); + Size2i size=c->get_combined_minimum_size(); - Rect2 r(sb->get_margin(MARGIN_LEFT),sb->get_margin(MARGIN_TOP)+vofs,w,size.y); + Rect2 r(sb->get_margin(MARGIN_LEFT),sb->get_margin(MARGIN_TOP)+vofs,w,size.y); - fit_child_in_rect(c,r); - cache_y.push_back(vofs+size.y*0.5); + fit_child_in_rect(c,r); + cache_y.push_back(vofs+size.y*0.5); - if (vofs>0) - vofs+=sep; - vofs+=size.y; + if (vofs>0) + vofs+=sep; + vofs+=size.y; - } + } - _change_notify(); - update(); - connpos_dirty=true; + _change_notify(); + update(); + connpos_dirty=true; } @@ -158,124 +158,124 @@ void GraphNode::_resort() { void GraphNode::_notification(int p_what) { - if (p_what==NOTIFICATION_DRAW) { + if (p_what==NOTIFICATION_DRAW) { - Ref sb=get_stylebox("frame"); - Ref port =get_icon("port"); - Ref close =get_icon("close"); - int close_offset = get_constant("close_offset"); - Ref title_font = get_font("title_font"); - int title_offset = get_constant("title_offset"); - Color title_color = get_color("title_color"); - Point2i icofs = -port->get_size()*0.5; - int edgeofs=get_constant("port_offset"); - icofs.y+=sb->get_margin(MARGIN_TOP); - draw_style_box(sb,Rect2(Point2(),get_size())); + Ref sb=get_stylebox(selected ? "selectedframe" : "frame"); + Ref port =get_icon("port"); + Ref close =get_icon("close"); + int close_offset = get_constant("close_offset"); + Ref title_font = get_font("title_font"); + int title_offset = get_constant("title_offset"); + Color title_color = get_color("title_color"); + Point2i icofs = -port->get_size()*0.5; + int edgeofs=get_constant("port_offset"); + icofs.y+=sb->get_margin(MARGIN_TOP); + draw_style_box(sb,Rect2(Point2(),get_size())); - int w = get_size().width-sb->get_minimum_size().x; + int w = get_size().width-sb->get_minimum_size().x; - if (show_close) - w-=close->get_width(); + if (show_close) + w-=close->get_width(); - draw_string(title_font,Point2(sb->get_margin(MARGIN_LEFT),-title_font->get_height()+title_font->get_ascent()+title_offset),title,title_color,w); - if (show_close) { - Vector2 cpos = Point2(w+sb->get_margin(MARGIN_LEFT),-close->get_height()+close_offset); - draw_texture(close,cpos); - close_rect.pos=cpos; - close_rect.size=close->get_size(); - } else { - close_rect=Rect2(); - } + draw_string(title_font,Point2(sb->get_margin(MARGIN_LEFT),-title_font->get_height()+title_font->get_ascent()+title_offset),title,title_color,w); + if (show_close) { + Vector2 cpos = Point2(w+sb->get_margin(MARGIN_LEFT),-close->get_height()+close_offset); + draw_texture(close,cpos); + close_rect.pos=cpos; + close_rect.size=close->get_size(); + } else { + close_rect=Rect2(); + } - for (Map::Element *E=slot_info.front();E;E=E->next()) { + for (Map::Element *E=slot_info.front();E;E=E->next()) { - if (E->key() < 0 || E->key()>=cache_y.size()) - continue; - if (!slot_info.has(E->key())) - continue; - const Slot &s=slot_info[E->key()]; - //left - if (s.enable_left) - port->draw(get_canvas_item(),icofs+Point2(edgeofs,cache_y[E->key()]),s.color_left); - if (s.enable_right) - port->draw(get_canvas_item(),icofs+Point2(get_size().x-edgeofs,cache_y[E->key()]),s.color_right); + if (E->key() < 0 || E->key()>=cache_y.size()) + continue; + if (!slot_info.has(E->key())) + continue; + const Slot &s=slot_info[E->key()]; + //left + if (s.enable_left) + port->draw(get_canvas_item(),icofs+Point2(edgeofs,cache_y[E->key()]),s.color_left); + if (s.enable_right) + port->draw(get_canvas_item(),icofs+Point2(get_size().x-edgeofs,cache_y[E->key()]),s.color_right); - } - } + } + } - if (p_what==NOTIFICATION_SORT_CHILDREN) { + if (p_what==NOTIFICATION_SORT_CHILDREN) { - _resort(); - } + _resort(); + } } void GraphNode::set_slot(int p_idx,bool p_enable_left,int p_type_left,const Color& p_color_left, bool p_enable_right,int p_type_right,const Color& p_color_right) { - ERR_FAIL_COND(p_idx<0); + ERR_FAIL_COND(p_idx<0); - if (!p_enable_left && p_type_left==0 && p_color_left==Color(1,1,1,1) && !p_enable_right && p_type_right==0 && p_color_right==Color(1,1,1,1)) { - slot_info.erase(p_idx); - return; - } + if (!p_enable_left && p_type_left==0 && p_color_left==Color(1,1,1,1) && !p_enable_right && p_type_right==0 && p_color_right==Color(1,1,1,1)) { + slot_info.erase(p_idx); + return; + } - Slot s; - s.enable_left=p_enable_left; - s.type_left=p_type_left; - s.color_left=p_color_left; - s.enable_right=p_enable_right; - s.type_right=p_type_right; - s.color_right=p_color_right; - slot_info[p_idx]=s; - update(); - connpos_dirty=true; + Slot s; + s.enable_left=p_enable_left; + s.type_left=p_type_left; + s.color_left=p_color_left; + s.enable_right=p_enable_right; + s.type_right=p_type_right; + s.color_right=p_color_right; + slot_info[p_idx]=s; + update(); + connpos_dirty=true; } void GraphNode::clear_slot(int p_idx){ - slot_info.erase(p_idx); - update(); - connpos_dirty=true; + slot_info.erase(p_idx); + update(); + connpos_dirty=true; } void GraphNode::clear_all_slots(){ - slot_info.clear(); - update(); - connpos_dirty=true; + slot_info.clear(); + update(); + connpos_dirty=true; } bool GraphNode::is_slot_enabled_left(int p_idx) const{ - if (!slot_info.has(p_idx)) - return false; - return slot_info[p_idx].enable_left; + if (!slot_info.has(p_idx)) + return false; + return slot_info[p_idx].enable_left; } int GraphNode::get_slot_type_left(int p_idx) const{ - if (!slot_info.has(p_idx)) - return 0; - return slot_info[p_idx].type_left; + if (!slot_info.has(p_idx)) + return 0; + return slot_info[p_idx].type_left; } Color GraphNode::get_slot_color_left(int p_idx) const{ - if (!slot_info.has(p_idx)) - return Color(1,1,1,1); - return slot_info[p_idx].color_left; + if (!slot_info.has(p_idx)) + return Color(1,1,1,1); + return slot_info[p_idx].color_left; } bool GraphNode::is_slot_enabled_right(int p_idx) const{ - if (!slot_info.has(p_idx)) - return false; - return slot_info[p_idx].enable_right; + if (!slot_info.has(p_idx)) + return false; + return slot_info[p_idx].enable_right; } @@ -283,301 +283,305 @@ bool GraphNode::is_slot_enabled_right(int p_idx) const{ int GraphNode::get_slot_type_right(int p_idx) const{ - if (!slot_info.has(p_idx)) - return 0; - return slot_info[p_idx].type_right; + if (!slot_info.has(p_idx)) + return 0; + return slot_info[p_idx].type_right; } Color GraphNode::get_slot_color_right(int p_idx) const{ - if (!slot_info.has(p_idx)) - return Color(1,1,1,1); - return slot_info[p_idx].color_right; + if (!slot_info.has(p_idx)) + return Color(1,1,1,1); + return slot_info[p_idx].color_right; } Size2 GraphNode::get_minimum_size() const { - Ref title_font = get_font("title_font"); + Ref title_font = get_font("title_font"); - int sep=get_constant("separation"); - Ref sb=get_stylebox("frame"); - bool first=true; + int sep=get_constant("separation"); + Ref sb=get_stylebox("frame"); + bool first=true; - Size2 minsize; - minsize.x=title_font->get_string_size(title).x; - if (show_close) { - Ref close =get_icon("close"); - minsize.x+=sep+close->get_width(); - } + Size2 minsize; + minsize.x=title_font->get_string_size(title).x; + if (show_close) { + Ref close =get_icon("close"); + minsize.x+=sep+close->get_width(); + } - for(int i=0;icast_to(); - if (!c) - continue; - if (c->is_set_as_toplevel()) - continue; + Control *c=get_child(i)->cast_to(); + if (!c) + continue; + if (c->is_set_as_toplevel()) + continue; - Size2i size=c->get_combined_minimum_size(); + Size2i size=c->get_combined_minimum_size(); - minsize.y+=size.y; - minsize.x=MAX(minsize.x,size.x); + minsize.y+=size.y; + minsize.x=MAX(minsize.x,size.x); - if (first) - first=false; - else - minsize.y+=sep; - } + if (first) + first=false; + else + minsize.y+=sep; + } - return minsize+sb->get_minimum_size(); + return minsize+sb->get_minimum_size(); } void GraphNode::set_title(const String& p_title) { - title=p_title; - minimum_size_changed(); - update(); + title=p_title; + minimum_size_changed(); + update(); } String GraphNode::get_title() const{ - return title; + return title; } void GraphNode::set_offset(const Vector2& p_offset) { - offset=p_offset; - emit_signal("offset_changed"); - update(); + offset=p_offset; + emit_signal("offset_changed"); + update(); } Vector2 GraphNode::get_offset() const { - return offset; + return offset; } +void GraphNode::set_selected(bool p_selected) +{ + selected = p_selected; + update(); +} + +bool GraphNode::is_selected() +{ + return selected; +} + +void GraphNode::set_drag(bool p_drag) +{ + if (p_drag) + drag_from=get_offset(); + else + emit_signal("dragged",drag_from,get_offset()); //useful for undo/redo +} + +Vector2 GraphNode::get_drag_from() +{ + return drag_from; +} void GraphNode::set_show_close_button(bool p_enable){ - show_close=p_enable; - update(); + show_close=p_enable; + update(); } bool GraphNode::is_close_button_visible() const{ - return show_close; + return show_close; } void GraphNode::_connpos_update() { - int edgeofs=get_constant("port_offset"); - int sep=get_constant("separation"); + int edgeofs=get_constant("port_offset"); + int sep=get_constant("separation"); - Ref sb=get_stylebox("frame"); - Ref port =get_icon("port"); - conn_input_cache.clear(); - conn_output_cache.clear(); - int vofs=0; + Ref sb=get_stylebox("frame"); + conn_input_cache.clear(); + conn_output_cache.clear(); + int vofs=0; - int idx=0; + int idx=0; - for(int i=0;icast_to(); - if (!c) - continue; - if (c->is_set_as_toplevel()) - continue; + for(int i=0;icast_to(); + if (!c) + continue; + if (c->is_set_as_toplevel()) + continue; - Size2i size=c->get_combined_minimum_size(); + Size2i size=c->get_combined_minimum_size(); - int y = sb->get_margin(MARGIN_TOP)+vofs; - int h = size.y; + int y = sb->get_margin(MARGIN_TOP)+vofs; + int h = size.y; - if (slot_info.has(idx)) { + if (slot_info.has(idx)) { - if (slot_info[idx].enable_left) { - ConnCache cc; - cc.pos=Point2i(edgeofs,y+h/2); - cc.type=slot_info[idx].type_left; - cc.color=slot_info[idx].color_left; - conn_input_cache.push_back(cc); - } - if (slot_info[idx].enable_right) { - ConnCache cc; - cc.pos=Point2i(get_size().width-edgeofs,y+h/2); - cc.type=slot_info[idx].type_right; - cc.color=slot_info[idx].color_right; - conn_output_cache.push_back(cc); - } - } + if (slot_info[idx].enable_left) { + ConnCache cc; + cc.pos=Point2i(edgeofs,y+h/2); + cc.type=slot_info[idx].type_left; + cc.color=slot_info[idx].color_left; + conn_input_cache.push_back(cc); + } + if (slot_info[idx].enable_right) { + ConnCache cc; + cc.pos=Point2i(get_size().width-edgeofs,y+h/2); + cc.type=slot_info[idx].type_right; + cc.color=slot_info[idx].color_right; + conn_output_cache.push_back(cc); + } + } - if (vofs>0) - vofs+=sep; - vofs+=size.y; - idx++; + if (vofs>0) + vofs+=sep; + vofs+=size.y; + idx++; - } + } - connpos_dirty=false; + connpos_dirty=false; } int GraphNode::get_connection_input_count() { - if (connpos_dirty) - _connpos_update(); + if (connpos_dirty) + _connpos_update(); - return conn_input_cache.size(); + return conn_input_cache.size(); } int GraphNode::get_connection_output_count() { - if (connpos_dirty) - _connpos_update(); + if (connpos_dirty) + _connpos_update(); - return conn_output_cache.size(); + return conn_output_cache.size(); } Vector2 GraphNode::get_connection_input_pos(int p_idx) { - if (connpos_dirty) - _connpos_update(); + if (connpos_dirty) + _connpos_update(); - ERR_FAIL_INDEX_V(p_idx,conn_input_cache.size(),Vector2()); - return conn_input_cache[p_idx].pos; + ERR_FAIL_INDEX_V(p_idx,conn_input_cache.size(),Vector2()); + return conn_input_cache[p_idx].pos; } int GraphNode::get_connection_input_type(int p_idx) { - if (connpos_dirty) - _connpos_update(); + if (connpos_dirty) + _connpos_update(); - ERR_FAIL_INDEX_V(p_idx,conn_input_cache.size(),0); - return conn_input_cache[p_idx].type; + ERR_FAIL_INDEX_V(p_idx,conn_input_cache.size(),0); + return conn_input_cache[p_idx].type; } Color GraphNode::get_connection_input_color(int p_idx) { - if (connpos_dirty) - _connpos_update(); + if (connpos_dirty) + _connpos_update(); - ERR_FAIL_INDEX_V(p_idx,conn_input_cache.size(),Color()); - return conn_input_cache[p_idx].color; + ERR_FAIL_INDEX_V(p_idx,conn_input_cache.size(),Color()); + return conn_input_cache[p_idx].color; } Vector2 GraphNode::get_connection_output_pos(int p_idx){ - if (connpos_dirty) - _connpos_update(); + if (connpos_dirty) + _connpos_update(); - ERR_FAIL_INDEX_V(p_idx,conn_output_cache.size(),Vector2()); - return conn_output_cache[p_idx].pos; + ERR_FAIL_INDEX_V(p_idx,conn_output_cache.size(),Vector2()); + return conn_output_cache[p_idx].pos; } int GraphNode::get_connection_output_type(int p_idx) { - if (connpos_dirty) - _connpos_update(); + if (connpos_dirty) + _connpos_update(); - ERR_FAIL_INDEX_V(p_idx,conn_output_cache.size(),0); - return conn_output_cache[p_idx].type; + ERR_FAIL_INDEX_V(p_idx,conn_output_cache.size(),0); + return conn_output_cache[p_idx].type; } Color GraphNode::get_connection_output_color(int p_idx) { - if (connpos_dirty) - _connpos_update(); + if (connpos_dirty) + _connpos_update(); - ERR_FAIL_INDEX_V(p_idx,conn_output_cache.size(),Color()); - return conn_output_cache[p_idx].color; + ERR_FAIL_INDEX_V(p_idx,conn_output_cache.size(),Color()); + return conn_output_cache[p_idx].color; } void GraphNode::_input_event(const InputEvent& p_ev) { - if (p_ev.type==InputEvent::MOUSE_BUTTON && p_ev.mouse_button.pressed && p_ev.mouse_button.button_index==BUTTON_LEFT) { + if (p_ev.type==InputEvent::MOUSE_BUTTON && p_ev.mouse_button.pressed && p_ev.mouse_button.button_index==BUTTON_LEFT) { - Vector2 mpos = Vector2(p_ev.mouse_button.x,p_ev.mouse_button.y); - if (close_rect.size!=Size2() && close_rect.has_point(mpos)) { - emit_signal("close_request"); - return; - } + Vector2 mpos = Vector2(p_ev.mouse_button.x,p_ev.mouse_button.y); + if (close_rect.size!=Size2() && close_rect.has_point(mpos)) { + emit_signal("close_request"); + return; + } + emit_signal("raise_request"); - drag_from=get_offset(); - drag_accum=Vector2(); - dragging=true; - emit_signal("raise_request"); - - } - - if (p_ev.type==InputEvent::MOUSE_BUTTON && !p_ev.mouse_button.pressed && p_ev.mouse_button.button_index==BUTTON_LEFT) { - - dragging=false; - emit_signal("dragged",drag_from,get_offset()); //useful for undo/redo - } - - if (p_ev.type==InputEvent::MOUSE_MOTION && dragging) { - - drag_accum+=Vector2(p_ev.mouse_motion.relative_x,p_ev.mouse_motion.relative_y); - set_offset(drag_from+drag_accum); - } + } } void GraphNode::_bind_methods() { - ObjectTypeDB::bind_method(_MD("set_title","title"),&GraphNode::set_title); - ObjectTypeDB::bind_method(_MD("get_title"),&GraphNode::get_title); - ObjectTypeDB::bind_method(_MD("_input_event"),&GraphNode::_input_event); + ObjectTypeDB::bind_method(_MD("set_title","title"),&GraphNode::set_title); + ObjectTypeDB::bind_method(_MD("get_title"),&GraphNode::get_title); + ObjectTypeDB::bind_method(_MD("_input_event"),&GraphNode::_input_event); - ObjectTypeDB::bind_method(_MD("set_slot","idx","enable_left","type_left","color_left","enable_right","type_right","color_right"),&GraphNode::set_slot); - ObjectTypeDB::bind_method(_MD("clear_slot","idx"),&GraphNode::clear_slot); - ObjectTypeDB::bind_method(_MD("clear_all_slots","idx"),&GraphNode::clear_all_slots); - ObjectTypeDB::bind_method(_MD("is_slot_enabled_left","idx"),&GraphNode::is_slot_enabled_left); - ObjectTypeDB::bind_method(_MD("get_slot_type_left","idx"),&GraphNode::get_slot_type_left); - ObjectTypeDB::bind_method(_MD("get_slot_color_left","idx"),&GraphNode::get_slot_color_left); - ObjectTypeDB::bind_method(_MD("is_slot_enabled_right","idx"),&GraphNode::is_slot_enabled_right); - ObjectTypeDB::bind_method(_MD("get_slot_type_right","idx"),&GraphNode::get_slot_type_right); - ObjectTypeDB::bind_method(_MD("get_slot_color_right","idx"),&GraphNode::get_slot_color_right); + ObjectTypeDB::bind_method(_MD("set_slot","idx","enable_left","type_left","color_left","enable_right","type_right","color_right"),&GraphNode::set_slot); + ObjectTypeDB::bind_method(_MD("clear_slot","idx"),&GraphNode::clear_slot); + ObjectTypeDB::bind_method(_MD("clear_all_slots","idx"),&GraphNode::clear_all_slots); + ObjectTypeDB::bind_method(_MD("is_slot_enabled_left","idx"),&GraphNode::is_slot_enabled_left); + ObjectTypeDB::bind_method(_MD("get_slot_type_left","idx"),&GraphNode::get_slot_type_left); + ObjectTypeDB::bind_method(_MD("get_slot_color_left","idx"),&GraphNode::get_slot_color_left); + ObjectTypeDB::bind_method(_MD("is_slot_enabled_right","idx"),&GraphNode::is_slot_enabled_right); + ObjectTypeDB::bind_method(_MD("get_slot_type_right","idx"),&GraphNode::get_slot_type_right); + ObjectTypeDB::bind_method(_MD("get_slot_color_right","idx"),&GraphNode::get_slot_color_right); - ObjectTypeDB::bind_method(_MD("set_offset","offset"),&GraphNode::set_offset); - ObjectTypeDB::bind_method(_MD("get_offset"),&GraphNode::get_offset); + ObjectTypeDB::bind_method(_MD("set_offset","offset"),&GraphNode::set_offset); + ObjectTypeDB::bind_method(_MD("get_offset"),&GraphNode::get_offset); - ObjectTypeDB::bind_method(_MD("get_connection_output_count"),&GraphNode::get_connection_output_count); - ObjectTypeDB::bind_method(_MD("get_connection_input_count"),&GraphNode::get_connection_input_count); + ObjectTypeDB::bind_method(_MD("get_connection_output_count"),&GraphNode::get_connection_output_count); + ObjectTypeDB::bind_method(_MD("get_connection_input_count"),&GraphNode::get_connection_input_count); - ObjectTypeDB::bind_method(_MD("get_connection_output_pos","idx"),&GraphNode::get_connection_output_pos); - ObjectTypeDB::bind_method(_MD("get_connection_output_type","idx"),&GraphNode::get_connection_output_type); - ObjectTypeDB::bind_method(_MD("get_connection_output_color","idx"),&GraphNode::get_connection_output_color); - ObjectTypeDB::bind_method(_MD("get_connection_input_pos","idx"),&GraphNode::get_connection_input_pos); - ObjectTypeDB::bind_method(_MD("get_connection_input_type","idx"),&GraphNode::get_connection_input_type); - ObjectTypeDB::bind_method(_MD("get_connection_input_color","idx"),&GraphNode::get_connection_input_color); + ObjectTypeDB::bind_method(_MD("get_connection_output_pos","idx"),&GraphNode::get_connection_output_pos); + ObjectTypeDB::bind_method(_MD("get_connection_output_type","idx"),&GraphNode::get_connection_output_type); + ObjectTypeDB::bind_method(_MD("get_connection_output_color","idx"),&GraphNode::get_connection_output_color); + ObjectTypeDB::bind_method(_MD("get_connection_input_pos","idx"),&GraphNode::get_connection_input_pos); + ObjectTypeDB::bind_method(_MD("get_connection_input_type","idx"),&GraphNode::get_connection_input_type); + ObjectTypeDB::bind_method(_MD("get_connection_input_color","idx"),&GraphNode::get_connection_input_color); - ObjectTypeDB::bind_method(_MD("set_show_close_button","show"),&GraphNode::set_show_close_button); - ObjectTypeDB::bind_method(_MD("is_close_button_visible"),&GraphNode::is_close_button_visible); + ObjectTypeDB::bind_method(_MD("set_show_close_button","show"),&GraphNode::set_show_close_button); + ObjectTypeDB::bind_method(_MD("is_close_button_visible"),&GraphNode::is_close_button_visible); - ADD_PROPERTY( PropertyInfo(Variant::STRING,"title"),_SCS("set_title"),_SCS("get_title")); - ADD_PROPERTY( PropertyInfo(Variant::BOOL,"show_close"),_SCS("set_show_close_button"),_SCS("is_close_button_visible")); + ADD_PROPERTY( PropertyInfo(Variant::STRING,"title"),_SCS("set_title"),_SCS("get_title")); + ADD_PROPERTY( PropertyInfo(Variant::BOOL,"show_close"),_SCS("set_show_close_button"),_SCS("is_close_button_visible")); - ADD_SIGNAL(MethodInfo("offset_changed")); - ADD_SIGNAL(MethodInfo("dragged",PropertyInfo(Variant::VECTOR2,"from"),PropertyInfo(Variant::VECTOR2,"to"))); - ADD_SIGNAL(MethodInfo("raise_request")); - ADD_SIGNAL(MethodInfo("close_request")); + ADD_SIGNAL(MethodInfo("offset_changed")); + ADD_SIGNAL(MethodInfo("dragged",PropertyInfo(Variant::VECTOR2,"from"),PropertyInfo(Variant::VECTOR2,"to"))); + ADD_SIGNAL(MethodInfo("raise_request")); + ADD_SIGNAL(MethodInfo("close_request")); } GraphNode::GraphNode() { - - dragging=false; - show_close=false; - connpos_dirty=true; + show_close=false; + connpos_dirty=true; } diff --git a/scene/gui/graph_node.h b/scene/gui/graph_node.h index 0d5cbf8dd333..6bece22ac584 100644 --- a/scene/gui/graph_node.h +++ b/scene/gui/graph_node.h @@ -5,96 +5,101 @@ class GraphNode : public Container { - OBJ_TYPE(GraphNode,Container); + OBJ_TYPE(GraphNode,Container); - struct Slot { - bool enable_left; - int type_left; - Color color_left; - bool enable_right; - int type_right; - Color color_right; + struct Slot { + bool enable_left; + int type_left; + Color color_left; + bool enable_right; + int type_right; + Color color_right; - Slot() { enable_left=false; type_left=0; color_left=Color(1,1,1,1); enable_right=false; type_right=0; color_right=Color(1,1,1,1); }; - }; + Slot() { enable_left=false; type_left=0; color_left=Color(1,1,1,1); enable_right=false; type_right=0; color_right=Color(1,1,1,1); } + }; - String title; - bool show_close; - Vector2 offset; + String title; + bool show_close; + Vector2 offset; - Rect2 close_rect; + Rect2 close_rect; - Vector cache_y; + Vector cache_y; - struct ConnCache { - Vector2 pos; - int type; - Color color; - }; + struct ConnCache { + Vector2 pos; + int type; + Color color; + }; - Vector conn_input_cache; - Vector conn_output_cache; + Vector conn_input_cache; + Vector conn_output_cache; - Map slot_info; + Map slot_info; - bool connpos_dirty; + bool connpos_dirty; - void _connpos_update(); - void _resort(); + void _connpos_update(); + void _resort(); - Vector2 drag_from; - Vector2 drag_accum; - bool dragging; + Vector2 drag_from; + bool selected; protected: - void _input_event(const InputEvent& p_ev); - void _notification(int p_what); - static void _bind_methods(); + void _input_event(const InputEvent& p_ev); + void _notification(int p_what); + static void _bind_methods(); - bool _set(const StringName& p_name, const Variant& p_value); - bool _get(const StringName& p_name,Variant &r_ret) const; - void _get_property_list( List *p_list) const; + bool _set(const StringName& p_name, const Variant& p_value); + bool _get(const StringName& p_name,Variant &r_ret) const; + void _get_property_list( List *p_list) const; public: - void set_slot(int p_idx,bool p_enable_left,int p_type_left,const Color& p_color_left, bool p_enable_right,int p_type_right,const Color& p_color_right); - void clear_slot(int p_idx); - void clear_all_slots(); - bool is_slot_enabled_left(int p_idx) const; - int get_slot_type_left(int p_idx) const; - Color get_slot_color_left(int p_idx) const; - bool is_slot_enabled_right(int p_idx) const; - int get_slot_type_right(int p_idx) const; - Color get_slot_color_right(int p_idx) const; + void set_slot(int p_idx,bool p_enable_left,int p_type_left,const Color& p_color_left, bool p_enable_right,int p_type_right,const Color& p_color_right); + void clear_slot(int p_idx); + void clear_all_slots(); + bool is_slot_enabled_left(int p_idx) const; + int get_slot_type_left(int p_idx) const; + Color get_slot_color_left(int p_idx) const; + bool is_slot_enabled_right(int p_idx) const; + int get_slot_type_right(int p_idx) const; + Color get_slot_color_right(int p_idx) const; - void set_title(const String& p_title); - String get_title() const; + void set_title(const String& p_title); + String get_title() const; - void set_offset(const Vector2& p_offset); - Vector2 get_offset() const; + void set_offset(const Vector2& p_offset); + Vector2 get_offset() const; - void set_show_close_button(bool p_enable); - bool is_close_button_visible() const; + void set_selected(bool p_selected); + bool is_selected(); - int get_connection_input_count() ; - int get_connection_output_count() ; - Vector2 get_connection_input_pos(int p_idx); - int get_connection_input_type(int p_idx); - Color get_connection_input_color(int p_idx); - Vector2 get_connection_output_pos(int p_idx); - int get_connection_output_type(int p_idx); - Color get_connection_output_color(int p_idx); + void set_drag(bool p_drag); + Vector2 get_drag_from(); + void set_show_close_button(bool p_enable); + bool is_close_button_visible() const; - virtual Size2 get_minimum_size() const; + int get_connection_input_count() ; + int get_connection_output_count() ; + Vector2 get_connection_input_pos(int p_idx); + int get_connection_input_type(int p_idx); + Color get_connection_input_color(int p_idx); + Vector2 get_connection_output_pos(int p_idx); + int get_connection_output_type(int p_idx); + Color get_connection_output_color(int p_idx); - GraphNode(); + + virtual Size2 get_minimum_size() const; + + GraphNode(); }; diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index 9a9048e3e5f8..667dfd46328d 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -558,9 +558,11 @@ void make_default_theme() { // GraphNode Ref graphsb = make_stylebox(graph_node_png,6,24,6,5,16,24,16,5); + Ref graphsbselected = make_stylebox(graph_node_selected_png,6,24,6,5,16,24,16,5); //graphsb->set_expand_margin_size(MARGIN_LEFT,10); //graphsb->set_expand_margin_size(MARGIN_RIGHT,10); t->set_stylebox("frame","GraphNode", graphsb ); + t->set_stylebox("selectedframe","GraphNode", graphsbselected ); t->set_constant("separation","GraphNode", 1 ); t->set_icon("port","GraphNode", make_icon( graph_port_png ) ); t->set_icon("close","GraphNode", make_icon( graph_node_close_png ) ); diff --git a/scene/resources/default_theme/graph_node_selected.png b/scene/resources/default_theme/graph_node_selected.png new file mode 100644 index 0000000000000000000000000000000000000000..06a9db440906367a5143d32760689640d17a7d9f GIT binary patch literal 738 zcmV<80v-K{P)WFU8GbZ8()Nlj2>E@cM*00KryL_t(o!|j*NY7`_vPT|71+4LMCsa>bMZtloV;yNU6h zW%=s$11(xxe^(sAZntyj2nNvEOMn#gh=-2A&9K&`00#ut+OXg! zZG2S>*4hvV0B4d`b~_0B8?E*hlOQgJR(p#e>~8?ufK5Bs1>jnv-h5W8&R_97uh3j; ztqa2b$8N9l5cmM>%18^>0L}rYfa*TYcL@9fz9)UOm7Jk|+7IrNg(fM-Ga5gxzwjsa ULiY9jt^fc407*qoM6N<$f_;uV%>V!Z literal 0 HcmV?d00001 diff --git a/scene/resources/default_theme/theme_data.h b/scene/resources/default_theme/theme_data.h index 03d851e74933..a00651a0b301 100644 --- a/scene/resources/default_theme/theme_data.h +++ b/scene/resources/default_theme/theme_data.h @@ -114,6 +114,11 @@ static const unsigned char graph_node_close_png[]={ }; +static const unsigned char graph_node_selected_png[]={ +0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0x40,0x8,0x6,0x0,0x0,0x0,0x13,0x7d,0xf7,0x96,0x0,0x0,0x0,0x6,0x62,0x4b,0x47,0x44,0x0,0xff,0x0,0xff,0x0,0xff,0xa0,0xbd,0xa7,0x93,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x13,0x0,0x0,0xb,0x13,0x1,0x0,0x9a,0x9c,0x18,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xdf,0x7,0x12,0x1,0xc,0x6,0x23,0x98,0xc7,0x50,0x0,0x0,0x0,0x1d,0x69,0x54,0x58,0x74,0x43,0x6f,0x6d,0x6d,0x65,0x6e,0x74,0x0,0x0,0x0,0x0,0x0,0x43,0x72,0x65,0x61,0x74,0x65,0x64,0x20,0x77,0x69,0x74,0x68,0x20,0x47,0x49,0x4d,0x50,0x64,0x2e,0x65,0x7,0x0,0x0,0x2,0x46,0x49,0x44,0x41,0x54,0x58,0xc3,0xed,0x97,0xcd,0x6a,0x13,0x51,0x14,0xc7,0x7f,0xe7,0xce,0x34,0x49,0xd,0xa6,0xb1,0x2a,0xe2,0x7,0x74,0xa1,0x6e,0x4,0x85,0xe2,0x3,0xb8,0x72,0x21,0xba,0x16,0x5c,0xb9,0x16,0x4,0x7d,0x84,0x3e,0x82,0x82,0xe0,0xda,0x95,0x2f,0x60,0x71,0xe1,0xca,0x7,0xd0,0x82,0xa5,0x6e,0xd4,0x45,0xc1,0x8f,0x4a,0x6c,0x9a,0x46,0x62,0x66,0xa6,0x73,0xef,0x71,0xe1,0x4c,0x92,0x99,0x4c,0x93,0x36,0xdd,0xc9,0xfc,0x37,0x77,0x3e,0xee,0xfd,0xdd,0x73,0xfe,0xf7,0xc,0xcc,0x11,0x86,0x12,0xc0,0x0,0x5e,0x32,0xa,0x59,0x29,0xe0,0x0,0x9b,0x8c,0xca,0xc8,0x24,0x3,0x1c,0x3,0x16,0x81,0xd3,0x40,0x3,0x98,0xcb,0x1,0xf6,0x80,0x2e,0xd0,0x2,0xda,0xc0,0x1f,0xc0,0xa5,0xbb,0xd6,0x81,0x4b,0xb,0xc7,0x9b,0xf,0x6a,0xd5,0xda,0xad,0x4a,0xa5,0x7a,0x81,0x2,0x45,0x51,0xf8,0x35,0x8,0x83,0xd7,0xbb,0xbf,0x3b,0xcf,0x81,0xcf,0x40,0x4f,0x92,0x9d,0x96,0x16,0x9b,0x27,0x9f,0x5c,0x5c,0xba,0x7c,0xfb,0xfe,0xcb,0x3b,0x34,0x2b,0x27,0x8a,0xd6,0xd3,0x89,0x76,0x78,0x71,0xef,0x15,0x5f,0x36,0x3f,0xad,0xb6,0x3b,0xdb,0x8f,0x81,0x4d,0x1,0x6a,0xc0,0xf2,0xd9,0x33,0xe7,0xdf,0xac,0xbc,0x7d,0x54,0xdf,0x73,0x11,0x81,0xed,0x17,0x2,0x6a,0xde,0x3c,0x73,0xa6,0xc2,0xca,0x8d,0xa7,0xbd,0x1f,0x3f,0xbf,0xdd,0x4,0xd6,0xfc,0xc4,0x87,0xba,0xef,0xf9,0xf5,0x6e,0xb4,0xc3,0x24,0xf5,0xe3,0x1e,0x7d,0x7a,0xf8,0x9e,0x5f,0x4f,0xd2,0x96,0x14,0xe0,0x1,0x58,0xb5,0x39,0xdb,0x1d,0x82,0x19,0x5c,0xe7,0xe4,0xa5,0x0,0x4d,0x8f,0x44,0x71,0xa8,0x2a,0x22,0x92,0x81,0x4c,0x92,0x3f,0x7a,0xe3,0xd4,0xe2,0x54,0x41,0xc1,0x13,0xf,0xc5,0xe1,0x54,0x31,0x22,0x8,0xa6,0x10,0x96,0x1,0x58,0x1d,0x4e,0x88,0x35,0x1e,0x79,0x9e,0xd6,0xd0,0x94,0x8,0x54,0xb3,0x93,0x1c,0x8a,0x41,0x6,0x63,0xfa,0x6c,0x5f,0x40,0xe4,0xa2,0xcc,0x4b,0x23,0x32,0xd8,0x37,0x4e,0x52,0x99,0x1c,0x41,0x2e,0x4c,0x9b,0xdd,0x6c,0xec,0xbe,0x20,0x5,0xe5,0xb0,0xca,0x99,0x68,0x93,0x48,0x14,0x41,0x30,0x22,0x3,0x63,0x5,0x41,0x51,0x3c,0x31,0x93,0x8f,0x31,0xf3,0xed,0x6a,0xf6,0x5b,0xfe,0xe7,0x85,0x9b,0x0,0x98,0x52,0x34,0x7,0x2a,0xa4,0xb4,0x74,0x8b,0x4c,0x2d,0x2a,0xa6,0xb1,0x42,0x32,0x8c,0x1b,0x39,0x3c,0x7b,0x37,0xbd,0x90,0xec,0x51,0x52,0x88,0x5d,0x3c,0x36,0x21,0xd,0x39,0x4d,0x4d,0x72,0xc5,0x94,0x1,0xac,0xde,0x7d,0x3f,0xbb,0x89,0xf1,0x9e,0x65,0xf9,0xea,0xf5,0x3,0x2d,0x5a,0x5b,0x7f,0x57,0x1c,0xc1,0x6e,0xb7,0x73,0xe8,0x8,0xc,0x47,0x54,0x9,0x28,0x1,0x25,0xa0,0x4,0x94,0x80,0x12,0x50,0x2,0xfe,0x4b,0x80,0x14,0xf4,0x88,0x87,0x8e,0xc0,0xcd,0xb0,0xd6,0xa5,0x0,0x7,0x4,0xd6,0xda,0xb0,0xe0,0x27,0x6d,0x7c,0x55,0xc,0xd6,0xda,0x10,0x8,0x0,0x67,0x92,0x56,0x76,0x3b,0x8,0xfb,0x1b,0xad,0xf6,0x16,0x93,0x20,0x2e,0x86,0x56,0x7b,0x8b,0x20,0xec,0x6f,0x0,0xdb,0x80,0x4d,0x3b,0xd7,0x5,0xe0,0x5a,0xa3,0xde,0x7c,0x56,0xab,0xce,0x5f,0xf1,0x3c,0xaf,0xd0,0x5c,0x6b,0xad,0xb,0xc2,0xfe,0xc7,0x6e,0xaf,0xf3,0x10,0xf8,0x0,0xec,0xca,0x48,0xb,0xd7,0x0,0xce,0x1,0xa7,0x80,0xea,0x3e,0xcd,0x77,0x8,0xfc,0x2,0xbe,0x27,0x7d,0xb4,0x95,0x9c,0xa1,0x7e,0xda,0xf,0xee,0x93,0x85,0x26,0x29,0xc7,0x33,0x1a,0x3f,0xae,0xbf,0xf0,0x27,0xf6,0x42,0xf6,0xf5,0xfd,0xae,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 +}; + + static const unsigned char graph_port_png[]={ 0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0xa,0x0,0x0,0x0,0xa,0x8,0x6,0x0,0x0,0x0,0x8d,0x32,0xcf,0xbd,0x0,0x0,0x0,0x6,0x62,0x4b,0x47,0x44,0x0,0x0,0x0,0x0,0x0,0x0,0xf9,0x43,0xbb,0x7f,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x13,0x0,0x0,0xb,0x13,0x1,0x0,0x9a,0x9c,0x18,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xde,0xc,0x14,0x17,0x20,0x3,0xeb,0x8f,0x3a,0xdb,0x0,0x0,0x0,0x19,0x74,0x45,0x58,0x74,0x43,0x6f,0x6d,0x6d,0x65,0x6e,0x74,0x0,0x43,0x72,0x65,0x61,0x74,0x65,0x64,0x20,0x77,0x69,0x74,0x68,0x20,0x47,0x49,0x4d,0x50,0x57,0x81,0xe,0x17,0x0,0x0,0x1,0x65,0x49,0x44,0x41,0x54,0x18,0xd3,0x4d,0xd0,0x4f,0x6b,0xda,0x70,0x1c,0x7,0xe0,0xcf,0x37,0x7f,0x7e,0x49,0x66,0xd2,0x64,0x61,0x5,0x61,0x76,0x47,0xf1,0xa4,0x2d,0xdb,0x75,0x5,0x11,0x84,0xb0,0x5e,0xeb,0xd9,0xeb,0xf4,0x6d,0xec,0x2d,0xf8,0x26,0xb6,0x77,0xe0,0x45,0xba,0xa3,0x6c,0xa0,0x3b,0xad,0x39,0xb6,0x36,0x8,0x1b,0x4b,0x32,0xd2,0xc6,0x6c,0x9a,0x4f,0x4f,0x85,0x3e,0x2f,0xe1,0x11,0x0,0x20,0x29,0xd3,0xe9,0xd4,0xda,0x6e,0xb7,0x23,0xdf,0xf7,0xbb,0x0,0x90,0xe7,0xf9,0x8f,0x66,0xb3,0xf9,0x79,0x36,0x9b,0x55,0x22,0x42,0x83,0xa4,0x44,0x51,0xf4,0xea,0xe2,0xe2,0xc3,0xf7,0xf1,0x78,0xdc,0xa,0x82,0x40,0x8,0x20,0xcf,0x32,0x2e,0x97,0xcb,0x4f,0x51,0x14,0xbd,0x25,0xf9,0x5b,0x26,0x93,0x89,0xdd,0xe9,0x74,0xe2,0xf7,0xe7,0xe7,0x27,0x59,0xfa,0x87,0x65,0xb9,0x13,0x0,0xb0,0x1d,0x9b,0xe1,0xcb,0x50,0xbe,0x5e,0x5d,0xdd,0xfe,0xbc,0xbe,0x6e,0x6b,0x49,0x92,0x8c,0x4e,0x7b,0xa7,0xad,0xbf,0x79,0x4e,0xd3,0x54,0x12,0x86,0x21,0xc2,0x30,0x84,0x32,0x95,0xe4,0x79,0xc6,0xde,0xd9,0x59,0x2b,0x49,0xee,0x46,0x86,0xeb,0xba,0x5d,0xfb,0x85,0x23,0x87,0xfd,0x1e,0xb6,0xed,0x40,0xd7,0x35,0x0,0x40,0x7d,0x38,0xa0,0xdc,0xed,0x44,0x37,0x74,0xb8,0xae,0xd7,0x35,0x48,0x62,0xff,0xff,0x1f,0xfc,0x20,0x80,0xae,0xe9,0x78,0x42,0x0,0xca,0xb2,0x90,0x65,0x19,0x58,0xd7,0xd0,0x8a,0xa2,0x58,0xa7,0x69,0x56,0x6b,0xa2,0x51,0x29,0x5,0xcb,0x52,0xb0,0x94,0x5,0x4b,0x29,0x88,0x8,0xd3,0x34,0xad,0x8b,0xfb,0x62,0xad,0xf,0x6,0x83,0xb8,0xaa,0xaa,0xb1,0xe7,0x79,0xbe,0x77,0x74,0x44,0xb7,0xe1,0x89,0x69,0x1a,0x28,0xcb,0x92,0x9b,0xcd,0x46,0x56,0xab,0xd5,0x86,0xe4,0x47,0x21,0x29,0xc3,0xe1,0xf0,0xb8,0xdf,0xef,0x7f,0x6b,0xb7,0xdb,0xaf,0x1b,0x8d,0x86,0x46,0x10,0xf,0xf7,0xf,0x75,0x1c,0xc7,0x77,0x8b,0xc5,0xe2,0xdd,0x7c,0x3e,0xff,0x25,0xcf,0xc3,0x6f,0x6e,0x6f,0x2e,0x1d,0xdb,0xe9,0x9,0x80,0xb2,0x2a,0xd7,0x27,0xad,0x37,0x5f,0x9e,0xc2,0x1f,0x1,0x3a,0xe6,0xa5,0x7b,0xef,0xf2,0xf3,0xcd,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 }; diff --git a/tools/editor/plugins/shader_graph_editor_plugin.cpp b/tools/editor/plugins/shader_graph_editor_plugin.cpp index b4fb14dbbc71..a0f7edbd933b 100644 --- a/tools/editor/plugins/shader_graph_editor_plugin.cpp +++ b/tools/editor/plugins/shader_graph_editor_plugin.cpp @@ -37,596 +37,596 @@ void GraphColorRampEdit::_input_event(const InputEvent& p_event) { - if (p_event.type==InputEvent::KEY && p_event.key.pressed && p_event.key.scancode==KEY_DELETE && grabbed!=-1) { - - points.remove(grabbed); - grabbed=-1; - update(); - emit_signal("ramp_changed"); - accept_event(); - } - - if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==1 && p_event.mouse_button.pressed) { + if (p_event.type==InputEvent::KEY && p_event.key.pressed && p_event.key.scancode==KEY_DELETE && grabbed!=-1) { + + points.remove(grabbed); + grabbed=-1; + update(); + emit_signal("ramp_changed"); + accept_event(); + } + + if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==1 && p_event.mouse_button.pressed) { - update(); - int x = p_event.mouse_button.x; - int total_w = get_size().width-get_size().height-3; - if (x>total_w+3) { - - if (grabbed==-1) - return; - Size2 ms = Size2(350, picker->get_combined_minimum_size().height+10); - picker->set_color(points[grabbed].color); - popup->set_pos(get_global_pos()-Size2(0,ms.height)); - popup->set_size(ms); - popup->popup(); - return; - } - - - float ofs = CLAMP(x/float(total_w),0,1); - - grabbed=-1; - grabbing=true; - int pos=-1; - for(int i=0;itotal_w+3) { + + if (grabbed==-1) + return; + Size2 ms = Size2(350, picker->get_combined_minimum_size().height+10); + picker->set_color(points[grabbed].color); + popup->set_pos(get_global_pos()-Size2(0,ms.height)); + popup->set_size(ms); + popup->popup(); + return; + } + + + float ofs = CLAMP(x/float(total_w),0,1); + + grabbed=-1; + grabbing=true; + int pos=-1; + for(int i=0;iconnect("color_changed",this,"_color_changed"); - } - if (p_what==NOTIFICATION_DRAW) { + if (p_what==NOTIFICATION_ENTER_TREE) { + picker->connect("color_changed",this,"_color_changed"); + } + if (p_what==NOTIFICATION_DRAW) { - Point prev; - prev.offset=0; - prev.color=Color(0,0,0); - int w = get_size().x; - int h = get_size().y; + Point prev; + prev.offset=0; + prev.color=Color(0,0,0); + int w = get_size().x; + int h = get_size().y; - int total_w = get_size().width-get_size().height-3; + int total_w = get_size().width-get_size().height-3; - for(int i=-1;i points; - Vector colors; - points.push_back(Vector2(prev.offset*total_w,h)); - points.push_back(Vector2(prev.offset*total_w,0)); - points.push_back(Vector2(next.offset*total_w,0)); - points.push_back(Vector2(next.offset*total_w,h)); - colors.push_back(prev.color); - colors.push_back(prev.color); - colors.push_back(next.color); - colors.push_back(next.color); - draw_primitive(points,colors,Vector()); - prev=next; - } + Vector points; + Vector colors; + points.push_back(Vector2(prev.offset*total_w,h)); + points.push_back(Vector2(prev.offset*total_w,0)); + points.push_back(Vector2(next.offset*total_w,0)); + points.push_back(Vector2(next.offset*total_w,h)); + colors.push_back(prev.color); + colors.push_back(prev.color); + colors.push_back(next.color); + colors.push_back(next.color); + draw_primitive(points,colors,Vector()); + prev=next; + } - for(int i=0;i& p_offsets,const Vector& p_colors) { - ERR_FAIL_COND(p_offsets.size()!=p_colors.size()); - points.clear(); - for(int i=0;i GraphColorRampEdit::get_offsets() const{ - Vector ret; - for(int i=0;i ret; + for(int i=0;i GraphColorRampEdit::get_colors() const{ - Vector ret; - for(int i=0;i ret; + for(int i=0;iadd_child(picker); - popup->set_child_rect(picker); - add_child(popup); + popup = memnew( PopupPanel ); + picker = memnew( ColorPicker ); + popup->add_child(picker); + popup->set_child_rect(picker); + add_child(popup); } //////////// void GraphCurveMapEdit::_input_event(const InputEvent& p_event) { - if (p_event.type==InputEvent::KEY && p_event.key.pressed && p_event.key.scancode==KEY_DELETE && grabbed!=-1) { + if (p_event.type==InputEvent::KEY && p_event.key.pressed && p_event.key.scancode==KEY_DELETE && grabbed!=-1) { - points.remove(grabbed); - grabbed=-1; - update(); - emit_signal("curve_changed"); - accept_event(); - } + points.remove(grabbed); + grabbed=-1; + update(); + emit_signal("curve_changed"); + accept_event(); + } - if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==1 && p_event.mouse_button.pressed) { + if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==1 && p_event.mouse_button.pressed) { - update(); - Point2 p = Vector2(p_event.mouse_button.x,p_event.mouse_button.y)/get_size(); - p.y=1.0-p.y; - grabbed=-1; - grabbing=true; + update(); + Point2 p = Vector2(p_event.mouse_button.x,p_event.mouse_button.y)/get_size(); + p.y=1.0-p.y; + grabbed=-1; + grabbing=true; - for(int i=0;icurve[cd->outline][lastx] = lasty; - } - else - { - cd->curve_ptr[cd->outline][lastx] = lasty; - if(gb_debug) printf("bender_plot_curve xmax:%d ymax:%d\n", (int)xmax, (int)ymax); - } + { + cd->curve[cd->outline][lastx] = lasty; + } + else + { + cd->curve_ptr[cd->outline][lastx] = lasty; + if(gb_debug) printf("bender_plot_curve xmax:%d ymax:%d\n", (int)xmax, (int)ymax); + } */ - /* loop over the curve */ - for (i = 0; i < ntimes; i++) - { - /* increment the x values */ - x += dx; - dx += dx2; - dx2 += dx3; - - /* increment the y values */ - y += dy; - dy += dy2; - dy2 += dy3; - - newx = CLAMP ((Math::round (x)), 0, xmax); - newy = CLAMP ((Math::round (y)), 0, ymax); - - /* if this point is different than the last one...then draw it */ - if ((lastx != newx) || (lasty != newy)) - { + /* loop over the curve */ + for (i = 0; i < ntimes; i++) + { + /* increment the x values */ + x += dx; + dx += dx2; + dx2 += dx3; + + /* increment the y values */ + y += dy; + dy += dy2; + dy2 += dy3; + + newx = CLAMP ((Math::round (x)), 0, xmax); + newy = CLAMP ((Math::round (y)), 0, ymax); + + /* if this point is different than the last one...then draw it */ + if ((lastx != newx) || (lasty != newy)) + { #if 0 - if(fix255) - { - /* use fixed array size (for the curve graph) */ - cd->curve[cd->outline][newx] = newy; - } - else - { - /* use dynamic allocated curve_ptr (for the real curve) */ - cd->curve_ptr[cd->outline][newx] = newy; - - if(gb_debug) printf("outline: %d cX: %d cY: %d\n", (int)cd->outline, (int)newx, (int)newy); - } + if(fix255) + { + /* use fixed array size (for the curve graph) */ + cd->curve[cd->outline][newx] = newy; + } + else + { + /* use dynamic allocated curve_ptr (for the real curve) */ + cd->curve_ptr[cd->outline][newx] = newy; + + if(gb_debug) printf("outline: %d cX: %d cY: %d\n", (int)cd->outline, (int)newx, (int)newy); + } #endif - draw_line(Vector2(lastx,ymax-lasty),Vector2(newx,ymax-newy),Color(0.8,0.8,0.8,0.8),2.0); - } + draw_line(Vector2(lastx,ymax-lasty),Vector2(newx,ymax-newy),Color(0.8,0.8,0.8,0.8),2.0); + } - lastx = newx; - lasty = newy; - } + lastx = newx; + lasty = newy; + } } void GraphCurveMapEdit::_notification(int p_what){ - if (p_what==NOTIFICATION_DRAW) { + if (p_what==NOTIFICATION_DRAW) { - draw_style_box(get_stylebox("bg","Tree"),Rect2(Point2(),get_size())); + draw_style_box(get_stylebox("bg","Tree"),Rect2(Point2(),get_size())); - int w = get_size().x; - int h = get_size().y; + int w = get_size().x; + int h = get_size().y; - Vector2 prev=Vector2(0,0); - Vector2 prev2=Vector2(0,0); + Vector2 prev=Vector2(0,0); + Vector2 prev2=Vector2(0,0); - for(int i=-1;i=points.size()) { - next=Vector2(1,1); - } else { - next=Vector2(points[i+1].offset,points[i+1].height); - } + Vector2 next; + Vector2 next2; + if (i+1>=points.size()) { + next=Vector2(1,1); + } else { + next=Vector2(points[i+1].offset,points[i+1].height); + } - if (i+2>=points.size()) { - next2=Vector2(1,1); - } else { - next2=Vector2(points[i+2].offset,points[i+2].height); - } + if (i+2>=points.size()) { + next2=Vector2(1,1); + } else { + next2=Vector2(points[i+2].offset,points[i+2].height); + } - /*if (i==-1 && prev.offset==next.offset) { - prev=next; - continue; - }*/ + /*if (i==-1 && prev.offset==next.offset) { + prev=next; + continue; + }*/ - _plot_curve(prev2,prev,next,next2); + _plot_curve(prev2,prev,next,next2); - prev2=prev; - prev=next; - } + prev2=prev; + prev=next; + } - for(int i=0;i& p_points) { - points.clear(); - for(int i=0;i GraphCurveMapEdit::get_points() const { - Vector ret; - for(int i=0;i ret; + for(int i=0;iget_undo_redo(); - ur->create_action("Change Scalar Constant",true); - ur->add_do_method(graph.ptr(),"scalar_const_node_set_value",type,p_id,p_value); - ur->add_undo_method(graph.ptr(),"scalar_const_node_set_value",type,p_id,graph->scalar_const_node_get_value(type,p_id)); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - block_update=true; - ur->commit_action(); - block_update=false; + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change Scalar Constant",true); + ur->add_do_method(graph.ptr(),"scalar_const_node_set_value",type,p_id,p_value); + ur->add_undo_method(graph.ptr(),"scalar_const_node_set_value",type,p_id,graph->scalar_const_node_get_value(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; } void ShaderGraphView::_vec_const_changed(double p_value, int p_id,Array p_arr){ - Vector3 val; - for(int i=0;iget_undo_redo(); - ur->create_action("Change Vec Constant",true); - ur->add_do_method(graph.ptr(),"vec_const_node_set_value",type,p_id,val); - ur->add_undo_method(graph.ptr(),"vec_const_node_set_value",type,p_id,graph->vec_const_node_get_value(type,p_id)); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - block_update=true; - ur->commit_action(); - block_update=false; + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change Vec Constant",true); + ur->add_do_method(graph.ptr(),"vec_const_node_set_value",type,p_id,val); + ur->add_undo_method(graph.ptr(),"vec_const_node_set_value",type,p_id,graph->vec_const_node_get_value(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; } void ShaderGraphView::_rgb_const_changed(const Color& p_color, int p_id){ - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - ur->create_action("Change RGB Constant",true); - ur->add_do_method(graph.ptr(),"rgb_const_node_set_value",type,p_id,p_color); - ur->add_undo_method(graph.ptr(),"rgb_const_node_set_value",type,p_id,graph->rgb_const_node_get_value(type,p_id)); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - block_update=true; - ur->commit_action(); - block_update=false; + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change RGB Constant",true); + ur->add_do_method(graph.ptr(),"rgb_const_node_set_value",type,p_id,p_color); + ur->add_undo_method(graph.ptr(),"rgb_const_node_set_value",type,p_id,graph->rgb_const_node_get_value(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; } void ShaderGraphView::_scalar_op_changed(int p_op, int p_id){ - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - ur->create_action("Change Scalar Operator"); - ur->add_do_method(graph.ptr(),"scalar_op_node_set_op",type,p_id,p_op); - ur->add_undo_method(graph.ptr(),"scalar_op_node_set_op",type,p_id,graph->scalar_op_node_get_op(type,p_id)); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - block_update=true; - ur->commit_action(); - block_update=false; + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change Scalar Operator"); + ur->add_do_method(graph.ptr(),"scalar_op_node_set_op",type,p_id,p_op); + ur->add_undo_method(graph.ptr(),"scalar_op_node_set_op",type,p_id,graph->scalar_op_node_get_op(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; } void ShaderGraphView::_vec_op_changed(int p_op, int p_id){ - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - ur->create_action("Change Vec Operator"); - ur->add_do_method(graph.ptr(),"vec_op_node_set_op",type,p_id,p_op); - ur->add_undo_method(graph.ptr(),"vec_op_node_set_op",type,p_id,graph->vec_op_node_get_op(type,p_id)); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - block_update=true; - ur->commit_action(); - block_update=false; + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change Vec Operator"); + ur->add_do_method(graph.ptr(),"vec_op_node_set_op",type,p_id,p_op); + ur->add_undo_method(graph.ptr(),"vec_op_node_set_op",type,p_id,graph->vec_op_node_get_op(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; } void ShaderGraphView::_vec_scalar_op_changed(int p_op, int p_id){ - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - ur->create_action("Change VecxScalar Operator"); - ur->add_do_method(graph.ptr(),"vec_scalar_op_node_set_op",type,p_id,p_op); - ur->add_undo_method(graph.ptr(),"vec_scalar_op_node_set_op",type,p_id,graph->vec_scalar_op_node_get_op(type,p_id)); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - block_update=true; - ur->commit_action(); - block_update=false; + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change VecxScalar Operator"); + ur->add_do_method(graph.ptr(),"vec_scalar_op_node_set_op",type,p_id,p_op); + ur->add_undo_method(graph.ptr(),"vec_scalar_op_node_set_op",type,p_id,graph->vec_scalar_op_node_get_op(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; } void ShaderGraphView::_rgb_op_changed(int p_op, int p_id){ - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - ur->create_action("Change RGB Operator"); - ur->add_do_method(graph.ptr(),"rgb_op_node_set_op",type,p_id,p_op); - ur->add_undo_method(graph.ptr(),"rgb_op_node_set_op",type,p_id,graph->rgb_op_node_get_op(type,p_id)); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - block_update=true; - ur->commit_action(); - block_update=false; + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change RGB Operator"); + ur->add_do_method(graph.ptr(),"rgb_op_node_set_op",type,p_id,p_op); + ur->add_undo_method(graph.ptr(),"rgb_op_node_set_op",type,p_id,graph->rgb_op_node_get_op(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; } void ShaderGraphView::_xform_inv_rev_changed(bool p_enabled, int p_id){ - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - ur->create_action("Toggle Rot Only"); - ur->add_do_method(graph.ptr(),"xform_vec_mult_node_set_no_translation",type,p_id,p_enabled); - ur->add_undo_method(graph.ptr(),"xform_vec_mult_node_set_no_translation",type,p_id,graph->xform_vec_mult_node_get_no_translation(type,p_id)); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - block_update=true; - ur->commit_action(); - block_update=false; + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Toggle Rot Only"); + ur->add_do_method(graph.ptr(),"xform_vec_mult_node_set_no_translation",type,p_id,p_enabled); + ur->add_undo_method(graph.ptr(),"xform_vec_mult_node_set_no_translation",type,p_id,graph->xform_vec_mult_node_get_no_translation(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; } void ShaderGraphView::_scalar_func_changed(int p_func, int p_id){ - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - ur->create_action("Change Scalar Function"); - ur->add_do_method(graph.ptr(),"scalar_func_node_set_function",type,p_id,p_func); - ur->add_undo_method(graph.ptr(),"scalar_func_node_set_function",type,p_id,graph->scalar_func_node_get_function(type,p_id)); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - block_update=true; - ur->commit_action(); - block_update=false; + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change Scalar Function"); + ur->add_do_method(graph.ptr(),"scalar_func_node_set_function",type,p_id,p_func); + ur->add_undo_method(graph.ptr(),"scalar_func_node_set_function",type,p_id,graph->scalar_func_node_get_function(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; } void ShaderGraphView::_vec_func_changed(int p_func, int p_id){ - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - ur->create_action("Change Vec Function"); - ur->add_do_method(graph.ptr(),"vec_func_node_set_function",type,p_id,p_func); - ur->add_undo_method(graph.ptr(),"vec_func_node_set_function",type,p_id,graph->vec_func_node_get_function(type,p_id)); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - block_update=true; - ur->commit_action(); - block_update=false; + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change Vec Function"); + ur->add_do_method(graph.ptr(),"vec_func_node_set_function",type,p_id,p_func); + ur->add_undo_method(graph.ptr(),"vec_func_node_set_function",type,p_id,graph->vec_func_node_get_function(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; } void ShaderGraphView::_scalar_input_changed(double p_value,int p_id){ - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - ur->create_action("Change Scalar Uniform",true); - ur->add_do_method(graph.ptr(),"scalar_input_node_set_value",type,p_id,p_value); - ur->add_undo_method(graph.ptr(),"scalar_input_node_set_value",type,p_id,graph->scalar_input_node_get_value(type,p_id)); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - block_update=true; - ur->commit_action(); - block_update=false; + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change Scalar Uniform",true); + ur->add_do_method(graph.ptr(),"scalar_input_node_set_value",type,p_id,p_value); + ur->add_undo_method(graph.ptr(),"scalar_input_node_set_value",type,p_id,graph->scalar_input_node_get_value(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; } void ShaderGraphView::_vec_input_changed(double p_value, int p_id,Array p_arr){ - Vector3 val; - for(int i=0;iget_undo_redo(); - ur->create_action("Change Vec Uniform",true); - ur->add_do_method(graph.ptr(),"vec_input_node_set_value",type,p_id,val); - ur->add_undo_method(graph.ptr(),"vec_input_node_set_value",type,p_id,graph->vec_input_node_get_value(type,p_id)); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - block_update=true; - ur->commit_action(); - block_update=false; + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change Vec Uniform",true); + ur->add_do_method(graph.ptr(),"vec_input_node_set_value",type,p_id,val); + ur->add_undo_method(graph.ptr(),"vec_input_node_set_value",type,p_id,graph->vec_input_node_get_value(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; } void ShaderGraphView::_xform_input_changed(int p_id, Node *p_button){ - ToolButton *tb = p_button->cast_to(); - ped_popup->set_pos(tb->get_global_pos()+Vector2(0,tb->get_size().height)); - ped_popup->set_size(tb->get_size()); - edited_id=p_id; - ped_popup->edit(NULL,"",Variant::TRANSFORM,graph->xform_input_node_get_value(type,p_id),PROPERTY_HINT_NONE,""); - ped_popup->popup(); + ToolButton *tb = p_button->cast_to(); + ped_popup->set_pos(tb->get_global_pos()+Vector2(0,tb->get_size().height)); + ped_popup->set_size(tb->get_size()); + edited_id=p_id; + ped_popup->edit(NULL,"",Variant::TRANSFORM,graph->xform_input_node_get_value(type,p_id),PROPERTY_HINT_NONE,""); + ped_popup->popup(); } void ShaderGraphView::_xform_const_changed(int p_id, Node *p_button){ - ToolButton *tb = p_button->cast_to(); - ped_popup->set_pos(tb->get_global_pos()+Vector2(0,tb->get_size().height)); - ped_popup->set_size(tb->get_size()); - edited_id=p_id; - ped_popup->edit(NULL,"",Variant::TRANSFORM,graph->xform_const_node_get_value(type,p_id),PROPERTY_HINT_NONE,""); - ped_popup->popup(); + ToolButton *tb = p_button->cast_to(); + ped_popup->set_pos(tb->get_global_pos()+Vector2(0,tb->get_size().height)); + ped_popup->set_size(tb->get_size()); + edited_id=p_id; + ped_popup->edit(NULL,"",Variant::TRANSFORM,graph->xform_const_node_get_value(type,p_id),PROPERTY_HINT_NONE,""); + ped_popup->popup(); } void ShaderGraphView::_rgb_input_changed(const Color& p_color, int p_id){ - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - ur->create_action("Change RGB Uniform",true); - ur->add_do_method(graph.ptr(),"rgb_input_node_set_value",type,p_id,p_color); - ur->add_undo_method(graph.ptr(),"rgb_input_node_set_value",type,p_id,graph->rgb_input_node_get_value(type,p_id)); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - block_update=true; - ur->commit_action(); - block_update=false; + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change RGB Uniform",true); + ur->add_do_method(graph.ptr(),"rgb_input_node_set_value",type,p_id,p_color); + ur->add_undo_method(graph.ptr(),"rgb_input_node_set_value",type,p_id,graph->rgb_input_node_get_value(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; } void ShaderGraphView::_tex_input_change(int p_id, Node *p_button){ @@ -879,180 +879,180 @@ void ShaderGraphView::_cube_input_change(int p_id){ void ShaderGraphView::_variant_edited() { - if (graph->node_get_type(type,edited_id)==ShaderGraph::NODE_XFORM_CONST) { + if (graph->node_get_type(type,edited_id)==ShaderGraph::NODE_XFORM_CONST) { - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - ur->create_action("Change XForm Uniform"); - ur->add_do_method(graph.ptr(),"xform_const_node_set_value",type,edited_id,ped_popup->get_variant()); - ur->add_undo_method(graph.ptr(),"xform_const_node_set_value",type,edited_id,graph->xform_const_node_get_value(type,edited_id)); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - ur->commit_action(); - } + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change XForm Uniform"); + ur->add_do_method(graph.ptr(),"xform_const_node_set_value",type,edited_id,ped_popup->get_variant()); + ur->add_undo_method(graph.ptr(),"xform_const_node_set_value",type,edited_id,graph->xform_const_node_get_value(type,edited_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + ur->commit_action(); + } - if (graph->node_get_type(type,edited_id)==ShaderGraph::NODE_XFORM_INPUT) { + if (graph->node_get_type(type,edited_id)==ShaderGraph::NODE_XFORM_INPUT) { - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - ur->create_action("Change XForm Uniform"); - ur->add_do_method(graph.ptr(),"xform_input_node_set_value",type,edited_id,ped_popup->get_variant()); - ur->add_undo_method(graph.ptr(),"xform_input_node_set_value",type,edited_id,graph->xform_input_node_get_value(type,edited_id)); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - ur->commit_action(); - } + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change XForm Uniform"); + ur->add_do_method(graph.ptr(),"xform_input_node_set_value",type,edited_id,ped_popup->get_variant()); + ur->add_undo_method(graph.ptr(),"xform_input_node_set_value",type,edited_id,graph->xform_input_node_get_value(type,edited_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + ur->commit_action(); + } - if (graph->node_get_type(type,edited_id)==ShaderGraph::NODE_TEXTURE_INPUT) { + if (graph->node_get_type(type,edited_id)==ShaderGraph::NODE_TEXTURE_INPUT) { - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - ur->create_action("Change Texture Uniform"); - ur->add_do_method(graph.ptr(),"texture_input_node_set_value",type,edited_id,ped_popup->get_variant()); - ur->add_undo_method(graph.ptr(),"texture_input_node_set_value",type,edited_id,graph->texture_input_node_get_value(type,edited_id)); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - ur->commit_action(); - } + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change Texture Uniform"); + ur->add_do_method(graph.ptr(),"texture_input_node_set_value",type,edited_id,ped_popup->get_variant()); + ur->add_undo_method(graph.ptr(),"texture_input_node_set_value",type,edited_id,graph->texture_input_node_get_value(type,edited_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + ur->commit_action(); + } - if (graph->node_get_type(type,edited_id)==ShaderGraph::NODE_CUBEMAP_INPUT) { + if (graph->node_get_type(type,edited_id)==ShaderGraph::NODE_CUBEMAP_INPUT) { - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - ur->create_action("Change Cubemap Uniform"); - ur->add_do_method(graph.ptr(),"cubemap_input_node_set_value",type,edited_id,ped_popup->get_variant()); - ur->add_undo_method(graph.ptr(),"cubemap_input_node_set_value",type,edited_id,graph->cubemap_input_node_get_value(type,edited_id)); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - ur->commit_action(); - } + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change Cubemap Uniform"); + ur->add_do_method(graph.ptr(),"cubemap_input_node_set_value",type,edited_id,ped_popup->get_variant()); + ur->add_undo_method(graph.ptr(),"cubemap_input_node_set_value",type,edited_id,graph->cubemap_input_node_get_value(type,edited_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + ur->commit_action(); + } } void ShaderGraphView::_comment_edited(int p_id,Node* p_button) { - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - TextEdit *te=p_button->cast_to(); - ur->create_action("Change Comment",true); - ur->add_do_method(graph.ptr(),"comment_node_set_text",type,p_id,te->get_text()); - ur->add_undo_method(graph.ptr(),"comment_node_set_text",type,p_id,graph->comment_node_get_text(type,p_id)); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - block_update=true; - ur->commit_action(); - block_update=false; + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + TextEdit *te=p_button->cast_to(); + ur->create_action("Change Comment",true); + ur->add_do_method(graph.ptr(),"comment_node_set_text",type,p_id,te->get_text()); + ur->add_undo_method(graph.ptr(),"comment_node_set_text",type,p_id,graph->comment_node_get_text(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; } void ShaderGraphView::_color_ramp_changed(int p_id,Node* p_ramp) { - GraphColorRampEdit *cr=p_ramp->cast_to(); + GraphColorRampEdit *cr=p_ramp->cast_to(); - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - Vector offsets=cr->get_offsets(); - Vector colors=cr->get_colors(); + Vector offsets=cr->get_offsets(); + Vector colors=cr->get_colors(); - DVector new_offsets; - DVector new_colors; - { - new_offsets.resize(offsets.size()); - new_colors.resize(colors.size()); - DVector::Write ow=new_offsets.write(); - DVector::Write cw=new_colors.write(); - for(int i=0;i new_offsets; + DVector new_colors; + { + new_offsets.resize(offsets.size()); + new_colors.resize(colors.size()); + DVector::Write ow=new_offsets.write(); + DVector::Write cw=new_colors.write(); + for(int i=0;i old_offsets=graph->color_ramp_node_get_offsets(type,p_id); - DVector old_colors=graph->color_ramp_node_get_colors(type,p_id); + DVector old_offsets=graph->color_ramp_node_get_offsets(type,p_id); + DVector old_colors=graph->color_ramp_node_get_colors(type,p_id); - if (old_offsets.size()!=new_offsets.size()) - ur->create_action("Add/Remove to Color Ramp"); - else - ur->create_action("Modify Color Ramp",true); + if (old_offsets.size()!=new_offsets.size()) + ur->create_action("Add/Remove to Color Ramp"); + else + ur->create_action("Modify Color Ramp",true); - ur->add_do_method(graph.ptr(),"color_ramp_node_set_ramp",type,p_id,new_colors,new_offsets); - ur->add_undo_method(graph.ptr(),"color_ramp_node_set_ramp",type,p_id,old_colors,old_offsets); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - block_update=true; - ur->commit_action(); - block_update=false; + ur->add_do_method(graph.ptr(),"color_ramp_node_set_ramp",type,p_id,new_colors,new_offsets); + ur->add_undo_method(graph.ptr(),"color_ramp_node_set_ramp",type,p_id,old_colors,old_offsets); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; } void ShaderGraphView::_curve_changed(int p_id,Node* p_curve) { - GraphCurveMapEdit *cr=p_curve->cast_to(); + GraphCurveMapEdit *cr=p_curve->cast_to(); - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - Vector points=cr->get_points(); + Vector points=cr->get_points(); - DVector new_points; - { - new_points.resize(points.size()); - DVector::Write ow=new_points.write(); - for(int i=0;i new_points; + { + new_points.resize(points.size()); + DVector::Write ow=new_points.write(); + for(int i=0;i old_points=graph->curve_map_node_get_points(type,p_id); + DVector old_points=graph->curve_map_node_get_points(type,p_id); - if (old_points.size()!=new_points.size()) - ur->create_action("Add/Remove to Curve Map"); - else - ur->create_action("Modify Curve Map",true); + if (old_points.size()!=new_points.size()) + ur->create_action("Add/Remove to Curve Map"); + else + ur->create_action("Modify Curve Map",true); - ur->add_do_method(graph.ptr(),"curve_map_node_set_points",type,p_id,new_points); - ur->add_undo_method(graph.ptr(),"curve_map_node_set_points",type,p_id,old_points); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - block_update=true; - ur->commit_action(); - block_update=false; + ur->add_do_method(graph.ptr(),"curve_map_node_set_points",type,p_id,new_points); + ur->add_undo_method(graph.ptr(),"curve_map_node_set_points",type,p_id,old_points); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; } void ShaderGraphView::_input_name_changed(const String& p_name, int p_id, Node *p_line_edit) { - LineEdit *le=p_line_edit->cast_to(); - ERR_FAIL_COND(!le); + LineEdit *le=p_line_edit->cast_to(); + ERR_FAIL_COND(!le); - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - ur->create_action("Change Input Name"); - ur->add_do_method(graph.ptr(),"input_node_set_name",type,p_id,p_name); - ur->add_undo_method(graph.ptr(),"input_node_set_name",type,p_id,graph->input_node_get_name(type,p_id)); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - block_update=true; - ur->commit_action(); - block_update=false; - le->set_text(graph->input_node_get_name(type,p_id)); + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change Input Name"); + ur->add_do_method(graph.ptr(),"input_node_set_name",type,p_id,p_name); + ur->add_undo_method(graph.ptr(),"input_node_set_name",type,p_id,graph->input_node_get_name(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; + le->set_text(graph->input_node_get_name(type,p_id)); } void ShaderGraphView::_tex_edited(int p_id,Node* p_button) { - ToolButton *tb = p_button->cast_to(); - ped_popup->set_pos(tb->get_global_pos()+Vector2(0,tb->get_size().height)); - ped_popup->set_size(tb->get_size()); - edited_id=p_id; - ped_popup->edit(NULL,"",Variant::OBJECT,graph->texture_input_node_get_value(type,p_id),PROPERTY_HINT_RESOURCE_TYPE,"Texture"); + ToolButton *tb = p_button->cast_to(); + ped_popup->set_pos(tb->get_global_pos()+Vector2(0,tb->get_size().height)); + ped_popup->set_size(tb->get_size()); + edited_id=p_id; + ped_popup->edit(NULL,"",Variant::OBJECT,graph->texture_input_node_get_value(type,p_id),PROPERTY_HINT_RESOURCE_TYPE,"Texture"); } void ShaderGraphView::_cube_edited(int p_id,Node* p_button) { - ToolButton *tb = p_button->cast_to(); - ped_popup->set_pos(tb->get_global_pos()+Vector2(0,tb->get_size().height)); - ped_popup->set_size(tb->get_size()); - edited_id=p_id; - ped_popup->edit(NULL,"",Variant::OBJECT,graph->cubemap_input_node_get_value(type,p_id),PROPERTY_HINT_RESOURCE_TYPE,"CubeMap"); + ToolButton *tb = p_button->cast_to(); + ped_popup->set_pos(tb->get_global_pos()+Vector2(0,tb->get_size().height)); + ped_popup->set_size(tb->get_size()); + edited_id=p_id; + ped_popup->edit(NULL,"",Variant::OBJECT,graph->cubemap_input_node_get_value(type,p_id),PROPERTY_HINT_RESOURCE_TYPE,"CubeMap"); } @@ -1061,983 +1061,994 @@ void ShaderGraphView::_cube_edited(int p_id,Node* p_button) { void ShaderGraphView::_connection_request(const String& p_from, int p_from_slot,const String& p_to,int p_to_slot) { - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - int from_idx=-1; - int to_idx=-1; - for (Map::Element *E=node_map.front();E;E=E->next()) { + int from_idx=-1; + int to_idx=-1; + for (Map::Element *E=node_map.front();E;E=E->next()) { - if (p_from==E->get()->get_name()) - from_idx=E->key(); - if (p_to==E->get()->get_name()) - to_idx=E->key(); - } + if (p_from==E->get()->get_name()) + from_idx=E->key(); + if (p_to==E->get()->get_name()) + to_idx=E->key(); + } - ERR_FAIL_COND(from_idx==-1); - ERR_FAIL_COND(to_idx==-1); + ERR_FAIL_COND(from_idx==-1); + ERR_FAIL_COND(to_idx==-1); - ur->create_action("Connect Graph Nodes"); + ur->create_action("Connect Graph Nodes"); - List conns; + List conns; - graph->get_node_connections(type,&conns); - //disconnect/reconnect dependencies - ur->add_undo_method(graph.ptr(),"disconnect_node",type,from_idx,p_from_slot,to_idx,p_to_slot); - for(List::Element *E=conns.front();E;E=E->next()) { + graph->get_node_connections(type,&conns); + //disconnect/reconnect dependencies + ur->add_undo_method(graph.ptr(),"disconnect_node",type,from_idx,p_from_slot,to_idx,p_to_slot); + for(List::Element *E=conns.front();E;E=E->next()) { - if (E->get().dst_id==to_idx && E->get().dst_slot==p_to_slot) { - ur->add_do_method(graph.ptr(),"disconnect_node",type,E->get().src_id,E->get().src_slot,E->get().dst_id,E->get().dst_slot); - ur->add_undo_method(graph.ptr(),"connect_node",type,E->get().src_id,E->get().src_slot,E->get().dst_id,E->get().dst_slot); - } - } - ur->add_do_method(graph.ptr(),"connect_node",type,from_idx,p_from_slot,to_idx,p_to_slot); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - ur->commit_action(); + if (E->get().dst_id==to_idx && E->get().dst_slot==p_to_slot) { + ur->add_do_method(graph.ptr(),"disconnect_node",type,E->get().src_id,E->get().src_slot,E->get().dst_id,E->get().dst_slot); + ur->add_undo_method(graph.ptr(),"connect_node",type,E->get().src_id,E->get().src_slot,E->get().dst_id,E->get().dst_slot); + } + } + ur->add_do_method(graph.ptr(),"connect_node",type,from_idx,p_from_slot,to_idx,p_to_slot); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + ur->commit_action(); } void ShaderGraphView::_disconnection_request(const String& p_from, int p_from_slot,const String& p_to,int p_to_slot) { - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - int from_idx=-1; - int to_idx=-1; - for (Map::Element *E=node_map.front();E;E=E->next()) { + int from_idx=-1; + int to_idx=-1; + for (Map::Element *E=node_map.front();E;E=E->next()) { - if (p_from==E->get()->get_name()) - from_idx=E->key(); - if (p_to==E->get()->get_name()) - to_idx=E->key(); - } + if (p_from==E->get()->get_name()) + from_idx=E->key(); + if (p_to==E->get()->get_name()) + to_idx=E->key(); + } - ERR_FAIL_COND(from_idx==-1); - ERR_FAIL_COND(to_idx==-1); + ERR_FAIL_COND(from_idx==-1); + ERR_FAIL_COND(to_idx==-1); - if (!graph->is_node_connected(type,from_idx,p_from_slot,to_idx,p_to_slot)) - return; //nothing to disconnect + if (!graph->is_node_connected(type,from_idx,p_from_slot,to_idx,p_to_slot)) + return; //nothing to disconnect - ur->create_action("Disconnect Graph Nodes"); + ur->create_action("Disconnect Graph Nodes"); - List conns; + List conns; - graph->get_node_connections(type,&conns); - //disconnect/reconnect dependencies - ur->add_do_method(graph.ptr(),"disconnect_node",type,from_idx,p_from_slot,to_idx,p_to_slot); - ur->add_undo_method(graph.ptr(),"connect_node",type,from_idx,p_from_slot,to_idx,p_to_slot); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - ur->commit_action(); + graph->get_node_connections(type,&conns); + //disconnect/reconnect dependencies + ur->add_do_method(graph.ptr(),"disconnect_node",type,from_idx,p_from_slot,to_idx,p_to_slot); + ur->add_undo_method(graph.ptr(),"connect_node",type,from_idx,p_from_slot,to_idx,p_to_slot); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + ur->commit_action(); } void ShaderGraphView::_node_removed(int p_id) { - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - ur->create_action("Remove Shader Graph Node"); + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Remove Shader Graph Node"); - ur->add_do_method(graph.ptr(),"node_remove",type,p_id); - ur->add_undo_method(graph.ptr(),"node_add",type,graph->node_get_type(type,p_id),p_id); - ur->add_undo_method(graph.ptr(),"node_set_state",type,p_id,graph->node_get_state(type,p_id)); - List conns; + ur->add_do_method(graph.ptr(),"node_remove",type,p_id); + ur->add_undo_method(graph.ptr(),"node_add",type,graph->node_get_type(type,p_id),p_id); + ur->add_undo_method(graph.ptr(),"node_set_state",type,p_id,graph->node_get_state(type,p_id)); + List conns; - graph->get_node_connections(type,&conns); - for(List::Element *E=conns.front();E;E=E->next()) { + graph->get_node_connections(type,&conns); + for(List::Element *E=conns.front();E;E=E->next()) { - if (E->get().dst_id==p_id || E->get().src_id==p_id) { - ur->add_undo_method(graph.ptr(),"connect_node",type,E->get().src_id,E->get().src_slot,E->get().dst_id,E->get().dst_slot); - } - } - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - ur->commit_action(); + if (E->get().dst_id==p_id || E->get().src_id==p_id) { + ur->add_undo_method(graph.ptr(),"connect_node",type,E->get().src_id,E->get().src_slot,E->get().dst_id,E->get().dst_slot); + } + } + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + ur->commit_action(); } +void ShaderGraphView::_begin_node_move() +{ + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Move Shader Graph Node"); +} + void ShaderGraphView::_node_moved(const Vector2& p_from, const Vector2& p_to,int p_id) { - ERR_FAIL_COND(!node_map.has(p_id)); - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - ur->create_action("Move Shader Graph Node"); - ur->add_do_method(this,"_move_node",p_id,p_to); - ur->add_undo_method(this,"_move_node",p_id,p_from); - ur->commit_action(); + ERR_FAIL_COND(!node_map.has(p_id)); + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->add_do_method(this,"_move_node",p_id,p_to); + ur->add_undo_method(this,"_move_node",p_id,p_from); +} + +void ShaderGraphView::_end_node_move() +{ + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->commit_action(); } void ShaderGraphView::_move_node(int p_id,const Vector2& p_to) { - ERR_FAIL_COND(!node_map.has(p_id)); - node_map[p_id]->set_offset(p_to); - graph->node_set_pos(type,p_id,p_to); + ERR_FAIL_COND(!node_map.has(p_id)); + node_map[p_id]->set_offset(p_to); + graph->node_set_pos(type,p_id,p_to); } void ShaderGraphView::_create_node(int p_id) { - GraphNode *gn = memnew( GraphNode ); - gn->set_show_close_button(true); - Color typecol[4]={ - Color(0.9,0.4,1), - Color(0.8,1,0.2), - Color(1,0.2,0.2), - Color(0,1,1) - }; - - - switch(graph->node_get_type(type,p_id)) { - - case ShaderGraph::NODE_INPUT: { - - gn->set_title("Input"); - - List si; - ShaderGraph::get_input_output_node_slot_info(graph->get_mode(),type,&si); - - int idx=0; - for (List::Element *E=si.front();E;E=E->next()) { - ShaderGraph::SlotInfo& s=E->get(); - if (s.dir==ShaderGraph::SLOT_IN) { - - Label *l= memnew( Label ); - l->set_text(s.name); - l->set_align(Label::ALIGN_RIGHT); - gn->add_child(l); - gn->set_slot(idx,false,0,Color(),true,s.type,typecol[s.type]); - idx++; - } - } - - } break; // all inputs (case Shader type dependent) - case ShaderGraph::NODE_SCALAR_CONST: { - gn->set_title("Scalar"); - SpinBox *sb = memnew( SpinBox ); - sb->set_min(-100000); - sb->set_max(100000); - sb->set_step(0.001); - sb->set_val(graph->scalar_const_node_get_value(type,p_id)); - sb->connect("value_changed",this,"_scalar_const_changed",varray(p_id)); - gn->add_child(sb); - gn->set_slot(0,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); - - } break; //scalar constant - case ShaderGraph::NODE_VEC_CONST: { - - gn->set_title("Vector"); - Array v3p(true); - for(int i=0;i<3;i++) { - HBoxContainer *hbc = memnew( HBoxContainer ); - Label *l = memnew( Label ); - l->set_text(String::chr('X'+i)); - hbc->add_child(l); - SpinBox *sb = memnew( SpinBox ); - sb->set_h_size_flags(Control::SIZE_EXPAND_FILL); - sb->set_min(-100000); - sb->set_max(100000); - sb->set_step(0.001); - sb->set_val(graph->vec_const_node_get_value(type,p_id)[i]); - sb->connect("value_changed",this,"_vec_const_changed",varray(p_id,v3p)); - v3p.push_back(sb); - hbc->add_child(sb); - gn->add_child(hbc); - } - gn->set_slot(0,false,0,Color(),true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); - - } break; //vec3 constant - case ShaderGraph::NODE_RGB_CONST: { - - gn->set_title("Color"); - ColorPickerButton *cpb = memnew( ColorPickerButton ); - cpb->set_color(graph->rgb_const_node_get_value(type,p_id)); - cpb->connect("color_changed",this,"_rgb_const_changed",varray(p_id)); - gn->add_child(cpb); - Label *l = memnew( Label ); - l->set_text("RGB"); - l->set_align(Label::ALIGN_RIGHT); - gn->add_child(l); - l = memnew( Label ); - l->set_text("Alpha"); - l->set_align(Label::ALIGN_RIGHT); - gn->add_child(l); - - gn->set_slot(1,false,0,Color(),true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); - gn->set_slot(2,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); - - } break; //rgb constant (shows a color picker instead) - case ShaderGraph::NODE_XFORM_CONST: { - gn->set_title("XForm"); - ToolButton *edit = memnew( ToolButton ); - edit->set_text("edit.."); - edit->connect("pressed",this,"_xform_const_changed",varray(p_id,edit)); - gn->add_child(edit); - gn->set_slot(0,false,0,Color(),true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM]); - - } break; // 4x4 matrix constant - case ShaderGraph::NODE_TIME: { - - gn->set_title("Time"); - Label *l = memnew( Label ); - l->set_text("(s)"); - l->set_align(Label::ALIGN_RIGHT); - gn->add_child(l); - gn->set_slot(0,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); - - } break; // time in seconds - case ShaderGraph::NODE_SCREEN_TEX: { - - gn->set_title("ScreenTex"); - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("UV"))); - hbc->add_spacer(); - hbc->add_child( memnew(Label("RGB"))); - gn->add_child(hbc); - gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); - - } break; // screen texture sampler (takes UV) (only usable in fragment case Shader) - case ShaderGraph::NODE_SCALAR_OP: { - - gn->set_title("ScalarOp"); - static const char* op_name[ShaderGraph::SCALAR_MAX_OP]={ - "Add", - "Sub", - "Mul", - "Div", - "Mod", - "Pow", - "Max", - "Min", - "Atan2" - }; - - OptionButton *ob = memnew( OptionButton ); - for(int i=0;iadd_item(op_name[i],i); - } - - ob->select(graph->scalar_op_node_get_op(type,p_id)); - ob->connect("item_selected",this,"_scalar_op_changed",varray(p_id)); - gn->add_child(ob); - - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("a"))); - hbc->add_spacer(); - hbc->add_child( memnew(Label("out"))); - gn->add_child(hbc); - gn->add_child( memnew(Label("b"))); - - gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); - gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); - - - } break; // scalar vs scalar op (mul: { } break; add: { } break; div: { } break; etc) - case ShaderGraph::NODE_VEC_OP: { - - gn->set_title("VecOp"); - static const char* op_name[ShaderGraph::VEC_MAX_OP]={ - "Add", - "Sub", - "Mul", - "Div", - "Mod", - "Pow", - "Max", - "Min", - "Cross" - }; - - OptionButton *ob = memnew( OptionButton ); - for(int i=0;iadd_item(op_name[i],i); - } - - ob->select(graph->vec_op_node_get_op(type,p_id)); - ob->connect("item_selected",this,"_vec_op_changed",varray(p_id)); - gn->add_child(ob); - - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("a"))); - hbc->add_spacer(); - hbc->add_child( memnew(Label("out"))); - gn->add_child(hbc); - gn->add_child( memnew(Label("b"))); - - gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); - gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); - - - } break; // vec3 vs vec3 op (mul: { } break;ad: { } break;div: { } break;crossprod: { } break;etc) - case ShaderGraph::NODE_VEC_SCALAR_OP: { - - gn->set_title("VecScalarOp"); - static const char* op_name[ShaderGraph::VEC_SCALAR_MAX_OP]={ - "Mul", - "Div", - "Pow", - }; - - OptionButton *ob = memnew( OptionButton ); - for(int i=0;iadd_item(op_name[i],i); - } - - ob->select(graph->vec_scalar_op_node_get_op(type,p_id)); - ob->connect("item_selected",this,"_vec_scalar_op_changed",varray(p_id)); - gn->add_child(ob); - - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("a"))); - hbc->add_spacer(); - hbc->add_child( memnew(Label("out"))); - gn->add_child(hbc); - gn->add_child( memnew(Label("b"))); - - gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); - gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); - - - } break; // vec3 vs scalar op (mul: { } break; add: { } break; div: { } break; etc) - case ShaderGraph::NODE_RGB_OP: { - - gn->set_title("RGB Op"); - static const char* op_name[ShaderGraph::RGB_MAX_OP]={ - "Screen", - "Difference", - "Darken", - "Lighten", - "Overlay", - "Dodge", - "Burn", - "SoftLight", - "HardLight" - }; - - OptionButton *ob = memnew( OptionButton ); - for(int i=0;iadd_item(op_name[i],i); - } - - ob->select(graph->rgb_op_node_get_op(type,p_id)); - ob->connect("item_selected",this,"_rgb_op_changed",varray(p_id)); - gn->add_child(ob); - - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("a"))); - hbc->add_spacer(); - hbc->add_child( memnew(Label("out"))); - gn->add_child(hbc); - gn->add_child( memnew(Label("b"))); - - gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); - gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); - - } break; // vec3 vs vec3 rgb op (with scalar amount): { } break; like brighten: { } break; darken: { } break; burn: { } break; dodge: { } break; multiply: { } break; etc. - case ShaderGraph::NODE_XFORM_MULT: { - - gn->set_title("XFMult"); - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_child( memnew(Label("a"))); - hbc->add_spacer(); - hbc->add_child( memnew(Label("out"))); - gn->add_child(hbc); - gn->add_child( memnew(Label("b"))); - - gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM],true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM]); - gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM],false,0,Color()); - - - } break; // mat4 x mat4 - case ShaderGraph::NODE_XFORM_VEC_MULT: { - - gn->set_title("XFVecMult"); - - Button *button = memnew( Button("RotOnly")); - button->set_toggle_mode(true); - button->set_pressed(graph->xform_vec_mult_node_get_no_translation(type,p_id)); - button->connect("toggled",this,"_xform_inv_rev_changed",varray(p_id)); - - gn->add_child(button); - - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("xf"))); - hbc->add_spacer(); - Label *l = memnew(Label("out")); - l->set_align(Label::ALIGN_RIGHT); - hbc->add_child( l); - gn->add_child(hbc); - gn->add_child( memnew(Label("vec"))); - - gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); - gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); - - } break; - case ShaderGraph::NODE_XFORM_VEC_INV_MULT: { - - gn->set_title("XFVecInvMult"); - - - Button *button = memnew( Button("RotOnly")); - button->set_toggle_mode(true); - button->set_pressed(graph->xform_vec_mult_node_get_no_translation(type,p_id)); - button->connect("toggled",this,"_xform_inv_rev_changed",varray(p_id)); - - gn->add_child(button); - - gn->add_child( memnew(Label("vec"))); - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("xf"))); - hbc->add_spacer(); - Label *l = memnew(Label("out")); - l->set_align(Label::ALIGN_RIGHT); - hbc->add_child( l); - gn->add_child(hbc); - - gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); - gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); - - - } break; // mat4 x vec3 inverse mult (with no-translation option) - case ShaderGraph::NODE_SCALAR_FUNC: { - - gn->set_title("ScalarFunc"); - static const char* func_name[ShaderGraph::SCALAR_MAX_FUNC]={ - "Sin", - "Cos", - "Tan", - "ASin", - "ACos", - "ATan", - "SinH", - "CosH", - "TanH", - "Log", - "Exp", - "Sqrt", - "Abs", - "Sign", - "Floor", - "Round", - "Ceil", - "Frac", - "Satr", - "Neg" - }; - - OptionButton *ob = memnew( OptionButton ); - for(int i=0;iadd_item(func_name[i],i); - } - - ob->select(graph->scalar_func_node_get_function(type,p_id)); - ob->connect("item_selected",this,"_scalar_func_changed",varray(p_id)); - gn->add_child(ob); - - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_child( memnew(Label("in"))); - hbc->add_spacer(); - hbc->add_child( memnew(Label("out"))); - gn->add_child(hbc); - - gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); - - - } break; // scalar function (sin: { } break; cos: { } break; etc) - case ShaderGraph::NODE_VEC_FUNC: { - - - - gn->set_title("VecFunc"); - static const char* func_name[ShaderGraph::VEC_MAX_FUNC]={ - "Normalize", - "Saturate", - "Negate", - "Reciprocal", - "RGB to HSV", - "HSV to RGB", - }; - - OptionButton *ob = memnew( OptionButton ); - for(int i=0;iadd_item(func_name[i],i); - } - - ob->select(graph->vec_func_node_get_function(type,p_id)); - ob->connect("item_selected",this,"_vec_func_changed",varray(p_id)); - gn->add_child(ob); - - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("in"))); - hbc->add_spacer(); - hbc->add_child( memnew(Label("out"))); - gn->add_child(hbc); - - gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); - - } break; // vector function (normalize: { } break; negate: { } break; reciprocal: { } break; rgb2hsv: { } break; hsv2rgb: { } break; etc: { } break; etc) - case ShaderGraph::NODE_VEC_LEN: { - gn->set_title("VecLength"); - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_child( memnew(Label("in"))); - hbc->add_spacer(); - hbc->add_child( memnew(Label("len"))); - gn->add_child(hbc); - - gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); - - } break; // vec3 length - case ShaderGraph::NODE_DOT_PROD: { - - gn->set_title("DotProduct"); - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("a"))); - hbc->add_spacer(); - hbc->add_child( memnew(Label("dp"))); - gn->add_child(hbc); - gn->add_child( memnew(Label("b"))); - - gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); - gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); - - } break; // vec3 . vec3 (dot product -> scalar output) - case ShaderGraph::NODE_VEC_TO_SCALAR: { - - gn->set_title("Vec2Scalar"); - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("vec"))); - hbc->add_spacer(); - Label *l=memnew(Label("x")); - l->set_align(Label::ALIGN_RIGHT); - hbc->add_child( l); - gn->add_child(hbc); - l=memnew(Label("y")); - l->set_align(Label::ALIGN_RIGHT); - gn->add_child( l ); - l=memnew(Label("z")); - l->set_align(Label::ALIGN_RIGHT); - gn->add_child( l); - - gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); - gn->set_slot(1,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); - gn->set_slot(2,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); - - - - - } break; // 1 vec3 input: { } break; 3 scalar outputs - case ShaderGraph::NODE_SCALAR_TO_VEC: { - - gn->set_title("Scalar2Vec"); - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_child( memnew(Label("x"))); - hbc->add_spacer(); - hbc->add_child( memnew(Label("vec"))); - gn->add_child(hbc); - gn->add_child( memnew(Label("y"))); - gn->add_child( memnew(Label("z"))); - - gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); - gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); - gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); - - } break; // 3 scalar input: { } break; 1 vec3 output - case ShaderGraph::NODE_VEC_TO_XFORM: { - - gn->set_title("Vec2XForm"); - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("x"))); - hbc->add_spacer(); - hbc->add_child( memnew(Label("xf"))); - gn->add_child(hbc); - gn->add_child( memnew(Label("y"))); - gn->add_child( memnew(Label("z"))); - gn->add_child( memnew(Label("ofs"))); - - gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM]); - gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); - gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); - gn->set_slot(3,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); - - } break; // 3 vec input: { } break; 1 xform output - case ShaderGraph::NODE_XFORM_TO_VEC: { - - gn->set_title("XForm2Vec"); - - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("xf"))); - hbc->add_spacer(); - Label *l=memnew(Label("x")); - l->set_align(Label::ALIGN_RIGHT); - hbc->add_child( l); - gn->add_child(hbc); - l=memnew(Label("y")); - l->set_align(Label::ALIGN_RIGHT); - gn->add_child( l ); - l=memnew(Label("z")); - l->set_align(Label::ALIGN_RIGHT); - gn->add_child( l); - l=memnew(Label("ofs")); - l->set_align(Label::ALIGN_RIGHT); - gn->add_child( l); - - gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); - gn->set_slot(1,false,0,Color(),true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); - gn->set_slot(2,false,0,Color(),true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); - gn->set_slot(3,false,0,Color(),true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); - - } break; // 3 vec input: { } break; 1 xform output - case ShaderGraph::NODE_SCALAR_INTERP: { - - gn->set_title("ScalarInterp"); - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("a"))); - hbc->add_spacer(); - hbc->add_child( memnew(Label("interp"))); - gn->add_child(hbc); - gn->add_child( memnew(Label("b"))); - gn->add_child( memnew(Label("c"))); - - gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); - gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); - gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); - - - } break; // scalar interpolation (with optional curve) - case ShaderGraph::NODE_VEC_INTERP: { - - gn->set_title("VecInterp"); - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_child( memnew(Label("a"))); - hbc->add_spacer(); - hbc->add_child( memnew(Label("interp"))); - gn->add_child(hbc); - gn->add_child( memnew(Label("b"))); - gn->add_child( memnew(Label("c"))); + GraphNode *gn = memnew( GraphNode ); + gn->set_show_close_button(true); + Color typecol[4]={ + Color(0.9,0.4,1), + Color(0.8,1,0.2), + Color(1,0.2,0.2), + Color(0,1,1) + }; + + + switch(graph->node_get_type(type,p_id)) { + + case ShaderGraph::NODE_INPUT: { + + gn->set_title("Input"); + + List si; + ShaderGraph::get_input_output_node_slot_info(graph->get_mode(),type,&si); + + int idx=0; + for (List::Element *E=si.front();E;E=E->next()) { + ShaderGraph::SlotInfo& s=E->get(); + if (s.dir==ShaderGraph::SLOT_IN) { + + Label *l= memnew( Label ); + l->set_text(s.name); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child(l); + gn->set_slot(idx,false,0,Color(),true,s.type,typecol[s.type]); + idx++; + } + } + + } break; // all inputs (case Shader type dependent) + case ShaderGraph::NODE_SCALAR_CONST: { + gn->set_title("Scalar"); + SpinBox *sb = memnew( SpinBox ); + sb->set_min(-100000); + sb->set_max(100000); + sb->set_step(0.001); + sb->set_val(graph->scalar_const_node_get_value(type,p_id)); + sb->connect("value_changed",this,"_scalar_const_changed",varray(p_id)); + gn->add_child(sb); + gn->set_slot(0,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + + } break; //scalar constant + case ShaderGraph::NODE_VEC_CONST: { + + gn->set_title("Vector"); + Array v3p(true); + for(int i=0;i<3;i++) { + HBoxContainer *hbc = memnew( HBoxContainer ); + Label *l = memnew( Label ); + l->set_text(String::chr('X'+i)); + hbc->add_child(l); + SpinBox *sb = memnew( SpinBox ); + sb->set_h_size_flags(Control::SIZE_EXPAND_FILL); + sb->set_min(-100000); + sb->set_max(100000); + sb->set_step(0.001); + sb->set_val(graph->vec_const_node_get_value(type,p_id)[i]); + sb->connect("value_changed",this,"_vec_const_changed",varray(p_id,v3p)); + v3p.push_back(sb); + hbc->add_child(sb); + gn->add_child(hbc); + } + gn->set_slot(0,false,0,Color(),true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + + } break; //vec3 constant + case ShaderGraph::NODE_RGB_CONST: { + + gn->set_title("Color"); + ColorPickerButton *cpb = memnew( ColorPickerButton ); + cpb->set_color(graph->rgb_const_node_get_value(type,p_id)); + cpb->connect("color_changed",this,"_rgb_const_changed",varray(p_id)); + gn->add_child(cpb); + Label *l = memnew( Label ); + l->set_text("RGB"); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child(l); + l = memnew( Label ); + l->set_text("Alpha"); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child(l); + + gn->set_slot(1,false,0,Color(),true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(2,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + + } break; //rgb constant (shows a color picker instead) + case ShaderGraph::NODE_XFORM_CONST: { + gn->set_title("XForm"); + ToolButton *edit = memnew( ToolButton ); + edit->set_text("edit.."); + edit->connect("pressed",this,"_xform_const_changed",varray(p_id,edit)); + gn->add_child(edit); + gn->set_slot(0,false,0,Color(),true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM]); + + } break; // 4x4 matrix constant + case ShaderGraph::NODE_TIME: { + + gn->set_title("Time"); + Label *l = memnew( Label ); + l->set_text("(s)"); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child(l); + gn->set_slot(0,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + + } break; // time in seconds + case ShaderGraph::NODE_SCREEN_TEX: { + + gn->set_title("ScreenTex"); + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("UV"))); + hbc->add_spacer(); + hbc->add_child( memnew(Label("RGB"))); + gn->add_child(hbc); + gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + + } break; // screen texture sampler (takes UV) (only usable in fragment case Shader) + case ShaderGraph::NODE_SCALAR_OP: { + + gn->set_title("ScalarOp"); + static const char* op_name[ShaderGraph::SCALAR_MAX_OP]={ + "Add", + "Sub", + "Mul", + "Div", + "Mod", + "Pow", + "Max", + "Min", + "Atan2" + }; + + OptionButton *ob = memnew( OptionButton ); + for(int i=0;iadd_item(op_name[i],i); + } + + ob->select(graph->scalar_op_node_get_op(type,p_id)); + ob->connect("item_selected",this,"_scalar_op_changed",varray(p_id)); + gn->add_child(ob); + + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("a"))); + hbc->add_spacer(); + hbc->add_child( memnew(Label("out"))); + gn->add_child(hbc); + gn->add_child( memnew(Label("b"))); + + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); + + + } break; // scalar vs scalar op (mul: { } break; add: { } break; div: { } break; etc) + case ShaderGraph::NODE_VEC_OP: { + + gn->set_title("VecOp"); + static const char* op_name[ShaderGraph::VEC_MAX_OP]={ + "Add", + "Sub", + "Mul", + "Div", + "Mod", + "Pow", + "Max", + "Min", + "Cross" + }; + + OptionButton *ob = memnew( OptionButton ); + for(int i=0;iadd_item(op_name[i],i); + } + + ob->select(graph->vec_op_node_get_op(type,p_id)); + ob->connect("item_selected",this,"_vec_op_changed",varray(p_id)); + gn->add_child(ob); + + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("a"))); + hbc->add_spacer(); + hbc->add_child( memnew(Label("out"))); + gn->add_child(hbc); + gn->add_child( memnew(Label("b"))); + + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); + + + } break; // vec3 vs vec3 op (mul: { } break;ad: { } break;div: { } break;crossprod: { } break;etc) + case ShaderGraph::NODE_VEC_SCALAR_OP: { + + gn->set_title("VecScalarOp"); + static const char* op_name[ShaderGraph::VEC_SCALAR_MAX_OP]={ + "Mul", + "Div", + "Pow", + }; + + OptionButton *ob = memnew( OptionButton ); + for(int i=0;iadd_item(op_name[i],i); + } + + ob->select(graph->vec_scalar_op_node_get_op(type,p_id)); + ob->connect("item_selected",this,"_vec_scalar_op_changed",varray(p_id)); + gn->add_child(ob); + + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("a"))); + hbc->add_spacer(); + hbc->add_child( memnew(Label("out"))); + gn->add_child(hbc); + gn->add_child( memnew(Label("b"))); + + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); + + + } break; // vec3 vs scalar op (mul: { } break; add: { } break; div: { } break; etc) + case ShaderGraph::NODE_RGB_OP: { + + gn->set_title("RGB Op"); + static const char* op_name[ShaderGraph::RGB_MAX_OP]={ + "Screen", + "Difference", + "Darken", + "Lighten", + "Overlay", + "Dodge", + "Burn", + "SoftLight", + "HardLight" + }; + + OptionButton *ob = memnew( OptionButton ); + for(int i=0;iadd_item(op_name[i],i); + } + + ob->select(graph->rgb_op_node_get_op(type,p_id)); + ob->connect("item_selected",this,"_rgb_op_changed",varray(p_id)); + gn->add_child(ob); + + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("a"))); + hbc->add_spacer(); + hbc->add_child( memnew(Label("out"))); + gn->add_child(hbc); + gn->add_child( memnew(Label("b"))); + + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); + + } break; // vec3 vs vec3 rgb op (with scalar amount): { } break; like brighten: { } break; darken: { } break; burn: { } break; dodge: { } break; multiply: { } break; etc. + case ShaderGraph::NODE_XFORM_MULT: { + + gn->set_title("XFMult"); + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_child( memnew(Label("a"))); + hbc->add_spacer(); + hbc->add_child( memnew(Label("out"))); + gn->add_child(hbc); + gn->add_child( memnew(Label("b"))); + + gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM],true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM]); + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM],false,0,Color()); + + + } break; // mat4 x mat4 + case ShaderGraph::NODE_XFORM_VEC_MULT: { + + gn->set_title("XFVecMult"); + + Button *button = memnew( Button("RotOnly")); + button->set_toggle_mode(true); + button->set_pressed(graph->xform_vec_mult_node_get_no_translation(type,p_id)); + button->connect("toggled",this,"_xform_inv_rev_changed",varray(p_id)); + + gn->add_child(button); + + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("xf"))); + hbc->add_spacer(); + Label *l = memnew(Label("out")); + l->set_align(Label::ALIGN_RIGHT); + hbc->add_child( l); + gn->add_child(hbc); + gn->add_child( memnew(Label("vec"))); + + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); + + } break; + case ShaderGraph::NODE_XFORM_VEC_INV_MULT: { + + gn->set_title("XFVecInvMult"); + + + Button *button = memnew( Button("RotOnly")); + button->set_toggle_mode(true); + button->set_pressed(graph->xform_vec_mult_node_get_no_translation(type,p_id)); + button->connect("toggled",this,"_xform_inv_rev_changed",varray(p_id)); + + gn->add_child(button); + + gn->add_child( memnew(Label("vec"))); + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("xf"))); + hbc->add_spacer(); + Label *l = memnew(Label("out")); + l->set_align(Label::ALIGN_RIGHT); + hbc->add_child( l); + gn->add_child(hbc); + + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); + gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + + + } break; // mat4 x vec3 inverse mult (with no-translation option) + case ShaderGraph::NODE_SCALAR_FUNC: { + + gn->set_title("ScalarFunc"); + static const char* func_name[ShaderGraph::SCALAR_MAX_FUNC]={ + "Sin", + "Cos", + "Tan", + "ASin", + "ACos", + "ATan", + "SinH", + "CosH", + "TanH", + "Log", + "Exp", + "Sqrt", + "Abs", + "Sign", + "Floor", + "Round", + "Ceil", + "Frac", + "Satr", + "Neg" + }; + + OptionButton *ob = memnew( OptionButton ); + for(int i=0;iadd_item(func_name[i],i); + } + + ob->select(graph->scalar_func_node_get_function(type,p_id)); + ob->connect("item_selected",this,"_scalar_func_changed",varray(p_id)); + gn->add_child(ob); + + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_child( memnew(Label("in"))); + hbc->add_spacer(); + hbc->add_child( memnew(Label("out"))); + gn->add_child(hbc); + + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + + + } break; // scalar function (sin: { } break; cos: { } break; etc) + case ShaderGraph::NODE_VEC_FUNC: { + + + + gn->set_title("VecFunc"); + static const char* func_name[ShaderGraph::VEC_MAX_FUNC]={ + "Normalize", + "Saturate", + "Negate", + "Reciprocal", + "RGB to HSV", + "HSV to RGB", + }; + + OptionButton *ob = memnew( OptionButton ); + for(int i=0;iadd_item(func_name[i],i); + } + + ob->select(graph->vec_func_node_get_function(type,p_id)); + ob->connect("item_selected",this,"_vec_func_changed",varray(p_id)); + gn->add_child(ob); + + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("in"))); + hbc->add_spacer(); + hbc->add_child( memnew(Label("out"))); + gn->add_child(hbc); + + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + + } break; // vector function (normalize: { } break; negate: { } break; reciprocal: { } break; rgb2hsv: { } break; hsv2rgb: { } break; etc: { } break; etc) + case ShaderGraph::NODE_VEC_LEN: { + gn->set_title("VecLength"); + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_child( memnew(Label("in"))); + hbc->add_spacer(); + hbc->add_child( memnew(Label("len"))); + gn->add_child(hbc); + + gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + + } break; // vec3 length + case ShaderGraph::NODE_DOT_PROD: { + + gn->set_title("DotProduct"); + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("a"))); + hbc->add_spacer(); + hbc->add_child( memnew(Label("dp"))); + gn->add_child(hbc); + gn->add_child( memnew(Label("b"))); + + gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); + + } break; // vec3 . vec3 (dot product -> scalar output) + case ShaderGraph::NODE_VEC_TO_SCALAR: { + + gn->set_title("Vec2Scalar"); + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("vec"))); + hbc->add_spacer(); + Label *l=memnew(Label("x")); + l->set_align(Label::ALIGN_RIGHT); + hbc->add_child( l); + gn->add_child(hbc); + l=memnew(Label("y")); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child( l ); + l=memnew(Label("z")); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child( l); + + gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + gn->set_slot(1,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + gn->set_slot(2,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + + + + + } break; // 1 vec3 input: { } break; 3 scalar outputs + case ShaderGraph::NODE_SCALAR_TO_VEC: { + + gn->set_title("Scalar2Vec"); + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_child( memnew(Label("x"))); + hbc->add_spacer(); + hbc->add_child( memnew(Label("vec"))); + gn->add_child(hbc); + gn->add_child( memnew(Label("y"))); + gn->add_child( memnew(Label("z"))); + + gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); + gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); + + } break; // 3 scalar input: { } break; 1 vec3 output + case ShaderGraph::NODE_VEC_TO_XFORM: { + + gn->set_title("Vec2XForm"); + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("x"))); + hbc->add_spacer(); + hbc->add_child( memnew(Label("xf"))); + gn->add_child(hbc); + gn->add_child( memnew(Label("y"))); + gn->add_child( memnew(Label("z"))); + gn->add_child( memnew(Label("ofs"))); + + gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM]); + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); + gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); + gn->set_slot(3,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); + + } break; // 3 vec input: { } break; 1 xform output + case ShaderGraph::NODE_XFORM_TO_VEC: { + + gn->set_title("XForm2Vec"); + + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("xf"))); + hbc->add_spacer(); + Label *l=memnew(Label("x")); + l->set_align(Label::ALIGN_RIGHT); + hbc->add_child( l); + gn->add_child(hbc); + l=memnew(Label("y")); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child( l ); + l=memnew(Label("z")); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child( l); + l=memnew(Label("ofs")); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child( l); + + gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(1,false,0,Color(),true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(2,false,0,Color(),true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(3,false,0,Color(),true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + + } break; // 3 vec input: { } break; 1 xform output + case ShaderGraph::NODE_SCALAR_INTERP: { + + gn->set_title("ScalarInterp"); + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("a"))); + hbc->add_spacer(); + hbc->add_child( memnew(Label("interp"))); + gn->add_child(hbc); + gn->add_child( memnew(Label("b"))); + gn->add_child( memnew(Label("c"))); + + gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); + gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); + + + } break; // scalar interpolation (with optional curve) + case ShaderGraph::NODE_VEC_INTERP: { + + gn->set_title("VecInterp"); + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_child( memnew(Label("a"))); + hbc->add_spacer(); + hbc->add_child( memnew(Label("interp"))); + gn->add_child(hbc); + gn->add_child( memnew(Label("b"))); + gn->add_child( memnew(Label("c"))); - gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); - gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); - gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); + gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); + gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); - } break; // vec3 interpolation (with optional curve) - case ShaderGraph::NODE_COLOR_RAMP: { - - gn->set_title("ColorRamp"); - GraphColorRampEdit * ramp = memnew( GraphColorRampEdit ); - - DVector offsets = graph->color_ramp_node_get_offsets(type,p_id); - DVector colors = graph->color_ramp_node_get_colors(type,p_id); - - int oc = offsets.size(); - - if (oc) { - DVector::Read rofs = offsets.read(); - DVector::Read rcol = colors.read(); - - Vector ofsv; - Vector colorv; - for(int i=0;iset_ramp(ofsv,colorv); - - } - - ramp->connect("ramp_changed",this,"_color_ramp_changed",varray(p_id,ramp)); - ramp->set_custom_minimum_size(Size2(128,1)); - gn->add_child(ramp); - - - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("c"))); - hbc->add_spacer(); - Label *l=memnew(Label("rgb")); - l->set_align(Label::ALIGN_RIGHT); - hbc->add_child( l); - gn->add_child(hbc); - l=memnew(Label("alpha")); - l->set_align(Label::ALIGN_RIGHT); - gn->add_child( l); - - - gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); - gn->set_slot(2,false,ShaderGraph::SLOT_MAX,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); - - - } break; // scalar interpolation (with optional curve) - case ShaderGraph::NODE_CURVE_MAP: { - - gn->set_title("CurveMap"); - GraphCurveMapEdit * map = memnew( GraphCurveMapEdit ); - - DVector points = graph->curve_map_node_get_points(type,p_id); - - int oc = points.size(); - - if (oc) { - DVector::Read rofs = points.read(); - - - Vector ofsv; - for(int i=0;iset_points(ofsv); - - } - map->connect("curve_changed",this,"_curve_changed",varray(p_id,map)); - - //map->connect("map_changed",this,"_curve_map_changed",varray(p_id,map)); - map->set_custom_minimum_size(Size2(128,64)); - gn->add_child(map); - - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("c"))); - hbc->add_spacer(); - Label *l=memnew(Label("cmap")); - l->set_align(Label::ALIGN_RIGHT); - hbc->add_child( l); - gn->add_child(hbc); - - - gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); - - - } break; // scalar interpolation (with optional curve) - - case ShaderGraph::NODE_SCALAR_INPUT: { - - gn->set_title("ScalarUniform"); - LineEdit *le = memnew( LineEdit ); - gn->add_child(le); - le->set_text(graph->input_node_get_name(type,p_id)); - le->connect("text_entered",this,"_input_name_changed",varray(p_id,le)); - SpinBox *sb = memnew( SpinBox ); - sb->set_min(-100000); - sb->set_max(100000); - sb->set_step(0.001); - sb->set_val(graph->scalar_input_node_get_value(type,p_id)); - sb->connect("value_changed",this,"_scalar_input_changed",varray(p_id)); - gn->add_child(sb); - gn->set_slot(1,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); - - } break; // scalar uniform (assignable in material) - case ShaderGraph::NODE_VEC_INPUT: { - - gn->set_title("VectorUniform"); - LineEdit *le = memnew( LineEdit ); - gn->add_child(le); - le->set_text(graph->input_node_get_name(type,p_id)); - le->connect("text_entered",this,"_input_name_changed",varray(p_id,le)); - Array v3p(true); - for(int i=0;i<3;i++) { - HBoxContainer *hbc = memnew( HBoxContainer ); - Label *l = memnew( Label ); - l->set_text(String::chr('X'+i)); - hbc->add_child(l); - SpinBox *sb = memnew( SpinBox ); - sb->set_h_size_flags(Control::SIZE_EXPAND_FILL); - sb->set_min(-100000); - sb->set_max(100000); - sb->set_step(0.001); - sb->set_val(graph->vec_input_node_get_value(type,p_id)[i]); - sb->connect("value_changed",this,"_vec_input_changed",varray(p_id,v3p)); - v3p.push_back(sb); - hbc->add_child(sb); - gn->add_child(hbc); - } - gn->set_slot(1,false,0,Color(),true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); - - } break; // vec3 uniform (assignable in material) - case ShaderGraph::NODE_RGB_INPUT: { - - gn->set_title("ColorUniform"); - LineEdit *le = memnew( LineEdit ); - gn->add_child(le); - le->set_text(graph->input_node_get_name(type,p_id)); - le->connect("text_entered",this,"_input_name_changed",varray(p_id,le)); - ColorPickerButton *cpb = memnew( ColorPickerButton ); - cpb->set_color(graph->rgb_input_node_get_value(type,p_id)); - cpb->connect("color_changed",this,"_rgb_input_changed",varray(p_id)); - gn->add_child(cpb); - Label *l = memnew( Label ); - l->set_text("RGB"); - l->set_align(Label::ALIGN_RIGHT); - gn->add_child(l); - l = memnew( Label ); - l->set_text("Alpha"); - l->set_align(Label::ALIGN_RIGHT); - gn->add_child(l); - - gn->set_slot(2,false,0,Color(),true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); - gn->set_slot(3,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); - - - } break; // color uniform (assignable in material) - case ShaderGraph::NODE_XFORM_INPUT: { - gn->set_title("XFUniform"); - LineEdit *le = memnew( LineEdit ); - gn->add_child(le); - le->set_text(graph->input_node_get_name(type,p_id)); - le->connect("text_entered",this,"_input_name_changed",varray(p_id,le)); - ToolButton *edit = memnew( ToolButton ); - edit->set_text("edit.."); - edit->connect("pressed",this,"_xform_input_changed",varray(p_id,edit)); - gn->add_child(edit); - gn->set_slot(1,false,0,Color(),true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM]); - - } break; // mat4 uniform (assignable in material) - case ShaderGraph::NODE_TEXTURE_INPUT: { - - gn->set_title("TexUniform"); - LineEdit *le = memnew( LineEdit ); - gn->add_child(le); - le->set_text(graph->input_node_get_name(type,p_id)); - le->connect("text_entered",this,"_input_name_changed",varray(p_id,le)); - TextureFrame *tex = memnew( TextureFrame ); - tex->set_expand(true); - tex->set_custom_minimum_size(Size2(80,80)); - gn->add_child(tex); - tex->set_texture(graph->texture_input_node_get_value(type,p_id)); - ToolButton *edit = memnew( ToolButton ); - edit->set_text("edit.."); - edit->connect("pressed",this,"_tex_edited",varray(p_id,edit)); - gn->add_child(edit); - - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("UV"))); - hbc->add_spacer(); - Label *l=memnew(Label("RGB")); - l->set_align(Label::ALIGN_RIGHT); - hbc->add_child(l); - gn->add_child(hbc); - l = memnew( Label ); - l->set_text("Alpha"); - l->set_align(Label::ALIGN_RIGHT); - gn->add_child(l); - - gn->set_slot(3,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); - gn->set_slot(4,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); - - } break; // texture input (assignable in material) - case ShaderGraph::NODE_CUBEMAP_INPUT: { - - gn->set_title("TexUniform"); - LineEdit *le = memnew( LineEdit ); - gn->add_child(le); - le->set_text(graph->input_node_get_name(type,p_id)); - le->connect("text_entered",this,"_input_name_changed",varray(p_id,le)); - - ToolButton *edit = memnew( ToolButton ); - edit->set_text("edit.."); - edit->connect("pressed",this,"_cube_edited",varray(p_id,edit)); - gn->add_child(edit); - - - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("UV"))); - hbc->add_spacer(); - Label *l=memnew(Label("RGB")); - l->set_align(Label::ALIGN_RIGHT); - hbc->add_child(l); - gn->add_child(hbc); - l = memnew( Label ); - l->set_text("Alpha"); - l->set_align(Label::ALIGN_RIGHT); - gn->add_child(l); - - gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); - gn->set_slot(3,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); - - } break; // cubemap input (assignable in material) - case ShaderGraph::NODE_DEFAULT_TEXTURE: { - - gn->set_title("CanvasItemTex"); - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("UV"))); - hbc->add_spacer(); - Label *l=memnew(Label("RGB")); - l->set_align(Label::ALIGN_RIGHT); - hbc->add_child(l); - gn->add_child(hbc); - l = memnew( Label ); - l->set_text("Alpha"); - l->set_align(Label::ALIGN_RIGHT); - gn->add_child(l); - - gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); - gn->set_slot(1,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); - - - } break; // screen texture sampler (takes UV) (only usable in fragment case Shader) - - case ShaderGraph::NODE_OUTPUT: { - gn->set_title("Output"); - - List si; - ShaderGraph::get_input_output_node_slot_info(graph->get_mode(),type,&si); - - int idx=0; - for (List::Element *E=si.front();E;E=E->next()) { - ShaderGraph::SlotInfo& s=E->get(); - if (s.dir==ShaderGraph::SLOT_OUT) { - - Label *l= memnew( Label ); - l->set_text(s.name); - l->set_align(Label::ALIGN_LEFT); - gn->add_child(l); - gn->set_slot(idx,true,s.type,typecol[s.type],false,0,Color()); - idx++; - } - } - - } break; // output (case Shader type dependent) - case ShaderGraph::NODE_COMMENT: { - gn->set_title("Comment"); - TextEdit *te = memnew(TextEdit); - te->set_custom_minimum_size(Size2(100,100)); - gn->add_child(te); - te->set_text(graph->comment_node_get_text(type,p_id)); - te->connect("text_changed",this,"_comment_edited",varray(p_id,te)); - - } break; // comment - - - - } - - gn->connect("dragged",this,"_node_moved",varray(p_id)); - gn->connect("close_request",this,"_node_removed",varray(p_id),CONNECT_DEFERRED); - graph_edit->add_child(gn); - node_map[p_id]=gn; - gn->set_offset(graph->node_get_pos(type,p_id)); + } break; // vec3 interpolation (with optional curve) + case ShaderGraph::NODE_COLOR_RAMP: { + + gn->set_title("ColorRamp"); + GraphColorRampEdit * ramp = memnew( GraphColorRampEdit ); + + DVector offsets = graph->color_ramp_node_get_offsets(type,p_id); + DVector colors = graph->color_ramp_node_get_colors(type,p_id); + + int oc = offsets.size(); + + if (oc) { + DVector::Read rofs = offsets.read(); + DVector::Read rcol = colors.read(); + + Vector ofsv; + Vector colorv; + for(int i=0;iset_ramp(ofsv,colorv); + + } + + ramp->connect("ramp_changed",this,"_color_ramp_changed",varray(p_id,ramp)); + ramp->set_custom_minimum_size(Size2(128,1)); + gn->add_child(ramp); + + + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("c"))); + hbc->add_spacer(); + Label *l=memnew(Label("rgb")); + l->set_align(Label::ALIGN_RIGHT); + hbc->add_child( l); + gn->add_child(hbc); + l=memnew(Label("alpha")); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child( l); + + + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(2,false,ShaderGraph::SLOT_MAX,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + + + } break; // scalar interpolation (with optional curve) + case ShaderGraph::NODE_CURVE_MAP: { + + gn->set_title("CurveMap"); + GraphCurveMapEdit * map = memnew( GraphCurveMapEdit ); + + DVector points = graph->curve_map_node_get_points(type,p_id); + + int oc = points.size(); + + if (oc) { + DVector::Read rofs = points.read(); + + + Vector ofsv; + for(int i=0;iset_points(ofsv); + + } + map->connect("curve_changed",this,"_curve_changed",varray(p_id,map)); + + //map->connect("map_changed",this,"_curve_map_changed",varray(p_id,map)); + map->set_custom_minimum_size(Size2(128,64)); + gn->add_child(map); + + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("c"))); + hbc->add_spacer(); + Label *l=memnew(Label("cmap")); + l->set_align(Label::ALIGN_RIGHT); + hbc->add_child( l); + gn->add_child(hbc); + + + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + + + } break; // scalar interpolation (with optional curve) + + case ShaderGraph::NODE_SCALAR_INPUT: { + + gn->set_title("ScalarUniform"); + LineEdit *le = memnew( LineEdit ); + gn->add_child(le); + le->set_text(graph->input_node_get_name(type,p_id)); + le->connect("text_entered",this,"_input_name_changed",varray(p_id,le)); + SpinBox *sb = memnew( SpinBox ); + sb->set_min(-100000); + sb->set_max(100000); + sb->set_step(0.001); + sb->set_val(graph->scalar_input_node_get_value(type,p_id)); + sb->connect("value_changed",this,"_scalar_input_changed",varray(p_id)); + gn->add_child(sb); + gn->set_slot(1,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + + } break; // scalar uniform (assignable in material) + case ShaderGraph::NODE_VEC_INPUT: { + + gn->set_title("VectorUniform"); + LineEdit *le = memnew( LineEdit ); + gn->add_child(le); + le->set_text(graph->input_node_get_name(type,p_id)); + le->connect("text_entered",this,"_input_name_changed",varray(p_id,le)); + Array v3p(true); + for(int i=0;i<3;i++) { + HBoxContainer *hbc = memnew( HBoxContainer ); + Label *l = memnew( Label ); + l->set_text(String::chr('X'+i)); + hbc->add_child(l); + SpinBox *sb = memnew( SpinBox ); + sb->set_h_size_flags(Control::SIZE_EXPAND_FILL); + sb->set_min(-100000); + sb->set_max(100000); + sb->set_step(0.001); + sb->set_val(graph->vec_input_node_get_value(type,p_id)[i]); + sb->connect("value_changed",this,"_vec_input_changed",varray(p_id,v3p)); + v3p.push_back(sb); + hbc->add_child(sb); + gn->add_child(hbc); + } + gn->set_slot(1,false,0,Color(),true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + + } break; // vec3 uniform (assignable in material) + case ShaderGraph::NODE_RGB_INPUT: { + + gn->set_title("ColorUniform"); + LineEdit *le = memnew( LineEdit ); + gn->add_child(le); + le->set_text(graph->input_node_get_name(type,p_id)); + le->connect("text_entered",this,"_input_name_changed",varray(p_id,le)); + ColorPickerButton *cpb = memnew( ColorPickerButton ); + cpb->set_color(graph->rgb_input_node_get_value(type,p_id)); + cpb->connect("color_changed",this,"_rgb_input_changed",varray(p_id)); + gn->add_child(cpb); + Label *l = memnew( Label ); + l->set_text("RGB"); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child(l); + l = memnew( Label ); + l->set_text("Alpha"); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child(l); + + gn->set_slot(2,false,0,Color(),true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(3,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + + + } break; // color uniform (assignable in material) + case ShaderGraph::NODE_XFORM_INPUT: { + gn->set_title("XFUniform"); + LineEdit *le = memnew( LineEdit ); + gn->add_child(le); + le->set_text(graph->input_node_get_name(type,p_id)); + le->connect("text_entered",this,"_input_name_changed",varray(p_id,le)); + ToolButton *edit = memnew( ToolButton ); + edit->set_text("edit.."); + edit->connect("pressed",this,"_xform_input_changed",varray(p_id,edit)); + gn->add_child(edit); + gn->set_slot(1,false,0,Color(),true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM]); + + } break; // mat4 uniform (assignable in material) + case ShaderGraph::NODE_TEXTURE_INPUT: { + + gn->set_title("TexUniform"); + LineEdit *le = memnew( LineEdit ); + gn->add_child(le); + le->set_text(graph->input_node_get_name(type,p_id)); + le->connect("text_entered",this,"_input_name_changed",varray(p_id,le)); + TextureFrame *tex = memnew( TextureFrame ); + tex->set_expand(true); + tex->set_custom_minimum_size(Size2(80,80)); + gn->add_child(tex); + tex->set_texture(graph->texture_input_node_get_value(type,p_id)); + ToolButton *edit = memnew( ToolButton ); + edit->set_text("edit.."); + edit->connect("pressed",this,"_tex_edited",varray(p_id,edit)); + gn->add_child(edit); + + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("UV"))); + hbc->add_spacer(); + Label *l=memnew(Label("RGB")); + l->set_align(Label::ALIGN_RIGHT); + hbc->add_child(l); + gn->add_child(hbc); + l = memnew( Label ); + l->set_text("Alpha"); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child(l); + + gn->set_slot(3,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(4,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + + } break; // texture input (assignable in material) + case ShaderGraph::NODE_CUBEMAP_INPUT: { + + gn->set_title("TexUniform"); + LineEdit *le = memnew( LineEdit ); + gn->add_child(le); + le->set_text(graph->input_node_get_name(type,p_id)); + le->connect("text_entered",this,"_input_name_changed",varray(p_id,le)); + + ToolButton *edit = memnew( ToolButton ); + edit->set_text("edit.."); + edit->connect("pressed",this,"_cube_edited",varray(p_id,edit)); + gn->add_child(edit); + + + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("UV"))); + hbc->add_spacer(); + Label *l=memnew(Label("RGB")); + l->set_align(Label::ALIGN_RIGHT); + hbc->add_child(l); + gn->add_child(hbc); + l = memnew( Label ); + l->set_text("Alpha"); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child(l); + + gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(3,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + + } break; // cubemap input (assignable in material) + case ShaderGraph::NODE_DEFAULT_TEXTURE: { + + gn->set_title("CanvasItemTex"); + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("UV"))); + hbc->add_spacer(); + Label *l=memnew(Label("RGB")); + l->set_align(Label::ALIGN_RIGHT); + hbc->add_child(l); + gn->add_child(hbc); + l = memnew( Label ); + l->set_text("Alpha"); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child(l); + + gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(1,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + + + } break; // screen texture sampler (takes UV) (only usable in fragment case Shader) + + case ShaderGraph::NODE_OUTPUT: { + gn->set_title("Output"); + gn->set_show_close_button(false); + + List si; + ShaderGraph::get_input_output_node_slot_info(graph->get_mode(),type,&si); + + int idx=0; + for (List::Element *E=si.front();E;E=E->next()) { + ShaderGraph::SlotInfo& s=E->get(); + if (s.dir==ShaderGraph::SLOT_OUT) { + + Label *l= memnew( Label ); + l->set_text(s.name); + l->set_align(Label::ALIGN_LEFT); + gn->add_child(l); + gn->set_slot(idx,true,s.type,typecol[s.type],false,0,Color()); + idx++; + } + } + + } break; // output (case Shader type dependent) + case ShaderGraph::NODE_COMMENT: { + gn->set_title("Comment"); + TextEdit *te = memnew(TextEdit); + te->set_custom_minimum_size(Size2(100,100)); + gn->add_child(te); + te->set_text(graph->comment_node_get_text(type,p_id)); + te->connect("text_changed",this,"_comment_edited",varray(p_id,te)); + + } break; // comment + + + + } + + gn->connect("dragged",this,"_node_moved",varray(p_id)); + gn->connect("close_request",this,"_node_removed",varray(p_id),CONNECT_DEFERRED); + graph_edit->add_child(gn); + node_map[p_id]=gn; + gn->set_offset(graph->node_get_pos(type,p_id)); } @@ -2045,36 +2056,36 @@ void ShaderGraphView::_create_node(int p_id) { void ShaderGraphView::_update_graph() { - if (block_update) - return; + if (block_update) + return; - for (Map::Element *E=node_map.front();E;E=E->next()) { + for (Map::Element *E=node_map.front();E;E=E->next()) { - memdelete(E->get()); - } + memdelete(E->get()); + } - node_map.clear(); + node_map.clear(); - if (!graph.is_valid()) - return; + if (!graph.is_valid()) + return; - List nl; - graph->get_node_list(type,&nl); + List nl; + graph->get_node_list(type,&nl); - for(List::Element *E=nl.front();E;E=E->next()) { + for(List::Element *E=nl.front();E;E=E->next()) { - _create_node(E->get()); - } - graph_edit->clear_connections(); + _create_node(E->get()); + } + graph_edit->clear_connections(); - List connections; - graph->get_node_connections(type,&connections); - for(List::Element *E=connections.front();E;E=E->next()) { + List connections; + graph->get_node_connections(type,&connections); + for(List::Element *E=connections.front();E;E=E->next()) { - ERR_CONTINUE(!node_map.has(E->get().src_id) || !node_map.has(E->get().dst_id)); - graph_edit->connect_node(node_map[E->get().src_id]->get_name(),E->get().src_slot,node_map[E->get().dst_id]->get_name(),E->get().dst_slot); - } + ERR_CONTINUE(!node_map.has(E->get().src_id) || !node_map.has(E->get().dst_id)); + graph_edit->connect_node(node_map[E->get().src_id]->get_name(),E->get().src_slot,node_map[E->get().dst_id]->get_name(),E->get().dst_slot); + } @@ -2082,305 +2093,309 @@ void ShaderGraphView::_update_graph() { void ShaderGraphView::_sg_updated() { - if (!graph.is_valid()) - return; - switch(graph->get_graph_error(type)) { - case ShaderGraph::GRAPH_OK: status->set_text(""); break; - case ShaderGraph::GRAPH_ERROR_CYCLIC: status->set_text("Error: Cyclic Connection Link"); break; - case ShaderGraph::GRAPH_ERROR_MISSING_CONNECTIONS: status->set_text("Error: Missing Input Connections"); break; - } + if (!graph.is_valid()) + return; + switch(graph->get_graph_error(type)) { + case ShaderGraph::GRAPH_OK: status->set_text(""); break; + case ShaderGraph::GRAPH_ERROR_CYCLIC: status->set_text("Error: Cyclic Connection Link"); break; + case ShaderGraph::GRAPH_ERROR_MISSING_CONNECTIONS: status->set_text("Error: Missing Input Connections"); break; + } } void ShaderGraphView::set_graph(Ref p_graph){ - if (graph.is_valid()) { - graph->disconnect("updated",this,"_sg_updated"); - } - graph=p_graph; - if (graph.is_valid()) { - graph->connect("updated",this,"_sg_updated"); - } - _update_graph(); - _sg_updated(); + if (graph.is_valid()) { + graph->disconnect("updated",this,"_sg_updated"); + } + graph=p_graph; + if (graph.is_valid()) { + graph->connect("updated",this,"_sg_updated"); + } + _update_graph(); + _sg_updated(); } void ShaderGraphView::_notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_TREE) { + if (p_what==NOTIFICATION_ENTER_TREE) { - ped_popup->connect("variant_changed",this,"_variant_edited"); - } + ped_popup->connect("variant_changed",this,"_variant_edited"); + } } void ShaderGraphView::add_node(int p_type, const Vector2 &location) { - List existing; - graph->get_node_list(type,&existing); - existing.sort(); - int newid=1; - for(List::Element *E=existing.front();E;E=E->next()) { - if (!E->next() || (E->get()+1!=E->next()->get())){ - newid=E->get()+1; - break; - } - } - - Vector2 init_ofs = location; - while(true) { - bool valid=true; - for(List::Element *E=existing.front();E;E=E->next()) { - Vector2 pos = graph->node_get_pos(type,E->get()); - if (init_ofs==pos) { - init_ofs+=Vector2(20,20); - valid=false; - break; - - } - } - - if (valid) - break; - } - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - ur->create_action("Add Shader Graph Node"); - ur->add_do_method(graph.ptr(),"node_add",type,p_type,newid); - ur->add_do_method(graph.ptr(),"node_set_pos",type,newid,init_ofs); - ur->add_undo_method(graph.ptr(),"node_remove",type,newid); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - ur->commit_action(); + List existing; + graph->get_node_list(type,&existing); + existing.sort(); + int newid=1; + for(List::Element *E=existing.front();E;E=E->next()) { + if (!E->next() || (E->get()+1!=E->next()->get())){ + newid=E->get()+1; + break; + } + } + + Vector2 init_ofs = location; + while(true) { + bool valid=true; + for(List::Element *E=existing.front();E;E=E->next()) { + Vector2 pos = graph->node_get_pos(type,E->get()); + if (init_ofs==pos) { + init_ofs+=Vector2(20,20); + valid=false; + break; + + } + } + + if (valid) + break; + } + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Add Shader Graph Node"); + ur->add_do_method(graph.ptr(),"node_add",type,p_type,newid); + ur->add_do_method(graph.ptr(),"node_set_pos",type,newid,init_ofs); + ur->add_undo_method(graph.ptr(),"node_remove",type,newid); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + ur->commit_action(); } void ShaderGraphView::_bind_methods() { - ObjectTypeDB::bind_method("_update_graph",&ShaderGraphView::_update_graph); - ObjectTypeDB::bind_method("_node_moved",&ShaderGraphView::_node_moved); - ObjectTypeDB::bind_method("_move_node",&ShaderGraphView::_move_node); - ObjectTypeDB::bind_method("_node_removed",&ShaderGraphView::_node_removed); - ObjectTypeDB::bind_method("_connection_request",&ShaderGraphView::_connection_request); - ObjectTypeDB::bind_method("_disconnection_request",&ShaderGraphView::_disconnection_request); - - ObjectTypeDB::bind_method("_scalar_const_changed",&ShaderGraphView::_scalar_const_changed); - ObjectTypeDB::bind_method("_vec_const_changed",&ShaderGraphView::_vec_const_changed); - ObjectTypeDB::bind_method("_rgb_const_changed",&ShaderGraphView::_rgb_const_changed); - ObjectTypeDB::bind_method("_xform_const_changed",&ShaderGraphView::_xform_const_changed); - ObjectTypeDB::bind_method("_scalar_op_changed",&ShaderGraphView::_scalar_op_changed); - ObjectTypeDB::bind_method("_vec_op_changed",&ShaderGraphView::_vec_op_changed); - ObjectTypeDB::bind_method("_vec_scalar_op_changed",&ShaderGraphView::_vec_scalar_op_changed); - ObjectTypeDB::bind_method("_rgb_op_changed",&ShaderGraphView::_rgb_op_changed); - ObjectTypeDB::bind_method("_xform_inv_rev_changed",&ShaderGraphView::_xform_inv_rev_changed); - ObjectTypeDB::bind_method("_scalar_func_changed",&ShaderGraphView::_scalar_func_changed); - ObjectTypeDB::bind_method("_vec_func_changed",&ShaderGraphView::_vec_func_changed); - ObjectTypeDB::bind_method("_scalar_input_changed",&ShaderGraphView::_scalar_input_changed); - ObjectTypeDB::bind_method("_vec_input_changed",&ShaderGraphView::_vec_input_changed); - ObjectTypeDB::bind_method("_xform_input_changed",&ShaderGraphView::_xform_input_changed); - ObjectTypeDB::bind_method("_rgb_input_changed",&ShaderGraphView::_rgb_input_changed); - ObjectTypeDB::bind_method("_tex_input_change",&ShaderGraphView::_tex_input_change); - ObjectTypeDB::bind_method("_cube_input_change",&ShaderGraphView::_cube_input_change); - ObjectTypeDB::bind_method("_input_name_changed",&ShaderGraphView::_input_name_changed); - ObjectTypeDB::bind_method("_tex_edited",&ShaderGraphView::_tex_edited); - ObjectTypeDB::bind_method("_variant_edited",&ShaderGraphView::_variant_edited); - ObjectTypeDB::bind_method("_cube_edited",&ShaderGraphView::_cube_edited); - ObjectTypeDB::bind_method("_comment_edited",&ShaderGraphView::_comment_edited); - ObjectTypeDB::bind_method("_color_ramp_changed",&ShaderGraphView::_color_ramp_changed); - ObjectTypeDB::bind_method("_curve_changed",&ShaderGraphView::_curve_changed); - - ObjectTypeDB::bind_method("_sg_updated",&ShaderGraphView::_sg_updated); + ObjectTypeDB::bind_method("_update_graph",&ShaderGraphView::_update_graph); + ObjectTypeDB::bind_method("_begin_node_move", &ShaderGraphView::_begin_node_move); + ObjectTypeDB::bind_method("_node_moved",&ShaderGraphView::_node_moved); + ObjectTypeDB::bind_method("_end_node_move", &ShaderGraphView::_end_node_move); + ObjectTypeDB::bind_method("_move_node",&ShaderGraphView::_move_node); + ObjectTypeDB::bind_method("_node_removed",&ShaderGraphView::_node_removed); + ObjectTypeDB::bind_method("_connection_request",&ShaderGraphView::_connection_request); + ObjectTypeDB::bind_method("_disconnection_request",&ShaderGraphView::_disconnection_request); + + ObjectTypeDB::bind_method("_scalar_const_changed",&ShaderGraphView::_scalar_const_changed); + ObjectTypeDB::bind_method("_vec_const_changed",&ShaderGraphView::_vec_const_changed); + ObjectTypeDB::bind_method("_rgb_const_changed",&ShaderGraphView::_rgb_const_changed); + ObjectTypeDB::bind_method("_xform_const_changed",&ShaderGraphView::_xform_const_changed); + ObjectTypeDB::bind_method("_scalar_op_changed",&ShaderGraphView::_scalar_op_changed); + ObjectTypeDB::bind_method("_vec_op_changed",&ShaderGraphView::_vec_op_changed); + ObjectTypeDB::bind_method("_vec_scalar_op_changed",&ShaderGraphView::_vec_scalar_op_changed); + ObjectTypeDB::bind_method("_rgb_op_changed",&ShaderGraphView::_rgb_op_changed); + ObjectTypeDB::bind_method("_xform_inv_rev_changed",&ShaderGraphView::_xform_inv_rev_changed); + ObjectTypeDB::bind_method("_scalar_func_changed",&ShaderGraphView::_scalar_func_changed); + ObjectTypeDB::bind_method("_vec_func_changed",&ShaderGraphView::_vec_func_changed); + ObjectTypeDB::bind_method("_scalar_input_changed",&ShaderGraphView::_scalar_input_changed); + ObjectTypeDB::bind_method("_vec_input_changed",&ShaderGraphView::_vec_input_changed); + ObjectTypeDB::bind_method("_xform_input_changed",&ShaderGraphView::_xform_input_changed); + ObjectTypeDB::bind_method("_rgb_input_changed",&ShaderGraphView::_rgb_input_changed); + ObjectTypeDB::bind_method("_tex_input_change",&ShaderGraphView::_tex_input_change); + ObjectTypeDB::bind_method("_cube_input_change",&ShaderGraphView::_cube_input_change); + ObjectTypeDB::bind_method("_input_name_changed",&ShaderGraphView::_input_name_changed); + ObjectTypeDB::bind_method("_tex_edited",&ShaderGraphView::_tex_edited); + ObjectTypeDB::bind_method("_variant_edited",&ShaderGraphView::_variant_edited); + ObjectTypeDB::bind_method("_cube_edited",&ShaderGraphView::_cube_edited); + ObjectTypeDB::bind_method("_comment_edited",&ShaderGraphView::_comment_edited); + ObjectTypeDB::bind_method("_color_ramp_changed",&ShaderGraphView::_color_ramp_changed); + ObjectTypeDB::bind_method("_curve_changed",&ShaderGraphView::_curve_changed); + + ObjectTypeDB::bind_method("_sg_updated",&ShaderGraphView::_sg_updated); } ShaderGraphView::ShaderGraphView(ShaderGraph::ShaderType p_type) { - type=p_type; - graph_edit = memnew( GraphEdit ); - block_update=false; - ped_popup = memnew( CustomPropertyEditor ); - graph_edit->add_child(ped_popup); - status = memnew( Label ); - graph_edit->get_top_layer()->add_child(status); - status->set_pos(Vector2(5,5)); - status->add_color_override("font_color_shadow",Color(0,0,0)); - status->add_color_override("font_color",Color(1,0.4,0.3)); - status->add_constant_override("shadow_as_outline",1); - status->add_constant_override("shadow_offset_x",2); - status->add_constant_override("shadow_offset_y",2); - status->set_text(""); + type=p_type; + graph_edit = memnew( GraphEdit ); + block_update=false; + ped_popup = memnew( CustomPropertyEditor ); + graph_edit->add_child(ped_popup); + status = memnew( Label ); + graph_edit->get_top_layer()->add_child(status); + graph_edit->connect("_begin_node_move", this, "_begin_node_move"); + graph_edit->connect("_end_node_move", this, "_end_node_move"); + status->set_pos(Vector2(5,5)); + status->add_color_override("font_color_shadow",Color(0,0,0)); + status->add_color_override("font_color",Color(1,0.4,0.3)); + status->add_constant_override("shadow_as_outline",1); + status->add_constant_override("shadow_offset_x",2); + status->add_constant_override("shadow_offset_y",2); + status->set_text(""); } //////////////edit////////////// void ShaderGraphEditor::edit(Ref p_shader) { - for(int i=0;iset_graph(p_shader); - } + for(int i=0;iset_graph(p_shader); + } } void ShaderGraphEditor::_add_node(int p_type) { - ShaderGraph::ShaderType shader_type=ShaderGraph::ShaderType(tabs->get_current_tab()); + ShaderGraph::ShaderType shader_type=ShaderGraph::ShaderType(tabs->get_current_tab()); - graph_edits[shader_type]->add_node(p_type, next_location); + graph_edits[shader_type]->add_node(p_type, next_location); } void ShaderGraphEditor::_popup_requested(const Vector2 &p_position) { - next_location = get_local_mouse_pos(); - popup->set_global_pos(p_position); - popup->set_size( Size2( 200, 0) ); - popup->popup(); - popup->call_deferred("grab_click_focus"); - popup->set_invalidate_click_until_motion(); + next_location = get_local_mouse_pos(); + popup->set_global_pos(p_position); + popup->set_size( Size2( 200, 0) ); + popup->popup(); + popup->call_deferred("grab_click_focus"); + popup->set_invalidate_click_until_motion(); } void ShaderGraphEditor::_notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_TREE) { + if (p_what==NOTIFICATION_ENTER_TREE) { - for(int i=0;iadd_icon_item(get_icon(ic,"EditorIcons"),v,i); - if (addsep) - popup->add_separator(); - } - popup->connect("item_pressed",this,"_add_node"); + String nn = node_names[i]; + String ic = nn.get_slice(":",0); + String v = nn.get_slice(":",1); + bool addsep=false; + if (nn.ends_with(":")) { + addsep=true; + } + popup->add_icon_item(get_icon(ic,"EditorIcons"),v,i); + if (addsep) + popup->add_separator(); + } + popup->connect("item_pressed",this,"_add_node"); - } + } } void ShaderGraphEditor::_bind_methods() { - ObjectTypeDB::bind_method("_add_node",&ShaderGraphEditor::_add_node); - ObjectTypeDB::bind_method("_popup_requested",&ShaderGraphEditor::_popup_requested); + ObjectTypeDB::bind_method("_add_node",&ShaderGraphEditor::_add_node); + ObjectTypeDB::bind_method("_popup_requested",&ShaderGraphEditor::_popup_requested); } const char* ShaderGraphEditor::node_names[ShaderGraph::NODE_TYPE_MAX]={ - "GraphInput:Input", // all inputs (shader type dependent) - "GraphScalar:Scalar Constant", //scalar constant - "GraphVector:Vector Constant", //vec3 constant - "GraphRgb:RGB Constant", //rgb constant (shows a color picker instead) - "GraphXform:XForm Constant", // 4x4 matrix constant - "GraphTime:Time:", // time in seconds - "GraphTexscreen:Screen Sample", // screen texture sampler (takes uv) (only usable in fragment shader) - "GraphScalarOp:Scalar Operator", // scalar vs scalar op (mul", add", div", etc) - "GraphVecOp:Vector Operator", // vec3 vs vec3 op (mul",ad",div",crossprod",etc) - "GraphVecScalarOp:Scalar+Vector Operator", // vec3 vs scalar op (mul", add", div", etc) - "GraphRgbOp:RGB Operator:", // vec3 vs vec3 rgb op (with scalar amount)", like brighten", darken", burn", dodge", multiply", etc. - "GraphXformMult:XForm Multiply", // mat4 x mat4 - "GraphXformVecMult:XForm+Vector Multiply", // mat4 x vec3 mult (with no-translation option) - "GraphXformVecImult:Form+Vector InvMultiply:", // mat4 x vec3 inverse mult (with no-translation option) - "GraphXformScalarFunc:Scalar Function", // scalar function (sin", cos", etc) - "GraphXformVecFunc:Vector Function", // vector function (normalize", negate", reciprocal", rgb2hsv", hsv2rgb", etc", etc) - "GraphVecLength:Vector Length", // vec3 length - "GraphVecDp:Dot Product:", // vec3 . vec3 (dot product -> scalar output) - "GraphVecToScalars:Vector -> Scalars", // 1 vec3 input", 3 scalar outputs - "GraphScalarsToVec:Scalars -> Vector", // 3 scalar input", 1 vec3 output - "GraphXformToVecs:XForm -> Vectors", // 3 vec input", 1 xform output - "GraphVecsToXform:Vectors -> XForm:", // 3 vec input", 1 xform output - "GraphScalarInterp:Scalar Interpolate", // scalar interpolation (with optional curve) - "GraphVecInterp:Vector Interpolate:", // vec3 interpolation (with optional curve) - "GraphColorRamp:Color Ramp", // vec3 interpolation (with optional curve) - "GraphCurveMap:Curve Remap:", // vec3 interpolation (with optional curve) - "GraphScalarUniform:Scalar Uniform", // scalar uniform (assignable in material) - "GraphVectorUniform:Vector Uniform", // vec3 uniform (assignable in material) - "GraphRgbUniform:RGB Uniform", // color uniform (assignable in material) - "GraphXformUniform:XForm Uniform", // mat4 uniform (assignable in material) - "GraphTextureUniform:Texture Uniform", // texture input (assignable in material) - "GraphCubeUniform:CubeMap Uniform:", // cubemap input (assignable in material) - "GraphDefaultTexture:CanvasItem Texture:", // cubemap input (assignable in material) - "Output", // output (shader type dependent) - "GraphComment:Comment", // comment + "GraphInput:Input", // all inputs (shader type dependent) + "GraphScalar:Scalar Constant", //scalar constant + "GraphVector:Vector Constant", //vec3 constant + "GraphRgb:RGB Constant", //rgb constant (shows a color picker instead) + "GraphXform:XForm Constant", // 4x4 matrix constant + "GraphTime:Time:", // time in seconds + "GraphTexscreen:Screen Sample", // screen texture sampler (takes uv) (only usable in fragment shader) + "GraphScalarOp:Scalar Operator", // scalar vs scalar op (mul", add", div", etc) + "GraphVecOp:Vector Operator", // vec3 vs vec3 op (mul",ad",div",crossprod",etc) + "GraphVecScalarOp:Scalar+Vector Operator", // vec3 vs scalar op (mul", add", div", etc) + "GraphRgbOp:RGB Operator:", // vec3 vs vec3 rgb op (with scalar amount)", like brighten", darken", burn", dodge", multiply", etc. + "GraphXformMult:XForm Multiply", // mat4 x mat4 + "GraphXformVecMult:XForm+Vector Multiply", // mat4 x vec3 mult (with no-translation option) + "GraphXformVecImult:Form+Vector InvMultiply:", // mat4 x vec3 inverse mult (with no-translation option) + "GraphXformScalarFunc:Scalar Function", // scalar function (sin", cos", etc) + "GraphXformVecFunc:Vector Function", // vector function (normalize", negate", reciprocal", rgb2hsv", hsv2rgb", etc", etc) + "GraphVecLength:Vector Length", // vec3 length + "GraphVecDp:Dot Product:", // vec3 . vec3 (dot product -> scalar output) + "GraphVecToScalars:Vector -> Scalars", // 1 vec3 input", 3 scalar outputs + "GraphScalarsToVec:Scalars -> Vector", // 3 scalar input", 1 vec3 output + "GraphXformToVecs:XForm -> Vectors", // 3 vec input", 1 xform output + "GraphVecsToXform:Vectors -> XForm:", // 3 vec input", 1 xform output + "GraphScalarInterp:Scalar Interpolate", // scalar interpolation (with optional curve) + "GraphVecInterp:Vector Interpolate:", // vec3 interpolation (with optional curve) + "GraphColorRamp:Color Ramp", // vec3 interpolation (with optional curve) + "GraphCurveMap:Curve Remap:", // vec3 interpolation (with optional curve) + "GraphScalarUniform:Scalar Uniform", // scalar uniform (assignable in material) + "GraphVectorUniform:Vector Uniform", // vec3 uniform (assignable in material) + "GraphRgbUniform:RGB Uniform", // color uniform (assignable in material) + "GraphXformUniform:XForm Uniform", // mat4 uniform (assignable in material) + "GraphTextureUniform:Texture Uniform", // texture input (assignable in material) + "GraphCubeUniform:CubeMap Uniform:", // cubemap input (assignable in material) + "GraphDefaultTexture:CanvasItem Texture:", // cubemap input (assignable in material) + "Output", // output (shader type dependent) + "GraphComment:Comment", // comment }; ShaderGraphEditor::ShaderGraphEditor(bool p_2d) { - _2d=p_2d; + _2d=p_2d; - HBoxContainer *hbc = memnew( HBoxContainer ); - popup = memnew( PopupMenu ); - hbc->add_child(popup); - add_child(hbc); + HBoxContainer *hbc = memnew( HBoxContainer ); + popup = memnew( PopupMenu ); + hbc->add_child(popup); + add_child(hbc); - tabs = memnew(TabContainer); - tabs->set_v_size_flags(SIZE_EXPAND_FILL); - add_child(tabs); - const char* sname[ShaderGraph::SHADER_TYPE_MAX]={ - "Vertex", - "Fragment", - "Light" - }; - for(int i=0;iset_v_size_flags(SIZE_EXPAND_FILL); + add_child(tabs); + const char* sname[ShaderGraph::SHADER_TYPE_MAX]={ + "Vertex", + "Fragment", + "Light" + }; + for(int i=0;iget_graph_edit()->set_name(sname[i]); - tabs->add_child(graph_edits[i]->get_graph_edit()); - graph_edits[i]->get_graph_edit()->connect("connection_request",graph_edits[i],"_connection_request"); - graph_edits[i]->get_graph_edit()->connect("disconnection_request",graph_edits[i],"_disconnection_request"); - graph_edits[i]->get_graph_edit()->connect("popup_request",this,"_popup_requested"); - graph_edits[i]->get_graph_edit()->set_right_disconnects(true); - } + graph_edits[i]= memnew( ShaderGraphView(ShaderGraph::ShaderType(i)) ); + add_child(graph_edits[i]); + graph_edits[i]->get_graph_edit()->set_name(sname[i]); + tabs->add_child(graph_edits[i]->get_graph_edit()); + graph_edits[i]->get_graph_edit()->connect("connection_request",graph_edits[i],"_connection_request"); + graph_edits[i]->get_graph_edit()->connect("disconnection_request",graph_edits[i],"_disconnection_request"); + graph_edits[i]->get_graph_edit()->connect("popup_request",this,"_popup_requested"); + graph_edits[i]->get_graph_edit()->set_right_disconnects(true); + } - tabs->set_current_tab(1); + tabs->set_current_tab(1); - set_custom_minimum_size(Size2(100,300)); + set_custom_minimum_size(Size2(100,300)); } void ShaderGraphEditorPlugin::edit(Object *p_object) { - shader_editor->edit(p_object->cast_to()); + shader_editor->edit(p_object->cast_to()); } bool ShaderGraphEditorPlugin::handles(Object *p_object) const { - ShaderGraph *shader=p_object->cast_to(); - if (!shader) - return false; - if (_2d) - return shader->get_mode()==Shader::MODE_CANVAS_ITEM; - else - return shader->get_mode()==Shader::MODE_MATERIAL; + ShaderGraph *shader=p_object->cast_to(); + if (!shader) + return false; + if (_2d) + return shader->get_mode()==Shader::MODE_CANVAS_ITEM; + else + return shader->get_mode()==Shader::MODE_MATERIAL; } void ShaderGraphEditorPlugin::make_visible(bool p_visible) { - if (p_visible) { - shader_editor->show(); - } else { + if (p_visible) { + shader_editor->show(); + } else { - shader_editor->hide(); - } + shader_editor->hide(); + } } ShaderGraphEditorPlugin::ShaderGraphEditorPlugin(EditorNode *p_node, bool p_2d) { - _2d=p_2d; - editor=p_node; - shader_editor = memnew( ShaderGraphEditor(p_2d) ); - shader_editor->hide(); - if (p_2d) - CanvasItemEditor::get_singleton()->get_bottom_split()->add_child(shader_editor); - else - SpatialEditor::get_singleton()->get_shader_split()->add_child(shader_editor); + _2d=p_2d; + editor=p_node; + shader_editor = memnew( ShaderGraphEditor(p_2d) ); + shader_editor->hide(); + if (p_2d) + CanvasItemEditor::get_singleton()->get_bottom_split()->add_child(shader_editor); + else + SpatialEditor::get_singleton()->get_shader_split()->add_child(shader_editor); // editor->get_viewport()->add_child(shader_editor); diff --git a/tools/editor/plugins/shader_graph_editor_plugin.h b/tools/editor/plugins/shader_graph_editor_plugin.h index c41ec68360c3..ea21a7706fbd 100644 --- a/tools/editor/plugins/shader_graph_editor_plugin.h +++ b/tools/editor/plugins/shader_graph_editor_plugin.h @@ -41,187 +41,189 @@ #include "tools/editor/property_editor.h" #include "scene/resources/shader_graph.h" /** - @author Juan Linietsky + @author Juan Linietsky */ class GraphColorRampEdit : public Control { - OBJ_TYPE(GraphColorRampEdit,Control); + OBJ_TYPE(GraphColorRampEdit,Control); - struct Point { + struct Point { - float offset; - Color color; - bool operator<(const Point& p_ponit) const { - return offset points; + bool grabbing; + int grabbed; + float grabbed_at; + Vector points; - void _color_changed(const Color& p_color); + void _color_changed(const Color& p_color); protected: - void _input_event(const InputEvent& p_event); - void _notification(int p_what); - static void _bind_methods(); + void _input_event(const InputEvent& p_event); + void _notification(int p_what); + static void _bind_methods(); public: - void set_ramp(const Vector& p_offsets,const Vector& p_colors); - Vector get_offsets() const; - Vector get_colors() const; - virtual Size2 get_minimum_size() const; - GraphColorRampEdit(); + void set_ramp(const Vector& p_offsets,const Vector& p_colors); + Vector get_offsets() const; + Vector get_colors() const; + virtual Size2 get_minimum_size() const; + GraphColorRampEdit(); }; class GraphCurveMapEdit : public Control { - OBJ_TYPE(GraphCurveMapEdit,Control); + OBJ_TYPE(GraphCurveMapEdit,Control); - struct Point { + struct Point { - float offset; - float height; - bool operator<(const Point& p_ponit) const { - return offset points; + bool grabbing; + int grabbed; + Vector points; - void _plot_curve(const Vector2& p_a,const Vector2& p_b,const Vector2& p_c,const Vector2& p_d); + void _plot_curve(const Vector2& p_a,const Vector2& p_b,const Vector2& p_c,const Vector2& p_d); protected: - void _input_event(const InputEvent& p_event); - void _notification(int p_what); - static void _bind_methods(); + void _input_event(const InputEvent& p_event); + void _notification(int p_what); + static void _bind_methods(); public: - void set_points(const Vector& p_points); - Vector get_points() const; - virtual Size2 get_minimum_size() const; - GraphCurveMapEdit(); + void set_points(const Vector& p_points); + Vector get_points() const; + virtual Size2 get_minimum_size() const; + GraphCurveMapEdit(); }; class ShaderGraphView : public Node { - OBJ_TYPE(ShaderGraphView,Node); - - - - CustomPropertyEditor *ped_popup; - bool block_update; - - Label *status; - GraphEdit *graph_edit; - Ref graph; - int edited_id; - - ShaderGraph::ShaderType type; - - void _update_graph(); - void _create_node(int p_id); - - - - void _connection_request(const String& p_from, int p_from_slot,const String& p_to,int p_to_slot); - void _disconnection_request(const String& p_from, int p_from_slot,const String& p_to,int p_to_slot); - - void _node_removed(int p_id); - void _node_moved(const Vector2& p_from, const Vector2& p_to,int p_id); - void _move_node(int p_id,const Vector2& p_to); - - void _scalar_const_changed(double p_value,int p_id); - void _vec_const_changed(double p_value, int p_id, Array p_arr); - void _rgb_const_changed(const Color& p_color, int p_id); - void _xform_const_changed(int p_id,Node* p_button); - void _scalar_op_changed(int p_op, int p_id); - void _vec_op_changed(int p_op, int p_id); - void _vec_scalar_op_changed(int p_op, int p_id); - void _rgb_op_changed(int p_op, int p_id); - void _xform_inv_rev_changed(bool p_enabled, int p_id); - void _scalar_func_changed(int p_func, int p_id); - void _vec_func_changed(int p_func, int p_id); - void _scalar_input_changed(double p_value,int p_id); - void _vec_input_changed(double p_value, int p_id, Array p_arr); - void _xform_input_changed(int p_id,Node* p_button); - void _rgb_input_changed(const Color& p_color, int p_id); - void _tex_input_change(int p_id,Node* p_button); - void _cube_input_change(int p_id); - void _input_name_changed(const String& p_name,int p_id,Node* p_line_edit); - void _tex_edited(int p_id,Node* p_button); - void _cube_edited(int p_id,Node* p_button); - void _variant_edited(); - void _comment_edited(int p_id,Node* p_button); - void _color_ramp_changed(int p_id,Node* p_ramp); - void _curve_changed(int p_id,Node* p_curve); - void _sg_updated(); - Map node_map; + OBJ_TYPE(ShaderGraphView,Node); + + + + CustomPropertyEditor *ped_popup; + bool block_update; + + Label *status; + GraphEdit *graph_edit; + Ref graph; + int edited_id; + + ShaderGraph::ShaderType type; + + void _update_graph(); + void _create_node(int p_id); + + + + void _connection_request(const String& p_from, int p_from_slot,const String& p_to,int p_to_slot); + void _disconnection_request(const String& p_from, int p_from_slot,const String& p_to,int p_to_slot); + + void _node_removed(int p_id); + void _begin_node_move(); + void _node_moved(const Vector2& p_from, const Vector2& p_to,int p_id); + void _end_node_move(); + void _move_node(int p_id,const Vector2& p_to); + + void _scalar_const_changed(double p_value,int p_id); + void _vec_const_changed(double p_value, int p_id, Array p_arr); + void _rgb_const_changed(const Color& p_color, int p_id); + void _xform_const_changed(int p_id,Node* p_button); + void _scalar_op_changed(int p_op, int p_id); + void _vec_op_changed(int p_op, int p_id); + void _vec_scalar_op_changed(int p_op, int p_id); + void _rgb_op_changed(int p_op, int p_id); + void _xform_inv_rev_changed(bool p_enabled, int p_id); + void _scalar_func_changed(int p_func, int p_id); + void _vec_func_changed(int p_func, int p_id); + void _scalar_input_changed(double p_value,int p_id); + void _vec_input_changed(double p_value, int p_id, Array p_arr); + void _xform_input_changed(int p_id,Node* p_button); + void _rgb_input_changed(const Color& p_color, int p_id); + void _tex_input_change(int p_id,Node* p_button); + void _cube_input_change(int p_id); + void _input_name_changed(const String& p_name,int p_id,Node* p_line_edit); + void _tex_edited(int p_id,Node* p_button); + void _cube_edited(int p_id,Node* p_button); + void _variant_edited(); + void _comment_edited(int p_id,Node* p_button); + void _color_ramp_changed(int p_id,Node* p_ramp); + void _curve_changed(int p_id,Node* p_curve); + void _sg_updated(); + Map node_map; protected: - void _notification(int p_what); - static void _bind_methods(); + void _notification(int p_what); + static void _bind_methods(); public: void add_node(int p_type, const Vector2 &location); - GraphEdit *get_graph_edit() { return graph_edit; } - void set_graph(Ref p_graph); + GraphEdit *get_graph_edit() { return graph_edit; } + void set_graph(Ref p_graph); - ShaderGraphView(ShaderGraph::ShaderType p_type=ShaderGraph::SHADER_TYPE_FRAGMENT); + ShaderGraphView(ShaderGraph::ShaderType p_type=ShaderGraph::SHADER_TYPE_FRAGMENT); }; class ShaderGraphEditor : public VBoxContainer { - OBJ_TYPE(ShaderGraphEditor,VBoxContainer); + OBJ_TYPE(ShaderGraphEditor,VBoxContainer); PopupMenu *popup; - TabContainer *tabs; - ShaderGraphView *graph_edits[ShaderGraph::SHADER_TYPE_MAX]; - static const char* node_names[ShaderGraph::NODE_TYPE_MAX]; + TabContainer *tabs; + ShaderGraphView *graph_edits[ShaderGraph::SHADER_TYPE_MAX]; + static const char* node_names[ShaderGraph::NODE_TYPE_MAX]; Vector2 next_location; - bool _2d; - void _add_node(int p_type); + bool _2d; + void _add_node(int p_type); void _popup_requested(const Vector2 &p_position); protected: - void _notification(int p_what); - static void _bind_methods(); + void _notification(int p_what); + static void _bind_methods(); public: - void edit(Ref p_shader); - ShaderGraphEditor(bool p_2d); + void edit(Ref p_shader); + ShaderGraphEditor(bool p_2d); }; class ShaderGraphEditorPlugin : public EditorPlugin { - OBJ_TYPE( ShaderGraphEditorPlugin, EditorPlugin ); + OBJ_TYPE( ShaderGraphEditorPlugin, EditorPlugin ); - bool _2d; - ShaderGraphEditor *shader_editor; - EditorNode *editor; + bool _2d; + ShaderGraphEditor *shader_editor; + EditorNode *editor; public: - virtual String get_name() const { return "ShaderGraph"; } - bool has_main_screen() const { return false; } - virtual void edit(Object *p_node); - virtual bool handles(Object *p_node) const; - virtual void make_visible(bool p_visible); + virtual String get_name() const { return "ShaderGraph"; } + bool has_main_screen() const { return false; } + virtual void edit(Object *p_node); + virtual bool handles(Object *p_node) const; + virtual void make_visible(bool p_visible); - ShaderGraphEditorPlugin(EditorNode *p_node,bool p_2d); - ~ShaderGraphEditorPlugin(); + ShaderGraphEditorPlugin(EditorNode *p_node,bool p_2d); + ~ShaderGraphEditorPlugin(); }; #endif From 2a43778793ba67c7edb7d96ab30c4c2a8c145c70 Mon Sep 17 00:00:00 2001 From: Mariano Javier Suligoy Date: Mon, 20 Jul 2015 22:15:06 -0300 Subject: [PATCH 03/11] Fix tab indent --- scene/gui/graph_edit.cpp | 920 ++-- scene/gui/graph_edit.h | 112 +- scene/gui/graph_node.cpp | 660 +-- scene/gui/graph_node.h | 126 +- .../resources/default_theme/default_theme.cpp | 90 +- .../plugins/shader_graph_editor_plugin.cpp | 3792 ++++++++--------- .../plugins/shader_graph_editor_plugin.h | 254 +- 7 files changed, 2977 insertions(+), 2977 deletions(-) diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index 4569c71d0b68..22a03504c6e5 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -3,385 +3,385 @@ #include "os/keyboard.h" bool GraphEditFilter::has_point(const Point2& p_point) const { - return ge->_filter_input(p_point); + return ge->_filter_input(p_point); } GraphEditFilter::GraphEditFilter(GraphEdit *p_edit) { - ge=p_edit; + ge=p_edit; } Error GraphEdit::connect_node(const StringName& p_from, int p_from_port,const StringName& p_to,int p_to_port) { - if (is_node_connected(p_from,p_from_port,p_to,p_to_port)) - return OK; - Connection c; - c.from=p_from; - c.from_port=p_from_port; - c.to=p_to; - c.to_port=p_to_port; - connections.push_back(c); - top_layer->update(); - - return OK; + if (is_node_connected(p_from,p_from_port,p_to,p_to_port)) + return OK; + Connection c; + c.from=p_from; + c.from_port=p_from_port; + c.to=p_to; + c.to_port=p_to_port; + connections.push_back(c); + top_layer->update(); + + return OK; } bool GraphEdit::is_node_connected(const StringName& p_from, int p_from_port,const StringName& p_to,int p_to_port) { - for(List::Element *E=connections.front();E;E=E->next()) { + for(List::Element *E=connections.front();E;E=E->next()) { - if (E->get().from==p_from && E->get().from_port==p_from_port && E->get().to==p_to && E->get().to_port==p_to_port) - return true; - } + if (E->get().from==p_from && E->get().from_port==p_from_port && E->get().to==p_to && E->get().to_port==p_to_port) + return true; + } - return false; + return false; } void GraphEdit::disconnect_node(const StringName& p_from, int p_from_port,const StringName& p_to,int p_to_port){ - for(List::Element *E=connections.front();E;E=E->next()) { + for(List::Element *E=connections.front();E;E=E->next()) { - if (E->get().from==p_from && E->get().from_port==p_from_port && E->get().to==p_to && E->get().to_port==p_to_port) { + if (E->get().from==p_from && E->get().from_port==p_from_port && E->get().to==p_to && E->get().to_port==p_to_port) { - connections.erase(E); - top_layer->update(); - return; - } - } + connections.erase(E); + top_layer->update(); + return; + } + } } void GraphEdit::get_connection_list(List *r_connections) const { - *r_connections=connections; + *r_connections=connections; } void GraphEdit::_scroll_moved(double) { - _update_scroll_offset(); - top_layer->update(); + _update_scroll_offset(); + top_layer->update(); } void GraphEdit::_update_scroll_offset() { - for(int i=0;icast_to(); - if (!gn) - continue; + GraphNode *gn=get_child(i)->cast_to(); + if (!gn) + continue; - Point2 pos=gn->get_offset(); - pos-=Point2(h_scroll->get_val(),v_scroll->get_val()); - gn->set_pos(pos); - } + Point2 pos=gn->get_offset(); + pos-=Point2(h_scroll->get_val(),v_scroll->get_val()); + gn->set_pos(pos); + } } void GraphEdit::_update_scroll() { - if (updating) - return; + if (updating) + return; - updating=true; - Rect2 screen; - for(int i=0;icast_to(); - if (!gn) - continue; + GraphNode *gn=get_child(i)->cast_to(); + if (!gn) + continue; - Rect2 r; - r.pos=gn->get_offset(); - r.size=gn->get_size(); - screen = screen.merge(r); - } + Rect2 r; + r.pos=gn->get_offset(); + r.size=gn->get_size(); + screen = screen.merge(r); + } - screen.pos-=get_size(); - screen.size+=get_size()*2.0; + screen.pos-=get_size(); + screen.size+=get_size()*2.0; - h_scroll->set_min(screen.pos.x); - h_scroll->set_max(screen.pos.x+screen.size.x); - h_scroll->set_page(get_size().x); - if (h_scroll->get_max() - h_scroll->get_min() <= h_scroll->get_page()) - h_scroll->hide(); - else - h_scroll->show(); + h_scroll->set_min(screen.pos.x); + h_scroll->set_max(screen.pos.x+screen.size.x); + h_scroll->set_page(get_size().x); + if (h_scroll->get_max() - h_scroll->get_min() <= h_scroll->get_page()) + h_scroll->hide(); + else + h_scroll->show(); - v_scroll->set_min(screen.pos.y); - v_scroll->set_max(screen.pos.y+screen.size.y); - v_scroll->set_page(get_size().y); + v_scroll->set_min(screen.pos.y); + v_scroll->set_max(screen.pos.y+screen.size.y); + v_scroll->set_page(get_size().y); - if (v_scroll->get_max() - v_scroll->get_min() <= v_scroll->get_page()) - v_scroll->hide(); - else - v_scroll->show(); + if (v_scroll->get_max() - v_scroll->get_min() <= v_scroll->get_page()) + v_scroll->hide(); + else + v_scroll->show(); - _update_scroll_offset(); - updating=false; + _update_scroll_offset(); + updating=false; } void GraphEdit::_graph_node_raised(Node* p_gn) { - GraphNode *gn=p_gn->cast_to(); - ERR_FAIL_COND(!gn); - gn->raise(); - top_layer->raise(); + GraphNode *gn=p_gn->cast_to(); + ERR_FAIL_COND(!gn); + gn->raise(); + top_layer->raise(); } void GraphEdit::_graph_node_moved(Node *p_gn) { - GraphNode *gn=p_gn->cast_to(); - ERR_FAIL_COND(!gn); - top_layer->update(); + GraphNode *gn=p_gn->cast_to(); + ERR_FAIL_COND(!gn); + top_layer->update(); } void GraphEdit::add_child_notify(Node *p_child) { - top_layer->call_deferred("raise"); //top layer always on top! - GraphNode *gn = p_child->cast_to(); - if (gn) { - gn->connect("offset_changed",this,"_graph_node_moved",varray(gn)); - gn->connect("raise_request",this,"_graph_node_raised",varray(gn)); - _graph_node_moved(gn); - gn->set_stop_mouse(false); - } + top_layer->call_deferred("raise"); //top layer always on top! + GraphNode *gn = p_child->cast_to(); + if (gn) { + gn->connect("offset_changed",this,"_graph_node_moved",varray(gn)); + gn->connect("raise_request",this,"_graph_node_raised",varray(gn)); + _graph_node_moved(gn); + gn->set_stop_mouse(false); + } } void GraphEdit::remove_child_notify(Node *p_child) { - top_layer->call_deferred("raise"); //top layer always on top! - GraphNode *gn = p_child->cast_to(); - if (gn) { - gn->disconnect("offset_changed",this,"_graph_node_moved"); - gn->disconnect("raise_request",this,"_graph_node_raised"); - } + top_layer->call_deferred("raise"); //top layer always on top! + GraphNode *gn = p_child->cast_to(); + if (gn) { + gn->disconnect("offset_changed",this,"_graph_node_moved"); + gn->disconnect("raise_request",this,"_graph_node_raised"); + } } void GraphEdit::_notification(int p_what) { - if (p_what==NOTIFICATION_READY) { - Size2 size = top_layer->get_size(); - Size2 hmin = h_scroll->get_combined_minimum_size(); - Size2 vmin = v_scroll->get_combined_minimum_size(); + if (p_what==NOTIFICATION_READY) { + Size2 size = top_layer->get_size(); + Size2 hmin = h_scroll->get_combined_minimum_size(); + Size2 vmin = v_scroll->get_combined_minimum_size(); - v_scroll->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_END,vmin.width); - v_scroll->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,0); - v_scroll->set_anchor_and_margin(MARGIN_TOP,ANCHOR_BEGIN,0); - v_scroll->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END,0); + v_scroll->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_END,vmin.width); + v_scroll->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,0); + v_scroll->set_anchor_and_margin(MARGIN_TOP,ANCHOR_BEGIN,0); + v_scroll->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END,0); - h_scroll->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_BEGIN,0); - h_scroll->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,0); - h_scroll->set_anchor_and_margin(MARGIN_TOP,ANCHOR_END,hmin.height); - h_scroll->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END,0); + h_scroll->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_BEGIN,0); + h_scroll->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,0); + h_scroll->set_anchor_and_margin(MARGIN_TOP,ANCHOR_END,hmin.height); + h_scroll->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END,0); - } - if (p_what==NOTIFICATION_DRAW) { - VS::get_singleton()->canvas_item_set_clip(get_canvas_item(),true); + } + if (p_what==NOTIFICATION_DRAW) { + VS::get_singleton()->canvas_item_set_clip(get_canvas_item(),true); - } + } - if (p_what==NOTIFICATION_RESIZED) { - _update_scroll(); - top_layer->update(); - } + if (p_what==NOTIFICATION_RESIZED) { + _update_scroll(); + top_layer->update(); + } } bool GraphEdit::_filter_input(const Point2& p_point) { - Ref port =get_icon("port","GraphNode"); + Ref port =get_icon("port","GraphNode"); - float grab_r=port->get_width()*0.5; - for(int i=get_child_count()-1;i>=0;i--) { + float grab_r=port->get_width()*0.5; + for(int i=get_child_count()-1;i>=0;i--) { - GraphNode *gn=get_child(i)->cast_to(); - if (!gn) - continue; + GraphNode *gn=get_child(i)->cast_to(); + if (!gn) + continue; - for(int j=0;jget_connection_output_count();j++) { + for(int j=0;jget_connection_output_count();j++) { - Vector2 pos = gn->get_connection_output_pos(j)+gn->get_pos(); - if (pos.distance_to(p_point)get_connection_output_pos(j)+gn->get_pos(); + if (pos.distance_to(p_point)get_connection_input_count();j++) { + for(int j=0;jget_connection_input_count();j++) { - Vector2 pos = gn->get_connection_input_pos(j)+gn->get_pos(); - if (pos.distance_to(p_point)get_connection_input_pos(j)+gn->get_pos(); + if (pos.distance_to(p_point) port =get_icon("port","GraphNode"); - Vector2 mpos(p_ev.mouse_button.x,p_ev.mouse_button.y); - float grab_r=port->get_width()*0.5; - for(int i=get_child_count()-1;i>=0;i--) { + Ref port =get_icon("port","GraphNode"); + Vector2 mpos(p_ev.mouse_button.x,p_ev.mouse_button.y); + float grab_r=port->get_width()*0.5; + for(int i=get_child_count()-1;i>=0;i--) { - GraphNode *gn=get_child(i)->cast_to(); - if (!gn) - continue; + GraphNode *gn=get_child(i)->cast_to(); + if (!gn) + continue; - for(int j=0;jget_connection_output_count();j++) { + for(int j=0;jget_connection_output_count();j++) { - Vector2 pos = gn->get_connection_output_pos(j)+gn->get_pos(); - if (pos.distance_to(mpos)get_connection_output_pos(j)+gn->get_pos(); + if (pos.distance_to(mpos)get_name(); - connecting_index=j; - connecting_out=true; - connecting_type=gn->get_connection_output_type(j); - connecting_color=gn->get_connection_output_color(j); - connecting_target=false; - connecting_to=pos; - return; - } + connecting=true; + connecting_from=gn->get_name(); + connecting_index=j; + connecting_out=true; + connecting_type=gn->get_connection_output_type(j); + connecting_color=gn->get_connection_output_color(j); + connecting_target=false; + connecting_to=pos; + return; + } - } + } - for(int j=0;jget_connection_input_count();j++) { + for(int j=0;jget_connection_input_count();j++) { - Vector2 pos = gn->get_connection_input_pos(j)+gn->get_pos(); + Vector2 pos = gn->get_connection_input_pos(j)+gn->get_pos(); - if (pos.distance_to(mpos)::Element*E=connections.front();E;E=E->next()) { + if (right_disconnects) { + //check disconnect + for (List::Element*E=connections.front();E;E=E->next()) { - if (E->get().to==gn->get_name() && E->get().to_port==j) { + if (E->get().to==gn->get_name() && E->get().to_port==j) { - Node*fr = get_node(String(E->get().from)); - if (fr && fr->cast_to()) { + Node*fr = get_node(String(E->get().from)); + if (fr && fr->cast_to()) { - connecting_from=E->get().from; - connecting_index=E->get().from_port; - connecting_out=true; - connecting_type=fr->cast_to()->get_connection_output_type(E->get().from_port); - connecting_color=fr->cast_to()->get_connection_output_color(E->get().from_port); - connecting_target=false; - connecting_to=pos; + connecting_from=E->get().from; + connecting_index=E->get().from_port; + connecting_out=true; + connecting_type=fr->cast_to()->get_connection_output_type(E->get().from_port); + connecting_color=fr->cast_to()->get_connection_output_color(E->get().from_port); + connecting_target=false; + connecting_to=pos; - emit_signal("disconnection_request",E->get().from,E->get().from_port,E->get().to,E->get().to_port); - fr = get_node(String(connecting_from)); //maybe it was erased - if (fr && fr->cast_to()) { - connecting=true; - } - return; - } + emit_signal("disconnection_request",E->get().from,E->get().from_port,E->get().to,E->get().to_port); + fr = get_node(String(connecting_from)); //maybe it was erased + if (fr && fr->cast_to()) { + connecting=true; + } + return; + } - } - } - } + } + } + } - connecting=true; - connecting_from=gn->get_name(); - connecting_index=j; - connecting_out=false; - connecting_type=gn->get_connection_input_type(j); - connecting_color=gn->get_connection_input_color(j); - connecting_target=false; - connecting_to=pos; - return; - } + connecting=true; + connecting_from=gn->get_name(); + connecting_index=j; + connecting_out=false; + connecting_type=gn->get_connection_input_type(j); + connecting_color=gn->get_connection_input_color(j); + connecting_target=false; + connecting_to=pos; + return; + } - } - } - } + } + } + } - if (p_ev.type==InputEvent::MOUSE_MOTION && connecting) { + if (p_ev.type==InputEvent::MOUSE_MOTION && connecting) { - connecting_to=Vector2(p_ev.mouse_motion.x,p_ev.mouse_motion.y); - connecting_target=false; - top_layer->update(); + connecting_to=Vector2(p_ev.mouse_motion.x,p_ev.mouse_motion.y); + connecting_target=false; + top_layer->update(); - Ref port =get_icon("port","GraphNode"); - Vector2 mpos(p_ev.mouse_button.x,p_ev.mouse_button.y); - float grab_r=port->get_width()*0.5; - for(int i=get_child_count()-1;i>=0;i--) { + Ref port =get_icon("port","GraphNode"); + Vector2 mpos(p_ev.mouse_button.x,p_ev.mouse_button.y); + float grab_r=port->get_width()*0.5; + for(int i=get_child_count()-1;i>=0;i--) { - GraphNode *gn=get_child(i)->cast_to(); - if (!gn) - continue; + GraphNode *gn=get_child(i)->cast_to(); + if (!gn) + continue; - if (!connecting_out) { - for(int j=0;jget_connection_output_count();j++) { + if (!connecting_out) { + for(int j=0;jget_connection_output_count();j++) { - Vector2 pos = gn->get_connection_output_pos(j)+gn->get_pos(); - int type =gn->get_connection_output_type(j); - if (type==connecting_type && pos.distance_to(mpos)get_connection_output_pos(j)+gn->get_pos(); + int type =gn->get_connection_output_type(j); + if (type==connecting_type && pos.distance_to(mpos)get_name(); - connecting_target_index=j; - return; - } + connecting_target=true; + connecting_to=pos; + connecting_target_to=gn->get_name(); + connecting_target_index=j; + return; + } - } - } else { + } + } else { - for(int j=0;jget_connection_input_count();j++) { + for(int j=0;jget_connection_input_count();j++) { - Vector2 pos = gn->get_connection_input_pos(j)+gn->get_pos(); - int type =gn->get_connection_input_type(j); - if (type==connecting_type && pos.distance_to(mpos)get_name(); - connecting_target_index=j; - return; - } - } - } - } - } + Vector2 pos = gn->get_connection_input_pos(j)+gn->get_pos(); + int type =gn->get_connection_input_type(j); + if (type==connecting_type && pos.distance_to(mpos)get_name(); + connecting_target_index=j; + return; + } + } + } + } + } - if (p_ev.type==InputEvent::MOUSE_BUTTON && p_ev.mouse_button.button_index==BUTTON_LEFT && !p_ev.mouse_button.pressed) { + if (p_ev.type==InputEvent::MOUSE_BUTTON && p_ev.mouse_button.button_index==BUTTON_LEFT && !p_ev.mouse_button.pressed) { - if (connecting && connecting_target) { + if (connecting && connecting_target) { - String from = connecting_from; - int from_slot = connecting_index; - String to =connecting_target_to; - int to_slot = connecting_target_index; + String from = connecting_from; + int from_slot = connecting_index; + String to =connecting_target_to; + int to_slot = connecting_target_index; - if (!connecting_out) { - SWAP(from,to); - SWAP(from_slot,to_slot); - } - emit_signal("connection_request",from,from_slot,to,to_slot); - - } - connecting=false; - top_layer->update(); + if (!connecting_out) { + SWAP(from,to); + SWAP(from_slot,to_slot); + } + emit_signal("connection_request",from,from_slot,to,to_slot); + + } + connecting=false; + top_layer->update(); - } + } @@ -389,295 +389,295 @@ void GraphEdit::_top_layer_input(const InputEvent& p_ev) { void GraphEdit::_draw_cos_line(const Vector2& p_from, const Vector2& p_to,const Color& p_color) { - static const int steps = 20; + static const int steps = 20; - Rect2 r; - r.pos=p_from; - r.expand_to(p_to); - Vector2 sign=Vector2((p_from.x < p_to.x) ? 1 : -1,(p_from.y < p_to.y) ? 1 : -1); - bool flip = sign.x * sign.y < 0; + Rect2 r; + r.pos=p_from; + r.expand_to(p_to); + Vector2 sign=Vector2((p_from.x < p_to.x) ? 1 : -1,(p_from.y < p_to.y) ? 1 : -1); + bool flip = sign.x * sign.y < 0; - Vector2 prev; - for(int i=0;i<=steps;i++) { + Vector2 prev; + for(int i=0;i<=steps;i++) { - float d = i/float(steps); - float c=-Math::cos(d*Math_PI) * 0.5+0.5; - if (flip) - c=1.0-c; - Vector2 p = r.pos+Vector2(d*r.size.width,c*r.size.height); + float d = i/float(steps); + float c=-Math::cos(d*Math_PI) * 0.5+0.5; + if (flip) + c=1.0-c; + Vector2 p = r.pos+Vector2(d*r.size.width,c*r.size.height); - if (i>0) { + if (i>0) { - top_layer->draw_line(prev,p,p_color,2); - } + top_layer->draw_line(prev,p,p_color,2); + } - prev=p; - } + prev=p; + } } void GraphEdit::_top_layer_draw() { - _update_scroll(); - - if (connecting) { - - Node *fromn = get_node(connecting_from); - ERR_FAIL_COND(!fromn); - GraphNode *from = fromn->cast_to(); - ERR_FAIL_COND(!from); - Vector2 pos; - if (connecting_out) - pos=from->get_connection_output_pos(connecting_index); - else - pos=from->get_connection_input_pos(connecting_index); - pos+=from->get_pos(); - - Vector2 topos; - topos=connecting_to; - - Color col=connecting_color; - - if (connecting_target) { - col.r+=0.4; - col.g+=0.4; - col.b+=0.4; - } - _draw_cos_line(pos,topos,col); - } - - List::Element* > to_erase; - for(List::Element *E=connections.front();E;E=E->next()) { - - NodePath fromnp(E->get().from); - - Node * from = get_node(fromnp); - if (!from) { - to_erase.push_back(E); - continue; - } - - GraphNode *gfrom = from->cast_to(); - - if (!gfrom) { - to_erase.push_back(E); - continue; - } - - NodePath tonp(E->get().to); - Node * to = get_node(tonp); - if (!to) { - to_erase.push_back(E); - continue; - } - - GraphNode *gto = to->cast_to(); - - if (!gto) { - to_erase.push_back(E); - continue; - } - - Vector2 frompos=gfrom->get_connection_output_pos(E->get().from_port)+gfrom->get_pos(); - Color color = gfrom->get_connection_output_color(E->get().from_port); - Vector2 topos=gto->get_connection_input_pos(E->get().to_port)+gto->get_pos(); - _draw_cos_line(frompos,topos,color); - - } - - while(to_erase.size()) { - connections.erase(to_erase.front()->get()); - to_erase.pop_front(); - } - //draw connections + _update_scroll(); + + if (connecting) { + + Node *fromn = get_node(connecting_from); + ERR_FAIL_COND(!fromn); + GraphNode *from = fromn->cast_to(); + ERR_FAIL_COND(!from); + Vector2 pos; + if (connecting_out) + pos=from->get_connection_output_pos(connecting_index); + else + pos=from->get_connection_input_pos(connecting_index); + pos+=from->get_pos(); + + Vector2 topos; + topos=connecting_to; + + Color col=connecting_color; + + if (connecting_target) { + col.r+=0.4; + col.g+=0.4; + col.b+=0.4; + } + _draw_cos_line(pos,topos,col); + } + + List::Element* > to_erase; + for(List::Element *E=connections.front();E;E=E->next()) { + + NodePath fromnp(E->get().from); + + Node * from = get_node(fromnp); + if (!from) { + to_erase.push_back(E); + continue; + } + + GraphNode *gfrom = from->cast_to(); + + if (!gfrom) { + to_erase.push_back(E); + continue; + } + + NodePath tonp(E->get().to); + Node * to = get_node(tonp); + if (!to) { + to_erase.push_back(E); + continue; + } + + GraphNode *gto = to->cast_to(); + + if (!gto) { + to_erase.push_back(E); + continue; + } + + Vector2 frompos=gfrom->get_connection_output_pos(E->get().from_port)+gfrom->get_pos(); + Color color = gfrom->get_connection_output_color(E->get().from_port); + Vector2 topos=gto->get_connection_input_pos(E->get().to_port)+gto->get_pos(); + _draw_cos_line(frompos,topos,color); + + } + + while(to_erase.size()) { + connections.erase(to_erase.front()->get()); + to_erase.pop_front(); + } + //draw connections } void GraphEdit::_input_event(const InputEvent& p_ev) { - if (p_ev.type==InputEvent::MOUSE_MOTION && (p_ev.mouse_motion.button_mask&BUTTON_MASK_MIDDLE || (p_ev.mouse_motion.button_mask&BUTTON_MASK_LEFT && Input::get_singleton()->is_key_pressed(KEY_SPACE)))) { - h_scroll->set_val( h_scroll->get_val() - p_ev.mouse_motion.relative_x ); - v_scroll->set_val( v_scroll->get_val() - p_ev.mouse_motion.relative_y ); - } + if (p_ev.type==InputEvent::MOUSE_MOTION && (p_ev.mouse_motion.button_mask&BUTTON_MASK_MIDDLE || (p_ev.mouse_motion.button_mask&BUTTON_MASK_LEFT && Input::get_singleton()->is_key_pressed(KEY_SPACE)))) { + h_scroll->set_val( h_scroll->get_val() - p_ev.mouse_motion.relative_x ); + v_scroll->set_val( v_scroll->get_val() - p_ev.mouse_motion.relative_y ); + } - if (p_ev.type==InputEvent::MOUSE_MOTION && dragging) { + if (p_ev.type==InputEvent::MOUSE_MOTION && dragging) { - just_selected=true; - drag_accum+=Vector2(p_ev.mouse_motion.relative_x,p_ev.mouse_motion.relative_y); - for(int i=get_child_count()-1;i>=0;i--) { - GraphNode *gn=get_child(i)->cast_to(); - if (gn && gn->is_selected()) - gn->set_offset(gn->get_drag_from()+drag_accum); - } - } + just_selected=true; + drag_accum+=Vector2(p_ev.mouse_motion.relative_x,p_ev.mouse_motion.relative_y); + for(int i=get_child_count()-1;i>=0;i--) { + GraphNode *gn=get_child(i)->cast_to(); + if (gn && gn->is_selected()) + gn->set_offset(gn->get_drag_from()+drag_accum); + } + } - if (p_ev.type== InputEvent::MOUSE_BUTTON) { + if (p_ev.type== InputEvent::MOUSE_BUTTON) { - const InputEventMouseButton &b=p_ev.mouse_button; + const InputEventMouseButton &b=p_ev.mouse_button; - if (b.button_index==BUTTON_RIGHT && b.pressed) - { - emit_signal("popup_request", Vector2(b.global_x, b.global_y)); - } + if (b.button_index==BUTTON_RIGHT && b.pressed) + { + emit_signal("popup_request", Vector2(b.global_x, b.global_y)); + } - if (b.button_index==BUTTON_LEFT && !b.pressed && dragging) { - if (!just_selected && drag_accum==Vector2() && Input::get_singleton()->is_key_pressed(KEY_CONTROL)) { - //deselect current node - for(int i=get_child_count()-1;i>=0;i--) { - GraphNode *gn=get_child(i)->cast_to(); + if (b.button_index==BUTTON_LEFT && !b.pressed && dragging) { + if (!just_selected && drag_accum==Vector2() && Input::get_singleton()->is_key_pressed(KEY_CONTROL)) { + //deselect current node + for(int i=get_child_count()-1;i>=0;i--) { + GraphNode *gn=get_child(i)->cast_to(); - if (gn && gn->get_rect().has_point(get_local_mouse_pos())) - gn->set_selected(false); - } - } + if (gn && gn->get_rect().has_point(get_local_mouse_pos())) + gn->set_selected(false); + } + } - if (drag_accum!=Vector2()) { + if (drag_accum!=Vector2()) { - emit_signal("_begin_node_move"); + emit_signal("_begin_node_move"); - for(int i=get_child_count()-1;i>=0;i--) { - GraphNode *gn=get_child(i)->cast_to(); - if (gn && gn->is_selected()) - gn->set_drag(false); - } + for(int i=get_child_count()-1;i>=0;i--) { + GraphNode *gn=get_child(i)->cast_to(); + if (gn && gn->is_selected()) + gn->set_drag(false); + } - emit_signal("_end_node_move"); - } + emit_signal("_end_node_move"); + } - dragging = false; + dragging = false; - top_layer->update(); - } + top_layer->update(); + } - if (b.button_index==BUTTON_LEFT && b.pressed) { + if (b.button_index==BUTTON_LEFT && b.pressed) { - GraphNode *gn; - for(int i=get_child_count()-1;i>=0;i--) { + GraphNode *gn; + for(int i=get_child_count()-1;i>=0;i--) { - gn=get_child(i)->cast_to(); + gn=get_child(i)->cast_to(); - if (gn && gn->get_rect().has_point(get_local_mouse_pos())) - break; - } + if (gn && gn->get_rect().has_point(get_local_mouse_pos())) + break; + } - if (gn) { + if (gn) { - if (_filter_input(Vector2(b.x,b.y))) - return; + if (_filter_input(Vector2(b.x,b.y))) + return; - dragging = true; - drag_accum = Vector2(); - just_selected = !gn->is_selected(); - if(!gn->is_selected() && !Input::get_singleton()->is_key_pressed(KEY_CONTROL)) { - for (int i = 0; i < get_child_count(); i++) { - GraphNode *o_gn = get_child(i)->cast_to(); - if (o_gn) - o_gn->set_selected(o_gn == gn); - } - } + dragging = true; + drag_accum = Vector2(); + just_selected = !gn->is_selected(); + if(!gn->is_selected() && !Input::get_singleton()->is_key_pressed(KEY_CONTROL)) { + for (int i = 0; i < get_child_count(); i++) { + GraphNode *o_gn = get_child(i)->cast_to(); + if (o_gn) + o_gn->set_selected(o_gn == gn); + } + } - gn->set_selected(true); - for (int i = 0; i < get_child_count(); i++) { - GraphNode *o_gn = get_child(i)->cast_to(); - if (!o_gn) - continue; - if (o_gn->is_selected()) - o_gn->set_drag(true); - } + gn->set_selected(true); + for (int i = 0; i < get_child_count(); i++) { + GraphNode *o_gn = get_child(i)->cast_to(); + if (!o_gn) + continue; + if (o_gn->is_selected()) + o_gn->set_drag(true); + } - } else { - for(int i=get_child_count()-1;i>=0;i--) { + } else { + for(int i=get_child_count()-1;i>=0;i--) { - GraphNode *gn=get_child(i)->cast_to(); - if (!gn) - continue; + GraphNode *gn=get_child(i)->cast_to(); + if (!gn) + continue; - gn->set_selected(false); - } - } - } - } + gn->set_selected(false); + } + } + } + } } void GraphEdit::clear_connections() { - connections.clear(); - update(); + connections.clear(); + update(); } void GraphEdit::set_right_disconnects(bool p_enable) { - right_disconnects=p_enable; + right_disconnects=p_enable; } bool GraphEdit::is_right_disconnects_enabled() const{ - return right_disconnects; + return right_disconnects; } Array GraphEdit::_get_connection_list() const { - List conns; - get_connection_list(&conns); - Array arr; - for(List::Element *E=conns.front();E;E=E->next()) { - Dictionary d; - d["from"]=E->get().from; - d["from_port"]=E->get().from_port; - d["to"]=E->get().to; - d["to_port"]=E->get().to_port; - arr.push_back(d); - } - return arr; + List conns; + get_connection_list(&conns); + Array arr; + for(List::Element *E=conns.front();E;E=E->next()) { + Dictionary d; + d["from"]=E->get().from; + d["from_port"]=E->get().from_port; + d["to"]=E->get().to; + d["to_port"]=E->get().to_port; + arr.push_back(d); + } + return arr; } void GraphEdit::_bind_methods() { - ObjectTypeDB::bind_method(_MD("connect_node:Error","from","from_port","to","to_port"),&GraphEdit::connect_node); - ObjectTypeDB::bind_method(_MD("is_node_connected","from","from_port","to","to_port"),&GraphEdit::is_node_connected); - ObjectTypeDB::bind_method(_MD("disconnect_node","from","from_port","to","to_port"),&GraphEdit::disconnect_node); - ObjectTypeDB::bind_method(_MD("get_connection_list"),&GraphEdit::_get_connection_list); + ObjectTypeDB::bind_method(_MD("connect_node:Error","from","from_port","to","to_port"),&GraphEdit::connect_node); + ObjectTypeDB::bind_method(_MD("is_node_connected","from","from_port","to","to_port"),&GraphEdit::is_node_connected); + ObjectTypeDB::bind_method(_MD("disconnect_node","from","from_port","to","to_port"),&GraphEdit::disconnect_node); + ObjectTypeDB::bind_method(_MD("get_connection_list"),&GraphEdit::_get_connection_list); - ObjectTypeDB::bind_method(_MD("set_right_disconnects","enable"),&GraphEdit::set_right_disconnects); - ObjectTypeDB::bind_method(_MD("is_right_disconnects_enabled"),&GraphEdit::is_right_disconnects_enabled); + ObjectTypeDB::bind_method(_MD("set_right_disconnects","enable"),&GraphEdit::set_right_disconnects); + ObjectTypeDB::bind_method(_MD("is_right_disconnects_enabled"),&GraphEdit::is_right_disconnects_enabled); - ObjectTypeDB::bind_method(_MD("_graph_node_moved"),&GraphEdit::_graph_node_moved); - ObjectTypeDB::bind_method(_MD("_graph_node_raised"),&GraphEdit::_graph_node_raised); + ObjectTypeDB::bind_method(_MD("_graph_node_moved"),&GraphEdit::_graph_node_moved); + ObjectTypeDB::bind_method(_MD("_graph_node_raised"),&GraphEdit::_graph_node_raised); - ObjectTypeDB::bind_method(_MD("_top_layer_input"),&GraphEdit::_top_layer_input); - ObjectTypeDB::bind_method(_MD("_top_layer_draw"),&GraphEdit::_top_layer_draw); - ObjectTypeDB::bind_method(_MD("_scroll_moved"),&GraphEdit::_scroll_moved); + ObjectTypeDB::bind_method(_MD("_top_layer_input"),&GraphEdit::_top_layer_input); + ObjectTypeDB::bind_method(_MD("_top_layer_draw"),&GraphEdit::_top_layer_draw); + ObjectTypeDB::bind_method(_MD("_scroll_moved"),&GraphEdit::_scroll_moved); - ObjectTypeDB::bind_method(_MD("_input_event"),&GraphEdit::_input_event); + ObjectTypeDB::bind_method(_MD("_input_event"),&GraphEdit::_input_event); - ADD_SIGNAL(MethodInfo("connection_request",PropertyInfo(Variant::STRING,"from"),PropertyInfo(Variant::INT,"from_slot"),PropertyInfo(Variant::STRING,"to"),PropertyInfo(Variant::INT,"to_slot"))); - ADD_SIGNAL(MethodInfo("disconnection_request",PropertyInfo(Variant::STRING,"from"),PropertyInfo(Variant::INT,"from_slot"),PropertyInfo(Variant::STRING,"to"),PropertyInfo(Variant::INT,"to_slot"))); - ADD_SIGNAL(MethodInfo("popup_request", PropertyInfo(Variant::VECTOR2,"p_position"))); - ADD_SIGNAL(MethodInfo("_begin_node_move")); - ADD_SIGNAL(MethodInfo("_end_node_move")); + ADD_SIGNAL(MethodInfo("connection_request",PropertyInfo(Variant::STRING,"from"),PropertyInfo(Variant::INT,"from_slot"),PropertyInfo(Variant::STRING,"to"),PropertyInfo(Variant::INT,"to_slot"))); + ADD_SIGNAL(MethodInfo("disconnection_request",PropertyInfo(Variant::STRING,"from"),PropertyInfo(Variant::INT,"from_slot"),PropertyInfo(Variant::STRING,"to"),PropertyInfo(Variant::INT,"to_slot"))); + ADD_SIGNAL(MethodInfo("popup_request", PropertyInfo(Variant::VECTOR2,"p_position"))); + ADD_SIGNAL(MethodInfo("_begin_node_move")); + ADD_SIGNAL(MethodInfo("_end_node_move")); } GraphEdit::GraphEdit() { - top_layer=NULL; - top_layer=memnew(GraphEditFilter(this)); - add_child(top_layer); - top_layer->set_stop_mouse(false); - top_layer->set_area_as_parent_rect(); - top_layer->connect("draw",this,"_top_layer_draw"); + top_layer=NULL; + top_layer=memnew(GraphEditFilter(this)); + add_child(top_layer); top_layer->set_stop_mouse(false); - top_layer->connect("input_event",this,"_top_layer_input"); + top_layer->set_area_as_parent_rect(); + top_layer->connect("draw",this,"_top_layer_draw"); + top_layer->set_stop_mouse(false); + top_layer->connect("input_event",this,"_top_layer_input"); - h_scroll = memnew(HScrollBar); - h_scroll->set_name("_h_scroll"); - top_layer->add_child(h_scroll); + h_scroll = memnew(HScrollBar); + h_scroll->set_name("_h_scroll"); + top_layer->add_child(h_scroll); - v_scroll = memnew(VScrollBar); - v_scroll->set_name("_v_scroll"); - top_layer->add_child(v_scroll); - updating=false; - connecting=false; - right_disconnects=false; + v_scroll = memnew(VScrollBar); + v_scroll->set_name("_v_scroll"); + top_layer->add_child(v_scroll); + updating=false; + connecting=false; + right_disconnects=false; - h_scroll->connect("value_changed", this,"_scroll_moved"); - v_scroll->connect("value_changed", this,"_scroll_moved"); + h_scroll->connect("value_changed", this,"_scroll_moved"); + v_scroll->connect("value_changed", this,"_scroll_moved"); } diff --git a/scene/gui/graph_edit.h b/scene/gui/graph_edit.h index 2f9a5fc954ea..5ab0f3300ebb 100644 --- a/scene/gui/graph_edit.h +++ b/scene/gui/graph_edit.h @@ -8,95 +8,95 @@ class GraphEdit; class GraphEditFilter : public Control { - OBJ_TYPE(GraphEditFilter,Control); + OBJ_TYPE(GraphEditFilter,Control); -friend class GraphEdit; - GraphEdit *ge; - virtual bool has_point(const Point2& p_point) const; + friend class GraphEdit; + GraphEdit *ge; + virtual bool has_point(const Point2& p_point) const; public: - GraphEditFilter(GraphEdit *p_edit); + GraphEditFilter(GraphEdit *p_edit); }; class GraphEdit : public Control { - OBJ_TYPE(GraphEdit,Control); + OBJ_TYPE(GraphEdit,Control); public: - struct Connection { - StringName from; - StringName to; - int from_port; - int to_port; + struct Connection { + StringName from; + StringName to; + int from_port; + int to_port; - }; + }; private: - HScrollBar* h_scroll; - VScrollBar* v_scroll; + HScrollBar* h_scroll; + VScrollBar* v_scroll; - bool connecting; - String connecting_from; - bool connecting_out; - int connecting_index; - int connecting_type; - Color connecting_color; - bool connecting_target; - Vector2 connecting_to; - String connecting_target_to; - int connecting_target_index; + bool connecting; + String connecting_from; + bool connecting_out; + int connecting_index; + int connecting_type; + Color connecting_color; + bool connecting_target; + Vector2 connecting_to; + String connecting_target_to; + int connecting_target_index; - bool dragging; - bool just_selected; - Vector2 drag_accum; + bool dragging; + bool just_selected; + Vector2 drag_accum; - bool right_disconnects; - bool updating; - List connections; + bool right_disconnects; + bool updating; + List connections; - void _draw_cos_line(const Vector2& p_from, const Vector2& p_to,const Color& p_color); + void _draw_cos_line(const Vector2& p_from, const Vector2& p_to,const Color& p_color); - void _graph_node_raised(Node* p_gn); - void _graph_node_moved(Node *p_gn); + void _graph_node_raised(Node* p_gn); + void _graph_node_moved(Node *p_gn); - void _update_scroll(); - void _scroll_moved(double); - void _input_event(const InputEvent& p_ev); + void _update_scroll(); + void _scroll_moved(double); + void _input_event(const InputEvent& p_ev); - GraphEditFilter *top_layer; - void _top_layer_input(const InputEvent& p_ev); - void _top_layer_draw(); - void _update_scroll_offset(); + GraphEditFilter *top_layer; + void _top_layer_input(const InputEvent& p_ev); + void _top_layer_draw(); + void _update_scroll_offset(); - Array _get_connection_list() const; + Array _get_connection_list() const; -friend class GraphEditFilter; - bool _filter_input(const Point2& p_point); + friend class GraphEditFilter; + bool _filter_input(const Point2& p_point); protected: - static void _bind_methods(); - virtual void add_child_notify(Node *p_child); - virtual void remove_child_notify(Node *p_child); - void _notification(int p_what); + static void _bind_methods(); + virtual void add_child_notify(Node *p_child); + virtual void remove_child_notify(Node *p_child); + void _notification(int p_what); public: - Error connect_node(const StringName& p_from, int p_from_port,const StringName& p_to,int p_to_port); - bool is_node_connected(const StringName& p_from, int p_from_port,const StringName& p_to,int p_to_port); - void disconnect_node(const StringName& p_from, int p_from_port,const StringName& p_to,int p_to_port); - void clear_connections(); + Error connect_node(const StringName& p_from, int p_from_port,const StringName& p_to,int p_to_port); + bool is_node_connected(const StringName& p_from, int p_from_port,const StringName& p_to,int p_to_port); + void disconnect_node(const StringName& p_from, int p_from_port,const StringName& p_to,int p_to_port); + void clear_connections(); - GraphEditFilter *get_top_layer() const { return top_layer; } - void get_connection_list(List *r_connections) const; + GraphEditFilter *get_top_layer() const { return top_layer; } + void get_connection_list(List *r_connections) const; - void set_right_disconnects(bool p_enable); - bool is_right_disconnects_enabled() const; + void set_right_disconnects(bool p_enable); + bool is_right_disconnects_enabled() const; - GraphEdit(); + GraphEdit(); }; #endif // GRAPHEdit_H diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp index 760eb6ceede7..f0917aa4d178 100644 --- a/scene/gui/graph_node.cpp +++ b/scene/gui/graph_node.cpp @@ -4,91 +4,91 @@ bool GraphNode::_set(const StringName& p_name, const Variant& p_value) { - if (!p_name.operator String().begins_with("slot/")) - return false; + if (!p_name.operator String().begins_with("slot/")) + return false; - int idx=p_name.operator String().get_slice("/",1).to_int(); - String what = p_name.operator String().get_slice("/",2); + int idx=p_name.operator String().get_slice("/",1).to_int(); + String what = p_name.operator String().get_slice("/",2); - Slot si; - if (slot_info.has(idx)) - si=slot_info[idx]; + Slot si; + if (slot_info.has(idx)) + si=slot_info[idx]; - if (what=="left_enabled") - si.enable_left=p_value; - else if (what=="left_type") - si.type_left=p_value; - else if (what=="left_color") - si.color_left=p_value; - else if (what=="right_enabled") - si.enable_right=p_value; - else if (what=="right_type") - si.type_right=p_value; - else if (what=="right_color") - si.color_right=p_value; - else - return false; + if (what=="left_enabled") + si.enable_left=p_value; + else if (what=="left_type") + si.type_left=p_value; + else if (what=="left_color") + si.color_left=p_value; + else if (what=="right_enabled") + si.enable_right=p_value; + else if (what=="right_type") + si.type_right=p_value; + else if (what=="right_color") + si.color_right=p_value; + else + return false; - set_slot(idx,si.enable_left,si.type_left,si.color_left,si.enable_right,si.type_right,si.color_right); - update(); - return true; + set_slot(idx,si.enable_left,si.type_left,si.color_left,si.enable_right,si.type_right,si.color_right); + update(); + return true; } bool GraphNode::_get(const StringName& p_name,Variant &r_ret) const{ - if (!p_name.operator String().begins_with("slot/")) { - return false; - } + if (!p_name.operator String().begins_with("slot/")) { + return false; + } - int idx=p_name.operator String().get_slice("/",1).to_int(); - String what = p_name.operator String().get_slice("/",2); + int idx=p_name.operator String().get_slice("/",1).to_int(); + String what = p_name.operator String().get_slice("/",2); - Slot si; - if (slot_info.has(idx)) - si=slot_info[idx]; + Slot si; + if (slot_info.has(idx)) + si=slot_info[idx]; - if (what=="left_enabled") - r_ret=si.enable_left; - else if (what=="left_type") - r_ret=si.type_left; - else if (what=="left_color") - r_ret=si.color_left; - else if (what=="right_enabled") - r_ret=si.enable_right; - else if (what=="right_type") - r_ret=si.type_right; - else if (what=="right_color") - r_ret=si.color_right; - else - return false; + if (what=="left_enabled") + r_ret=si.enable_left; + else if (what=="left_type") + r_ret=si.type_left; + else if (what=="left_color") + r_ret=si.color_left; + else if (what=="right_enabled") + r_ret=si.enable_right; + else if (what=="right_type") + r_ret=si.type_right; + else if (what=="right_color") + r_ret=si.color_right; + else + return false; - return true; + return true; } void GraphNode::_get_property_list( List *p_list) const{ - int idx=0; - for(int i=0;icast_to(); - if (!c || c->is_set_as_toplevel() ) - continue; + int idx=0; + for(int i=0;icast_to(); + if (!c || c->is_set_as_toplevel() ) + continue; - String base="slot/"+itos(idx)+"/"; + String base="slot/"+itos(idx)+"/"; - p_list->push_back(PropertyInfo(Variant::BOOL,base+"left_enabled")); - p_list->push_back(PropertyInfo(Variant::INT,base+"left_type")); - p_list->push_back(PropertyInfo(Variant::COLOR,base+"left_color")); - p_list->push_back(PropertyInfo(Variant::BOOL,base+"right_enabled")); - p_list->push_back(PropertyInfo(Variant::INT,base+"right_type")); - p_list->push_back(PropertyInfo(Variant::COLOR,base+"right_color")); + p_list->push_back(PropertyInfo(Variant::BOOL,base+"left_enabled")); + p_list->push_back(PropertyInfo(Variant::INT,base+"left_type")); + p_list->push_back(PropertyInfo(Variant::COLOR,base+"left_color")); + p_list->push_back(PropertyInfo(Variant::BOOL,base+"right_enabled")); + p_list->push_back(PropertyInfo(Variant::INT,base+"right_type")); + p_list->push_back(PropertyInfo(Variant::COLOR,base+"right_color")); - idx++; - } + idx++; + } } @@ -96,61 +96,61 @@ void GraphNode::_resort() { - int sep=get_constant("separation"); - Ref sb=get_stylebox("frame"); - bool first=true; + int sep=get_constant("separation"); + Ref sb=get_stylebox("frame"); + bool first=true; - Size2 minsize; + Size2 minsize; - for(int i=0;icast_to(); - if (!c) - continue; - if (c->is_set_as_toplevel()) - continue; + for(int i=0;icast_to(); + if (!c) + continue; + if (c->is_set_as_toplevel()) + continue; - Size2i size=c->get_combined_minimum_size(); + Size2i size=c->get_combined_minimum_size(); - minsize.y+=size.y; - minsize.x=MAX(minsize.x,size.x); + minsize.y+=size.y; + minsize.x=MAX(minsize.x,size.x); - if (first) - first=false; - else - minsize.y+=sep; + if (first) + first=false; + else + minsize.y+=sep; - } + } - int vofs=0; - int w = get_size().x - sb->get_minimum_size().x; + int vofs=0; + int w = get_size().x - sb->get_minimum_size().x; - cache_y.clear(); - for(int i=0;icast_to(); - if (!c) - continue; - if (c->is_set_as_toplevel()) - continue; + cache_y.clear(); + for(int i=0;icast_to(); + if (!c) + continue; + if (c->is_set_as_toplevel()) + continue; - Size2i size=c->get_combined_minimum_size(); + Size2i size=c->get_combined_minimum_size(); - Rect2 r(sb->get_margin(MARGIN_LEFT),sb->get_margin(MARGIN_TOP)+vofs,w,size.y); + Rect2 r(sb->get_margin(MARGIN_LEFT),sb->get_margin(MARGIN_TOP)+vofs,w,size.y); - fit_child_in_rect(c,r); - cache_y.push_back(vofs+size.y*0.5); + fit_child_in_rect(c,r); + cache_y.push_back(vofs+size.y*0.5); - if (vofs>0) - vofs+=sep; - vofs+=size.y; + if (vofs>0) + vofs+=sep; + vofs+=size.y; - } + } - _change_notify(); - update(); - connpos_dirty=true; + _change_notify(); + update(); + connpos_dirty=true; } @@ -158,124 +158,124 @@ void GraphNode::_resort() { void GraphNode::_notification(int p_what) { - if (p_what==NOTIFICATION_DRAW) { + if (p_what==NOTIFICATION_DRAW) { - Ref sb=get_stylebox(selected ? "selectedframe" : "frame"); - Ref port =get_icon("port"); - Ref close =get_icon("close"); - int close_offset = get_constant("close_offset"); - Ref title_font = get_font("title_font"); - int title_offset = get_constant("title_offset"); - Color title_color = get_color("title_color"); - Point2i icofs = -port->get_size()*0.5; - int edgeofs=get_constant("port_offset"); - icofs.y+=sb->get_margin(MARGIN_TOP); - draw_style_box(sb,Rect2(Point2(),get_size())); + Ref sb=get_stylebox(selected ? "selectedframe" : "frame"); + Ref port =get_icon("port"); + Ref close =get_icon("close"); + int close_offset = get_constant("close_offset"); + Ref title_font = get_font("title_font"); + int title_offset = get_constant("title_offset"); + Color title_color = get_color("title_color"); + Point2i icofs = -port->get_size()*0.5; + int edgeofs=get_constant("port_offset"); + icofs.y+=sb->get_margin(MARGIN_TOP); + draw_style_box(sb,Rect2(Point2(),get_size())); - int w = get_size().width-sb->get_minimum_size().x; + int w = get_size().width-sb->get_minimum_size().x; - if (show_close) - w-=close->get_width(); + if (show_close) + w-=close->get_width(); - draw_string(title_font,Point2(sb->get_margin(MARGIN_LEFT),-title_font->get_height()+title_font->get_ascent()+title_offset),title,title_color,w); - if (show_close) { - Vector2 cpos = Point2(w+sb->get_margin(MARGIN_LEFT),-close->get_height()+close_offset); - draw_texture(close,cpos); - close_rect.pos=cpos; - close_rect.size=close->get_size(); - } else { - close_rect=Rect2(); - } + draw_string(title_font,Point2(sb->get_margin(MARGIN_LEFT),-title_font->get_height()+title_font->get_ascent()+title_offset),title,title_color,w); + if (show_close) { + Vector2 cpos = Point2(w+sb->get_margin(MARGIN_LEFT),-close->get_height()+close_offset); + draw_texture(close,cpos); + close_rect.pos=cpos; + close_rect.size=close->get_size(); + } else { + close_rect=Rect2(); + } - for (Map::Element *E=slot_info.front();E;E=E->next()) { + for (Map::Element *E=slot_info.front();E;E=E->next()) { - if (E->key() < 0 || E->key()>=cache_y.size()) - continue; - if (!slot_info.has(E->key())) - continue; - const Slot &s=slot_info[E->key()]; - //left - if (s.enable_left) - port->draw(get_canvas_item(),icofs+Point2(edgeofs,cache_y[E->key()]),s.color_left); - if (s.enable_right) - port->draw(get_canvas_item(),icofs+Point2(get_size().x-edgeofs,cache_y[E->key()]),s.color_right); + if (E->key() < 0 || E->key()>=cache_y.size()) + continue; + if (!slot_info.has(E->key())) + continue; + const Slot &s=slot_info[E->key()]; + //left + if (s.enable_left) + port->draw(get_canvas_item(),icofs+Point2(edgeofs,cache_y[E->key()]),s.color_left); + if (s.enable_right) + port->draw(get_canvas_item(),icofs+Point2(get_size().x-edgeofs,cache_y[E->key()]),s.color_right); - } - } + } + } - if (p_what==NOTIFICATION_SORT_CHILDREN) { + if (p_what==NOTIFICATION_SORT_CHILDREN) { - _resort(); - } + _resort(); + } } void GraphNode::set_slot(int p_idx,bool p_enable_left,int p_type_left,const Color& p_color_left, bool p_enable_right,int p_type_right,const Color& p_color_right) { - ERR_FAIL_COND(p_idx<0); + ERR_FAIL_COND(p_idx<0); - if (!p_enable_left && p_type_left==0 && p_color_left==Color(1,1,1,1) && !p_enable_right && p_type_right==0 && p_color_right==Color(1,1,1,1)) { - slot_info.erase(p_idx); - return; - } + if (!p_enable_left && p_type_left==0 && p_color_left==Color(1,1,1,1) && !p_enable_right && p_type_right==0 && p_color_right==Color(1,1,1,1)) { + slot_info.erase(p_idx); + return; + } - Slot s; - s.enable_left=p_enable_left; - s.type_left=p_type_left; - s.color_left=p_color_left; - s.enable_right=p_enable_right; - s.type_right=p_type_right; - s.color_right=p_color_right; - slot_info[p_idx]=s; - update(); - connpos_dirty=true; + Slot s; + s.enable_left=p_enable_left; + s.type_left=p_type_left; + s.color_left=p_color_left; + s.enable_right=p_enable_right; + s.type_right=p_type_right; + s.color_right=p_color_right; + slot_info[p_idx]=s; + update(); + connpos_dirty=true; } void GraphNode::clear_slot(int p_idx){ - slot_info.erase(p_idx); - update(); - connpos_dirty=true; + slot_info.erase(p_idx); + update(); + connpos_dirty=true; } void GraphNode::clear_all_slots(){ - slot_info.clear(); - update(); - connpos_dirty=true; + slot_info.clear(); + update(); + connpos_dirty=true; } bool GraphNode::is_slot_enabled_left(int p_idx) const{ - if (!slot_info.has(p_idx)) - return false; - return slot_info[p_idx].enable_left; + if (!slot_info.has(p_idx)) + return false; + return slot_info[p_idx].enable_left; } int GraphNode::get_slot_type_left(int p_idx) const{ - if (!slot_info.has(p_idx)) - return 0; - return slot_info[p_idx].type_left; + if (!slot_info.has(p_idx)) + return 0; + return slot_info[p_idx].type_left; } Color GraphNode::get_slot_color_left(int p_idx) const{ - if (!slot_info.has(p_idx)) - return Color(1,1,1,1); - return slot_info[p_idx].color_left; + if (!slot_info.has(p_idx)) + return Color(1,1,1,1); + return slot_info[p_idx].color_left; } bool GraphNode::is_slot_enabled_right(int p_idx) const{ - if (!slot_info.has(p_idx)) - return false; - return slot_info[p_idx].enable_right; + if (!slot_info.has(p_idx)) + return false; + return slot_info[p_idx].enable_right; } @@ -283,305 +283,305 @@ bool GraphNode::is_slot_enabled_right(int p_idx) const{ int GraphNode::get_slot_type_right(int p_idx) const{ - if (!slot_info.has(p_idx)) - return 0; - return slot_info[p_idx].type_right; + if (!slot_info.has(p_idx)) + return 0; + return slot_info[p_idx].type_right; } Color GraphNode::get_slot_color_right(int p_idx) const{ - if (!slot_info.has(p_idx)) - return Color(1,1,1,1); - return slot_info[p_idx].color_right; + if (!slot_info.has(p_idx)) + return Color(1,1,1,1); + return slot_info[p_idx].color_right; } Size2 GraphNode::get_minimum_size() const { - Ref title_font = get_font("title_font"); + Ref title_font = get_font("title_font"); - int sep=get_constant("separation"); - Ref sb=get_stylebox("frame"); - bool first=true; + int sep=get_constant("separation"); + Ref sb=get_stylebox("frame"); + bool first=true; - Size2 minsize; - minsize.x=title_font->get_string_size(title).x; - if (show_close) { - Ref close =get_icon("close"); - minsize.x+=sep+close->get_width(); - } + Size2 minsize; + minsize.x=title_font->get_string_size(title).x; + if (show_close) { + Ref close =get_icon("close"); + minsize.x+=sep+close->get_width(); + } - for(int i=0;icast_to(); - if (!c) - continue; - if (c->is_set_as_toplevel()) - continue; + Control *c=get_child(i)->cast_to(); + if (!c) + continue; + if (c->is_set_as_toplevel()) + continue; - Size2i size=c->get_combined_minimum_size(); + Size2i size=c->get_combined_minimum_size(); - minsize.y+=size.y; - minsize.x=MAX(minsize.x,size.x); + minsize.y+=size.y; + minsize.x=MAX(minsize.x,size.x); - if (first) - first=false; - else - minsize.y+=sep; - } + if (first) + first=false; + else + minsize.y+=sep; + } - return minsize+sb->get_minimum_size(); + return minsize+sb->get_minimum_size(); } void GraphNode::set_title(const String& p_title) { - title=p_title; - minimum_size_changed(); - update(); + title=p_title; + minimum_size_changed(); + update(); } String GraphNode::get_title() const{ - return title; + return title; } void GraphNode::set_offset(const Vector2& p_offset) { - offset=p_offset; - emit_signal("offset_changed"); - update(); + offset=p_offset; + emit_signal("offset_changed"); + update(); } Vector2 GraphNode::get_offset() const { - return offset; + return offset; } void GraphNode::set_selected(bool p_selected) { - selected = p_selected; - update(); + selected = p_selected; + update(); } bool GraphNode::is_selected() { - return selected; + return selected; } void GraphNode::set_drag(bool p_drag) { - if (p_drag) - drag_from=get_offset(); - else - emit_signal("dragged",drag_from,get_offset()); //useful for undo/redo + if (p_drag) + drag_from=get_offset(); + else + emit_signal("dragged",drag_from,get_offset()); //useful for undo/redo } Vector2 GraphNode::get_drag_from() { - return drag_from; + return drag_from; } void GraphNode::set_show_close_button(bool p_enable){ - show_close=p_enable; - update(); + show_close=p_enable; + update(); } bool GraphNode::is_close_button_visible() const{ - return show_close; + return show_close; } void GraphNode::_connpos_update() { - int edgeofs=get_constant("port_offset"); - int sep=get_constant("separation"); + int edgeofs=get_constant("port_offset"); + int sep=get_constant("separation"); - Ref sb=get_stylebox("frame"); - conn_input_cache.clear(); - conn_output_cache.clear(); - int vofs=0; + Ref sb=get_stylebox("frame"); + conn_input_cache.clear(); + conn_output_cache.clear(); + int vofs=0; - int idx=0; + int idx=0; - for(int i=0;icast_to(); - if (!c) - continue; - if (c->is_set_as_toplevel()) - continue; + for(int i=0;icast_to(); + if (!c) + continue; + if (c->is_set_as_toplevel()) + continue; - Size2i size=c->get_combined_minimum_size(); + Size2i size=c->get_combined_minimum_size(); - int y = sb->get_margin(MARGIN_TOP)+vofs; - int h = size.y; + int y = sb->get_margin(MARGIN_TOP)+vofs; + int h = size.y; - if (slot_info.has(idx)) { + if (slot_info.has(idx)) { - if (slot_info[idx].enable_left) { - ConnCache cc; - cc.pos=Point2i(edgeofs,y+h/2); - cc.type=slot_info[idx].type_left; - cc.color=slot_info[idx].color_left; - conn_input_cache.push_back(cc); - } - if (slot_info[idx].enable_right) { - ConnCache cc; - cc.pos=Point2i(get_size().width-edgeofs,y+h/2); - cc.type=slot_info[idx].type_right; - cc.color=slot_info[idx].color_right; - conn_output_cache.push_back(cc); - } - } + if (slot_info[idx].enable_left) { + ConnCache cc; + cc.pos=Point2i(edgeofs,y+h/2); + cc.type=slot_info[idx].type_left; + cc.color=slot_info[idx].color_left; + conn_input_cache.push_back(cc); + } + if (slot_info[idx].enable_right) { + ConnCache cc; + cc.pos=Point2i(get_size().width-edgeofs,y+h/2); + cc.type=slot_info[idx].type_right; + cc.color=slot_info[idx].color_right; + conn_output_cache.push_back(cc); + } + } - if (vofs>0) - vofs+=sep; - vofs+=size.y; - idx++; + if (vofs>0) + vofs+=sep; + vofs+=size.y; + idx++; - } + } - connpos_dirty=false; + connpos_dirty=false; } int GraphNode::get_connection_input_count() { - if (connpos_dirty) - _connpos_update(); + if (connpos_dirty) + _connpos_update(); - return conn_input_cache.size(); + return conn_input_cache.size(); } int GraphNode::get_connection_output_count() { - if (connpos_dirty) - _connpos_update(); + if (connpos_dirty) + _connpos_update(); - return conn_output_cache.size(); + return conn_output_cache.size(); } Vector2 GraphNode::get_connection_input_pos(int p_idx) { - if (connpos_dirty) - _connpos_update(); + if (connpos_dirty) + _connpos_update(); - ERR_FAIL_INDEX_V(p_idx,conn_input_cache.size(),Vector2()); - return conn_input_cache[p_idx].pos; + ERR_FAIL_INDEX_V(p_idx,conn_input_cache.size(),Vector2()); + return conn_input_cache[p_idx].pos; } int GraphNode::get_connection_input_type(int p_idx) { - if (connpos_dirty) - _connpos_update(); + if (connpos_dirty) + _connpos_update(); - ERR_FAIL_INDEX_V(p_idx,conn_input_cache.size(),0); - return conn_input_cache[p_idx].type; + ERR_FAIL_INDEX_V(p_idx,conn_input_cache.size(),0); + return conn_input_cache[p_idx].type; } Color GraphNode::get_connection_input_color(int p_idx) { - if (connpos_dirty) - _connpos_update(); + if (connpos_dirty) + _connpos_update(); - ERR_FAIL_INDEX_V(p_idx,conn_input_cache.size(),Color()); - return conn_input_cache[p_idx].color; + ERR_FAIL_INDEX_V(p_idx,conn_input_cache.size(),Color()); + return conn_input_cache[p_idx].color; } Vector2 GraphNode::get_connection_output_pos(int p_idx){ - if (connpos_dirty) - _connpos_update(); + if (connpos_dirty) + _connpos_update(); - ERR_FAIL_INDEX_V(p_idx,conn_output_cache.size(),Vector2()); - return conn_output_cache[p_idx].pos; + ERR_FAIL_INDEX_V(p_idx,conn_output_cache.size(),Vector2()); + return conn_output_cache[p_idx].pos; } int GraphNode::get_connection_output_type(int p_idx) { - if (connpos_dirty) - _connpos_update(); + if (connpos_dirty) + _connpos_update(); - ERR_FAIL_INDEX_V(p_idx,conn_output_cache.size(),0); - return conn_output_cache[p_idx].type; + ERR_FAIL_INDEX_V(p_idx,conn_output_cache.size(),0); + return conn_output_cache[p_idx].type; } Color GraphNode::get_connection_output_color(int p_idx) { - if (connpos_dirty) - _connpos_update(); + if (connpos_dirty) + _connpos_update(); - ERR_FAIL_INDEX_V(p_idx,conn_output_cache.size(),Color()); - return conn_output_cache[p_idx].color; + ERR_FAIL_INDEX_V(p_idx,conn_output_cache.size(),Color()); + return conn_output_cache[p_idx].color; } void GraphNode::_input_event(const InputEvent& p_ev) { - if (p_ev.type==InputEvent::MOUSE_BUTTON && p_ev.mouse_button.pressed && p_ev.mouse_button.button_index==BUTTON_LEFT) { + if (p_ev.type==InputEvent::MOUSE_BUTTON && p_ev.mouse_button.pressed && p_ev.mouse_button.button_index==BUTTON_LEFT) { - Vector2 mpos = Vector2(p_ev.mouse_button.x,p_ev.mouse_button.y); - if (close_rect.size!=Size2() && close_rect.has_point(mpos)) { - emit_signal("close_request"); - return; - } - emit_signal("raise_request"); + Vector2 mpos = Vector2(p_ev.mouse_button.x,p_ev.mouse_button.y); + if (close_rect.size!=Size2() && close_rect.has_point(mpos)) { + emit_signal("close_request"); + return; + } + emit_signal("raise_request"); - } + } } void GraphNode::_bind_methods() { - ObjectTypeDB::bind_method(_MD("set_title","title"),&GraphNode::set_title); - ObjectTypeDB::bind_method(_MD("get_title"),&GraphNode::get_title); - ObjectTypeDB::bind_method(_MD("_input_event"),&GraphNode::_input_event); + ObjectTypeDB::bind_method(_MD("set_title","title"),&GraphNode::set_title); + ObjectTypeDB::bind_method(_MD("get_title"),&GraphNode::get_title); + ObjectTypeDB::bind_method(_MD("_input_event"),&GraphNode::_input_event); - ObjectTypeDB::bind_method(_MD("set_slot","idx","enable_left","type_left","color_left","enable_right","type_right","color_right"),&GraphNode::set_slot); - ObjectTypeDB::bind_method(_MD("clear_slot","idx"),&GraphNode::clear_slot); - ObjectTypeDB::bind_method(_MD("clear_all_slots","idx"),&GraphNode::clear_all_slots); - ObjectTypeDB::bind_method(_MD("is_slot_enabled_left","idx"),&GraphNode::is_slot_enabled_left); - ObjectTypeDB::bind_method(_MD("get_slot_type_left","idx"),&GraphNode::get_slot_type_left); - ObjectTypeDB::bind_method(_MD("get_slot_color_left","idx"),&GraphNode::get_slot_color_left); - ObjectTypeDB::bind_method(_MD("is_slot_enabled_right","idx"),&GraphNode::is_slot_enabled_right); - ObjectTypeDB::bind_method(_MD("get_slot_type_right","idx"),&GraphNode::get_slot_type_right); - ObjectTypeDB::bind_method(_MD("get_slot_color_right","idx"),&GraphNode::get_slot_color_right); + ObjectTypeDB::bind_method(_MD("set_slot","idx","enable_left","type_left","color_left","enable_right","type_right","color_right"),&GraphNode::set_slot); + ObjectTypeDB::bind_method(_MD("clear_slot","idx"),&GraphNode::clear_slot); + ObjectTypeDB::bind_method(_MD("clear_all_slots","idx"),&GraphNode::clear_all_slots); + ObjectTypeDB::bind_method(_MD("is_slot_enabled_left","idx"),&GraphNode::is_slot_enabled_left); + ObjectTypeDB::bind_method(_MD("get_slot_type_left","idx"),&GraphNode::get_slot_type_left); + ObjectTypeDB::bind_method(_MD("get_slot_color_left","idx"),&GraphNode::get_slot_color_left); + ObjectTypeDB::bind_method(_MD("is_slot_enabled_right","idx"),&GraphNode::is_slot_enabled_right); + ObjectTypeDB::bind_method(_MD("get_slot_type_right","idx"),&GraphNode::get_slot_type_right); + ObjectTypeDB::bind_method(_MD("get_slot_color_right","idx"),&GraphNode::get_slot_color_right); - ObjectTypeDB::bind_method(_MD("set_offset","offset"),&GraphNode::set_offset); - ObjectTypeDB::bind_method(_MD("get_offset"),&GraphNode::get_offset); + ObjectTypeDB::bind_method(_MD("set_offset","offset"),&GraphNode::set_offset); + ObjectTypeDB::bind_method(_MD("get_offset"),&GraphNode::get_offset); - ObjectTypeDB::bind_method(_MD("get_connection_output_count"),&GraphNode::get_connection_output_count); - ObjectTypeDB::bind_method(_MD("get_connection_input_count"),&GraphNode::get_connection_input_count); + ObjectTypeDB::bind_method(_MD("get_connection_output_count"),&GraphNode::get_connection_output_count); + ObjectTypeDB::bind_method(_MD("get_connection_input_count"),&GraphNode::get_connection_input_count); - ObjectTypeDB::bind_method(_MD("get_connection_output_pos","idx"),&GraphNode::get_connection_output_pos); - ObjectTypeDB::bind_method(_MD("get_connection_output_type","idx"),&GraphNode::get_connection_output_type); - ObjectTypeDB::bind_method(_MD("get_connection_output_color","idx"),&GraphNode::get_connection_output_color); - ObjectTypeDB::bind_method(_MD("get_connection_input_pos","idx"),&GraphNode::get_connection_input_pos); - ObjectTypeDB::bind_method(_MD("get_connection_input_type","idx"),&GraphNode::get_connection_input_type); - ObjectTypeDB::bind_method(_MD("get_connection_input_color","idx"),&GraphNode::get_connection_input_color); + ObjectTypeDB::bind_method(_MD("get_connection_output_pos","idx"),&GraphNode::get_connection_output_pos); + ObjectTypeDB::bind_method(_MD("get_connection_output_type","idx"),&GraphNode::get_connection_output_type); + ObjectTypeDB::bind_method(_MD("get_connection_output_color","idx"),&GraphNode::get_connection_output_color); + ObjectTypeDB::bind_method(_MD("get_connection_input_pos","idx"),&GraphNode::get_connection_input_pos); + ObjectTypeDB::bind_method(_MD("get_connection_input_type","idx"),&GraphNode::get_connection_input_type); + ObjectTypeDB::bind_method(_MD("get_connection_input_color","idx"),&GraphNode::get_connection_input_color); - ObjectTypeDB::bind_method(_MD("set_show_close_button","show"),&GraphNode::set_show_close_button); - ObjectTypeDB::bind_method(_MD("is_close_button_visible"),&GraphNode::is_close_button_visible); + ObjectTypeDB::bind_method(_MD("set_show_close_button","show"),&GraphNode::set_show_close_button); + ObjectTypeDB::bind_method(_MD("is_close_button_visible"),&GraphNode::is_close_button_visible); - ADD_PROPERTY( PropertyInfo(Variant::STRING,"title"),_SCS("set_title"),_SCS("get_title")); - ADD_PROPERTY( PropertyInfo(Variant::BOOL,"show_close"),_SCS("set_show_close_button"),_SCS("is_close_button_visible")); + ADD_PROPERTY( PropertyInfo(Variant::STRING,"title"),_SCS("set_title"),_SCS("get_title")); + ADD_PROPERTY( PropertyInfo(Variant::BOOL,"show_close"),_SCS("set_show_close_button"),_SCS("is_close_button_visible")); - ADD_SIGNAL(MethodInfo("offset_changed")); - ADD_SIGNAL(MethodInfo("dragged",PropertyInfo(Variant::VECTOR2,"from"),PropertyInfo(Variant::VECTOR2,"to"))); - ADD_SIGNAL(MethodInfo("raise_request")); - ADD_SIGNAL(MethodInfo("close_request")); + ADD_SIGNAL(MethodInfo("offset_changed")); + ADD_SIGNAL(MethodInfo("dragged",PropertyInfo(Variant::VECTOR2,"from"),PropertyInfo(Variant::VECTOR2,"to"))); + ADD_SIGNAL(MethodInfo("raise_request")); + ADD_SIGNAL(MethodInfo("close_request")); } GraphNode::GraphNode() { - show_close=false; - connpos_dirty=true; + show_close=false; + connpos_dirty=true; } diff --git a/scene/gui/graph_node.h b/scene/gui/graph_node.h index 6bece22ac584..201529380dd0 100644 --- a/scene/gui/graph_node.h +++ b/scene/gui/graph_node.h @@ -5,101 +5,101 @@ class GraphNode : public Container { - OBJ_TYPE(GraphNode,Container); + OBJ_TYPE(GraphNode,Container); - struct Slot { - bool enable_left; - int type_left; - Color color_left; - bool enable_right; - int type_right; - Color color_right; + struct Slot { + bool enable_left; + int type_left; + Color color_left; + bool enable_right; + int type_right; + Color color_right; - Slot() { enable_left=false; type_left=0; color_left=Color(1,1,1,1); enable_right=false; type_right=0; color_right=Color(1,1,1,1); } - }; + Slot() { enable_left=false; type_left=0; color_left=Color(1,1,1,1); enable_right=false; type_right=0; color_right=Color(1,1,1,1); } + }; - String title; - bool show_close; - Vector2 offset; + String title; + bool show_close; + Vector2 offset; - Rect2 close_rect; + Rect2 close_rect; - Vector cache_y; + Vector cache_y; - struct ConnCache { - Vector2 pos; - int type; - Color color; - }; + struct ConnCache { + Vector2 pos; + int type; + Color color; + }; - Vector conn_input_cache; - Vector conn_output_cache; + Vector conn_input_cache; + Vector conn_output_cache; - Map slot_info; + Map slot_info; - bool connpos_dirty; + bool connpos_dirty; - void _connpos_update(); - void _resort(); + void _connpos_update(); + void _resort(); - Vector2 drag_from; - bool selected; + Vector2 drag_from; + bool selected; protected: - void _input_event(const InputEvent& p_ev); - void _notification(int p_what); - static void _bind_methods(); + void _input_event(const InputEvent& p_ev); + void _notification(int p_what); + static void _bind_methods(); - bool _set(const StringName& p_name, const Variant& p_value); - bool _get(const StringName& p_name,Variant &r_ret) const; - void _get_property_list( List *p_list) const; + bool _set(const StringName& p_name, const Variant& p_value); + bool _get(const StringName& p_name,Variant &r_ret) const; + void _get_property_list( List *p_list) const; public: - void set_slot(int p_idx,bool p_enable_left,int p_type_left,const Color& p_color_left, bool p_enable_right,int p_type_right,const Color& p_color_right); - void clear_slot(int p_idx); - void clear_all_slots(); - bool is_slot_enabled_left(int p_idx) const; - int get_slot_type_left(int p_idx) const; - Color get_slot_color_left(int p_idx) const; - bool is_slot_enabled_right(int p_idx) const; - int get_slot_type_right(int p_idx) const; - Color get_slot_color_right(int p_idx) const; + void set_slot(int p_idx,bool p_enable_left,int p_type_left,const Color& p_color_left, bool p_enable_right,int p_type_right,const Color& p_color_right); + void clear_slot(int p_idx); + void clear_all_slots(); + bool is_slot_enabled_left(int p_idx) const; + int get_slot_type_left(int p_idx) const; + Color get_slot_color_left(int p_idx) const; + bool is_slot_enabled_right(int p_idx) const; + int get_slot_type_right(int p_idx) const; + Color get_slot_color_right(int p_idx) const; - void set_title(const String& p_title); - String get_title() const; + void set_title(const String& p_title); + String get_title() const; - void set_offset(const Vector2& p_offset); - Vector2 get_offset() const; + void set_offset(const Vector2& p_offset); + Vector2 get_offset() const; - void set_selected(bool p_selected); - bool is_selected(); + void set_selected(bool p_selected); + bool is_selected(); - void set_drag(bool p_drag); - Vector2 get_drag_from(); + void set_drag(bool p_drag); + Vector2 get_drag_from(); - void set_show_close_button(bool p_enable); - bool is_close_button_visible() const; + void set_show_close_button(bool p_enable); + bool is_close_button_visible() const; - int get_connection_input_count() ; - int get_connection_output_count() ; - Vector2 get_connection_input_pos(int p_idx); - int get_connection_input_type(int p_idx); - Color get_connection_input_color(int p_idx); - Vector2 get_connection_output_pos(int p_idx); - int get_connection_output_type(int p_idx); - Color get_connection_output_color(int p_idx); + int get_connection_input_count() ; + int get_connection_output_count() ; + Vector2 get_connection_input_pos(int p_idx); + int get_connection_input_type(int p_idx); + Color get_connection_input_color(int p_idx); + Vector2 get_connection_output_pos(int p_idx); + int get_connection_output_type(int p_idx); + Color get_connection_output_color(int p_idx); - virtual Size2 get_minimum_size() const; + virtual Size2 get_minimum_size() const; - GraphNode(); + GraphNode(); }; diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index 667dfd46328d..58ba5fba254c 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -31,7 +31,7 @@ static TexCacheMap *tex_cache; template static Ref make_stylebox(T p_src,float p_left, float p_top, float p_right, float p_botton,float p_margin_left=-1, float p_margin_top=-1, float p_margin_right=-1, float p_margin_botton=-1, bool p_draw_center=true) { - + Ref texture; @@ -56,17 +56,17 @@ static Ref make_stylebox(T p_src,float p_left, float p_top, flo style->set_default_margin( MARGIN_BOTTOM, p_margin_botton ); style->set_default_margin( MARGIN_TOP, p_margin_top ); style->set_draw_center(p_draw_center); - + return style; } template static Ref make_icon(T p_src) { - - + + Ref texture( memnew( ImageTexture ) ); texture->create_from_image( Image(p_src),ImageTexture::FLAG_FILTER ); - + return texture; } @@ -75,7 +75,7 @@ static Ref make_font(int p_height,int p_ascent, int p_valign, int p_charco Ref font( memnew( Font ) ); font->add_texture( p_texture ); - + for (int i=0;i make_font(int p_height,int p_ascent, int p_valign, int p_charco font->add_char( chr, 0, frect, align,advance ); - + } - + font->set_height( p_height ); font->set_ascent( p_ascent ); @@ -152,12 +152,12 @@ static Ref make_font2(int p_height,int p_ascent, int p_charcount, const in static Ref make_empty_stylebox(float p_margin_left=-1, float p_margin_top=-1, float p_margin_right=-1, float p_margin_botton=-1) { Ref style( memnew( StyleBoxEmpty) ); - + style->set_default_margin( MARGIN_LEFT, p_margin_left ); style->set_default_margin( MARGIN_RIGHT, p_margin_right ); style->set_default_margin( MARGIN_BOTTOM, p_margin_botton ); style->set_default_margin( MARGIN_TOP, p_margin_top ); - + return style; } @@ -300,49 +300,49 @@ void make_default_theme() { t->set_constant("hseparation","MenuButton", 0 ); - // CheckBox + // CheckBox - Ref cbx_empty = memnew( StyleBoxEmpty ); - cbx_empty->set_default_margin(MARGIN_LEFT,22); - cbx_empty->set_default_margin(MARGIN_RIGHT,4); - cbx_empty->set_default_margin(MARGIN_TOP,4); - cbx_empty->set_default_margin(MARGIN_BOTTOM,5); - Ref cbx_focus = focus; - cbx_focus->set_default_margin(MARGIN_LEFT,4); - cbx_focus->set_default_margin(MARGIN_RIGHT,22); - cbx_focus->set_default_margin(MARGIN_TOP,4); - cbx_focus->set_default_margin(MARGIN_BOTTOM,5); + Ref cbx_empty = memnew( StyleBoxEmpty ); + cbx_empty->set_default_margin(MARGIN_LEFT,22); + cbx_empty->set_default_margin(MARGIN_RIGHT,4); + cbx_empty->set_default_margin(MARGIN_TOP,4); + cbx_empty->set_default_margin(MARGIN_BOTTOM,5); + Ref cbx_focus = focus; + cbx_focus->set_default_margin(MARGIN_LEFT,4); + cbx_focus->set_default_margin(MARGIN_RIGHT,22); + cbx_focus->set_default_margin(MARGIN_TOP,4); + cbx_focus->set_default_margin(MARGIN_BOTTOM,5); - t->set_stylebox("normal","CheckBox", cbx_empty ); - t->set_stylebox("pressed","CheckBox", cbx_empty ); - t->set_stylebox("disabled","CheckBox", cbx_empty ); - t->set_stylebox("hover","CheckBox", cbx_empty ); - t->set_stylebox("focus","CheckBox", cbx_focus ); + t->set_stylebox("normal","CheckBox", cbx_empty ); + t->set_stylebox("pressed","CheckBox", cbx_empty ); + t->set_stylebox("disabled","CheckBox", cbx_empty ); + t->set_stylebox("hover","CheckBox", cbx_empty ); + t->set_stylebox("focus","CheckBox", cbx_focus ); - t->set_icon("checked", "CheckBox", make_icon(checked_png)); - t->set_icon("unchecked", "CheckBox", make_icon(unchecked_png)); - t->set_icon("radio_checked", "CheckBox", make_icon(radio_checked_png)); - t->set_icon("radio_unchecked", "CheckBox", make_icon(radio_unchecked_png)); + t->set_icon("checked", "CheckBox", make_icon(checked_png)); + t->set_icon("unchecked", "CheckBox", make_icon(unchecked_png)); + t->set_icon("radio_checked", "CheckBox", make_icon(radio_checked_png)); + t->set_icon("radio_unchecked", "CheckBox", make_icon(radio_unchecked_png)); - t->set_font("font","CheckBox", default_font ); + t->set_font("font","CheckBox", default_font ); - t->set_color("font_color","CheckBox", control_font_color ); - t->set_color("font_color_pressed","CheckBox", control_font_color_pressed ); - t->set_color("font_color_hover","CheckBox", control_font_color_hover ); - t->set_color("font_color_disabled","CheckBox", control_font_color_disabled ); + t->set_color("font_color","CheckBox", control_font_color ); + t->set_color("font_color_pressed","CheckBox", control_font_color_pressed ); + t->set_color("font_color_hover","CheckBox", control_font_color_hover ); + t->set_color("font_color_disabled","CheckBox", control_font_color_disabled ); - t->set_constant("hseparation","CheckBox",4); - t->set_constant("check_vadjust","CheckBox",0); + t->set_constant("hseparation","CheckBox",4); + t->set_constant("check_vadjust","CheckBox",0); // CheckButton - + Ref cb_empty = memnew( StyleBoxEmpty ); cb_empty->set_default_margin(MARGIN_LEFT,6); cb_empty->set_default_margin(MARGIN_RIGHT,70); cb_empty->set_default_margin(MARGIN_TOP,4); - cb_empty->set_default_margin(MARGIN_BOTTOM,4); + cb_empty->set_default_margin(MARGIN_BOTTOM,4); t->set_stylebox("normal","CheckButton", cb_empty ); t->set_stylebox("pressed","CheckButton", cb_empty ); @@ -366,7 +366,7 @@ void make_default_theme() { // Label - + t->set_font("font","Label", default_font ); t->set_color("font_color","Label", Color(1,1,1) ); @@ -558,11 +558,11 @@ void make_default_theme() { // GraphNode Ref graphsb = make_stylebox(graph_node_png,6,24,6,5,16,24,16,5); - Ref graphsbselected = make_stylebox(graph_node_selected_png,6,24,6,5,16,24,16,5); + Ref graphsbselected = make_stylebox(graph_node_selected_png,6,24,6,5,16,24,16,5); //graphsb->set_expand_margin_size(MARGIN_LEFT,10); //graphsb->set_expand_margin_size(MARGIN_RIGHT,10); t->set_stylebox("frame","GraphNode", graphsb ); - t->set_stylebox("selectedframe","GraphNode", graphsbselected ); + t->set_stylebox("selectedframe","GraphNode", graphsbselected ); t->set_constant("separation","GraphNode", 1 ); t->set_icon("port","GraphNode", make_icon( graph_port_png ) ); t->set_icon("close","GraphNode", make_icon( graph_node_close_png ) ); @@ -713,7 +713,7 @@ void make_default_theme() { // FileDialog - + t->set_icon("folder","FileDialog",make_icon(icon_folder_png)); t->set_color("files_disabled","FileDialog",Color(0,0,0,0.7)); @@ -877,10 +877,10 @@ void make_default_theme() { #endif void clear_default_theme() { - + Theme::set_default( Ref() ); Theme::set_default_icon( Ref< Texture >() ); - Theme::set_default_style( Ref< StyleBox >() ); + Theme::set_default_style( Ref< StyleBox >() ); Theme::set_default_font( Ref< Font >() ); } diff --git a/tools/editor/plugins/shader_graph_editor_plugin.cpp b/tools/editor/plugins/shader_graph_editor_plugin.cpp index a0f7edbd933b..6e95432b99fe 100644 --- a/tools/editor/plugins/shader_graph_editor_plugin.cpp +++ b/tools/editor/plugins/shader_graph_editor_plugin.cpp @@ -37,596 +37,596 @@ void GraphColorRampEdit::_input_event(const InputEvent& p_event) { - if (p_event.type==InputEvent::KEY && p_event.key.pressed && p_event.key.scancode==KEY_DELETE && grabbed!=-1) { - - points.remove(grabbed); - grabbed=-1; - update(); - emit_signal("ramp_changed"); - accept_event(); - } - - if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==1 && p_event.mouse_button.pressed) { + if (p_event.type==InputEvent::KEY && p_event.key.pressed && p_event.key.scancode==KEY_DELETE && grabbed!=-1) { + + points.remove(grabbed); + grabbed=-1; + update(); + emit_signal("ramp_changed"); + accept_event(); + } + + if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==1 && p_event.mouse_button.pressed) { - update(); - int x = p_event.mouse_button.x; - int total_w = get_size().width-get_size().height-3; - if (x>total_w+3) { - - if (grabbed==-1) - return; - Size2 ms = Size2(350, picker->get_combined_minimum_size().height+10); - picker->set_color(points[grabbed].color); - popup->set_pos(get_global_pos()-Size2(0,ms.height)); - popup->set_size(ms); - popup->popup(); - return; - } - - - float ofs = CLAMP(x/float(total_w),0,1); - - grabbed=-1; - grabbing=true; - int pos=-1; - for(int i=0;itotal_w+3) { + + if (grabbed==-1) + return; + Size2 ms = Size2(350, picker->get_combined_minimum_size().height+10); + picker->set_color(points[grabbed].color); + popup->set_pos(get_global_pos()-Size2(0,ms.height)); + popup->set_size(ms); + popup->popup(); + return; + } + + + float ofs = CLAMP(x/float(total_w),0,1); + + grabbed=-1; + grabbing=true; + int pos=-1; + for(int i=0;iconnect("color_changed",this,"_color_changed"); - } - if (p_what==NOTIFICATION_DRAW) { + if (p_what==NOTIFICATION_ENTER_TREE) { + picker->connect("color_changed",this,"_color_changed"); + } + if (p_what==NOTIFICATION_DRAW) { - Point prev; - prev.offset=0; - prev.color=Color(0,0,0); - int w = get_size().x; - int h = get_size().y; + Point prev; + prev.offset=0; + prev.color=Color(0,0,0); + int w = get_size().x; + int h = get_size().y; - int total_w = get_size().width-get_size().height-3; + int total_w = get_size().width-get_size().height-3; - for(int i=-1;i points; - Vector colors; - points.push_back(Vector2(prev.offset*total_w,h)); - points.push_back(Vector2(prev.offset*total_w,0)); - points.push_back(Vector2(next.offset*total_w,0)); - points.push_back(Vector2(next.offset*total_w,h)); - colors.push_back(prev.color); - colors.push_back(prev.color); - colors.push_back(next.color); - colors.push_back(next.color); - draw_primitive(points,colors,Vector()); - prev=next; - } + Vector points; + Vector colors; + points.push_back(Vector2(prev.offset*total_w,h)); + points.push_back(Vector2(prev.offset*total_w,0)); + points.push_back(Vector2(next.offset*total_w,0)); + points.push_back(Vector2(next.offset*total_w,h)); + colors.push_back(prev.color); + colors.push_back(prev.color); + colors.push_back(next.color); + colors.push_back(next.color); + draw_primitive(points,colors,Vector()); + prev=next; + } - for(int i=0;i& p_offsets,const Vector& p_colors) { - ERR_FAIL_COND(p_offsets.size()!=p_colors.size()); - points.clear(); - for(int i=0;i GraphColorRampEdit::get_offsets() const{ - Vector ret; - for(int i=0;i ret; + for(int i=0;i GraphColorRampEdit::get_colors() const{ - Vector ret; - for(int i=0;i ret; + for(int i=0;iadd_child(picker); - popup->set_child_rect(picker); - add_child(popup); + popup = memnew( PopupPanel ); + picker = memnew( ColorPicker ); + popup->add_child(picker); + popup->set_child_rect(picker); + add_child(popup); } //////////// void GraphCurveMapEdit::_input_event(const InputEvent& p_event) { - if (p_event.type==InputEvent::KEY && p_event.key.pressed && p_event.key.scancode==KEY_DELETE && grabbed!=-1) { + if (p_event.type==InputEvent::KEY && p_event.key.pressed && p_event.key.scancode==KEY_DELETE && grabbed!=-1) { - points.remove(grabbed); - grabbed=-1; - update(); - emit_signal("curve_changed"); - accept_event(); - } + points.remove(grabbed); + grabbed=-1; + update(); + emit_signal("curve_changed"); + accept_event(); + } - if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==1 && p_event.mouse_button.pressed) { + if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==1 && p_event.mouse_button.pressed) { - update(); - Point2 p = Vector2(p_event.mouse_button.x,p_event.mouse_button.y)/get_size(); - p.y=1.0-p.y; - grabbed=-1; - grabbing=true; + update(); + Point2 p = Vector2(p_event.mouse_button.x,p_event.mouse_button.y)/get_size(); + p.y=1.0-p.y; + grabbed=-1; + grabbing=true; - for(int i=0;icurve[cd->outline][lastx] = lasty; - } - else - { - cd->curve_ptr[cd->outline][lastx] = lasty; - if(gb_debug) printf("bender_plot_curve xmax:%d ymax:%d\n", (int)xmax, (int)ymax); - } + float geometry[4][4]; + float tmp1[4][4]; + float tmp2[4][4]; + float deltas[4][4]; + double x, dx, dx2, dx3; + double y, dy, dy2, dy3; + double d, d2, d3; + int lastx, lasty; + int newx, newy; + int ntimes; + int i,j; + + int xmax=get_size().x; + int ymax=get_size().y; + + /* construct the geometry matrix from the segment */ + for (i = 0; i < 4; i++) { + geometry[i][2] = 0; + geometry[i][3] = 0; + } + + geometry[0][0] = (p_a[0] * xmax); + geometry[1][0] = (p_b[0] * xmax); + geometry[2][0] = (p_c[0] * xmax); + geometry[3][0] = (p_d[0] * xmax); + + geometry[0][1] = (p_a[1] * ymax); + geometry[1][1] = (p_b[1] * ymax); + geometry[2][1] = (p_c[1] * ymax); + geometry[3][1] = (p_d[1] * ymax); + + /* subdivide the curve ntimes (1000) times */ + ntimes = 4 * xmax; + /* ntimes can be adjusted to give a finer or coarser curve */ + d = 1.0 / ntimes; + d2 = d * d; + d3 = d * d * d; + + /* construct a temporary matrix for determining the forward differencing deltas */ + tmp2[0][0] = 0; tmp2[0][1] = 0; tmp2[0][2] = 0; tmp2[0][3] = 1; + tmp2[1][0] = d3; tmp2[1][1] = d2; tmp2[1][2] = d; tmp2[1][3] = 0; + tmp2[2][0] = 6*d3; tmp2[2][1] = 2*d2; tmp2[2][2] = 0; tmp2[2][3] = 0; + tmp2[3][0] = 6*d3; tmp2[3][1] = 0; tmp2[3][2] = 0; tmp2[3][3] = 0; + + /* compose the basis and geometry matrices */ + + static const float CR_basis[4][4] = + { + { -0.5, 1.5, -1.5, 0.5 }, + { 1.0, -2.5, 2.0, -0.5 }, + { -0.5, 0.0, 0.5, 0.0 }, + { 0.0, 1.0, 0.0, 0.0 }, + }; + + for (i = 0; i < 4; i++) + { + for (j = 0; j < 4; j++) + { + tmp1[i][j] = (CR_basis[i][0] * geometry[0][j] + + CR_basis[i][1] * geometry[1][j] + + CR_basis[i][2] * geometry[2][j] + + CR_basis[i][3] * geometry[3][j]); + } + } + /* compose the above results to get the deltas matrix */ + + for (i = 0; i < 4; i++) + { + for (j = 0; j < 4; j++) + { + deltas[i][j] = (tmp2[i][0] * tmp1[0][j] + + tmp2[i][1] * tmp1[1][j] + + tmp2[i][2] * tmp1[2][j] + + tmp2[i][3] * tmp1[3][j]); + } + } + + + /* extract the x deltas */ + x = deltas[0][0]; + dx = deltas[1][0]; + dx2 = deltas[2][0]; + dx3 = deltas[3][0]; + + /* extract the y deltas */ + y = deltas[0][1]; + dy = deltas[1][1]; + dy2 = deltas[2][1]; + dy3 = deltas[3][1]; + + + lastx = CLAMP (x, 0, xmax); + lasty = CLAMP (y, 0, ymax); + + /* if (fix255) + { + cd->curve[cd->outline][lastx] = lasty; + } + else + { + cd->curve_ptr[cd->outline][lastx] = lasty; + if(gb_debug) printf("bender_plot_curve xmax:%d ymax:%d\n", (int)xmax, (int)ymax); + } */ - /* loop over the curve */ - for (i = 0; i < ntimes; i++) - { - /* increment the x values */ - x += dx; - dx += dx2; - dx2 += dx3; - - /* increment the y values */ - y += dy; - dy += dy2; - dy2 += dy3; - - newx = CLAMP ((Math::round (x)), 0, xmax); - newy = CLAMP ((Math::round (y)), 0, ymax); - - /* if this point is different than the last one...then draw it */ - if ((lastx != newx) || (lasty != newy)) - { + /* loop over the curve */ + for (i = 0; i < ntimes; i++) + { + /* increment the x values */ + x += dx; + dx += dx2; + dx2 += dx3; + + /* increment the y values */ + y += dy; + dy += dy2; + dy2 += dy3; + + newx = CLAMP ((Math::round (x)), 0, xmax); + newy = CLAMP ((Math::round (y)), 0, ymax); + + /* if this point is different than the last one...then draw it */ + if ((lastx != newx) || (lasty != newy)) + { #if 0 - if(fix255) - { - /* use fixed array size (for the curve graph) */ - cd->curve[cd->outline][newx] = newy; - } - else - { - /* use dynamic allocated curve_ptr (for the real curve) */ - cd->curve_ptr[cd->outline][newx] = newy; - - if(gb_debug) printf("outline: %d cX: %d cY: %d\n", (int)cd->outline, (int)newx, (int)newy); - } + if(fix255) + { + /* use fixed array size (for the curve graph) */ + cd->curve[cd->outline][newx] = newy; + } + else + { + /* use dynamic allocated curve_ptr (for the real curve) */ + cd->curve_ptr[cd->outline][newx] = newy; + + if(gb_debug) printf("outline: %d cX: %d cY: %d\n", (int)cd->outline, (int)newx, (int)newy); + } #endif - draw_line(Vector2(lastx,ymax-lasty),Vector2(newx,ymax-newy),Color(0.8,0.8,0.8,0.8),2.0); - } + draw_line(Vector2(lastx,ymax-lasty),Vector2(newx,ymax-newy),Color(0.8,0.8,0.8,0.8),2.0); + } - lastx = newx; - lasty = newy; - } + lastx = newx; + lasty = newy; + } } void GraphCurveMapEdit::_notification(int p_what){ - if (p_what==NOTIFICATION_DRAW) { + if (p_what==NOTIFICATION_DRAW) { - draw_style_box(get_stylebox("bg","Tree"),Rect2(Point2(),get_size())); + draw_style_box(get_stylebox("bg","Tree"),Rect2(Point2(),get_size())); - int w = get_size().x; - int h = get_size().y; + int w = get_size().x; + int h = get_size().y; - Vector2 prev=Vector2(0,0); - Vector2 prev2=Vector2(0,0); + Vector2 prev=Vector2(0,0); + Vector2 prev2=Vector2(0,0); - for(int i=-1;i=points.size()) { - next=Vector2(1,1); - } else { - next=Vector2(points[i+1].offset,points[i+1].height); - } + Vector2 next; + Vector2 next2; + if (i+1>=points.size()) { + next=Vector2(1,1); + } else { + next=Vector2(points[i+1].offset,points[i+1].height); + } - if (i+2>=points.size()) { - next2=Vector2(1,1); - } else { - next2=Vector2(points[i+2].offset,points[i+2].height); - } + if (i+2>=points.size()) { + next2=Vector2(1,1); + } else { + next2=Vector2(points[i+2].offset,points[i+2].height); + } - /*if (i==-1 && prev.offset==next.offset) { - prev=next; - continue; - }*/ + /*if (i==-1 && prev.offset==next.offset) { + prev=next; + continue; + }*/ - _plot_curve(prev2,prev,next,next2); + _plot_curve(prev2,prev,next,next2); - prev2=prev; - prev=next; - } + prev2=prev; + prev=next; + } - for(int i=0;i& p_points) { - points.clear(); - for(int i=0;i GraphCurveMapEdit::get_points() const { - Vector ret; - for(int i=0;i ret; + for(int i=0;iget_undo_redo(); - ur->create_action("Change Scalar Constant",true); - ur->add_do_method(graph.ptr(),"scalar_const_node_set_value",type,p_id,p_value); - ur->add_undo_method(graph.ptr(),"scalar_const_node_set_value",type,p_id,graph->scalar_const_node_get_value(type,p_id)); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - block_update=true; - ur->commit_action(); - block_update=false; + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change Scalar Constant",true); + ur->add_do_method(graph.ptr(),"scalar_const_node_set_value",type,p_id,p_value); + ur->add_undo_method(graph.ptr(),"scalar_const_node_set_value",type,p_id,graph->scalar_const_node_get_value(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; } void ShaderGraphView::_vec_const_changed(double p_value, int p_id,Array p_arr){ - Vector3 val; - for(int i=0;iget_undo_redo(); - ur->create_action("Change Vec Constant",true); - ur->add_do_method(graph.ptr(),"vec_const_node_set_value",type,p_id,val); - ur->add_undo_method(graph.ptr(),"vec_const_node_set_value",type,p_id,graph->vec_const_node_get_value(type,p_id)); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - block_update=true; - ur->commit_action(); - block_update=false; + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change Vec Constant",true); + ur->add_do_method(graph.ptr(),"vec_const_node_set_value",type,p_id,val); + ur->add_undo_method(graph.ptr(),"vec_const_node_set_value",type,p_id,graph->vec_const_node_get_value(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; } void ShaderGraphView::_rgb_const_changed(const Color& p_color, int p_id){ - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - ur->create_action("Change RGB Constant",true); - ur->add_do_method(graph.ptr(),"rgb_const_node_set_value",type,p_id,p_color); - ur->add_undo_method(graph.ptr(),"rgb_const_node_set_value",type,p_id,graph->rgb_const_node_get_value(type,p_id)); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - block_update=true; - ur->commit_action(); - block_update=false; + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change RGB Constant",true); + ur->add_do_method(graph.ptr(),"rgb_const_node_set_value",type,p_id,p_color); + ur->add_undo_method(graph.ptr(),"rgb_const_node_set_value",type,p_id,graph->rgb_const_node_get_value(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; } void ShaderGraphView::_scalar_op_changed(int p_op, int p_id){ - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - ur->create_action("Change Scalar Operator"); - ur->add_do_method(graph.ptr(),"scalar_op_node_set_op",type,p_id,p_op); - ur->add_undo_method(graph.ptr(),"scalar_op_node_set_op",type,p_id,graph->scalar_op_node_get_op(type,p_id)); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - block_update=true; - ur->commit_action(); - block_update=false; + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change Scalar Operator"); + ur->add_do_method(graph.ptr(),"scalar_op_node_set_op",type,p_id,p_op); + ur->add_undo_method(graph.ptr(),"scalar_op_node_set_op",type,p_id,graph->scalar_op_node_get_op(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; } void ShaderGraphView::_vec_op_changed(int p_op, int p_id){ - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - ur->create_action("Change Vec Operator"); - ur->add_do_method(graph.ptr(),"vec_op_node_set_op",type,p_id,p_op); - ur->add_undo_method(graph.ptr(),"vec_op_node_set_op",type,p_id,graph->vec_op_node_get_op(type,p_id)); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - block_update=true; - ur->commit_action(); - block_update=false; + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change Vec Operator"); + ur->add_do_method(graph.ptr(),"vec_op_node_set_op",type,p_id,p_op); + ur->add_undo_method(graph.ptr(),"vec_op_node_set_op",type,p_id,graph->vec_op_node_get_op(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; } void ShaderGraphView::_vec_scalar_op_changed(int p_op, int p_id){ - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - ur->create_action("Change VecxScalar Operator"); - ur->add_do_method(graph.ptr(),"vec_scalar_op_node_set_op",type,p_id,p_op); - ur->add_undo_method(graph.ptr(),"vec_scalar_op_node_set_op",type,p_id,graph->vec_scalar_op_node_get_op(type,p_id)); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - block_update=true; - ur->commit_action(); - block_update=false; + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change VecxScalar Operator"); + ur->add_do_method(graph.ptr(),"vec_scalar_op_node_set_op",type,p_id,p_op); + ur->add_undo_method(graph.ptr(),"vec_scalar_op_node_set_op",type,p_id,graph->vec_scalar_op_node_get_op(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; } void ShaderGraphView::_rgb_op_changed(int p_op, int p_id){ - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - ur->create_action("Change RGB Operator"); - ur->add_do_method(graph.ptr(),"rgb_op_node_set_op",type,p_id,p_op); - ur->add_undo_method(graph.ptr(),"rgb_op_node_set_op",type,p_id,graph->rgb_op_node_get_op(type,p_id)); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - block_update=true; - ur->commit_action(); - block_update=false; + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change RGB Operator"); + ur->add_do_method(graph.ptr(),"rgb_op_node_set_op",type,p_id,p_op); + ur->add_undo_method(graph.ptr(),"rgb_op_node_set_op",type,p_id,graph->rgb_op_node_get_op(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; } void ShaderGraphView::_xform_inv_rev_changed(bool p_enabled, int p_id){ - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - ur->create_action("Toggle Rot Only"); - ur->add_do_method(graph.ptr(),"xform_vec_mult_node_set_no_translation",type,p_id,p_enabled); - ur->add_undo_method(graph.ptr(),"xform_vec_mult_node_set_no_translation",type,p_id,graph->xform_vec_mult_node_get_no_translation(type,p_id)); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - block_update=true; - ur->commit_action(); - block_update=false; + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Toggle Rot Only"); + ur->add_do_method(graph.ptr(),"xform_vec_mult_node_set_no_translation",type,p_id,p_enabled); + ur->add_undo_method(graph.ptr(),"xform_vec_mult_node_set_no_translation",type,p_id,graph->xform_vec_mult_node_get_no_translation(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; } void ShaderGraphView::_scalar_func_changed(int p_func, int p_id){ - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - ur->create_action("Change Scalar Function"); - ur->add_do_method(graph.ptr(),"scalar_func_node_set_function",type,p_id,p_func); - ur->add_undo_method(graph.ptr(),"scalar_func_node_set_function",type,p_id,graph->scalar_func_node_get_function(type,p_id)); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - block_update=true; - ur->commit_action(); - block_update=false; + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change Scalar Function"); + ur->add_do_method(graph.ptr(),"scalar_func_node_set_function",type,p_id,p_func); + ur->add_undo_method(graph.ptr(),"scalar_func_node_set_function",type,p_id,graph->scalar_func_node_get_function(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; } void ShaderGraphView::_vec_func_changed(int p_func, int p_id){ - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - ur->create_action("Change Vec Function"); - ur->add_do_method(graph.ptr(),"vec_func_node_set_function",type,p_id,p_func); - ur->add_undo_method(graph.ptr(),"vec_func_node_set_function",type,p_id,graph->vec_func_node_get_function(type,p_id)); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - block_update=true; - ur->commit_action(); - block_update=false; + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change Vec Function"); + ur->add_do_method(graph.ptr(),"vec_func_node_set_function",type,p_id,p_func); + ur->add_undo_method(graph.ptr(),"vec_func_node_set_function",type,p_id,graph->vec_func_node_get_function(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; } void ShaderGraphView::_scalar_input_changed(double p_value,int p_id){ - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - ur->create_action("Change Scalar Uniform",true); - ur->add_do_method(graph.ptr(),"scalar_input_node_set_value",type,p_id,p_value); - ur->add_undo_method(graph.ptr(),"scalar_input_node_set_value",type,p_id,graph->scalar_input_node_get_value(type,p_id)); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - block_update=true; - ur->commit_action(); - block_update=false; + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change Scalar Uniform",true); + ur->add_do_method(graph.ptr(),"scalar_input_node_set_value",type,p_id,p_value); + ur->add_undo_method(graph.ptr(),"scalar_input_node_set_value",type,p_id,graph->scalar_input_node_get_value(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; } void ShaderGraphView::_vec_input_changed(double p_value, int p_id,Array p_arr){ - Vector3 val; - for(int i=0;iget_undo_redo(); - ur->create_action("Change Vec Uniform",true); - ur->add_do_method(graph.ptr(),"vec_input_node_set_value",type,p_id,val); - ur->add_undo_method(graph.ptr(),"vec_input_node_set_value",type,p_id,graph->vec_input_node_get_value(type,p_id)); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - block_update=true; - ur->commit_action(); - block_update=false; + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change Vec Uniform",true); + ur->add_do_method(graph.ptr(),"vec_input_node_set_value",type,p_id,val); + ur->add_undo_method(graph.ptr(),"vec_input_node_set_value",type,p_id,graph->vec_input_node_get_value(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; } void ShaderGraphView::_xform_input_changed(int p_id, Node *p_button){ - ToolButton *tb = p_button->cast_to(); - ped_popup->set_pos(tb->get_global_pos()+Vector2(0,tb->get_size().height)); - ped_popup->set_size(tb->get_size()); - edited_id=p_id; - ped_popup->edit(NULL,"",Variant::TRANSFORM,graph->xform_input_node_get_value(type,p_id),PROPERTY_HINT_NONE,""); - ped_popup->popup(); + ToolButton *tb = p_button->cast_to(); + ped_popup->set_pos(tb->get_global_pos()+Vector2(0,tb->get_size().height)); + ped_popup->set_size(tb->get_size()); + edited_id=p_id; + ped_popup->edit(NULL,"",Variant::TRANSFORM,graph->xform_input_node_get_value(type,p_id),PROPERTY_HINT_NONE,""); + ped_popup->popup(); } void ShaderGraphView::_xform_const_changed(int p_id, Node *p_button){ - ToolButton *tb = p_button->cast_to(); - ped_popup->set_pos(tb->get_global_pos()+Vector2(0,tb->get_size().height)); - ped_popup->set_size(tb->get_size()); - edited_id=p_id; - ped_popup->edit(NULL,"",Variant::TRANSFORM,graph->xform_const_node_get_value(type,p_id),PROPERTY_HINT_NONE,""); - ped_popup->popup(); + ToolButton *tb = p_button->cast_to(); + ped_popup->set_pos(tb->get_global_pos()+Vector2(0,tb->get_size().height)); + ped_popup->set_size(tb->get_size()); + edited_id=p_id; + ped_popup->edit(NULL,"",Variant::TRANSFORM,graph->xform_const_node_get_value(type,p_id),PROPERTY_HINT_NONE,""); + ped_popup->popup(); } void ShaderGraphView::_rgb_input_changed(const Color& p_color, int p_id){ - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - ur->create_action("Change RGB Uniform",true); - ur->add_do_method(graph.ptr(),"rgb_input_node_set_value",type,p_id,p_color); - ur->add_undo_method(graph.ptr(),"rgb_input_node_set_value",type,p_id,graph->rgb_input_node_get_value(type,p_id)); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - block_update=true; - ur->commit_action(); - block_update=false; + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change RGB Uniform",true); + ur->add_do_method(graph.ptr(),"rgb_input_node_set_value",type,p_id,p_color); + ur->add_undo_method(graph.ptr(),"rgb_input_node_set_value",type,p_id,graph->rgb_input_node_get_value(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; } void ShaderGraphView::_tex_input_change(int p_id, Node *p_button){ @@ -879,180 +879,180 @@ void ShaderGraphView::_cube_input_change(int p_id){ void ShaderGraphView::_variant_edited() { - if (graph->node_get_type(type,edited_id)==ShaderGraph::NODE_XFORM_CONST) { + if (graph->node_get_type(type,edited_id)==ShaderGraph::NODE_XFORM_CONST) { - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - ur->create_action("Change XForm Uniform"); - ur->add_do_method(graph.ptr(),"xform_const_node_set_value",type,edited_id,ped_popup->get_variant()); - ur->add_undo_method(graph.ptr(),"xform_const_node_set_value",type,edited_id,graph->xform_const_node_get_value(type,edited_id)); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - ur->commit_action(); - } + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change XForm Uniform"); + ur->add_do_method(graph.ptr(),"xform_const_node_set_value",type,edited_id,ped_popup->get_variant()); + ur->add_undo_method(graph.ptr(),"xform_const_node_set_value",type,edited_id,graph->xform_const_node_get_value(type,edited_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + ur->commit_action(); + } - if (graph->node_get_type(type,edited_id)==ShaderGraph::NODE_XFORM_INPUT) { + if (graph->node_get_type(type,edited_id)==ShaderGraph::NODE_XFORM_INPUT) { - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - ur->create_action("Change XForm Uniform"); - ur->add_do_method(graph.ptr(),"xform_input_node_set_value",type,edited_id,ped_popup->get_variant()); - ur->add_undo_method(graph.ptr(),"xform_input_node_set_value",type,edited_id,graph->xform_input_node_get_value(type,edited_id)); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - ur->commit_action(); - } + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change XForm Uniform"); + ur->add_do_method(graph.ptr(),"xform_input_node_set_value",type,edited_id,ped_popup->get_variant()); + ur->add_undo_method(graph.ptr(),"xform_input_node_set_value",type,edited_id,graph->xform_input_node_get_value(type,edited_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + ur->commit_action(); + } - if (graph->node_get_type(type,edited_id)==ShaderGraph::NODE_TEXTURE_INPUT) { + if (graph->node_get_type(type,edited_id)==ShaderGraph::NODE_TEXTURE_INPUT) { - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - ur->create_action("Change Texture Uniform"); - ur->add_do_method(graph.ptr(),"texture_input_node_set_value",type,edited_id,ped_popup->get_variant()); - ur->add_undo_method(graph.ptr(),"texture_input_node_set_value",type,edited_id,graph->texture_input_node_get_value(type,edited_id)); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - ur->commit_action(); - } + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change Texture Uniform"); + ur->add_do_method(graph.ptr(),"texture_input_node_set_value",type,edited_id,ped_popup->get_variant()); + ur->add_undo_method(graph.ptr(),"texture_input_node_set_value",type,edited_id,graph->texture_input_node_get_value(type,edited_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + ur->commit_action(); + } - if (graph->node_get_type(type,edited_id)==ShaderGraph::NODE_CUBEMAP_INPUT) { + if (graph->node_get_type(type,edited_id)==ShaderGraph::NODE_CUBEMAP_INPUT) { - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - ur->create_action("Change Cubemap Uniform"); - ur->add_do_method(graph.ptr(),"cubemap_input_node_set_value",type,edited_id,ped_popup->get_variant()); - ur->add_undo_method(graph.ptr(),"cubemap_input_node_set_value",type,edited_id,graph->cubemap_input_node_get_value(type,edited_id)); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - ur->commit_action(); - } + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change Cubemap Uniform"); + ur->add_do_method(graph.ptr(),"cubemap_input_node_set_value",type,edited_id,ped_popup->get_variant()); + ur->add_undo_method(graph.ptr(),"cubemap_input_node_set_value",type,edited_id,graph->cubemap_input_node_get_value(type,edited_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + ur->commit_action(); + } } void ShaderGraphView::_comment_edited(int p_id,Node* p_button) { - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - TextEdit *te=p_button->cast_to(); - ur->create_action("Change Comment",true); - ur->add_do_method(graph.ptr(),"comment_node_set_text",type,p_id,te->get_text()); - ur->add_undo_method(graph.ptr(),"comment_node_set_text",type,p_id,graph->comment_node_get_text(type,p_id)); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - block_update=true; - ur->commit_action(); - block_update=false; + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + TextEdit *te=p_button->cast_to(); + ur->create_action("Change Comment",true); + ur->add_do_method(graph.ptr(),"comment_node_set_text",type,p_id,te->get_text()); + ur->add_undo_method(graph.ptr(),"comment_node_set_text",type,p_id,graph->comment_node_get_text(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; } void ShaderGraphView::_color_ramp_changed(int p_id,Node* p_ramp) { - GraphColorRampEdit *cr=p_ramp->cast_to(); + GraphColorRampEdit *cr=p_ramp->cast_to(); - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - Vector offsets=cr->get_offsets(); - Vector colors=cr->get_colors(); + Vector offsets=cr->get_offsets(); + Vector colors=cr->get_colors(); - DVector new_offsets; - DVector new_colors; - { - new_offsets.resize(offsets.size()); - new_colors.resize(colors.size()); - DVector::Write ow=new_offsets.write(); - DVector::Write cw=new_colors.write(); - for(int i=0;i new_offsets; + DVector new_colors; + { + new_offsets.resize(offsets.size()); + new_colors.resize(colors.size()); + DVector::Write ow=new_offsets.write(); + DVector::Write cw=new_colors.write(); + for(int i=0;i old_offsets=graph->color_ramp_node_get_offsets(type,p_id); - DVector old_colors=graph->color_ramp_node_get_colors(type,p_id); + DVector old_offsets=graph->color_ramp_node_get_offsets(type,p_id); + DVector old_colors=graph->color_ramp_node_get_colors(type,p_id); - if (old_offsets.size()!=new_offsets.size()) - ur->create_action("Add/Remove to Color Ramp"); - else - ur->create_action("Modify Color Ramp",true); + if (old_offsets.size()!=new_offsets.size()) + ur->create_action("Add/Remove to Color Ramp"); + else + ur->create_action("Modify Color Ramp",true); - ur->add_do_method(graph.ptr(),"color_ramp_node_set_ramp",type,p_id,new_colors,new_offsets); - ur->add_undo_method(graph.ptr(),"color_ramp_node_set_ramp",type,p_id,old_colors,old_offsets); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - block_update=true; - ur->commit_action(); - block_update=false; + ur->add_do_method(graph.ptr(),"color_ramp_node_set_ramp",type,p_id,new_colors,new_offsets); + ur->add_undo_method(graph.ptr(),"color_ramp_node_set_ramp",type,p_id,old_colors,old_offsets); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; } void ShaderGraphView::_curve_changed(int p_id,Node* p_curve) { - GraphCurveMapEdit *cr=p_curve->cast_to(); + GraphCurveMapEdit *cr=p_curve->cast_to(); - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - Vector points=cr->get_points(); + Vector points=cr->get_points(); - DVector new_points; - { - new_points.resize(points.size()); - DVector::Write ow=new_points.write(); - for(int i=0;i new_points; + { + new_points.resize(points.size()); + DVector::Write ow=new_points.write(); + for(int i=0;i old_points=graph->curve_map_node_get_points(type,p_id); + DVector old_points=graph->curve_map_node_get_points(type,p_id); - if (old_points.size()!=new_points.size()) - ur->create_action("Add/Remove to Curve Map"); - else - ur->create_action("Modify Curve Map",true); + if (old_points.size()!=new_points.size()) + ur->create_action("Add/Remove to Curve Map"); + else + ur->create_action("Modify Curve Map",true); - ur->add_do_method(graph.ptr(),"curve_map_node_set_points",type,p_id,new_points); - ur->add_undo_method(graph.ptr(),"curve_map_node_set_points",type,p_id,old_points); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - block_update=true; - ur->commit_action(); - block_update=false; + ur->add_do_method(graph.ptr(),"curve_map_node_set_points",type,p_id,new_points); + ur->add_undo_method(graph.ptr(),"curve_map_node_set_points",type,p_id,old_points); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; } void ShaderGraphView::_input_name_changed(const String& p_name, int p_id, Node *p_line_edit) { - LineEdit *le=p_line_edit->cast_to(); - ERR_FAIL_COND(!le); + LineEdit *le=p_line_edit->cast_to(); + ERR_FAIL_COND(!le); - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - ur->create_action("Change Input Name"); - ur->add_do_method(graph.ptr(),"input_node_set_name",type,p_id,p_name); - ur->add_undo_method(graph.ptr(),"input_node_set_name",type,p_id,graph->input_node_get_name(type,p_id)); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - block_update=true; - ur->commit_action(); - block_update=false; - le->set_text(graph->input_node_get_name(type,p_id)); + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change Input Name"); + ur->add_do_method(graph.ptr(),"input_node_set_name",type,p_id,p_name); + ur->add_undo_method(graph.ptr(),"input_node_set_name",type,p_id,graph->input_node_get_name(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; + le->set_text(graph->input_node_get_name(type,p_id)); } void ShaderGraphView::_tex_edited(int p_id,Node* p_button) { - ToolButton *tb = p_button->cast_to(); - ped_popup->set_pos(tb->get_global_pos()+Vector2(0,tb->get_size().height)); - ped_popup->set_size(tb->get_size()); - edited_id=p_id; - ped_popup->edit(NULL,"",Variant::OBJECT,graph->texture_input_node_get_value(type,p_id),PROPERTY_HINT_RESOURCE_TYPE,"Texture"); + ToolButton *tb = p_button->cast_to(); + ped_popup->set_pos(tb->get_global_pos()+Vector2(0,tb->get_size().height)); + ped_popup->set_size(tb->get_size()); + edited_id=p_id; + ped_popup->edit(NULL,"",Variant::OBJECT,graph->texture_input_node_get_value(type,p_id),PROPERTY_HINT_RESOURCE_TYPE,"Texture"); } void ShaderGraphView::_cube_edited(int p_id,Node* p_button) { - ToolButton *tb = p_button->cast_to(); - ped_popup->set_pos(tb->get_global_pos()+Vector2(0,tb->get_size().height)); - ped_popup->set_size(tb->get_size()); - edited_id=p_id; - ped_popup->edit(NULL,"",Variant::OBJECT,graph->cubemap_input_node_get_value(type,p_id),PROPERTY_HINT_RESOURCE_TYPE,"CubeMap"); + ToolButton *tb = p_button->cast_to(); + ped_popup->set_pos(tb->get_global_pos()+Vector2(0,tb->get_size().height)); + ped_popup->set_size(tb->get_size()); + edited_id=p_id; + ped_popup->edit(NULL,"",Variant::OBJECT,graph->cubemap_input_node_get_value(type,p_id),PROPERTY_HINT_RESOURCE_TYPE,"CubeMap"); } @@ -1061,994 +1061,994 @@ void ShaderGraphView::_cube_edited(int p_id,Node* p_button) { void ShaderGraphView::_connection_request(const String& p_from, int p_from_slot,const String& p_to,int p_to_slot) { - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - int from_idx=-1; - int to_idx=-1; - for (Map::Element *E=node_map.front();E;E=E->next()) { + int from_idx=-1; + int to_idx=-1; + for (Map::Element *E=node_map.front();E;E=E->next()) { - if (p_from==E->get()->get_name()) - from_idx=E->key(); - if (p_to==E->get()->get_name()) - to_idx=E->key(); - } + if (p_from==E->get()->get_name()) + from_idx=E->key(); + if (p_to==E->get()->get_name()) + to_idx=E->key(); + } - ERR_FAIL_COND(from_idx==-1); - ERR_FAIL_COND(to_idx==-1); + ERR_FAIL_COND(from_idx==-1); + ERR_FAIL_COND(to_idx==-1); - ur->create_action("Connect Graph Nodes"); + ur->create_action("Connect Graph Nodes"); - List conns; + List conns; - graph->get_node_connections(type,&conns); - //disconnect/reconnect dependencies - ur->add_undo_method(graph.ptr(),"disconnect_node",type,from_idx,p_from_slot,to_idx,p_to_slot); - for(List::Element *E=conns.front();E;E=E->next()) { + graph->get_node_connections(type,&conns); + //disconnect/reconnect dependencies + ur->add_undo_method(graph.ptr(),"disconnect_node",type,from_idx,p_from_slot,to_idx,p_to_slot); + for(List::Element *E=conns.front();E;E=E->next()) { - if (E->get().dst_id==to_idx && E->get().dst_slot==p_to_slot) { - ur->add_do_method(graph.ptr(),"disconnect_node",type,E->get().src_id,E->get().src_slot,E->get().dst_id,E->get().dst_slot); - ur->add_undo_method(graph.ptr(),"connect_node",type,E->get().src_id,E->get().src_slot,E->get().dst_id,E->get().dst_slot); - } - } - ur->add_do_method(graph.ptr(),"connect_node",type,from_idx,p_from_slot,to_idx,p_to_slot); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - ur->commit_action(); + if (E->get().dst_id==to_idx && E->get().dst_slot==p_to_slot) { + ur->add_do_method(graph.ptr(),"disconnect_node",type,E->get().src_id,E->get().src_slot,E->get().dst_id,E->get().dst_slot); + ur->add_undo_method(graph.ptr(),"connect_node",type,E->get().src_id,E->get().src_slot,E->get().dst_id,E->get().dst_slot); + } + } + ur->add_do_method(graph.ptr(),"connect_node",type,from_idx,p_from_slot,to_idx,p_to_slot); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + ur->commit_action(); } void ShaderGraphView::_disconnection_request(const String& p_from, int p_from_slot,const String& p_to,int p_to_slot) { - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - int from_idx=-1; - int to_idx=-1; - for (Map::Element *E=node_map.front();E;E=E->next()) { + int from_idx=-1; + int to_idx=-1; + for (Map::Element *E=node_map.front();E;E=E->next()) { - if (p_from==E->get()->get_name()) - from_idx=E->key(); - if (p_to==E->get()->get_name()) - to_idx=E->key(); - } + if (p_from==E->get()->get_name()) + from_idx=E->key(); + if (p_to==E->get()->get_name()) + to_idx=E->key(); + } - ERR_FAIL_COND(from_idx==-1); - ERR_FAIL_COND(to_idx==-1); + ERR_FAIL_COND(from_idx==-1); + ERR_FAIL_COND(to_idx==-1); - if (!graph->is_node_connected(type,from_idx,p_from_slot,to_idx,p_to_slot)) - return; //nothing to disconnect + if (!graph->is_node_connected(type,from_idx,p_from_slot,to_idx,p_to_slot)) + return; //nothing to disconnect - ur->create_action("Disconnect Graph Nodes"); + ur->create_action("Disconnect Graph Nodes"); - List conns; + List conns; - graph->get_node_connections(type,&conns); - //disconnect/reconnect dependencies - ur->add_do_method(graph.ptr(),"disconnect_node",type,from_idx,p_from_slot,to_idx,p_to_slot); - ur->add_undo_method(graph.ptr(),"connect_node",type,from_idx,p_from_slot,to_idx,p_to_slot); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - ur->commit_action(); + graph->get_node_connections(type,&conns); + //disconnect/reconnect dependencies + ur->add_do_method(graph.ptr(),"disconnect_node",type,from_idx,p_from_slot,to_idx,p_to_slot); + ur->add_undo_method(graph.ptr(),"connect_node",type,from_idx,p_from_slot,to_idx,p_to_slot); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + ur->commit_action(); } void ShaderGraphView::_node_removed(int p_id) { - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - ur->create_action("Remove Shader Graph Node"); + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Remove Shader Graph Node"); - ur->add_do_method(graph.ptr(),"node_remove",type,p_id); - ur->add_undo_method(graph.ptr(),"node_add",type,graph->node_get_type(type,p_id),p_id); - ur->add_undo_method(graph.ptr(),"node_set_state",type,p_id,graph->node_get_state(type,p_id)); - List conns; + ur->add_do_method(graph.ptr(),"node_remove",type,p_id); + ur->add_undo_method(graph.ptr(),"node_add",type,graph->node_get_type(type,p_id),p_id); + ur->add_undo_method(graph.ptr(),"node_set_state",type,p_id,graph->node_get_state(type,p_id)); + List conns; - graph->get_node_connections(type,&conns); - for(List::Element *E=conns.front();E;E=E->next()) { + graph->get_node_connections(type,&conns); + for(List::Element *E=conns.front();E;E=E->next()) { - if (E->get().dst_id==p_id || E->get().src_id==p_id) { - ur->add_undo_method(graph.ptr(),"connect_node",type,E->get().src_id,E->get().src_slot,E->get().dst_id,E->get().dst_slot); - } - } - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - ur->commit_action(); + if (E->get().dst_id==p_id || E->get().src_id==p_id) { + ur->add_undo_method(graph.ptr(),"connect_node",type,E->get().src_id,E->get().src_slot,E->get().dst_id,E->get().dst_slot); + } + } + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + ur->commit_action(); } void ShaderGraphView::_begin_node_move() { - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - ur->create_action("Move Shader Graph Node"); + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Move Shader Graph Node"); } void ShaderGraphView::_node_moved(const Vector2& p_from, const Vector2& p_to,int p_id) { - ERR_FAIL_COND(!node_map.has(p_id)); - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - ur->add_do_method(this,"_move_node",p_id,p_to); - ur->add_undo_method(this,"_move_node",p_id,p_from); + ERR_FAIL_COND(!node_map.has(p_id)); + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->add_do_method(this,"_move_node",p_id,p_to); + ur->add_undo_method(this,"_move_node",p_id,p_from); } void ShaderGraphView::_end_node_move() { - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - ur->commit_action(); + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->commit_action(); } void ShaderGraphView::_move_node(int p_id,const Vector2& p_to) { - ERR_FAIL_COND(!node_map.has(p_id)); - node_map[p_id]->set_offset(p_to); - graph->node_set_pos(type,p_id,p_to); + ERR_FAIL_COND(!node_map.has(p_id)); + node_map[p_id]->set_offset(p_to); + graph->node_set_pos(type,p_id,p_to); } void ShaderGraphView::_create_node(int p_id) { - GraphNode *gn = memnew( GraphNode ); - gn->set_show_close_button(true); - Color typecol[4]={ - Color(0.9,0.4,1), - Color(0.8,1,0.2), - Color(1,0.2,0.2), - Color(0,1,1) - }; - - - switch(graph->node_get_type(type,p_id)) { - - case ShaderGraph::NODE_INPUT: { - - gn->set_title("Input"); - - List si; - ShaderGraph::get_input_output_node_slot_info(graph->get_mode(),type,&si); - - int idx=0; - for (List::Element *E=si.front();E;E=E->next()) { - ShaderGraph::SlotInfo& s=E->get(); - if (s.dir==ShaderGraph::SLOT_IN) { - - Label *l= memnew( Label ); - l->set_text(s.name); - l->set_align(Label::ALIGN_RIGHT); - gn->add_child(l); - gn->set_slot(idx,false,0,Color(),true,s.type,typecol[s.type]); - idx++; - } - } - - } break; // all inputs (case Shader type dependent) - case ShaderGraph::NODE_SCALAR_CONST: { - gn->set_title("Scalar"); - SpinBox *sb = memnew( SpinBox ); - sb->set_min(-100000); - sb->set_max(100000); - sb->set_step(0.001); - sb->set_val(graph->scalar_const_node_get_value(type,p_id)); - sb->connect("value_changed",this,"_scalar_const_changed",varray(p_id)); - gn->add_child(sb); - gn->set_slot(0,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); - - } break; //scalar constant - case ShaderGraph::NODE_VEC_CONST: { - - gn->set_title("Vector"); - Array v3p(true); - for(int i=0;i<3;i++) { - HBoxContainer *hbc = memnew( HBoxContainer ); - Label *l = memnew( Label ); - l->set_text(String::chr('X'+i)); - hbc->add_child(l); - SpinBox *sb = memnew( SpinBox ); - sb->set_h_size_flags(Control::SIZE_EXPAND_FILL); - sb->set_min(-100000); - sb->set_max(100000); - sb->set_step(0.001); - sb->set_val(graph->vec_const_node_get_value(type,p_id)[i]); - sb->connect("value_changed",this,"_vec_const_changed",varray(p_id,v3p)); - v3p.push_back(sb); - hbc->add_child(sb); - gn->add_child(hbc); - } - gn->set_slot(0,false,0,Color(),true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); - - } break; //vec3 constant - case ShaderGraph::NODE_RGB_CONST: { - - gn->set_title("Color"); - ColorPickerButton *cpb = memnew( ColorPickerButton ); - cpb->set_color(graph->rgb_const_node_get_value(type,p_id)); - cpb->connect("color_changed",this,"_rgb_const_changed",varray(p_id)); - gn->add_child(cpb); - Label *l = memnew( Label ); - l->set_text("RGB"); - l->set_align(Label::ALIGN_RIGHT); - gn->add_child(l); - l = memnew( Label ); - l->set_text("Alpha"); - l->set_align(Label::ALIGN_RIGHT); - gn->add_child(l); - - gn->set_slot(1,false,0,Color(),true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); - gn->set_slot(2,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); - - } break; //rgb constant (shows a color picker instead) - case ShaderGraph::NODE_XFORM_CONST: { - gn->set_title("XForm"); - ToolButton *edit = memnew( ToolButton ); - edit->set_text("edit.."); - edit->connect("pressed",this,"_xform_const_changed",varray(p_id,edit)); - gn->add_child(edit); - gn->set_slot(0,false,0,Color(),true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM]); - - } break; // 4x4 matrix constant - case ShaderGraph::NODE_TIME: { - - gn->set_title("Time"); - Label *l = memnew( Label ); - l->set_text("(s)"); - l->set_align(Label::ALIGN_RIGHT); - gn->add_child(l); - gn->set_slot(0,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); - - } break; // time in seconds - case ShaderGraph::NODE_SCREEN_TEX: { - - gn->set_title("ScreenTex"); - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("UV"))); - hbc->add_spacer(); - hbc->add_child( memnew(Label("RGB"))); - gn->add_child(hbc); - gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); - - } break; // screen texture sampler (takes UV) (only usable in fragment case Shader) - case ShaderGraph::NODE_SCALAR_OP: { - - gn->set_title("ScalarOp"); - static const char* op_name[ShaderGraph::SCALAR_MAX_OP]={ - "Add", - "Sub", - "Mul", - "Div", - "Mod", - "Pow", - "Max", - "Min", - "Atan2" - }; - - OptionButton *ob = memnew( OptionButton ); - for(int i=0;iadd_item(op_name[i],i); - } - - ob->select(graph->scalar_op_node_get_op(type,p_id)); - ob->connect("item_selected",this,"_scalar_op_changed",varray(p_id)); - gn->add_child(ob); - - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("a"))); - hbc->add_spacer(); - hbc->add_child( memnew(Label("out"))); - gn->add_child(hbc); - gn->add_child( memnew(Label("b"))); - - gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); - gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); - - - } break; // scalar vs scalar op (mul: { } break; add: { } break; div: { } break; etc) - case ShaderGraph::NODE_VEC_OP: { - - gn->set_title("VecOp"); - static const char* op_name[ShaderGraph::VEC_MAX_OP]={ - "Add", - "Sub", - "Mul", - "Div", - "Mod", - "Pow", - "Max", - "Min", - "Cross" - }; - - OptionButton *ob = memnew( OptionButton ); - for(int i=0;iadd_item(op_name[i],i); - } - - ob->select(graph->vec_op_node_get_op(type,p_id)); - ob->connect("item_selected",this,"_vec_op_changed",varray(p_id)); - gn->add_child(ob); - - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("a"))); - hbc->add_spacer(); - hbc->add_child( memnew(Label("out"))); - gn->add_child(hbc); - gn->add_child( memnew(Label("b"))); - - gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); - gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); - - - } break; // vec3 vs vec3 op (mul: { } break;ad: { } break;div: { } break;crossprod: { } break;etc) - case ShaderGraph::NODE_VEC_SCALAR_OP: { - - gn->set_title("VecScalarOp"); - static const char* op_name[ShaderGraph::VEC_SCALAR_MAX_OP]={ - "Mul", - "Div", - "Pow", - }; - - OptionButton *ob = memnew( OptionButton ); - for(int i=0;iadd_item(op_name[i],i); - } - - ob->select(graph->vec_scalar_op_node_get_op(type,p_id)); - ob->connect("item_selected",this,"_vec_scalar_op_changed",varray(p_id)); - gn->add_child(ob); - - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("a"))); - hbc->add_spacer(); - hbc->add_child( memnew(Label("out"))); - gn->add_child(hbc); - gn->add_child( memnew(Label("b"))); - - gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); - gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); - - - } break; // vec3 vs scalar op (mul: { } break; add: { } break; div: { } break; etc) - case ShaderGraph::NODE_RGB_OP: { - - gn->set_title("RGB Op"); - static const char* op_name[ShaderGraph::RGB_MAX_OP]={ - "Screen", - "Difference", - "Darken", - "Lighten", - "Overlay", - "Dodge", - "Burn", - "SoftLight", - "HardLight" - }; - - OptionButton *ob = memnew( OptionButton ); - for(int i=0;iadd_item(op_name[i],i); - } - - ob->select(graph->rgb_op_node_get_op(type,p_id)); - ob->connect("item_selected",this,"_rgb_op_changed",varray(p_id)); - gn->add_child(ob); - - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("a"))); - hbc->add_spacer(); - hbc->add_child( memnew(Label("out"))); - gn->add_child(hbc); - gn->add_child( memnew(Label("b"))); - - gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); - gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); - - } break; // vec3 vs vec3 rgb op (with scalar amount): { } break; like brighten: { } break; darken: { } break; burn: { } break; dodge: { } break; multiply: { } break; etc. - case ShaderGraph::NODE_XFORM_MULT: { - - gn->set_title("XFMult"); - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_child( memnew(Label("a"))); - hbc->add_spacer(); - hbc->add_child( memnew(Label("out"))); - gn->add_child(hbc); - gn->add_child( memnew(Label("b"))); - - gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM],true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM]); - gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM],false,0,Color()); - - - } break; // mat4 x mat4 - case ShaderGraph::NODE_XFORM_VEC_MULT: { - - gn->set_title("XFVecMult"); - - Button *button = memnew( Button("RotOnly")); - button->set_toggle_mode(true); - button->set_pressed(graph->xform_vec_mult_node_get_no_translation(type,p_id)); - button->connect("toggled",this,"_xform_inv_rev_changed",varray(p_id)); - - gn->add_child(button); - - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("xf"))); - hbc->add_spacer(); - Label *l = memnew(Label("out")); - l->set_align(Label::ALIGN_RIGHT); - hbc->add_child( l); - gn->add_child(hbc); - gn->add_child( memnew(Label("vec"))); - - gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); - gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); - - } break; - case ShaderGraph::NODE_XFORM_VEC_INV_MULT: { - - gn->set_title("XFVecInvMult"); - - - Button *button = memnew( Button("RotOnly")); - button->set_toggle_mode(true); - button->set_pressed(graph->xform_vec_mult_node_get_no_translation(type,p_id)); - button->connect("toggled",this,"_xform_inv_rev_changed",varray(p_id)); - - gn->add_child(button); - - gn->add_child( memnew(Label("vec"))); - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("xf"))); - hbc->add_spacer(); - Label *l = memnew(Label("out")); - l->set_align(Label::ALIGN_RIGHT); - hbc->add_child( l); - gn->add_child(hbc); - - gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); - gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); - - - } break; // mat4 x vec3 inverse mult (with no-translation option) - case ShaderGraph::NODE_SCALAR_FUNC: { - - gn->set_title("ScalarFunc"); - static const char* func_name[ShaderGraph::SCALAR_MAX_FUNC]={ - "Sin", - "Cos", - "Tan", - "ASin", - "ACos", - "ATan", - "SinH", - "CosH", - "TanH", - "Log", - "Exp", - "Sqrt", - "Abs", - "Sign", - "Floor", - "Round", - "Ceil", - "Frac", - "Satr", - "Neg" - }; - - OptionButton *ob = memnew( OptionButton ); - for(int i=0;iadd_item(func_name[i],i); - } - - ob->select(graph->scalar_func_node_get_function(type,p_id)); - ob->connect("item_selected",this,"_scalar_func_changed",varray(p_id)); - gn->add_child(ob); - - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_child( memnew(Label("in"))); - hbc->add_spacer(); - hbc->add_child( memnew(Label("out"))); - gn->add_child(hbc); - - gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); - - - } break; // scalar function (sin: { } break; cos: { } break; etc) - case ShaderGraph::NODE_VEC_FUNC: { - - - - gn->set_title("VecFunc"); - static const char* func_name[ShaderGraph::VEC_MAX_FUNC]={ - "Normalize", - "Saturate", - "Negate", - "Reciprocal", - "RGB to HSV", - "HSV to RGB", - }; - - OptionButton *ob = memnew( OptionButton ); - for(int i=0;iadd_item(func_name[i],i); - } - - ob->select(graph->vec_func_node_get_function(type,p_id)); - ob->connect("item_selected",this,"_vec_func_changed",varray(p_id)); - gn->add_child(ob); - - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("in"))); - hbc->add_spacer(); - hbc->add_child( memnew(Label("out"))); - gn->add_child(hbc); - - gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); - - } break; // vector function (normalize: { } break; negate: { } break; reciprocal: { } break; rgb2hsv: { } break; hsv2rgb: { } break; etc: { } break; etc) - case ShaderGraph::NODE_VEC_LEN: { - gn->set_title("VecLength"); - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_child( memnew(Label("in"))); - hbc->add_spacer(); - hbc->add_child( memnew(Label("len"))); - gn->add_child(hbc); - - gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); - - } break; // vec3 length - case ShaderGraph::NODE_DOT_PROD: { - - gn->set_title("DotProduct"); - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("a"))); - hbc->add_spacer(); - hbc->add_child( memnew(Label("dp"))); - gn->add_child(hbc); - gn->add_child( memnew(Label("b"))); - - gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); - gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); - - } break; // vec3 . vec3 (dot product -> scalar output) - case ShaderGraph::NODE_VEC_TO_SCALAR: { - - gn->set_title("Vec2Scalar"); - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("vec"))); - hbc->add_spacer(); - Label *l=memnew(Label("x")); - l->set_align(Label::ALIGN_RIGHT); - hbc->add_child( l); - gn->add_child(hbc); - l=memnew(Label("y")); - l->set_align(Label::ALIGN_RIGHT); - gn->add_child( l ); - l=memnew(Label("z")); - l->set_align(Label::ALIGN_RIGHT); - gn->add_child( l); - - gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); - gn->set_slot(1,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); - gn->set_slot(2,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); - - - - - } break; // 1 vec3 input: { } break; 3 scalar outputs - case ShaderGraph::NODE_SCALAR_TO_VEC: { - - gn->set_title("Scalar2Vec"); - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_child( memnew(Label("x"))); - hbc->add_spacer(); - hbc->add_child( memnew(Label("vec"))); - gn->add_child(hbc); - gn->add_child( memnew(Label("y"))); - gn->add_child( memnew(Label("z"))); - - gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); - gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); - gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); - - } break; // 3 scalar input: { } break; 1 vec3 output - case ShaderGraph::NODE_VEC_TO_XFORM: { - - gn->set_title("Vec2XForm"); - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("x"))); - hbc->add_spacer(); - hbc->add_child( memnew(Label("xf"))); - gn->add_child(hbc); - gn->add_child( memnew(Label("y"))); - gn->add_child( memnew(Label("z"))); - gn->add_child( memnew(Label("ofs"))); - - gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM]); - gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); - gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); - gn->set_slot(3,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); - - } break; // 3 vec input: { } break; 1 xform output - case ShaderGraph::NODE_XFORM_TO_VEC: { - - gn->set_title("XForm2Vec"); - - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("xf"))); - hbc->add_spacer(); - Label *l=memnew(Label("x")); - l->set_align(Label::ALIGN_RIGHT); - hbc->add_child( l); - gn->add_child(hbc); - l=memnew(Label("y")); - l->set_align(Label::ALIGN_RIGHT); - gn->add_child( l ); - l=memnew(Label("z")); - l->set_align(Label::ALIGN_RIGHT); - gn->add_child( l); - l=memnew(Label("ofs")); - l->set_align(Label::ALIGN_RIGHT); - gn->add_child( l); - - gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); - gn->set_slot(1,false,0,Color(),true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); - gn->set_slot(2,false,0,Color(),true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); - gn->set_slot(3,false,0,Color(),true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); - - } break; // 3 vec input: { } break; 1 xform output - case ShaderGraph::NODE_SCALAR_INTERP: { - - gn->set_title("ScalarInterp"); - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("a"))); - hbc->add_spacer(); - hbc->add_child( memnew(Label("interp"))); - gn->add_child(hbc); - gn->add_child( memnew(Label("b"))); - gn->add_child( memnew(Label("c"))); - - gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); - gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); - gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); - - - } break; // scalar interpolation (with optional curve) - case ShaderGraph::NODE_VEC_INTERP: { - - gn->set_title("VecInterp"); - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_child( memnew(Label("a"))); - hbc->add_spacer(); - hbc->add_child( memnew(Label("interp"))); - gn->add_child(hbc); - gn->add_child( memnew(Label("b"))); - gn->add_child( memnew(Label("c"))); + GraphNode *gn = memnew( GraphNode ); + gn->set_show_close_button(true); + Color typecol[4]={ + Color(0.9,0.4,1), + Color(0.8,1,0.2), + Color(1,0.2,0.2), + Color(0,1,1) + }; + + + switch(graph->node_get_type(type,p_id)) { + + case ShaderGraph::NODE_INPUT: { + + gn->set_title("Input"); + + List si; + ShaderGraph::get_input_output_node_slot_info(graph->get_mode(),type,&si); + + int idx=0; + for (List::Element *E=si.front();E;E=E->next()) { + ShaderGraph::SlotInfo& s=E->get(); + if (s.dir==ShaderGraph::SLOT_IN) { + + Label *l= memnew( Label ); + l->set_text(s.name); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child(l); + gn->set_slot(idx,false,0,Color(),true,s.type,typecol[s.type]); + idx++; + } + } + + } break; // all inputs (case Shader type dependent) + case ShaderGraph::NODE_SCALAR_CONST: { + gn->set_title("Scalar"); + SpinBox *sb = memnew( SpinBox ); + sb->set_min(-100000); + sb->set_max(100000); + sb->set_step(0.001); + sb->set_val(graph->scalar_const_node_get_value(type,p_id)); + sb->connect("value_changed",this,"_scalar_const_changed",varray(p_id)); + gn->add_child(sb); + gn->set_slot(0,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + + } break; //scalar constant + case ShaderGraph::NODE_VEC_CONST: { + + gn->set_title("Vector"); + Array v3p(true); + for(int i=0;i<3;i++) { + HBoxContainer *hbc = memnew( HBoxContainer ); + Label *l = memnew( Label ); + l->set_text(String::chr('X'+i)); + hbc->add_child(l); + SpinBox *sb = memnew( SpinBox ); + sb->set_h_size_flags(Control::SIZE_EXPAND_FILL); + sb->set_min(-100000); + sb->set_max(100000); + sb->set_step(0.001); + sb->set_val(graph->vec_const_node_get_value(type,p_id)[i]); + sb->connect("value_changed",this,"_vec_const_changed",varray(p_id,v3p)); + v3p.push_back(sb); + hbc->add_child(sb); + gn->add_child(hbc); + } + gn->set_slot(0,false,0,Color(),true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + + } break; //vec3 constant + case ShaderGraph::NODE_RGB_CONST: { + + gn->set_title("Color"); + ColorPickerButton *cpb = memnew( ColorPickerButton ); + cpb->set_color(graph->rgb_const_node_get_value(type,p_id)); + cpb->connect("color_changed",this,"_rgb_const_changed",varray(p_id)); + gn->add_child(cpb); + Label *l = memnew( Label ); + l->set_text("RGB"); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child(l); + l = memnew( Label ); + l->set_text("Alpha"); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child(l); + + gn->set_slot(1,false,0,Color(),true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(2,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + + } break; //rgb constant (shows a color picker instead) + case ShaderGraph::NODE_XFORM_CONST: { + gn->set_title("XForm"); + ToolButton *edit = memnew( ToolButton ); + edit->set_text("edit.."); + edit->connect("pressed",this,"_xform_const_changed",varray(p_id,edit)); + gn->add_child(edit); + gn->set_slot(0,false,0,Color(),true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM]); + + } break; // 4x4 matrix constant + case ShaderGraph::NODE_TIME: { + + gn->set_title("Time"); + Label *l = memnew( Label ); + l->set_text("(s)"); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child(l); + gn->set_slot(0,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + + } break; // time in seconds + case ShaderGraph::NODE_SCREEN_TEX: { + + gn->set_title("ScreenTex"); + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("UV"))); + hbc->add_spacer(); + hbc->add_child( memnew(Label("RGB"))); + gn->add_child(hbc); + gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + + } break; // screen texture sampler (takes UV) (only usable in fragment case Shader) + case ShaderGraph::NODE_SCALAR_OP: { + + gn->set_title("ScalarOp"); + static const char* op_name[ShaderGraph::SCALAR_MAX_OP]={ + "Add", + "Sub", + "Mul", + "Div", + "Mod", + "Pow", + "Max", + "Min", + "Atan2" + }; + + OptionButton *ob = memnew( OptionButton ); + for(int i=0;iadd_item(op_name[i],i); + } + + ob->select(graph->scalar_op_node_get_op(type,p_id)); + ob->connect("item_selected",this,"_scalar_op_changed",varray(p_id)); + gn->add_child(ob); + + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("a"))); + hbc->add_spacer(); + hbc->add_child( memnew(Label("out"))); + gn->add_child(hbc); + gn->add_child( memnew(Label("b"))); + + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); + + + } break; // scalar vs scalar op (mul: { } break; add: { } break; div: { } break; etc) + case ShaderGraph::NODE_VEC_OP: { + + gn->set_title("VecOp"); + static const char* op_name[ShaderGraph::VEC_MAX_OP]={ + "Add", + "Sub", + "Mul", + "Div", + "Mod", + "Pow", + "Max", + "Min", + "Cross" + }; + + OptionButton *ob = memnew( OptionButton ); + for(int i=0;iadd_item(op_name[i],i); + } + + ob->select(graph->vec_op_node_get_op(type,p_id)); + ob->connect("item_selected",this,"_vec_op_changed",varray(p_id)); + gn->add_child(ob); + + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("a"))); + hbc->add_spacer(); + hbc->add_child( memnew(Label("out"))); + gn->add_child(hbc); + gn->add_child( memnew(Label("b"))); + + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); + + + } break; // vec3 vs vec3 op (mul: { } break;ad: { } break;div: { } break;crossprod: { } break;etc) + case ShaderGraph::NODE_VEC_SCALAR_OP: { + + gn->set_title("VecScalarOp"); + static const char* op_name[ShaderGraph::VEC_SCALAR_MAX_OP]={ + "Mul", + "Div", + "Pow", + }; + + OptionButton *ob = memnew( OptionButton ); + for(int i=0;iadd_item(op_name[i],i); + } + + ob->select(graph->vec_scalar_op_node_get_op(type,p_id)); + ob->connect("item_selected",this,"_vec_scalar_op_changed",varray(p_id)); + gn->add_child(ob); + + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("a"))); + hbc->add_spacer(); + hbc->add_child( memnew(Label("out"))); + gn->add_child(hbc); + gn->add_child( memnew(Label("b"))); + + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); + + + } break; // vec3 vs scalar op (mul: { } break; add: { } break; div: { } break; etc) + case ShaderGraph::NODE_RGB_OP: { + + gn->set_title("RGB Op"); + static const char* op_name[ShaderGraph::RGB_MAX_OP]={ + "Screen", + "Difference", + "Darken", + "Lighten", + "Overlay", + "Dodge", + "Burn", + "SoftLight", + "HardLight" + }; + + OptionButton *ob = memnew( OptionButton ); + for(int i=0;iadd_item(op_name[i],i); + } + + ob->select(graph->rgb_op_node_get_op(type,p_id)); + ob->connect("item_selected",this,"_rgb_op_changed",varray(p_id)); + gn->add_child(ob); + + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("a"))); + hbc->add_spacer(); + hbc->add_child( memnew(Label("out"))); + gn->add_child(hbc); + gn->add_child( memnew(Label("b"))); + + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); + + } break; // vec3 vs vec3 rgb op (with scalar amount): { } break; like brighten: { } break; darken: { } break; burn: { } break; dodge: { } break; multiply: { } break; etc. + case ShaderGraph::NODE_XFORM_MULT: { + + gn->set_title("XFMult"); + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_child( memnew(Label("a"))); + hbc->add_spacer(); + hbc->add_child( memnew(Label("out"))); + gn->add_child(hbc); + gn->add_child( memnew(Label("b"))); + + gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM],true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM]); + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM],false,0,Color()); + + + } break; // mat4 x mat4 + case ShaderGraph::NODE_XFORM_VEC_MULT: { + + gn->set_title("XFVecMult"); + + Button *button = memnew( Button("RotOnly")); + button->set_toggle_mode(true); + button->set_pressed(graph->xform_vec_mult_node_get_no_translation(type,p_id)); + button->connect("toggled",this,"_xform_inv_rev_changed",varray(p_id)); + + gn->add_child(button); + + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("xf"))); + hbc->add_spacer(); + Label *l = memnew(Label("out")); + l->set_align(Label::ALIGN_RIGHT); + hbc->add_child( l); + gn->add_child(hbc); + gn->add_child( memnew(Label("vec"))); + + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); + + } break; + case ShaderGraph::NODE_XFORM_VEC_INV_MULT: { + + gn->set_title("XFVecInvMult"); + + + Button *button = memnew( Button("RotOnly")); + button->set_toggle_mode(true); + button->set_pressed(graph->xform_vec_mult_node_get_no_translation(type,p_id)); + button->connect("toggled",this,"_xform_inv_rev_changed",varray(p_id)); + + gn->add_child(button); + + gn->add_child( memnew(Label("vec"))); + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("xf"))); + hbc->add_spacer(); + Label *l = memnew(Label("out")); + l->set_align(Label::ALIGN_RIGHT); + hbc->add_child( l); + gn->add_child(hbc); + + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); + gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + + + } break; // mat4 x vec3 inverse mult (with no-translation option) + case ShaderGraph::NODE_SCALAR_FUNC: { + + gn->set_title("ScalarFunc"); + static const char* func_name[ShaderGraph::SCALAR_MAX_FUNC]={ + "Sin", + "Cos", + "Tan", + "ASin", + "ACos", + "ATan", + "SinH", + "CosH", + "TanH", + "Log", + "Exp", + "Sqrt", + "Abs", + "Sign", + "Floor", + "Round", + "Ceil", + "Frac", + "Satr", + "Neg" + }; + + OptionButton *ob = memnew( OptionButton ); + for(int i=0;iadd_item(func_name[i],i); + } + + ob->select(graph->scalar_func_node_get_function(type,p_id)); + ob->connect("item_selected",this,"_scalar_func_changed",varray(p_id)); + gn->add_child(ob); + + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_child( memnew(Label("in"))); + hbc->add_spacer(); + hbc->add_child( memnew(Label("out"))); + gn->add_child(hbc); + + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + + + } break; // scalar function (sin: { } break; cos: { } break; etc) + case ShaderGraph::NODE_VEC_FUNC: { + + + + gn->set_title("VecFunc"); + static const char* func_name[ShaderGraph::VEC_MAX_FUNC]={ + "Normalize", + "Saturate", + "Negate", + "Reciprocal", + "RGB to HSV", + "HSV to RGB", + }; + + OptionButton *ob = memnew( OptionButton ); + for(int i=0;iadd_item(func_name[i],i); + } + + ob->select(graph->vec_func_node_get_function(type,p_id)); + ob->connect("item_selected",this,"_vec_func_changed",varray(p_id)); + gn->add_child(ob); + + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("in"))); + hbc->add_spacer(); + hbc->add_child( memnew(Label("out"))); + gn->add_child(hbc); + + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + + } break; // vector function (normalize: { } break; negate: { } break; reciprocal: { } break; rgb2hsv: { } break; hsv2rgb: { } break; etc: { } break; etc) + case ShaderGraph::NODE_VEC_LEN: { + gn->set_title("VecLength"); + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_child( memnew(Label("in"))); + hbc->add_spacer(); + hbc->add_child( memnew(Label("len"))); + gn->add_child(hbc); + + gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + + } break; // vec3 length + case ShaderGraph::NODE_DOT_PROD: { + + gn->set_title("DotProduct"); + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("a"))); + hbc->add_spacer(); + hbc->add_child( memnew(Label("dp"))); + gn->add_child(hbc); + gn->add_child( memnew(Label("b"))); + + gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); + + } break; // vec3 . vec3 (dot product -> scalar output) + case ShaderGraph::NODE_VEC_TO_SCALAR: { + + gn->set_title("Vec2Scalar"); + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("vec"))); + hbc->add_spacer(); + Label *l=memnew(Label("x")); + l->set_align(Label::ALIGN_RIGHT); + hbc->add_child( l); + gn->add_child(hbc); + l=memnew(Label("y")); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child( l ); + l=memnew(Label("z")); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child( l); + + gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + gn->set_slot(1,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + gn->set_slot(2,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + + + + + } break; // 1 vec3 input: { } break; 3 scalar outputs + case ShaderGraph::NODE_SCALAR_TO_VEC: { + + gn->set_title("Scalar2Vec"); + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_child( memnew(Label("x"))); + hbc->add_spacer(); + hbc->add_child( memnew(Label("vec"))); + gn->add_child(hbc); + gn->add_child( memnew(Label("y"))); + gn->add_child( memnew(Label("z"))); + + gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); + gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); + + } break; // 3 scalar input: { } break; 1 vec3 output + case ShaderGraph::NODE_VEC_TO_XFORM: { + + gn->set_title("Vec2XForm"); + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("x"))); + hbc->add_spacer(); + hbc->add_child( memnew(Label("xf"))); + gn->add_child(hbc); + gn->add_child( memnew(Label("y"))); + gn->add_child( memnew(Label("z"))); + gn->add_child( memnew(Label("ofs"))); + + gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM]); + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); + gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); + gn->set_slot(3,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); + + } break; // 3 vec input: { } break; 1 xform output + case ShaderGraph::NODE_XFORM_TO_VEC: { + + gn->set_title("XForm2Vec"); + + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("xf"))); + hbc->add_spacer(); + Label *l=memnew(Label("x")); + l->set_align(Label::ALIGN_RIGHT); + hbc->add_child( l); + gn->add_child(hbc); + l=memnew(Label("y")); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child( l ); + l=memnew(Label("z")); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child( l); + l=memnew(Label("ofs")); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child( l); + + gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(1,false,0,Color(),true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(2,false,0,Color(),true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(3,false,0,Color(),true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + + } break; // 3 vec input: { } break; 1 xform output + case ShaderGraph::NODE_SCALAR_INTERP: { + + gn->set_title("ScalarInterp"); + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("a"))); + hbc->add_spacer(); + hbc->add_child( memnew(Label("interp"))); + gn->add_child(hbc); + gn->add_child( memnew(Label("b"))); + gn->add_child( memnew(Label("c"))); + + gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); + gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); + + + } break; // scalar interpolation (with optional curve) + case ShaderGraph::NODE_VEC_INTERP: { + + gn->set_title("VecInterp"); + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_child( memnew(Label("a"))); + hbc->add_spacer(); + hbc->add_child( memnew(Label("interp"))); + gn->add_child(hbc); + gn->add_child( memnew(Label("b"))); + gn->add_child( memnew(Label("c"))); - gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); - gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); - gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); + gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); + gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); - } break; // vec3 interpolation (with optional curve) - case ShaderGraph::NODE_COLOR_RAMP: { - - gn->set_title("ColorRamp"); - GraphColorRampEdit * ramp = memnew( GraphColorRampEdit ); - - DVector offsets = graph->color_ramp_node_get_offsets(type,p_id); - DVector colors = graph->color_ramp_node_get_colors(type,p_id); - - int oc = offsets.size(); - - if (oc) { - DVector::Read rofs = offsets.read(); - DVector::Read rcol = colors.read(); - - Vector ofsv; - Vector colorv; - for(int i=0;iset_ramp(ofsv,colorv); - - } - - ramp->connect("ramp_changed",this,"_color_ramp_changed",varray(p_id,ramp)); - ramp->set_custom_minimum_size(Size2(128,1)); - gn->add_child(ramp); - - - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("c"))); - hbc->add_spacer(); - Label *l=memnew(Label("rgb")); - l->set_align(Label::ALIGN_RIGHT); - hbc->add_child( l); - gn->add_child(hbc); - l=memnew(Label("alpha")); - l->set_align(Label::ALIGN_RIGHT); - gn->add_child( l); - - - gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); - gn->set_slot(2,false,ShaderGraph::SLOT_MAX,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); - - - } break; // scalar interpolation (with optional curve) - case ShaderGraph::NODE_CURVE_MAP: { - - gn->set_title("CurveMap"); - GraphCurveMapEdit * map = memnew( GraphCurveMapEdit ); - - DVector points = graph->curve_map_node_get_points(type,p_id); - - int oc = points.size(); - - if (oc) { - DVector::Read rofs = points.read(); - - - Vector ofsv; - for(int i=0;iset_points(ofsv); - - } - map->connect("curve_changed",this,"_curve_changed",varray(p_id,map)); - - //map->connect("map_changed",this,"_curve_map_changed",varray(p_id,map)); - map->set_custom_minimum_size(Size2(128,64)); - gn->add_child(map); - - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("c"))); - hbc->add_spacer(); - Label *l=memnew(Label("cmap")); - l->set_align(Label::ALIGN_RIGHT); - hbc->add_child( l); - gn->add_child(hbc); - - - gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); - - - } break; // scalar interpolation (with optional curve) - - case ShaderGraph::NODE_SCALAR_INPUT: { - - gn->set_title("ScalarUniform"); - LineEdit *le = memnew( LineEdit ); - gn->add_child(le); - le->set_text(graph->input_node_get_name(type,p_id)); - le->connect("text_entered",this,"_input_name_changed",varray(p_id,le)); - SpinBox *sb = memnew( SpinBox ); - sb->set_min(-100000); - sb->set_max(100000); - sb->set_step(0.001); - sb->set_val(graph->scalar_input_node_get_value(type,p_id)); - sb->connect("value_changed",this,"_scalar_input_changed",varray(p_id)); - gn->add_child(sb); - gn->set_slot(1,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); - - } break; // scalar uniform (assignable in material) - case ShaderGraph::NODE_VEC_INPUT: { - - gn->set_title("VectorUniform"); - LineEdit *le = memnew( LineEdit ); - gn->add_child(le); - le->set_text(graph->input_node_get_name(type,p_id)); - le->connect("text_entered",this,"_input_name_changed",varray(p_id,le)); - Array v3p(true); - for(int i=0;i<3;i++) { - HBoxContainer *hbc = memnew( HBoxContainer ); - Label *l = memnew( Label ); - l->set_text(String::chr('X'+i)); - hbc->add_child(l); - SpinBox *sb = memnew( SpinBox ); - sb->set_h_size_flags(Control::SIZE_EXPAND_FILL); - sb->set_min(-100000); - sb->set_max(100000); - sb->set_step(0.001); - sb->set_val(graph->vec_input_node_get_value(type,p_id)[i]); - sb->connect("value_changed",this,"_vec_input_changed",varray(p_id,v3p)); - v3p.push_back(sb); - hbc->add_child(sb); - gn->add_child(hbc); - } - gn->set_slot(1,false,0,Color(),true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); - - } break; // vec3 uniform (assignable in material) - case ShaderGraph::NODE_RGB_INPUT: { - - gn->set_title("ColorUniform"); - LineEdit *le = memnew( LineEdit ); - gn->add_child(le); - le->set_text(graph->input_node_get_name(type,p_id)); - le->connect("text_entered",this,"_input_name_changed",varray(p_id,le)); - ColorPickerButton *cpb = memnew( ColorPickerButton ); - cpb->set_color(graph->rgb_input_node_get_value(type,p_id)); - cpb->connect("color_changed",this,"_rgb_input_changed",varray(p_id)); - gn->add_child(cpb); - Label *l = memnew( Label ); - l->set_text("RGB"); - l->set_align(Label::ALIGN_RIGHT); - gn->add_child(l); - l = memnew( Label ); - l->set_text("Alpha"); - l->set_align(Label::ALIGN_RIGHT); - gn->add_child(l); - - gn->set_slot(2,false,0,Color(),true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); - gn->set_slot(3,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); - - - } break; // color uniform (assignable in material) - case ShaderGraph::NODE_XFORM_INPUT: { - gn->set_title("XFUniform"); - LineEdit *le = memnew( LineEdit ); - gn->add_child(le); - le->set_text(graph->input_node_get_name(type,p_id)); - le->connect("text_entered",this,"_input_name_changed",varray(p_id,le)); - ToolButton *edit = memnew( ToolButton ); - edit->set_text("edit.."); - edit->connect("pressed",this,"_xform_input_changed",varray(p_id,edit)); - gn->add_child(edit); - gn->set_slot(1,false,0,Color(),true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM]); - - } break; // mat4 uniform (assignable in material) - case ShaderGraph::NODE_TEXTURE_INPUT: { - - gn->set_title("TexUniform"); - LineEdit *le = memnew( LineEdit ); - gn->add_child(le); - le->set_text(graph->input_node_get_name(type,p_id)); - le->connect("text_entered",this,"_input_name_changed",varray(p_id,le)); - TextureFrame *tex = memnew( TextureFrame ); - tex->set_expand(true); - tex->set_custom_minimum_size(Size2(80,80)); - gn->add_child(tex); - tex->set_texture(graph->texture_input_node_get_value(type,p_id)); - ToolButton *edit = memnew( ToolButton ); - edit->set_text("edit.."); - edit->connect("pressed",this,"_tex_edited",varray(p_id,edit)); - gn->add_child(edit); - - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("UV"))); - hbc->add_spacer(); - Label *l=memnew(Label("RGB")); - l->set_align(Label::ALIGN_RIGHT); - hbc->add_child(l); - gn->add_child(hbc); - l = memnew( Label ); - l->set_text("Alpha"); - l->set_align(Label::ALIGN_RIGHT); - gn->add_child(l); - - gn->set_slot(3,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); - gn->set_slot(4,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); - - } break; // texture input (assignable in material) - case ShaderGraph::NODE_CUBEMAP_INPUT: { - - gn->set_title("TexUniform"); - LineEdit *le = memnew( LineEdit ); - gn->add_child(le); - le->set_text(graph->input_node_get_name(type,p_id)); - le->connect("text_entered",this,"_input_name_changed",varray(p_id,le)); - - ToolButton *edit = memnew( ToolButton ); - edit->set_text("edit.."); - edit->connect("pressed",this,"_cube_edited",varray(p_id,edit)); - gn->add_child(edit); - - - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("UV"))); - hbc->add_spacer(); - Label *l=memnew(Label("RGB")); - l->set_align(Label::ALIGN_RIGHT); - hbc->add_child(l); - gn->add_child(hbc); - l = memnew( Label ); - l->set_text("Alpha"); - l->set_align(Label::ALIGN_RIGHT); - gn->add_child(l); - - gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); - gn->set_slot(3,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); - - } break; // cubemap input (assignable in material) - case ShaderGraph::NODE_DEFAULT_TEXTURE: { - - gn->set_title("CanvasItemTex"); - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("UV"))); - hbc->add_spacer(); - Label *l=memnew(Label("RGB")); - l->set_align(Label::ALIGN_RIGHT); - hbc->add_child(l); - gn->add_child(hbc); - l = memnew( Label ); - l->set_text("Alpha"); - l->set_align(Label::ALIGN_RIGHT); - gn->add_child(l); - - gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); - gn->set_slot(1,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); - - - } break; // screen texture sampler (takes UV) (only usable in fragment case Shader) - - case ShaderGraph::NODE_OUTPUT: { - gn->set_title("Output"); - gn->set_show_close_button(false); - - List si; - ShaderGraph::get_input_output_node_slot_info(graph->get_mode(),type,&si); - - int idx=0; - for (List::Element *E=si.front();E;E=E->next()) { - ShaderGraph::SlotInfo& s=E->get(); - if (s.dir==ShaderGraph::SLOT_OUT) { - - Label *l= memnew( Label ); - l->set_text(s.name); - l->set_align(Label::ALIGN_LEFT); - gn->add_child(l); - gn->set_slot(idx,true,s.type,typecol[s.type],false,0,Color()); - idx++; - } - } - - } break; // output (case Shader type dependent) - case ShaderGraph::NODE_COMMENT: { - gn->set_title("Comment"); - TextEdit *te = memnew(TextEdit); - te->set_custom_minimum_size(Size2(100,100)); - gn->add_child(te); - te->set_text(graph->comment_node_get_text(type,p_id)); - te->connect("text_changed",this,"_comment_edited",varray(p_id,te)); - - } break; // comment - - - - } - - gn->connect("dragged",this,"_node_moved",varray(p_id)); - gn->connect("close_request",this,"_node_removed",varray(p_id),CONNECT_DEFERRED); - graph_edit->add_child(gn); - node_map[p_id]=gn; - gn->set_offset(graph->node_get_pos(type,p_id)); + } break; // vec3 interpolation (with optional curve) + case ShaderGraph::NODE_COLOR_RAMP: { + + gn->set_title("ColorRamp"); + GraphColorRampEdit * ramp = memnew( GraphColorRampEdit ); + + DVector offsets = graph->color_ramp_node_get_offsets(type,p_id); + DVector colors = graph->color_ramp_node_get_colors(type,p_id); + + int oc = offsets.size(); + + if (oc) { + DVector::Read rofs = offsets.read(); + DVector::Read rcol = colors.read(); + + Vector ofsv; + Vector colorv; + for(int i=0;iset_ramp(ofsv,colorv); + + } + + ramp->connect("ramp_changed",this,"_color_ramp_changed",varray(p_id,ramp)); + ramp->set_custom_minimum_size(Size2(128,1)); + gn->add_child(ramp); + + + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("c"))); + hbc->add_spacer(); + Label *l=memnew(Label("rgb")); + l->set_align(Label::ALIGN_RIGHT); + hbc->add_child( l); + gn->add_child(hbc); + l=memnew(Label("alpha")); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child( l); + + + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(2,false,ShaderGraph::SLOT_MAX,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + + + } break; // scalar interpolation (with optional curve) + case ShaderGraph::NODE_CURVE_MAP: { + + gn->set_title("CurveMap"); + GraphCurveMapEdit * map = memnew( GraphCurveMapEdit ); + + DVector points = graph->curve_map_node_get_points(type,p_id); + + int oc = points.size(); + + if (oc) { + DVector::Read rofs = points.read(); + + + Vector ofsv; + for(int i=0;iset_points(ofsv); + + } + map->connect("curve_changed",this,"_curve_changed",varray(p_id,map)); + + //map->connect("map_changed",this,"_curve_map_changed",varray(p_id,map)); + map->set_custom_minimum_size(Size2(128,64)); + gn->add_child(map); + + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("c"))); + hbc->add_spacer(); + Label *l=memnew(Label("cmap")); + l->set_align(Label::ALIGN_RIGHT); + hbc->add_child( l); + gn->add_child(hbc); + + + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + + + } break; // scalar interpolation (with optional curve) + + case ShaderGraph::NODE_SCALAR_INPUT: { + + gn->set_title("ScalarUniform"); + LineEdit *le = memnew( LineEdit ); + gn->add_child(le); + le->set_text(graph->input_node_get_name(type,p_id)); + le->connect("text_entered",this,"_input_name_changed",varray(p_id,le)); + SpinBox *sb = memnew( SpinBox ); + sb->set_min(-100000); + sb->set_max(100000); + sb->set_step(0.001); + sb->set_val(graph->scalar_input_node_get_value(type,p_id)); + sb->connect("value_changed",this,"_scalar_input_changed",varray(p_id)); + gn->add_child(sb); + gn->set_slot(1,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + + } break; // scalar uniform (assignable in material) + case ShaderGraph::NODE_VEC_INPUT: { + + gn->set_title("VectorUniform"); + LineEdit *le = memnew( LineEdit ); + gn->add_child(le); + le->set_text(graph->input_node_get_name(type,p_id)); + le->connect("text_entered",this,"_input_name_changed",varray(p_id,le)); + Array v3p(true); + for(int i=0;i<3;i++) { + HBoxContainer *hbc = memnew( HBoxContainer ); + Label *l = memnew( Label ); + l->set_text(String::chr('X'+i)); + hbc->add_child(l); + SpinBox *sb = memnew( SpinBox ); + sb->set_h_size_flags(Control::SIZE_EXPAND_FILL); + sb->set_min(-100000); + sb->set_max(100000); + sb->set_step(0.001); + sb->set_val(graph->vec_input_node_get_value(type,p_id)[i]); + sb->connect("value_changed",this,"_vec_input_changed",varray(p_id,v3p)); + v3p.push_back(sb); + hbc->add_child(sb); + gn->add_child(hbc); + } + gn->set_slot(1,false,0,Color(),true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + + } break; // vec3 uniform (assignable in material) + case ShaderGraph::NODE_RGB_INPUT: { + + gn->set_title("ColorUniform"); + LineEdit *le = memnew( LineEdit ); + gn->add_child(le); + le->set_text(graph->input_node_get_name(type,p_id)); + le->connect("text_entered",this,"_input_name_changed",varray(p_id,le)); + ColorPickerButton *cpb = memnew( ColorPickerButton ); + cpb->set_color(graph->rgb_input_node_get_value(type,p_id)); + cpb->connect("color_changed",this,"_rgb_input_changed",varray(p_id)); + gn->add_child(cpb); + Label *l = memnew( Label ); + l->set_text("RGB"); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child(l); + l = memnew( Label ); + l->set_text("Alpha"); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child(l); + + gn->set_slot(2,false,0,Color(),true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(3,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + + + } break; // color uniform (assignable in material) + case ShaderGraph::NODE_XFORM_INPUT: { + gn->set_title("XFUniform"); + LineEdit *le = memnew( LineEdit ); + gn->add_child(le); + le->set_text(graph->input_node_get_name(type,p_id)); + le->connect("text_entered",this,"_input_name_changed",varray(p_id,le)); + ToolButton *edit = memnew( ToolButton ); + edit->set_text("edit.."); + edit->connect("pressed",this,"_xform_input_changed",varray(p_id,edit)); + gn->add_child(edit); + gn->set_slot(1,false,0,Color(),true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM]); + + } break; // mat4 uniform (assignable in material) + case ShaderGraph::NODE_TEXTURE_INPUT: { + + gn->set_title("TexUniform"); + LineEdit *le = memnew( LineEdit ); + gn->add_child(le); + le->set_text(graph->input_node_get_name(type,p_id)); + le->connect("text_entered",this,"_input_name_changed",varray(p_id,le)); + TextureFrame *tex = memnew( TextureFrame ); + tex->set_expand(true); + tex->set_custom_minimum_size(Size2(80,80)); + gn->add_child(tex); + tex->set_texture(graph->texture_input_node_get_value(type,p_id)); + ToolButton *edit = memnew( ToolButton ); + edit->set_text("edit.."); + edit->connect("pressed",this,"_tex_edited",varray(p_id,edit)); + gn->add_child(edit); + + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("UV"))); + hbc->add_spacer(); + Label *l=memnew(Label("RGB")); + l->set_align(Label::ALIGN_RIGHT); + hbc->add_child(l); + gn->add_child(hbc); + l = memnew( Label ); + l->set_text("Alpha"); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child(l); + + gn->set_slot(3,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(4,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + + } break; // texture input (assignable in material) + case ShaderGraph::NODE_CUBEMAP_INPUT: { + + gn->set_title("TexUniform"); + LineEdit *le = memnew( LineEdit ); + gn->add_child(le); + le->set_text(graph->input_node_get_name(type,p_id)); + le->connect("text_entered",this,"_input_name_changed",varray(p_id,le)); + + ToolButton *edit = memnew( ToolButton ); + edit->set_text("edit.."); + edit->connect("pressed",this,"_cube_edited",varray(p_id,edit)); + gn->add_child(edit); + + + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("UV"))); + hbc->add_spacer(); + Label *l=memnew(Label("RGB")); + l->set_align(Label::ALIGN_RIGHT); + hbc->add_child(l); + gn->add_child(hbc); + l = memnew( Label ); + l->set_text("Alpha"); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child(l); + + gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(3,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + + } break; // cubemap input (assignable in material) + case ShaderGraph::NODE_DEFAULT_TEXTURE: { + + gn->set_title("CanvasItemTex"); + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("UV"))); + hbc->add_spacer(); + Label *l=memnew(Label("RGB")); + l->set_align(Label::ALIGN_RIGHT); + hbc->add_child(l); + gn->add_child(hbc); + l = memnew( Label ); + l->set_text("Alpha"); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child(l); + + gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(1,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + + + } break; // screen texture sampler (takes UV) (only usable in fragment case Shader) + + case ShaderGraph::NODE_OUTPUT: { + gn->set_title("Output"); + gn->set_show_close_button(false); + + List si; + ShaderGraph::get_input_output_node_slot_info(graph->get_mode(),type,&si); + + int idx=0; + for (List::Element *E=si.front();E;E=E->next()) { + ShaderGraph::SlotInfo& s=E->get(); + if (s.dir==ShaderGraph::SLOT_OUT) { + + Label *l= memnew( Label ); + l->set_text(s.name); + l->set_align(Label::ALIGN_LEFT); + gn->add_child(l); + gn->set_slot(idx,true,s.type,typecol[s.type],false,0,Color()); + idx++; + } + } + + } break; // output (case Shader type dependent) + case ShaderGraph::NODE_COMMENT: { + gn->set_title("Comment"); + TextEdit *te = memnew(TextEdit); + te->set_custom_minimum_size(Size2(100,100)); + gn->add_child(te); + te->set_text(graph->comment_node_get_text(type,p_id)); + te->connect("text_changed",this,"_comment_edited",varray(p_id,te)); + + } break; // comment + + + + } + + gn->connect("dragged",this,"_node_moved",varray(p_id)); + gn->connect("close_request",this,"_node_removed",varray(p_id),CONNECT_DEFERRED); + graph_edit->add_child(gn); + node_map[p_id]=gn; + gn->set_offset(graph->node_get_pos(type,p_id)); } @@ -2056,36 +2056,36 @@ void ShaderGraphView::_create_node(int p_id) { void ShaderGraphView::_update_graph() { - if (block_update) - return; + if (block_update) + return; - for (Map::Element *E=node_map.front();E;E=E->next()) { + for (Map::Element *E=node_map.front();E;E=E->next()) { - memdelete(E->get()); - } + memdelete(E->get()); + } - node_map.clear(); + node_map.clear(); - if (!graph.is_valid()) - return; + if (!graph.is_valid()) + return; - List nl; - graph->get_node_list(type,&nl); + List nl; + graph->get_node_list(type,&nl); - for(List::Element *E=nl.front();E;E=E->next()) { + for(List::Element *E=nl.front();E;E=E->next()) { - _create_node(E->get()); - } - graph_edit->clear_connections(); + _create_node(E->get()); + } + graph_edit->clear_connections(); - List connections; - graph->get_node_connections(type,&connections); - for(List::Element *E=connections.front();E;E=E->next()) { + List connections; + graph->get_node_connections(type,&connections); + for(List::Element *E=connections.front();E;E=E->next()) { - ERR_CONTINUE(!node_map.has(E->get().src_id) || !node_map.has(E->get().dst_id)); - graph_edit->connect_node(node_map[E->get().src_id]->get_name(),E->get().src_slot,node_map[E->get().dst_id]->get_name(),E->get().dst_slot); - } + ERR_CONTINUE(!node_map.has(E->get().src_id) || !node_map.has(E->get().dst_id)); + graph_edit->connect_node(node_map[E->get().src_id]->get_name(),E->get().src_slot,node_map[E->get().dst_id]->get_name(),E->get().dst_slot); + } @@ -2093,314 +2093,314 @@ void ShaderGraphView::_update_graph() { void ShaderGraphView::_sg_updated() { - if (!graph.is_valid()) - return; - switch(graph->get_graph_error(type)) { - case ShaderGraph::GRAPH_OK: status->set_text(""); break; - case ShaderGraph::GRAPH_ERROR_CYCLIC: status->set_text("Error: Cyclic Connection Link"); break; - case ShaderGraph::GRAPH_ERROR_MISSING_CONNECTIONS: status->set_text("Error: Missing Input Connections"); break; - } + if (!graph.is_valid()) + return; + switch(graph->get_graph_error(type)) { + case ShaderGraph::GRAPH_OK: status->set_text(""); break; + case ShaderGraph::GRAPH_ERROR_CYCLIC: status->set_text("Error: Cyclic Connection Link"); break; + case ShaderGraph::GRAPH_ERROR_MISSING_CONNECTIONS: status->set_text("Error: Missing Input Connections"); break; + } } void ShaderGraphView::set_graph(Ref p_graph){ - if (graph.is_valid()) { - graph->disconnect("updated",this,"_sg_updated"); - } - graph=p_graph; - if (graph.is_valid()) { - graph->connect("updated",this,"_sg_updated"); - } - _update_graph(); - _sg_updated(); + if (graph.is_valid()) { + graph->disconnect("updated",this,"_sg_updated"); + } + graph=p_graph; + if (graph.is_valid()) { + graph->connect("updated",this,"_sg_updated"); + } + _update_graph(); + _sg_updated(); } void ShaderGraphView::_notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_TREE) { + if (p_what==NOTIFICATION_ENTER_TREE) { - ped_popup->connect("variant_changed",this,"_variant_edited"); - } - } + ped_popup->connect("variant_changed",this,"_variant_edited"); + } +} void ShaderGraphView::add_node(int p_type, const Vector2 &location) { - List existing; - graph->get_node_list(type,&existing); - existing.sort(); - int newid=1; - for(List::Element *E=existing.front();E;E=E->next()) { - if (!E->next() || (E->get()+1!=E->next()->get())){ - newid=E->get()+1; - break; - } - } - - Vector2 init_ofs = location; - while(true) { - bool valid=true; - for(List::Element *E=existing.front();E;E=E->next()) { - Vector2 pos = graph->node_get_pos(type,E->get()); - if (init_ofs==pos) { - init_ofs+=Vector2(20,20); - valid=false; - break; - - } - } - - if (valid) - break; - } - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - ur->create_action("Add Shader Graph Node"); - ur->add_do_method(graph.ptr(),"node_add",type,p_type,newid); - ur->add_do_method(graph.ptr(),"node_set_pos",type,newid,init_ofs); - ur->add_undo_method(graph.ptr(),"node_remove",type,newid); - ur->add_do_method(this,"_update_graph"); - ur->add_undo_method(this,"_update_graph"); - ur->commit_action(); + List existing; + graph->get_node_list(type,&existing); + existing.sort(); + int newid=1; + for(List::Element *E=existing.front();E;E=E->next()) { + if (!E->next() || (E->get()+1!=E->next()->get())){ + newid=E->get()+1; + break; + } + } + + Vector2 init_ofs = location; + while(true) { + bool valid=true; + for(List::Element *E=existing.front();E;E=E->next()) { + Vector2 pos = graph->node_get_pos(type,E->get()); + if (init_ofs==pos) { + init_ofs+=Vector2(20,20); + valid=false; + break; + + } + } + + if (valid) + break; + } + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Add Shader Graph Node"); + ur->add_do_method(graph.ptr(),"node_add",type,p_type,newid); + ur->add_do_method(graph.ptr(),"node_set_pos",type,newid,init_ofs); + ur->add_undo_method(graph.ptr(),"node_remove",type,newid); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + ur->commit_action(); } void ShaderGraphView::_bind_methods() { - ObjectTypeDB::bind_method("_update_graph",&ShaderGraphView::_update_graph); - ObjectTypeDB::bind_method("_begin_node_move", &ShaderGraphView::_begin_node_move); - ObjectTypeDB::bind_method("_node_moved",&ShaderGraphView::_node_moved); - ObjectTypeDB::bind_method("_end_node_move", &ShaderGraphView::_end_node_move); - ObjectTypeDB::bind_method("_move_node",&ShaderGraphView::_move_node); - ObjectTypeDB::bind_method("_node_removed",&ShaderGraphView::_node_removed); - ObjectTypeDB::bind_method("_connection_request",&ShaderGraphView::_connection_request); - ObjectTypeDB::bind_method("_disconnection_request",&ShaderGraphView::_disconnection_request); - - ObjectTypeDB::bind_method("_scalar_const_changed",&ShaderGraphView::_scalar_const_changed); - ObjectTypeDB::bind_method("_vec_const_changed",&ShaderGraphView::_vec_const_changed); - ObjectTypeDB::bind_method("_rgb_const_changed",&ShaderGraphView::_rgb_const_changed); - ObjectTypeDB::bind_method("_xform_const_changed",&ShaderGraphView::_xform_const_changed); - ObjectTypeDB::bind_method("_scalar_op_changed",&ShaderGraphView::_scalar_op_changed); - ObjectTypeDB::bind_method("_vec_op_changed",&ShaderGraphView::_vec_op_changed); - ObjectTypeDB::bind_method("_vec_scalar_op_changed",&ShaderGraphView::_vec_scalar_op_changed); - ObjectTypeDB::bind_method("_rgb_op_changed",&ShaderGraphView::_rgb_op_changed); - ObjectTypeDB::bind_method("_xform_inv_rev_changed",&ShaderGraphView::_xform_inv_rev_changed); - ObjectTypeDB::bind_method("_scalar_func_changed",&ShaderGraphView::_scalar_func_changed); - ObjectTypeDB::bind_method("_vec_func_changed",&ShaderGraphView::_vec_func_changed); - ObjectTypeDB::bind_method("_scalar_input_changed",&ShaderGraphView::_scalar_input_changed); - ObjectTypeDB::bind_method("_vec_input_changed",&ShaderGraphView::_vec_input_changed); - ObjectTypeDB::bind_method("_xform_input_changed",&ShaderGraphView::_xform_input_changed); - ObjectTypeDB::bind_method("_rgb_input_changed",&ShaderGraphView::_rgb_input_changed); - ObjectTypeDB::bind_method("_tex_input_change",&ShaderGraphView::_tex_input_change); - ObjectTypeDB::bind_method("_cube_input_change",&ShaderGraphView::_cube_input_change); - ObjectTypeDB::bind_method("_input_name_changed",&ShaderGraphView::_input_name_changed); - ObjectTypeDB::bind_method("_tex_edited",&ShaderGraphView::_tex_edited); - ObjectTypeDB::bind_method("_variant_edited",&ShaderGraphView::_variant_edited); - ObjectTypeDB::bind_method("_cube_edited",&ShaderGraphView::_cube_edited); - ObjectTypeDB::bind_method("_comment_edited",&ShaderGraphView::_comment_edited); - ObjectTypeDB::bind_method("_color_ramp_changed",&ShaderGraphView::_color_ramp_changed); - ObjectTypeDB::bind_method("_curve_changed",&ShaderGraphView::_curve_changed); - - ObjectTypeDB::bind_method("_sg_updated",&ShaderGraphView::_sg_updated); + ObjectTypeDB::bind_method("_update_graph",&ShaderGraphView::_update_graph); + ObjectTypeDB::bind_method("_begin_node_move", &ShaderGraphView::_begin_node_move); + ObjectTypeDB::bind_method("_node_moved",&ShaderGraphView::_node_moved); + ObjectTypeDB::bind_method("_end_node_move", &ShaderGraphView::_end_node_move); + ObjectTypeDB::bind_method("_move_node",&ShaderGraphView::_move_node); + ObjectTypeDB::bind_method("_node_removed",&ShaderGraphView::_node_removed); + ObjectTypeDB::bind_method("_connection_request",&ShaderGraphView::_connection_request); + ObjectTypeDB::bind_method("_disconnection_request",&ShaderGraphView::_disconnection_request); + + ObjectTypeDB::bind_method("_scalar_const_changed",&ShaderGraphView::_scalar_const_changed); + ObjectTypeDB::bind_method("_vec_const_changed",&ShaderGraphView::_vec_const_changed); + ObjectTypeDB::bind_method("_rgb_const_changed",&ShaderGraphView::_rgb_const_changed); + ObjectTypeDB::bind_method("_xform_const_changed",&ShaderGraphView::_xform_const_changed); + ObjectTypeDB::bind_method("_scalar_op_changed",&ShaderGraphView::_scalar_op_changed); + ObjectTypeDB::bind_method("_vec_op_changed",&ShaderGraphView::_vec_op_changed); + ObjectTypeDB::bind_method("_vec_scalar_op_changed",&ShaderGraphView::_vec_scalar_op_changed); + ObjectTypeDB::bind_method("_rgb_op_changed",&ShaderGraphView::_rgb_op_changed); + ObjectTypeDB::bind_method("_xform_inv_rev_changed",&ShaderGraphView::_xform_inv_rev_changed); + ObjectTypeDB::bind_method("_scalar_func_changed",&ShaderGraphView::_scalar_func_changed); + ObjectTypeDB::bind_method("_vec_func_changed",&ShaderGraphView::_vec_func_changed); + ObjectTypeDB::bind_method("_scalar_input_changed",&ShaderGraphView::_scalar_input_changed); + ObjectTypeDB::bind_method("_vec_input_changed",&ShaderGraphView::_vec_input_changed); + ObjectTypeDB::bind_method("_xform_input_changed",&ShaderGraphView::_xform_input_changed); + ObjectTypeDB::bind_method("_rgb_input_changed",&ShaderGraphView::_rgb_input_changed); + ObjectTypeDB::bind_method("_tex_input_change",&ShaderGraphView::_tex_input_change); + ObjectTypeDB::bind_method("_cube_input_change",&ShaderGraphView::_cube_input_change); + ObjectTypeDB::bind_method("_input_name_changed",&ShaderGraphView::_input_name_changed); + ObjectTypeDB::bind_method("_tex_edited",&ShaderGraphView::_tex_edited); + ObjectTypeDB::bind_method("_variant_edited",&ShaderGraphView::_variant_edited); + ObjectTypeDB::bind_method("_cube_edited",&ShaderGraphView::_cube_edited); + ObjectTypeDB::bind_method("_comment_edited",&ShaderGraphView::_comment_edited); + ObjectTypeDB::bind_method("_color_ramp_changed",&ShaderGraphView::_color_ramp_changed); + ObjectTypeDB::bind_method("_curve_changed",&ShaderGraphView::_curve_changed); + + ObjectTypeDB::bind_method("_sg_updated",&ShaderGraphView::_sg_updated); } ShaderGraphView::ShaderGraphView(ShaderGraph::ShaderType p_type) { - type=p_type; - graph_edit = memnew( GraphEdit ); - block_update=false; - ped_popup = memnew( CustomPropertyEditor ); - graph_edit->add_child(ped_popup); - status = memnew( Label ); - graph_edit->get_top_layer()->add_child(status); - graph_edit->connect("_begin_node_move", this, "_begin_node_move"); - graph_edit->connect("_end_node_move", this, "_end_node_move"); - status->set_pos(Vector2(5,5)); - status->add_color_override("font_color_shadow",Color(0,0,0)); - status->add_color_override("font_color",Color(1,0.4,0.3)); - status->add_constant_override("shadow_as_outline",1); - status->add_constant_override("shadow_offset_x",2); - status->add_constant_override("shadow_offset_y",2); - status->set_text(""); + type=p_type; + graph_edit = memnew( GraphEdit ); + block_update=false; + ped_popup = memnew( CustomPropertyEditor ); + graph_edit->add_child(ped_popup); + status = memnew( Label ); + graph_edit->get_top_layer()->add_child(status); + graph_edit->connect("_begin_node_move", this, "_begin_node_move"); + graph_edit->connect("_end_node_move", this, "_end_node_move"); + status->set_pos(Vector2(5,5)); + status->add_color_override("font_color_shadow",Color(0,0,0)); + status->add_color_override("font_color",Color(1,0.4,0.3)); + status->add_constant_override("shadow_as_outline",1); + status->add_constant_override("shadow_offset_x",2); + status->add_constant_override("shadow_offset_y",2); + status->set_text(""); } //////////////edit////////////// void ShaderGraphEditor::edit(Ref p_shader) { - for(int i=0;iset_graph(p_shader); - } + for(int i=0;iset_graph(p_shader); + } } void ShaderGraphEditor::_add_node(int p_type) { - ShaderGraph::ShaderType shader_type=ShaderGraph::ShaderType(tabs->get_current_tab()); + ShaderGraph::ShaderType shader_type=ShaderGraph::ShaderType(tabs->get_current_tab()); - graph_edits[shader_type]->add_node(p_type, next_location); + graph_edits[shader_type]->add_node(p_type, next_location); } void ShaderGraphEditor::_popup_requested(const Vector2 &p_position) { - next_location = get_local_mouse_pos(); - popup->set_global_pos(p_position); - popup->set_size( Size2( 200, 0) ); - popup->popup(); - popup->call_deferred("grab_click_focus"); - popup->set_invalidate_click_until_motion(); + next_location = get_local_mouse_pos(); + popup->set_global_pos(p_position); + popup->set_size( Size2( 200, 0) ); + popup->popup(); + popup->call_deferred("grab_click_focus"); + popup->set_invalidate_click_until_motion(); } void ShaderGraphEditor::_notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_TREE) { + if (p_what==NOTIFICATION_ENTER_TREE) { - for(int i=0;iadd_icon_item(get_icon(ic,"EditorIcons"),v,i); - if (addsep) - popup->add_separator(); - } - popup->connect("item_pressed",this,"_add_node"); + String nn = node_names[i]; + String ic = nn.get_slice(":",0); + String v = nn.get_slice(":",1); + bool addsep=false; + if (nn.ends_with(":")) { + addsep=true; + } + popup->add_icon_item(get_icon(ic,"EditorIcons"),v,i); + if (addsep) + popup->add_separator(); + } + popup->connect("item_pressed",this,"_add_node"); - } + } } void ShaderGraphEditor::_bind_methods() { - ObjectTypeDB::bind_method("_add_node",&ShaderGraphEditor::_add_node); - ObjectTypeDB::bind_method("_popup_requested",&ShaderGraphEditor::_popup_requested); + ObjectTypeDB::bind_method("_add_node",&ShaderGraphEditor::_add_node); + ObjectTypeDB::bind_method("_popup_requested",&ShaderGraphEditor::_popup_requested); } const char* ShaderGraphEditor::node_names[ShaderGraph::NODE_TYPE_MAX]={ - "GraphInput:Input", // all inputs (shader type dependent) - "GraphScalar:Scalar Constant", //scalar constant - "GraphVector:Vector Constant", //vec3 constant - "GraphRgb:RGB Constant", //rgb constant (shows a color picker instead) - "GraphXform:XForm Constant", // 4x4 matrix constant - "GraphTime:Time:", // time in seconds - "GraphTexscreen:Screen Sample", // screen texture sampler (takes uv) (only usable in fragment shader) - "GraphScalarOp:Scalar Operator", // scalar vs scalar op (mul", add", div", etc) - "GraphVecOp:Vector Operator", // vec3 vs vec3 op (mul",ad",div",crossprod",etc) - "GraphVecScalarOp:Scalar+Vector Operator", // vec3 vs scalar op (mul", add", div", etc) - "GraphRgbOp:RGB Operator:", // vec3 vs vec3 rgb op (with scalar amount)", like brighten", darken", burn", dodge", multiply", etc. - "GraphXformMult:XForm Multiply", // mat4 x mat4 - "GraphXformVecMult:XForm+Vector Multiply", // mat4 x vec3 mult (with no-translation option) - "GraphXformVecImult:Form+Vector InvMultiply:", // mat4 x vec3 inverse mult (with no-translation option) - "GraphXformScalarFunc:Scalar Function", // scalar function (sin", cos", etc) - "GraphXformVecFunc:Vector Function", // vector function (normalize", negate", reciprocal", rgb2hsv", hsv2rgb", etc", etc) - "GraphVecLength:Vector Length", // vec3 length - "GraphVecDp:Dot Product:", // vec3 . vec3 (dot product -> scalar output) - "GraphVecToScalars:Vector -> Scalars", // 1 vec3 input", 3 scalar outputs - "GraphScalarsToVec:Scalars -> Vector", // 3 scalar input", 1 vec3 output - "GraphXformToVecs:XForm -> Vectors", // 3 vec input", 1 xform output - "GraphVecsToXform:Vectors -> XForm:", // 3 vec input", 1 xform output - "GraphScalarInterp:Scalar Interpolate", // scalar interpolation (with optional curve) - "GraphVecInterp:Vector Interpolate:", // vec3 interpolation (with optional curve) - "GraphColorRamp:Color Ramp", // vec3 interpolation (with optional curve) - "GraphCurveMap:Curve Remap:", // vec3 interpolation (with optional curve) - "GraphScalarUniform:Scalar Uniform", // scalar uniform (assignable in material) - "GraphVectorUniform:Vector Uniform", // vec3 uniform (assignable in material) - "GraphRgbUniform:RGB Uniform", // color uniform (assignable in material) - "GraphXformUniform:XForm Uniform", // mat4 uniform (assignable in material) - "GraphTextureUniform:Texture Uniform", // texture input (assignable in material) - "GraphCubeUniform:CubeMap Uniform:", // cubemap input (assignable in material) - "GraphDefaultTexture:CanvasItem Texture:", // cubemap input (assignable in material) - "Output", // output (shader type dependent) - "GraphComment:Comment", // comment + "GraphInput:Input", // all inputs (shader type dependent) + "GraphScalar:Scalar Constant", //scalar constant + "GraphVector:Vector Constant", //vec3 constant + "GraphRgb:RGB Constant", //rgb constant (shows a color picker instead) + "GraphXform:XForm Constant", // 4x4 matrix constant + "GraphTime:Time:", // time in seconds + "GraphTexscreen:Screen Sample", // screen texture sampler (takes uv) (only usable in fragment shader) + "GraphScalarOp:Scalar Operator", // scalar vs scalar op (mul", add", div", etc) + "GraphVecOp:Vector Operator", // vec3 vs vec3 op (mul",ad",div",crossprod",etc) + "GraphVecScalarOp:Scalar+Vector Operator", // vec3 vs scalar op (mul", add", div", etc) + "GraphRgbOp:RGB Operator:", // vec3 vs vec3 rgb op (with scalar amount)", like brighten", darken", burn", dodge", multiply", etc. + "GraphXformMult:XForm Multiply", // mat4 x mat4 + "GraphXformVecMult:XForm+Vector Multiply", // mat4 x vec3 mult (with no-translation option) + "GraphXformVecImult:Form+Vector InvMultiply:", // mat4 x vec3 inverse mult (with no-translation option) + "GraphXformScalarFunc:Scalar Function", // scalar function (sin", cos", etc) + "GraphXformVecFunc:Vector Function", // vector function (normalize", negate", reciprocal", rgb2hsv", hsv2rgb", etc", etc) + "GraphVecLength:Vector Length", // vec3 length + "GraphVecDp:Dot Product:", // vec3 . vec3 (dot product -> scalar output) + "GraphVecToScalars:Vector -> Scalars", // 1 vec3 input", 3 scalar outputs + "GraphScalarsToVec:Scalars -> Vector", // 3 scalar input", 1 vec3 output + "GraphXformToVecs:XForm -> Vectors", // 3 vec input", 1 xform output + "GraphVecsToXform:Vectors -> XForm:", // 3 vec input", 1 xform output + "GraphScalarInterp:Scalar Interpolate", // scalar interpolation (with optional curve) + "GraphVecInterp:Vector Interpolate:", // vec3 interpolation (with optional curve) + "GraphColorRamp:Color Ramp", // vec3 interpolation (with optional curve) + "GraphCurveMap:Curve Remap:", // vec3 interpolation (with optional curve) + "GraphScalarUniform:Scalar Uniform", // scalar uniform (assignable in material) + "GraphVectorUniform:Vector Uniform", // vec3 uniform (assignable in material) + "GraphRgbUniform:RGB Uniform", // color uniform (assignable in material) + "GraphXformUniform:XForm Uniform", // mat4 uniform (assignable in material) + "GraphTextureUniform:Texture Uniform", // texture input (assignable in material) + "GraphCubeUniform:CubeMap Uniform:", // cubemap input (assignable in material) + "GraphDefaultTexture:CanvasItem Texture:", // cubemap input (assignable in material) + "Output", // output (shader type dependent) + "GraphComment:Comment", // comment }; ShaderGraphEditor::ShaderGraphEditor(bool p_2d) { - _2d=p_2d; + _2d=p_2d; - HBoxContainer *hbc = memnew( HBoxContainer ); - popup = memnew( PopupMenu ); - hbc->add_child(popup); - add_child(hbc); + HBoxContainer *hbc = memnew( HBoxContainer ); + popup = memnew( PopupMenu ); + hbc->add_child(popup); + add_child(hbc); - tabs = memnew(TabContainer); - tabs->set_v_size_flags(SIZE_EXPAND_FILL); - add_child(tabs); - const char* sname[ShaderGraph::SHADER_TYPE_MAX]={ - "Vertex", - "Fragment", - "Light" - }; - for(int i=0;iset_v_size_flags(SIZE_EXPAND_FILL); + add_child(tabs); + const char* sname[ShaderGraph::SHADER_TYPE_MAX]={ + "Vertex", + "Fragment", + "Light" + }; + for(int i=0;iget_graph_edit()->set_name(sname[i]); - tabs->add_child(graph_edits[i]->get_graph_edit()); - graph_edits[i]->get_graph_edit()->connect("connection_request",graph_edits[i],"_connection_request"); - graph_edits[i]->get_graph_edit()->connect("disconnection_request",graph_edits[i],"_disconnection_request"); - graph_edits[i]->get_graph_edit()->connect("popup_request",this,"_popup_requested"); - graph_edits[i]->get_graph_edit()->set_right_disconnects(true); - } + graph_edits[i]= memnew( ShaderGraphView(ShaderGraph::ShaderType(i)) ); + add_child(graph_edits[i]); + graph_edits[i]->get_graph_edit()->set_name(sname[i]); + tabs->add_child(graph_edits[i]->get_graph_edit()); + graph_edits[i]->get_graph_edit()->connect("connection_request",graph_edits[i],"_connection_request"); + graph_edits[i]->get_graph_edit()->connect("disconnection_request",graph_edits[i],"_disconnection_request"); + graph_edits[i]->get_graph_edit()->connect("popup_request",this,"_popup_requested"); + graph_edits[i]->get_graph_edit()->set_right_disconnects(true); + } - tabs->set_current_tab(1); + tabs->set_current_tab(1); - set_custom_minimum_size(Size2(100,300)); + set_custom_minimum_size(Size2(100,300)); } void ShaderGraphEditorPlugin::edit(Object *p_object) { - shader_editor->edit(p_object->cast_to()); + shader_editor->edit(p_object->cast_to()); } bool ShaderGraphEditorPlugin::handles(Object *p_object) const { - ShaderGraph *shader=p_object->cast_to(); - if (!shader) - return false; - if (_2d) - return shader->get_mode()==Shader::MODE_CANVAS_ITEM; - else - return shader->get_mode()==Shader::MODE_MATERIAL; + ShaderGraph *shader=p_object->cast_to(); + if (!shader) + return false; + if (_2d) + return shader->get_mode()==Shader::MODE_CANVAS_ITEM; + else + return shader->get_mode()==Shader::MODE_MATERIAL; } void ShaderGraphEditorPlugin::make_visible(bool p_visible) { - if (p_visible) { - shader_editor->show(); - } else { + if (p_visible) { + shader_editor->show(); + } else { - shader_editor->hide(); - } + shader_editor->hide(); + } } ShaderGraphEditorPlugin::ShaderGraphEditorPlugin(EditorNode *p_node, bool p_2d) { - _2d=p_2d; - editor=p_node; - shader_editor = memnew( ShaderGraphEditor(p_2d) ); - shader_editor->hide(); - if (p_2d) - CanvasItemEditor::get_singleton()->get_bottom_split()->add_child(shader_editor); - else - SpatialEditor::get_singleton()->get_shader_split()->add_child(shader_editor); + _2d=p_2d; + editor=p_node; + shader_editor = memnew( ShaderGraphEditor(p_2d) ); + shader_editor->hide(); + if (p_2d) + CanvasItemEditor::get_singleton()->get_bottom_split()->add_child(shader_editor); + else + SpatialEditor::get_singleton()->get_shader_split()->add_child(shader_editor); -// editor->get_viewport()->add_child(shader_editor); -// shader_editor->set_area_as_parent_rect(); -// shader_editor->hide(); + // editor->get_viewport()->add_child(shader_editor); + // shader_editor->set_area_as_parent_rect(); + // shader_editor->hide(); } diff --git a/tools/editor/plugins/shader_graph_editor_plugin.h b/tools/editor/plugins/shader_graph_editor_plugin.h index ea21a7706fbd..5f93b9df7d17 100644 --- a/tools/editor/plugins/shader_graph_editor_plugin.h +++ b/tools/editor/plugins/shader_graph_editor_plugin.h @@ -41,189 +41,189 @@ #include "tools/editor/property_editor.h" #include "scene/resources/shader_graph.h" /** - @author Juan Linietsky + @author Juan Linietsky */ class GraphColorRampEdit : public Control { - OBJ_TYPE(GraphColorRampEdit,Control); + OBJ_TYPE(GraphColorRampEdit,Control); - struct Point { + struct Point { - float offset; - Color color; - bool operator<(const Point& p_ponit) const { - return offset points; + bool grabbing; + int grabbed; + float grabbed_at; + Vector points; - void _color_changed(const Color& p_color); + void _color_changed(const Color& p_color); protected: - void _input_event(const InputEvent& p_event); - void _notification(int p_what); - static void _bind_methods(); + void _input_event(const InputEvent& p_event); + void _notification(int p_what); + static void _bind_methods(); public: - void set_ramp(const Vector& p_offsets,const Vector& p_colors); - Vector get_offsets() const; - Vector get_colors() const; - virtual Size2 get_minimum_size() const; - GraphColorRampEdit(); + void set_ramp(const Vector& p_offsets,const Vector& p_colors); + Vector get_offsets() const; + Vector get_colors() const; + virtual Size2 get_minimum_size() const; + GraphColorRampEdit(); }; class GraphCurveMapEdit : public Control { - OBJ_TYPE(GraphCurveMapEdit,Control); + OBJ_TYPE(GraphCurveMapEdit,Control); - struct Point { + struct Point { - float offset; - float height; - bool operator<(const Point& p_ponit) const { - return offset points; + bool grabbing; + int grabbed; + Vector points; - void _plot_curve(const Vector2& p_a,const Vector2& p_b,const Vector2& p_c,const Vector2& p_d); + void _plot_curve(const Vector2& p_a,const Vector2& p_b,const Vector2& p_c,const Vector2& p_d); protected: - void _input_event(const InputEvent& p_event); - void _notification(int p_what); - static void _bind_methods(); + void _input_event(const InputEvent& p_event); + void _notification(int p_what); + static void _bind_methods(); public: - void set_points(const Vector& p_points); - Vector get_points() const; - virtual Size2 get_minimum_size() const; - GraphCurveMapEdit(); + void set_points(const Vector& p_points); + Vector get_points() const; + virtual Size2 get_minimum_size() const; + GraphCurveMapEdit(); }; class ShaderGraphView : public Node { - OBJ_TYPE(ShaderGraphView,Node); - - - - CustomPropertyEditor *ped_popup; - bool block_update; - - Label *status; - GraphEdit *graph_edit; - Ref graph; - int edited_id; - - ShaderGraph::ShaderType type; - - void _update_graph(); - void _create_node(int p_id); - - - - void _connection_request(const String& p_from, int p_from_slot,const String& p_to,int p_to_slot); - void _disconnection_request(const String& p_from, int p_from_slot,const String& p_to,int p_to_slot); - - void _node_removed(int p_id); - void _begin_node_move(); - void _node_moved(const Vector2& p_from, const Vector2& p_to,int p_id); - void _end_node_move(); - void _move_node(int p_id,const Vector2& p_to); - - void _scalar_const_changed(double p_value,int p_id); - void _vec_const_changed(double p_value, int p_id, Array p_arr); - void _rgb_const_changed(const Color& p_color, int p_id); - void _xform_const_changed(int p_id,Node* p_button); - void _scalar_op_changed(int p_op, int p_id); - void _vec_op_changed(int p_op, int p_id); - void _vec_scalar_op_changed(int p_op, int p_id); - void _rgb_op_changed(int p_op, int p_id); - void _xform_inv_rev_changed(bool p_enabled, int p_id); - void _scalar_func_changed(int p_func, int p_id); - void _vec_func_changed(int p_func, int p_id); - void _scalar_input_changed(double p_value,int p_id); - void _vec_input_changed(double p_value, int p_id, Array p_arr); - void _xform_input_changed(int p_id,Node* p_button); - void _rgb_input_changed(const Color& p_color, int p_id); - void _tex_input_change(int p_id,Node* p_button); - void _cube_input_change(int p_id); - void _input_name_changed(const String& p_name,int p_id,Node* p_line_edit); - void _tex_edited(int p_id,Node* p_button); - void _cube_edited(int p_id,Node* p_button); - void _variant_edited(); - void _comment_edited(int p_id,Node* p_button); - void _color_ramp_changed(int p_id,Node* p_ramp); - void _curve_changed(int p_id,Node* p_curve); - void _sg_updated(); - Map node_map; + OBJ_TYPE(ShaderGraphView,Node); + + + + CustomPropertyEditor *ped_popup; + bool block_update; + + Label *status; + GraphEdit *graph_edit; + Ref graph; + int edited_id; + + ShaderGraph::ShaderType type; + + void _update_graph(); + void _create_node(int p_id); + + + + void _connection_request(const String& p_from, int p_from_slot,const String& p_to,int p_to_slot); + void _disconnection_request(const String& p_from, int p_from_slot,const String& p_to,int p_to_slot); + + void _node_removed(int p_id); + void _begin_node_move(); + void _node_moved(const Vector2& p_from, const Vector2& p_to,int p_id); + void _end_node_move(); + void _move_node(int p_id,const Vector2& p_to); + + void _scalar_const_changed(double p_value,int p_id); + void _vec_const_changed(double p_value, int p_id, Array p_arr); + void _rgb_const_changed(const Color& p_color, int p_id); + void _xform_const_changed(int p_id,Node* p_button); + void _scalar_op_changed(int p_op, int p_id); + void _vec_op_changed(int p_op, int p_id); + void _vec_scalar_op_changed(int p_op, int p_id); + void _rgb_op_changed(int p_op, int p_id); + void _xform_inv_rev_changed(bool p_enabled, int p_id); + void _scalar_func_changed(int p_func, int p_id); + void _vec_func_changed(int p_func, int p_id); + void _scalar_input_changed(double p_value,int p_id); + void _vec_input_changed(double p_value, int p_id, Array p_arr); + void _xform_input_changed(int p_id,Node* p_button); + void _rgb_input_changed(const Color& p_color, int p_id); + void _tex_input_change(int p_id,Node* p_button); + void _cube_input_change(int p_id); + void _input_name_changed(const String& p_name,int p_id,Node* p_line_edit); + void _tex_edited(int p_id,Node* p_button); + void _cube_edited(int p_id,Node* p_button); + void _variant_edited(); + void _comment_edited(int p_id,Node* p_button); + void _color_ramp_changed(int p_id,Node* p_ramp); + void _curve_changed(int p_id,Node* p_curve); + void _sg_updated(); + Map node_map; protected: - void _notification(int p_what); - static void _bind_methods(); + void _notification(int p_what); + static void _bind_methods(); public: - void add_node(int p_type, const Vector2 &location); - GraphEdit *get_graph_edit() { return graph_edit; } - void set_graph(Ref p_graph); + void add_node(int p_type, const Vector2 &location); + GraphEdit *get_graph_edit() { return graph_edit; } + void set_graph(Ref p_graph); - ShaderGraphView(ShaderGraph::ShaderType p_type=ShaderGraph::SHADER_TYPE_FRAGMENT); + ShaderGraphView(ShaderGraph::ShaderType p_type=ShaderGraph::SHADER_TYPE_FRAGMENT); }; class ShaderGraphEditor : public VBoxContainer { - OBJ_TYPE(ShaderGraphEditor,VBoxContainer); + OBJ_TYPE(ShaderGraphEditor,VBoxContainer); - PopupMenu *popup; - TabContainer *tabs; - ShaderGraphView *graph_edits[ShaderGraph::SHADER_TYPE_MAX]; - static const char* node_names[ShaderGraph::NODE_TYPE_MAX]; - Vector2 next_location; + PopupMenu *popup; + TabContainer *tabs; + ShaderGraphView *graph_edits[ShaderGraph::SHADER_TYPE_MAX]; + static const char* node_names[ShaderGraph::NODE_TYPE_MAX]; + Vector2 next_location; - bool _2d; - void _add_node(int p_type); - void _popup_requested(const Vector2 &p_position); + bool _2d; + void _add_node(int p_type); + void _popup_requested(const Vector2 &p_position); protected: - void _notification(int p_what); - static void _bind_methods(); + void _notification(int p_what); + static void _bind_methods(); public: - void edit(Ref p_shader); - ShaderGraphEditor(bool p_2d); + void edit(Ref p_shader); + ShaderGraphEditor(bool p_2d); }; class ShaderGraphEditorPlugin : public EditorPlugin { - OBJ_TYPE( ShaderGraphEditorPlugin, EditorPlugin ); + OBJ_TYPE( ShaderGraphEditorPlugin, EditorPlugin ); - bool _2d; - ShaderGraphEditor *shader_editor; - EditorNode *editor; + bool _2d; + ShaderGraphEditor *shader_editor; + EditorNode *editor; public: - virtual String get_name() const { return "ShaderGraph"; } - bool has_main_screen() const { return false; } - virtual void edit(Object *p_node); - virtual bool handles(Object *p_node) const; - virtual void make_visible(bool p_visible); + virtual String get_name() const { return "ShaderGraph"; } + bool has_main_screen() const { return false; } + virtual void edit(Object *p_node); + virtual bool handles(Object *p_node) const; + virtual void make_visible(bool p_visible); - ShaderGraphEditorPlugin(EditorNode *p_node,bool p_2d); - ~ShaderGraphEditorPlugin(); + ShaderGraphEditorPlugin(EditorNode *p_node,bool p_2d); + ~ShaderGraphEditorPlugin(); }; #endif From bdde79a3f433dbff244e544b72ac8946d8d9b44b Mon Sep 17 00:00:00 2001 From: Mariano Javier Suligoy Date: Fri, 24 Jul 2015 21:59:48 -0300 Subject: [PATCH 04/11] Box selection for GraphNodes --- scene/gui/graph_edit.cpp | 91 ++++++++++++++++++++++++++++++++++++---- scene/gui/graph_edit.h | 7 ++++ 2 files changed, 90 insertions(+), 8 deletions(-) diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index 22a03504c6e5..003486dcf182 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -169,7 +169,6 @@ void GraphEdit::remove_child_notify(Node *p_child) { void GraphEdit::_notification(int p_what) { if (p_what==NOTIFICATION_READY) { - Size2 size = top_layer->get_size(); Size2 hmin = h_scroll->get_combined_minimum_size(); Size2 vmin = v_scroll->get_combined_minimum_size(); @@ -488,7 +487,8 @@ void GraphEdit::_top_layer_draw() { connections.erase(to_erase.front()->get()); to_erase.pop_front(); } - //draw connections + if (box_selecting) + top_layer->draw_rect(box_selecting_rect,Color(0.7,0.7,1.0,0.3)); } void GraphEdit::_input_event(const InputEvent& p_ev) { @@ -509,13 +509,51 @@ void GraphEdit::_input_event(const InputEvent& p_ev) { } } + if (p_ev.type==InputEvent::MOUSE_MOTION && box_selecting) { + box_selecting_to = get_local_mouse_pos(); + + box_selecting_rect = Rect2(MIN(box_selecting_from.x,box_selecting_to.x), + MIN(box_selecting_from.y,box_selecting_to.y), + ABS(box_selecting_from.x-box_selecting_to.x), + ABS(box_selecting_from.y-box_selecting_to.y)); + + for(int i=get_child_count()-1;i>=0;i--) { + + GraphNode *gn=get_child(i)->cast_to(); + if (!gn) + continue; + + bool in_box = gn->get_rect().intersects(box_selecting_rect); + + if (in_box) + gn->set_selected(box_selection_mode_aditive); + else + gn->set_selected(previus_selected.find(gn)!=NULL); + } + + top_layer->update(); + } + if (p_ev.type== InputEvent::MOUSE_BUTTON) { const InputEventMouseButton &b=p_ev.mouse_button; if (b.button_index==BUTTON_RIGHT && b.pressed) { - emit_signal("popup_request", Vector2(b.global_x, b.global_y)); + if (box_selecting) { + box_selecting = false; + for(int i=get_child_count()-1;i>=0;i--) { + + GraphNode *gn=get_child(i)->cast_to(); + if (!gn) + continue; + + gn->set_selected(previus_selected.find(gn)!=NULL); + } + top_layer->update(); + } else { + emit_signal("popup_request", Vector2(b.global_x, b.global_y)); + } } if (b.button_index==BUTTON_LEFT && !b.pressed && dragging) { @@ -584,16 +622,50 @@ void GraphEdit::_input_event(const InputEvent& p_ev) { } } else { - for(int i=get_child_count()-1;i>=0;i--) { + box_selecting = true; + box_selecting_from = get_local_mouse_pos(); + if (b.mod.control) { + box_selection_mode_aditive = true; + previus_selected.clear(); + for(int i=get_child_count()-1;i>=0;i--) { + + GraphNode *gn=get_child(i)->cast_to(); + if (!gn || !gn->is_selected()) + continue; + + previus_selected.push_back(gn); + } + } else if (b.mod.shift) { + box_selection_mode_aditive = false; + previus_selected.clear(); + for(int i=get_child_count()-1;i>=0;i--) { - GraphNode *gn=get_child(i)->cast_to(); - if (!gn) - continue; + GraphNode *gn=get_child(i)->cast_to(); + if (!gn || !gn->is_selected()) + continue; - gn->set_selected(false); + previus_selected.push_back(gn); + } + } else { + box_selection_mode_aditive = true; + previus_selected.clear(); + for(int i=get_child_count()-1;i>=0;i--) { + + GraphNode *gn=get_child(i)->cast_to(); + if (!gn) + continue; + + gn->set_selected(false); + } } } } + + if (b.button_index==BUTTON_LEFT && !b.pressed && box_selecting) { + box_selecting = false; + previus_selected.clear(); + top_layer->update(); + } } } @@ -678,6 +750,9 @@ GraphEdit::GraphEdit() { connecting=false; right_disconnects=false; + box_selecting = false; + dragging = false; + h_scroll->connect("value_changed", this,"_scroll_moved"); v_scroll->connect("value_changed", this,"_scroll_moved"); } diff --git a/scene/gui/graph_edit.h b/scene/gui/graph_edit.h index 5ab0f3300ebb..44f5a369c2f1 100644 --- a/scene/gui/graph_edit.h +++ b/scene/gui/graph_edit.h @@ -53,6 +53,13 @@ class GraphEdit : public Control { bool just_selected; Vector2 drag_accum; + bool box_selecting; + bool box_selection_mode_aditive; + Point2 box_selecting_from; + Point2 box_selecting_to; + Rect2 box_selecting_rect; + List previus_selected; + bool right_disconnects; bool updating; List connections; From 5ffd818fb195a6e9bea48ec03ad52a77080a8d25 Mon Sep 17 00:00:00 2001 From: Mariano Javier Suligoy Date: Sat, 25 Jul 2015 21:16:07 -0300 Subject: [PATCH 05/11] Duplicate GraphNode(s) [Control+D] --- scene/gui/graph_edit.cpp | 10 ++++- scene/gui/graph_node.cpp | 18 ++++---- scene/resources/shader_graph.cpp | 41 ++++++++++++++++++ scene/resources/shader_graph.h | 4 ++ .../plugins/shader_graph_editor_plugin.cpp | 43 +++++++++++++++++-- .../plugins/shader_graph_editor_plugin.h | 2 + 6 files changed, 106 insertions(+), 12 deletions(-) diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index 003486dcf182..a81542ea17af 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -534,7 +534,7 @@ void GraphEdit::_input_event(const InputEvent& p_ev) { top_layer->update(); } - if (p_ev.type== InputEvent::MOUSE_BUTTON) { + if (p_ev.type==InputEvent::MOUSE_BUTTON) { const InputEventMouseButton &b=p_ev.mouse_button; @@ -667,6 +667,11 @@ void GraphEdit::_input_event(const InputEvent& p_ev) { top_layer->update(); } } + + if (p_ev.type==InputEvent::KEY && p_ev.key.scancode==KEY_D && p_ev.key.pressed && p_ev.key.mod.command) { + emit_signal("duplicate_nodes_request"); + accept_event(); + } } void GraphEdit::clear_connections() { @@ -723,6 +728,7 @@ void GraphEdit::_bind_methods() { ADD_SIGNAL(MethodInfo("connection_request",PropertyInfo(Variant::STRING,"from"),PropertyInfo(Variant::INT,"from_slot"),PropertyInfo(Variant::STRING,"to"),PropertyInfo(Variant::INT,"to_slot"))); ADD_SIGNAL(MethodInfo("disconnection_request",PropertyInfo(Variant::STRING,"from"),PropertyInfo(Variant::INT,"from_slot"),PropertyInfo(Variant::STRING,"to"),PropertyInfo(Variant::INT,"to_slot"))); ADD_SIGNAL(MethodInfo("popup_request", PropertyInfo(Variant::VECTOR2,"p_position"))); + ADD_SIGNAL(MethodInfo("duplicate_nodes_request")); ADD_SIGNAL(MethodInfo("_begin_node_move")); ADD_SIGNAL(MethodInfo("_end_node_move")); } @@ -730,6 +736,8 @@ void GraphEdit::_bind_methods() { GraphEdit::GraphEdit() { + set_focus_mode(FOCUS_ALL); + top_layer=NULL; top_layer=memnew(GraphEditFilter(this)); add_child(top_layer); diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp index f0917aa4d178..5efc9757b75d 100644 --- a/scene/gui/graph_node.cpp +++ b/scene/gui/graph_node.cpp @@ -525,15 +525,17 @@ Color GraphNode::get_connection_output_color(int p_idx) { void GraphNode::_input_event(const InputEvent& p_ev) { - if (p_ev.type==InputEvent::MOUSE_BUTTON && p_ev.mouse_button.pressed && p_ev.mouse_button.button_index==BUTTON_LEFT) { - - Vector2 mpos = Vector2(p_ev.mouse_button.x,p_ev.mouse_button.y); - if (close_rect.size!=Size2() && close_rect.has_point(mpos)) { - emit_signal("close_request"); - return; + if (p_ev.type==InputEvent::MOUSE_BUTTON) { + get_parent_control()->grab_focus(); + if(p_ev.mouse_button.pressed && p_ev.mouse_button.button_index==BUTTON_LEFT) { + + Vector2 mpos = Vector2(p_ev.mouse_button.x,p_ev.mouse_button.y); + if (close_rect.size!=Size2() && close_rect.has_point(mpos)) { + emit_signal("close_request"); + return; + } + emit_signal("raise_request"); } - emit_signal("raise_request"); - } } diff --git a/scene/resources/shader_graph.cpp b/scene/resources/shader_graph.cpp index a0766ff317f8..108aad3c56c2 100644 --- a/scene/resources/shader_graph.cpp +++ b/scene/resources/shader_graph.cpp @@ -824,6 +824,47 @@ float ShaderGraph::texture_node_get_filter_strength(ShaderType p_type,float p_id return arr[1]; } +void ShaderGraph::duplicate_nodes(ShaderType p_which, List &p_nodes) +{ + //Create new node IDs + Map duplicates = Map(); + int i=1; + for(List::Element *E=p_nodes.front();E; E=E->next()) { + while (shader[p_which].node_map.has(i)) + i++; + duplicates.insert(E->get(), i); + i++; + } + + for(List::Element *E = p_nodes.front();E; E=E->next()) { + + const Node &n=shader[p_which].node_map[E->get()]; + Node nn=n; + nn.id=duplicates.find(n.id)->get(); + nn.pos += Vector2(0,100); + for (Map::Element *C=nn.connections.front();C;C=C->next()) { + SourceSlot &c=C->get(); + if (p_nodes.find(c.id)) + c.id=duplicates.find(c.id)->get(); + } + shader[p_which].node_map[nn.id]=nn; + } + _request_update(); +} + +List ShaderGraph::generate_ids(ShaderType p_type, int count) +{ + List ids = List(); + int i=1; + while (ids.size() < count) { + while (shader[p_type].node_map.has(i)) + i++; + ids.push_back(i); + i++; + } + return ids; +} + void ShaderGraph::scalar_op_node_set_op(ShaderType p_type,float p_id,ScalarOp p_op){ diff --git a/scene/resources/shader_graph.h b/scene/resources/shader_graph.h index fd6540a7477a..d3a297cd6c4d 100644 --- a/scene/resources/shader_graph.h +++ b/scene/resources/shader_graph.h @@ -216,6 +216,10 @@ class ShaderGraph : public Shader { void texture_node_set_filter_strength(ShaderType p_which,float p_id,float p_strength); float texture_node_get_filter_strength(ShaderType p_which,float p_id) const; + void duplicate_nodes(ShaderType p_which, List &p_nodes); + + List generate_ids(ShaderType p_type, int count); + enum ScalarOp { SCALAR_OP_ADD, SCALAR_OP_SUB, diff --git a/tools/editor/plugins/shader_graph_editor_plugin.cpp b/tools/editor/plugins/shader_graph_editor_plugin.cpp index 6e95432b99fe..3ab536ab6edc 100644 --- a/tools/editor/plugins/shader_graph_editor_plugin.cpp +++ b/tools/editor/plugins/shader_graph_editor_plugin.cpp @@ -1184,6 +1184,43 @@ void ShaderGraphView::_move_node(int p_id,const Vector2& p_to) { graph->node_set_pos(type,p_id,p_to); } +void ShaderGraphView::_duplicate_nodes_request() +{ + Array s_id; + + for(Map::Element *E=node_map.front();E;E=E->next()) { + ShaderGraph::NodeType t=graph->node_get_type(type, E->key()); + if (t==ShaderGraph::NODE_OUTPUT || t==ShaderGraph::NODE_INPUT) + continue; + GraphNode *gn = E->get(); + if (gn && gn->is_selected()) + s_id.push_back(E->key()); + } + + if (s_id.size()==0) + return; + + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Duplicate Graph Node(s)"); + ur->add_do_method(this,"_duplicate_nodes",s_id); + List n_ids = graph->generate_ids(type, s_id.size()); + for (List::Element *E=n_ids.front();E;E=E->next()) + ur->add_undo_method(graph.ptr(),"node_remove",type,E->get()); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + ur->commit_action(); + +} + +void ShaderGraphView::_duplicate_nodes(Array &p_nodes) +{ + List n = List(); + for (int i=0; iduplicate_nodes(type, n); + call_deferred("_update_graph"); +} + void ShaderGraphView::_create_node(int p_id) { @@ -2087,8 +2124,6 @@ void ShaderGraphView::_update_graph() { graph_edit->connect_node(node_map[E->get().src_id]->get_name(),E->get().src_slot,node_map[E->get().dst_id]->get_name(),E->get().dst_slot); } - - } void ShaderGraphView::_sg_updated() { @@ -2175,6 +2210,8 @@ void ShaderGraphView::_bind_methods() { ObjectTypeDB::bind_method("_node_removed",&ShaderGraphView::_node_removed); ObjectTypeDB::bind_method("_connection_request",&ShaderGraphView::_connection_request); ObjectTypeDB::bind_method("_disconnection_request",&ShaderGraphView::_disconnection_request); + ObjectTypeDB::bind_method("_duplicate_nodes_request", &ShaderGraphView::_duplicate_nodes_request); + ObjectTypeDB::bind_method("_duplicate_nodes", &ShaderGraphView::_duplicate_nodes); ObjectTypeDB::bind_method("_scalar_const_changed",&ShaderGraphView::_scalar_const_changed); ObjectTypeDB::bind_method("_vec_const_changed",&ShaderGraphView::_vec_const_changed); @@ -2250,7 +2287,6 @@ void ShaderGraphEditor::_popup_requested(const Vector2 &p_position) popup->set_invalidate_click_until_motion(); } - void ShaderGraphEditor::_notification(int p_what) { if (p_what==NOTIFICATION_ENTER_TREE) { @@ -2349,6 +2385,7 @@ ShaderGraphEditor::ShaderGraphEditor(bool p_2d) { tabs->add_child(graph_edits[i]->get_graph_edit()); graph_edits[i]->get_graph_edit()->connect("connection_request",graph_edits[i],"_connection_request"); graph_edits[i]->get_graph_edit()->connect("disconnection_request",graph_edits[i],"_disconnection_request"); + graph_edits[i]->get_graph_edit()->connect("duplicate_nodes_request", graph_edits[i], "_duplicate_nodes_request"); graph_edits[i]->get_graph_edit()->connect("popup_request",this,"_popup_requested"); graph_edits[i]->get_graph_edit()->set_right_disconnects(true); } diff --git a/tools/editor/plugins/shader_graph_editor_plugin.h b/tools/editor/plugins/shader_graph_editor_plugin.h index 5f93b9df7d17..faf6d7d64eff 100644 --- a/tools/editor/plugins/shader_graph_editor_plugin.h +++ b/tools/editor/plugins/shader_graph_editor_plugin.h @@ -145,6 +145,8 @@ class ShaderGraphView : public Node { void _node_moved(const Vector2& p_from, const Vector2& p_to,int p_id); void _end_node_move(); void _move_node(int p_id,const Vector2& p_to); + void _duplicate_nodes_request(); + void _duplicate_nodes(Array &p_nodes); void _scalar_const_changed(double p_value,int p_id); void _vec_const_changed(double p_value, int p_id, Array p_arr); From add0105c4e89e586fb3d3a9646a9ffc747d2e881 Mon Sep 17 00:00:00 2001 From: Mariano Javier Suligoy Date: Sat, 25 Jul 2015 22:05:45 -0300 Subject: [PATCH 06/11] Little fix: don't create an empty undo/redo command when trying to add a second Input GraphNode --- scene/resources/shader_graph.cpp | 9 +++++++++ scene/resources/shader_graph.h | 2 ++ tools/editor/plugins/shader_graph_editor_plugin.cpp | 3 +++ 3 files changed, 14 insertions(+) diff --git a/scene/resources/shader_graph.cpp b/scene/resources/shader_graph.cpp index 108aad3c56c2..952266769841 100644 --- a/scene/resources/shader_graph.cpp +++ b/scene/resources/shader_graph.cpp @@ -142,6 +142,15 @@ ShaderGraph::GraphError ShaderGraph::get_graph_error(ShaderType p_type) const { return shader[p_type].error; } +int ShaderGraph::node_count(ShaderType p_which, int p_type) +{ + int count=0; + for (Map::Element *E=shader[p_which].node_map.front();E;E=E->next()) + if (E->get().type==p_type) + count++; + return count; +} + void ShaderGraph::_bind_methods() { ObjectTypeDB::bind_method(_MD("_update_shader"),&ShaderGraph::_update_shader); diff --git a/scene/resources/shader_graph.h b/scene/resources/shader_graph.h index d3a297cd6c4d..b93567538dcb 100644 --- a/scene/resources/shader_graph.h +++ b/scene/resources/shader_graph.h @@ -365,6 +365,8 @@ class ShaderGraph : public Shader { GraphError get_graph_error(ShaderType p_type) const; + int node_count(ShaderType p_which, int p_type); + static int get_type_input_count(NodeType p_type); static int get_type_output_count(NodeType p_type); static SlotType get_type_input_type(NodeType p_type,int p_idx); diff --git a/tools/editor/plugins/shader_graph_editor_plugin.cpp b/tools/editor/plugins/shader_graph_editor_plugin.cpp index 3ab536ab6edc..370688d6f5b5 100644 --- a/tools/editor/plugins/shader_graph_editor_plugin.cpp +++ b/tools/editor/plugins/shader_graph_editor_plugin.cpp @@ -2162,6 +2162,9 @@ void ShaderGraphView::_notification(int p_what) { void ShaderGraphView::add_node(int p_type, const Vector2 &location) { + if ((p_type==ShaderGraph::NODE_INPUT||p_type==ShaderGraph::NODE_INPUT) && graph->node_count(type, p_type)>0) + return; + List existing; graph->get_node_list(type,&existing); existing.sort(); From d7279ddaf2aa98ed962d84d466f21dc2f39522c9 Mon Sep 17 00:00:00 2001 From: Mariano Javier Suligoy Date: Sun, 26 Jul 2015 21:57:27 -0300 Subject: [PATCH 07/11] Delete selected nodes with the Delete key --- scene/gui/graph_edit.cpp | 7 ++++ .../plugins/shader_graph_editor_plugin.cpp | 41 +++++++++++++++++++ .../plugins/shader_graph_editor_plugin.h | 1 + 3 files changed, 49 insertions(+) diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index a81542ea17af..deb31517988b 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -672,6 +672,12 @@ void GraphEdit::_input_event(const InputEvent& p_ev) { emit_signal("duplicate_nodes_request"); accept_event(); } + + if (p_ev.type==InputEvent::KEY && p_ev.key.scancode==KEY_DELETE && p_ev.key.pressed) { + emit_signal("delete_nodes_request"); + accept_event(); + } + } void GraphEdit::clear_connections() { @@ -729,6 +735,7 @@ void GraphEdit::_bind_methods() { ADD_SIGNAL(MethodInfo("disconnection_request",PropertyInfo(Variant::STRING,"from"),PropertyInfo(Variant::INT,"from_slot"),PropertyInfo(Variant::STRING,"to"),PropertyInfo(Variant::INT,"to_slot"))); ADD_SIGNAL(MethodInfo("popup_request", PropertyInfo(Variant::VECTOR2,"p_position"))); ADD_SIGNAL(MethodInfo("duplicate_nodes_request")); + ADD_SIGNAL(MethodInfo("delete_nodes_request")); ADD_SIGNAL(MethodInfo("_begin_node_move")); ADD_SIGNAL(MethodInfo("_end_node_move")); } diff --git a/tools/editor/plugins/shader_graph_editor_plugin.cpp b/tools/editor/plugins/shader_graph_editor_plugin.cpp index 370688d6f5b5..b2de10ca201a 100644 --- a/tools/editor/plugins/shader_graph_editor_plugin.cpp +++ b/tools/editor/plugins/shader_graph_editor_plugin.cpp @@ -1221,6 +1221,45 @@ void ShaderGraphView::_duplicate_nodes(Array &p_nodes) call_deferred("_update_graph"); } +void ShaderGraphView::_delete_nodes_request() +{ + List s_id=List(); + + for(Map::Element *E=node_map.front();E;E=E->next()) { + ShaderGraph::NodeType t=graph->node_get_type(type, E->key()); + if (t==ShaderGraph::NODE_OUTPUT) + continue; + GraphNode *gn = E->get(); + if (gn && gn->is_selected()) + s_id.push_back(E->key()); + } + + if (s_id.size()==0) + return; + + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Delete Shader Graph Node(s)"); + + for (List::Element *N=s_id.front();N;N=N->next()) { + ur->add_do_method(graph.ptr(),"node_remove",type,N->get()); + ur->add_undo_method(graph.ptr(),"node_add",type,graph->node_get_type(type,N->get()),N->get()); + ur->add_undo_method(graph.ptr(),"node_set_state",type,N->get(),graph->node_get_state(type,N->get())); + List conns; + + graph->get_node_connections(type,&conns); + for(List::Element *E=conns.front();E;E=E->next()) { + + if (E->get().dst_id==N->get() || E->get().src_id==N->get()) { + ur->add_undo_method(graph.ptr(),"connect_node",type,E->get().src_id,E->get().src_slot,E->get().dst_id,E->get().dst_slot); + } + } + } + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + ur->commit_action(); + +} + void ShaderGraphView::_create_node(int p_id) { @@ -2215,6 +2254,7 @@ void ShaderGraphView::_bind_methods() { ObjectTypeDB::bind_method("_disconnection_request",&ShaderGraphView::_disconnection_request); ObjectTypeDB::bind_method("_duplicate_nodes_request", &ShaderGraphView::_duplicate_nodes_request); ObjectTypeDB::bind_method("_duplicate_nodes", &ShaderGraphView::_duplicate_nodes); + ObjectTypeDB::bind_method("_delete_nodes_request", &ShaderGraphView::_delete_nodes_request); ObjectTypeDB::bind_method("_scalar_const_changed",&ShaderGraphView::_scalar_const_changed); ObjectTypeDB::bind_method("_vec_const_changed",&ShaderGraphView::_vec_const_changed); @@ -2390,6 +2430,7 @@ ShaderGraphEditor::ShaderGraphEditor(bool p_2d) { graph_edits[i]->get_graph_edit()->connect("disconnection_request",graph_edits[i],"_disconnection_request"); graph_edits[i]->get_graph_edit()->connect("duplicate_nodes_request", graph_edits[i], "_duplicate_nodes_request"); graph_edits[i]->get_graph_edit()->connect("popup_request",this,"_popup_requested"); + graph_edits[i]->get_graph_edit()->connect("delete_nodes_request",graph_edits[i],"_delete_nodes_request"); graph_edits[i]->get_graph_edit()->set_right_disconnects(true); } diff --git a/tools/editor/plugins/shader_graph_editor_plugin.h b/tools/editor/plugins/shader_graph_editor_plugin.h index faf6d7d64eff..36443efeb057 100644 --- a/tools/editor/plugins/shader_graph_editor_plugin.h +++ b/tools/editor/plugins/shader_graph_editor_plugin.h @@ -147,6 +147,7 @@ class ShaderGraphView : public Node { void _move_node(int p_id,const Vector2& p_to); void _duplicate_nodes_request(); void _duplicate_nodes(Array &p_nodes); + void _delete_nodes_request(); void _scalar_const_changed(double p_value,int p_id); void _vec_const_changed(double p_value, int p_id, Array p_arr); From ea448cb779c9268f6213a8e741cfc793704ca2fe Mon Sep 17 00:00:00 2001 From: Mariano Javier Suligoy Date: Sat, 29 Aug 2015 21:09:11 -0300 Subject: [PATCH 08/11] Edit default values. WARNING!!! Do not merge these changes, default values are not compiled into shaders yet! --- core/object.h | 64 +- .../resources/default_theme/default_theme.cpp | 8 +- .../default_theme/graph_node_default.png | Bin 0 -> 289 bytes .../graph_node_default_focus.png | Bin 0 -> 408 bytes scene/resources/default_theme/theme_data.h | 10 + scene/resources/shader_graph.cpp | 150 +++-- scene/resources/shader_graph.h | 9 +- .../plugins/shader_graph_editor_plugin.cpp | 437 ++++++++++++-- .../plugins/shader_graph_editor_plugin.h | 6 + tools/editor/property_editor.cpp | 561 ++++++++++-------- tools/editor/property_editor.h | 46 +- 11 files changed, 890 insertions(+), 401 deletions(-) create mode 100644 scene/resources/default_theme/graph_node_default.png create mode 100644 scene/resources/default_theme/graph_node_default_focus.png diff --git a/core/object.h b/core/object.h index eb0e78a8c3d9..981a83958cb4 100644 --- a/core/object.h +++ b/core/object.h @@ -49,7 +49,7 @@ enum PropertyHint { PROPERTY_HINT_NONE, ///< no hint provided. - PROPERTY_HINT_RANGE, ///< hint_text = "min,max,step" + PROPERTY_HINT_RANGE, ///< hint_text = "min,max,step,slider; //slider is optional" PROPERTY_HINT_EXP_RANGE, ///< hint_text = "min,max,step", exponential edit PROPERTY_HINT_ENUM, ///< hint_text= "val1,val2,val3,etc" PROPERTY_HINT_EXP_EASING, /// exponential easing funciton (Math::ease) @@ -58,12 +58,12 @@ enum PropertyHint { PROPERTY_HINT_KEY_ACCEL, ///< hint_text= "length" (as integer) PROPERTY_HINT_FLAGS, ///< hint_text= "flag1,flag2,etc" (as bit flags) PROPERTY_HINT_ALL_FLAGS, - PROPERTY_HINT_FILE, ///< a file path must be passed, hint_text (optionally) is a filter "*.png,*.wav,*.doc," + PROPERTY_HINT_FILE, ///< a file path must be passed, hint_text (optionally) is a filter "*.png,*.wav,*.doc," PROPERTY_HINT_DIR, ///< a directort path must be passed PROPERTY_HINT_GLOBAL_FILE, ///< a file path must be passed, hint_text (optionally) is a filter "*.png,*.wav,*.doc," PROPERTY_HINT_GLOBAL_DIR, ///< a directort path must be passed PROPERTY_HINT_RESOURCE_TYPE, ///< a resource object type - PROPERTY_HINT_MULTILINE_TEXT, ///< used for string properties that can contain multiple lines + PROPERTY_HINT_MULTILINE_TEXT, ///< used for string properties that can contain multiple lines PROPERTY_HINT_COLOR_NO_ALPHA, ///< used for ignoring alpha component when editing a color PROPERTY_HINT_IMAGE_COMPRESS_LOSSY, PROPERTY_HINT_IMAGE_COMPRESS_LOSSLESS, @@ -71,7 +71,7 @@ enum PropertyHint { }; enum PropertyUsageFlags { - + PROPERTY_USAGE_STORAGE=1, PROPERTY_USAGE_EDITOR=2, PROPERTY_USAGE_NETWORK=4, @@ -102,15 +102,15 @@ enum PropertyUsageFlags { #define ADD_PROPERTYINO( m_property, m_setter, m_getter, m_index ) ObjectTypeDB::add_property( get_type_static(), (m_property).added_usage(PROPERTY_USAGE_STORE_IF_NONONE), m_setter, m_getter, m_index ) struct PropertyInfo { - - Variant::Type type; + + Variant::Type type; String name; PropertyHint hint; - String hint_string; + String hint_string; uint32_t usage; _FORCE_INLINE_ PropertyInfo added_usage(int p_fl) const { PropertyInfo pi=*this; pi.usage|=p_fl; return pi; } - + PropertyInfo() { type=Variant::NIL; hint=PROPERTY_HINT_NONE; usage = PROPERTY_USAGE_DEFAULT; } PropertyInfo( Variant::Type p_type, const String p_name, PropertyHint p_hint=PROPERTY_HINT_NONE, const String& p_hint_string="",uint32_t p_usage=PROPERTY_USAGE_DEFAULT) { type=p_type; name=p_name; hint=p_hint; hint_string=p_hint_string; usage=p_usage; @@ -125,23 +125,23 @@ struct PropertyInfo { Array convert_property_list(const List * p_list); struct MethodInfo { - + String name; List arguments; Vector default_arguments; PropertyInfo return_val; uint32_t flags; int id; - + inline bool operator<(const MethodInfo& p_method) const { return id==p_method.id?(name < p_method.name):(id *p_list,bool p_reversed) const {}; virtual void _notificationv(int p_notification,bool p_reversed) {}; - + static String _get_category() { return ""; } static void _bind_methods(); bool _set(const StringName& p_name,const Variant &p_property) { return false; }; bool _get(const StringName& p_name,Variant &r_property) const { return false; }; void _get_property_list(List *p_list) const {}; void _notification(int p_notification) {}; - + _FORCE_INLINE_ static void (*_get_bind_methods())() { return &Object::_bind_methods; } @@ -431,13 +431,13 @@ friend void postinitialize_handler(Object*); } _FORCE_INLINE_ void (Object::* (_get_get_property_list() const))(List *p_list) const{ return &Object::_get_property_list; - } + } _FORCE_INLINE_ void (Object::* (_get_notification() const))(int){ return &Object::_notification; - } + } static void get_valid_parents_static(List *p_parents); static void _get_valid_parents_static(List *p_parents); - + void cancel_delete(); @@ -485,7 +485,7 @@ friend void postinitialize_handler(Object*); void add_change_receptor( Object *p_receptor ); void remove_change_receptor( Object *p_receptor ); - + template T *cast_to() { @@ -500,7 +500,7 @@ friend void postinitialize_handler(Object*); return NULL; #endif } - + template const T *cast_to() const { @@ -517,11 +517,11 @@ friend void postinitialize_handler(Object*); } enum { - + NOTIFICATION_POSTINITIALIZE=0, NOTIFICATION_PREDELETE=1 }; - + /* TYPE API */ static void get_inheritance_list_static(List* p_inheritance_list) { p_inheritance_list->push_back("Object"); } @@ -545,7 +545,7 @@ friend void postinitialize_handler(Object*); return *_type_ptr; } } - + /* IAPI */ // void set(const String& p_name, const Variant& p_value); // Variant get(const String& p_name) const; @@ -554,7 +554,7 @@ friend void postinitialize_handler(Object*); Variant get(const StringName& p_name, bool *r_valid=NULL) const; void get_property_list(List *p_list,bool p_reversed=false) const; - + bool has_method(const StringName& p_method) const; void get_method_list(List *p_list) const; Variant callv(const StringName& p_method,const Array& p_args); @@ -564,14 +564,14 @@ friend void postinitialize_handler(Object*); Variant call(const StringName& p_name, VARIANT_ARG_LIST); // C++ helper void call_multilevel(const StringName& p_name, VARIANT_ARG_LIST); // C++ helper - void notification(int p_notification,bool p_reversed=false); + void notification(int p_notification,bool p_reversed=false); //used mainly by script, get and set all INCLUDING string virtual Variant getvar(const Variant& p_key, bool *r_valid=NULL) const; virtual void setvar(const Variant& p_key, const Variant& p_value,bool *r_valid=NULL); /* SCRIPT */ - + void set_script(const RefPtr& p_script); RefPtr get_script() const; @@ -614,14 +614,14 @@ friend void postinitialize_handler(Object*); StringName tr(const StringName& p_message) const; //translate message (alternative) bool _is_queued_for_deletion; // set to true by SceneTree::queue_delete() - bool is_queued_for_deletion() const; + bool is_queued_for_deletion() const; _FORCE_INLINE_ void set_message_translation(bool p_enable) { _can_translate=p_enable; } _FORCE_INLINE_ bool can_translate_messages() const { return _can_translate; } void clear_internal_resource_paths(); - Object(); + Object(); virtual ~Object(); }; @@ -649,13 +649,13 @@ class ObjectDB { static HashMap instance_checks; static uint32_t instance_counter; -friend class Object; +friend class Object; friend void unregister_core_types(); static void cleanup(); static uint32_t add_instance(Object *p_object); static void remove_instance(Object *p_object); -public: +public: typedef void (*DebugFunc)(Object *p_obj); diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index 819d0a5cb944..3ee4da597472 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -556,12 +556,16 @@ void make_default_theme() { // GraphNode - Ref graphsb = make_stylebox(graph_node_png,6,24,6,5,16,24,16,5); - Ref graphsbselected = make_stylebox(graph_node_selected_png,6,24,6,5,16,24,16,5); + Ref graphsb = make_stylebox(graph_node_png,6,24,6,5,3,24,16,5); + Ref graphsbselected = make_stylebox(graph_node_selected_png,6,24,6,5,3,24,16,5); + Ref graphsbdefault = make_stylebox(graph_node_default_png,4,4,4,4,6,4,4,4); + Ref graphsbdeffocus = make_stylebox(graph_node_default_focus_png,4,4,4,4,6,4,4,4); //graphsb->set_expand_margin_size(MARGIN_LEFT,10); //graphsb->set_expand_margin_size(MARGIN_RIGHT,10); t->set_stylebox("frame","GraphNode", graphsb ); t->set_stylebox("selectedframe","GraphNode", graphsbselected ); + t->set_stylebox("defaultframe", "GraphNode", graphsbdefault ); + t->set_stylebox("defaultfocus", "GraphNode", graphsbdeffocus ); t->set_constant("separation","GraphNode", 1 ); t->set_icon("port","GraphNode", make_icon( graph_port_png ) ); t->set_icon("close","GraphNode", make_icon( graph_node_close_png ) ); diff --git a/scene/resources/default_theme/graph_node_default.png b/scene/resources/default_theme/graph_node_default.png new file mode 100644 index 0000000000000000000000000000000000000000..ea6ec52828f2402912c19549eb84392359e1c754 GIT binary patch literal 289 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmP~hm^P;ug`W17NC%9W=KSdbAE1aYF-JD%fR4Vl$uzQ znxasiS(2gP?&%wlqL<1J6mRu(aSX9I{dTe;SF?kN%l%zT6&wu|SXMhIu%FC)Q{*>$ zf!skYCxNEjN6T}41U(*a_k5Vmwyff64`W`#!`U02tiQ+Xzkr!-a{BTETrMd^bvfzopr070{0m;e9( literal 0 HcmV?d00001 diff --git a/scene/resources/default_theme/graph_node_default_focus.png b/scene/resources/default_theme/graph_node_default_focus.png new file mode 100644 index 0000000000000000000000000000000000000000..b7c38ae481714a79ae20277bc40dcf5e7b071d71 GIT binary patch literal 408 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmP~hcqLnOw3gw6QGc6W=KSdbAE1aYF-JD%fR4Vl$uzQ znxasiS(2gP?&%wlqL<1J6#wJt;uvCadhcXMFBV50*ZNagB2M~8TG>C?+*`EA@%o~L z39k~?#k`WdbKPnBQy!t$yEB)zymXZP=*-dbM0b+>L8VDd2Xq_t>Q|KR?Brl{@Q5or zyEeO|`W4%QQchvPQzpJg%uRU?f41n`{@La}!wp7*2`rvZ<_J1DXr_t=c3G{nKxA zU&S+8h+X(6rl7=bd!gFVWm~uQ?ALicQ-sdsl-@XVY|5p{tM2KS<=JoA)bS?dYvSgc vG0YW=3CC@Mg(sT7oO|QtmjjRX?fGo&xuA1@;jyzapaAl8^>bP0l+XkKget().param2; Array conns; - conns.resize(E->get().connections.size()*3); + conns.resize(E->get().connections.size()*3+E->get().defaults.size()*3); int idx2=0; for(Map::Element*F=E->get().connections.front();F;F=F->next()) { @@ -123,6 +126,14 @@ Dictionary ShaderGraph::_get_data() const { conns[idx2+2]=F->get().slot; idx2+=3; } + for(Map::Element*F=E->get().defaults.front();F;F=F->next()) { + + conns[idx2+0]=SLOT_DEFAULT_VALUE; + conns[idx2+1]=F->key(); + conns[idx2+2]=F->get(); + idx2+=3; + } + data[idx+5]=conns; idx+=6; } @@ -164,6 +175,9 @@ void ShaderGraph::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_node_list","shader_type"),&ShaderGraph::_get_node_list); + ObjectTypeDB::bind_method(_MD("default_set_value","shader_type","id","param_id","value"), &ShaderGraph::default_set_value); + ObjectTypeDB::bind_method(_MD("default_get_value","shader_type","id","param_id"), &ShaderGraph::default_get_value); + ObjectTypeDB::bind_method(_MD("scalar_const_node_set_value","shader_type","id","value"),&ShaderGraph::scalar_const_node_set_value); ObjectTypeDB::bind_method(_MD("scalar_const_node_get_value","shader_type","id"),&ShaderGraph::scalar_const_node_set_value); @@ -546,7 +560,7 @@ void ShaderGraph::node_add(ShaderType p_type, NodeType p_node_type,int p_id) { case NODE_RGB_INPUT: {node.param1=_find_unique_name("Color");node.param2=Color();} break; // color uniform (assignable in material) case NODE_XFORM_INPUT: {node.param1=_find_unique_name("XForm"); node.param2=Transform();} break; // mat4 uniform (assignable in material) case NODE_TEXTURE_INPUT: {node.param1=_find_unique_name("Tex"); } break; // texture input (assignable in material) - case NODE_CUBEMAP_INPUT: {node.param1=_find_unique_name("Cube"); } break; // cubemap input (assignable in material) + case NODE_CUBEMAP_INPUT: {node.param1=_find_unique_name("Cube"); } break; // cubemap input (assignable in material) case NODE_DEFAULT_TEXTURE: {}; break; case NODE_OUTPUT: {} break; // output (shader type dependent) case NODE_COMMENT: {} break; // comment @@ -692,6 +706,18 @@ void ShaderGraph::get_node_connections(ShaderType p_type,List *p_con } } +bool ShaderGraph::is_slot_connected(ShaderGraph::ShaderType p_type, int p_dst_id, int slot_id) +{ + for(const Map::Element *E=shader[p_type].node_map.front();E;E=E->next()) { + for (const Map::Element *F=E->get().connections.front();F;F=F->next()) { + + if (p_dst_id == E->key() && slot_id==F->key()) + return true; + } + } + return false; +} + void ShaderGraph::clear(ShaderType p_type) { @@ -1005,6 +1031,33 @@ ShaderGraph::ScalarFunc ShaderGraph::scalar_func_node_get_function(ShaderType p_ return ScalarFunc(func); } +void ShaderGraph::default_set_value(ShaderGraph::ShaderType p_which, int p_id, int p_param, const Variant &p_value) +{ + ERR_FAIL_INDEX(p_which,3); + ERR_FAIL_COND(!shader[p_which].node_map.has(p_id)); + Node& n = shader[p_which].node_map[p_id]; + if(p_value.get_type()==Variant::NIL) + n.defaults.erase(n.defaults.find(p_param)); + else + n.defaults[p_param]=p_value; + + _request_update(); + +} + +Variant ShaderGraph::default_get_value(ShaderGraph::ShaderType p_which, int p_id, int p_param) +{ + ERR_FAIL_INDEX_V(p_which,3,Variant()); + ERR_FAIL_COND_V(!shader[p_which].node_map.has(p_id),Variant()); + const Node& n = shader[p_which].node_map[p_id]; + + if (!n.defaults.has(p_param)) + return Variant(); + return n.defaults[p_param]; +} + + + void ShaderGraph::vec_func_node_set_function(ShaderType p_type,int p_id,VecFunc p_func){ ERR_FAIL_INDEX(p_type,3); @@ -1030,52 +1083,52 @@ ShaderGraph::VecFunc ShaderGraph::vec_func_node_get_function(ShaderType p_type, void ShaderGraph::color_ramp_node_set_ramp(ShaderType p_type,int p_id,const DVector& p_colors, const DVector& p_offsets){ - ERR_FAIL_INDEX(p_type,3); - ERR_FAIL_COND(!shader[p_type].node_map.has(p_id)); - ERR_FAIL_COND(p_colors.size()!=p_offsets.size()); - Node& n = shader[p_type].node_map[p_id]; - n.param1=p_colors; - n.param2=p_offsets; - _request_update(); + ERR_FAIL_INDEX(p_type,3); + ERR_FAIL_COND(!shader[p_type].node_map.has(p_id)); + ERR_FAIL_COND(p_colors.size()!=p_offsets.size()); + Node& n = shader[p_type].node_map[p_id]; + n.param1=p_colors; + n.param2=p_offsets; + _request_update(); } DVector ShaderGraph::color_ramp_node_get_colors(ShaderType p_type,int p_id) const{ - ERR_FAIL_INDEX_V(p_type,3,DVector()); - ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),DVector()); - const Node& n = shader[p_type].node_map[p_id]; - return n.param1; + ERR_FAIL_INDEX_V(p_type,3,DVector()); + ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),DVector()); + const Node& n = shader[p_type].node_map[p_id]; + return n.param1; } DVector ShaderGraph::color_ramp_node_get_offsets(ShaderType p_type,int p_id) const{ - ERR_FAIL_INDEX_V(p_type,3,DVector()); - ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),DVector()); - const Node& n = shader[p_type].node_map[p_id]; - return n.param2; + ERR_FAIL_INDEX_V(p_type,3,DVector()); + ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),DVector()); + const Node& n = shader[p_type].node_map[p_id]; + return n.param2; } void ShaderGraph::curve_map_node_set_points(ShaderType p_type,int p_id,const DVector& p_points) { - ERR_FAIL_INDEX(p_type,3); - ERR_FAIL_COND(!shader[p_type].node_map.has(p_id)); - Node& n = shader[p_type].node_map[p_id]; - n.param1=p_points; - _request_update(); + ERR_FAIL_INDEX(p_type,3); + ERR_FAIL_COND(!shader[p_type].node_map.has(p_id)); + Node& n = shader[p_type].node_map[p_id]; + n.param1=p_points; + _request_update(); } DVector ShaderGraph::curve_map_node_get_points(ShaderType p_type,int p_id) const{ - ERR_FAIL_INDEX_V(p_type,3,DVector()); - ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),DVector()); - const Node& n = shader[p_type].node_map[p_id]; - return n.param1; + ERR_FAIL_INDEX_V(p_type,3,DVector()); + ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),DVector()); + const Node& n = shader[p_type].node_map[p_id]; + return n.param1; } @@ -1265,6 +1318,12 @@ Variant ShaderGraph::node_get_state(ShaderType p_type,int p_id) const { s["pos"]=n.pos; s["param1"]=n.param1; s["param2"]=n.param2; + Array keys; + for (Map::Element *E=n.defaults.front();E;E=E->next()) { + keys.append(E->key()); + s[E->key()]=E->get(); + } + s["default_keys"]=keys; return s; } @@ -1277,10 +1336,15 @@ void ShaderGraph::node_set_state(ShaderType p_type,int p_id,const Variant& p_sta ERR_FAIL_COND(!d.has("pos")); ERR_FAIL_COND(!d.has("param1")); ERR_FAIL_COND(!d.has("param2")); + ERR_FAIL_COND(!d.has("default_keys")); + n.pos=d["pos"]; n.param1=d["param1"]; n.param2=d["param2"]; - + Array keys = d["default_keys"]; + for(int i=0;i defaults; int id; mutable int order; // used for sorting int sort_order; @@ -318,6 +320,9 @@ class ShaderGraph : public Shader { VEC_MAX_FUNC }; + void default_set_value(ShaderType p_which,int p_id,int p_param, const Variant& p_value); + Variant default_get_value(ShaderType p_which,int p_id,int p_param); + void vec_func_node_set_function(ShaderType p_which,int p_id,VecFunc p_func); VecFunc vec_func_node_get_function(ShaderType p_which,int p_id) const; @@ -358,6 +363,8 @@ class ShaderGraph : public Shader { void get_node_connections(ShaderType p_which,List *p_connections) const; + bool is_slot_connected(ShaderType p_which,int p_dst_id,int slot_id); + void clear(ShaderType p_which); Variant node_get_state(ShaderType p_type, int p_node) const; diff --git a/tools/editor/plugins/shader_graph_editor_plugin.cpp b/tools/editor/plugins/shader_graph_editor_plugin.cpp index b2de10ca201a..12a9dce6b737 100644 --- a/tools/editor/plugins/shader_graph_editor_plugin.cpp +++ b/tools/editor/plugins/shader_graph_editor_plugin.cpp @@ -29,6 +29,7 @@ #include "shader_graph_editor_plugin.h" +#include "scene/gui/check_box.h" #include "scene/gui/menu_button.h" #include "scene/gui/panel.h" #include "spatial_editor_plugin.h" @@ -840,6 +841,7 @@ void ShaderGraphView::_xform_input_changed(int p_id, Node *p_button){ ped_popup->set_pos(tb->get_global_pos()+Vector2(0,tb->get_size().height)); ped_popup->set_size(tb->get_size()); edited_id=p_id; + edited_def=-1; ped_popup->edit(NULL,"",Variant::TRANSFORM,graph->xform_input_node_get_value(type,p_id),PROPERTY_HINT_NONE,""); ped_popup->popup(); @@ -850,6 +852,7 @@ void ShaderGraphView::_xform_const_changed(int p_id, Node *p_button){ ped_popup->set_pos(tb->get_global_pos()+Vector2(0,tb->get_size().height)); ped_popup->set_size(tb->get_size()); edited_id=p_id; + edited_def=-1; ped_popup->edit(NULL,"",Variant::TRANSFORM,graph->xform_const_node_get_value(type,p_id),PROPERTY_HINT_NONE,""); ped_popup->popup(); @@ -879,6 +882,35 @@ void ShaderGraphView::_cube_input_change(int p_id){ void ShaderGraphView::_variant_edited() { + if (edited_def != -1) { + + Variant v = ped_popup->get_variant(); + Variant v2 = graph->default_get_value(type,edited_id,edited_def); + if (v2.get_type() == Variant::NIL) + switch (v.get_type()) { + case Variant::VECTOR3: + v2=Vector3(); + break; + case Variant::REAL: + v2=0.0; + break; + case Variant::TRANSFORM: + v2=Transform(); + break; + case Variant::COLOR: + v2=Color(); + break; + } + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change default value"); + ur->add_do_method(graph.ptr(),"default_set_value",type,edited_id,edited_def, v); + ur->add_undo_method(graph.ptr(),"default_set_value",type,edited_id,edited_def, v2); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + ur->commit_action(); + return; + } + if (graph->node_get_type(type,edited_id)==ShaderGraph::NODE_XFORM_CONST) { UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); @@ -1043,6 +1075,7 @@ void ShaderGraphView::_tex_edited(int p_id,Node* p_button) { ped_popup->set_pos(tb->get_global_pos()+Vector2(0,tb->get_size().height)); ped_popup->set_size(tb->get_size()); edited_id=p_id; + edited_def=-1; ped_popup->edit(NULL,"",Variant::OBJECT,graph->texture_input_node_get_value(type,p_id),PROPERTY_HINT_RESOURCE_TYPE,"Texture"); } @@ -1052,6 +1085,7 @@ void ShaderGraphView::_cube_edited(int p_id,Node* p_button) { ped_popup->set_pos(tb->get_global_pos()+Vector2(0,tb->get_size().height)); ped_popup->set_size(tb->get_size()); edited_id=p_id; + edited_def=-1; ped_popup->edit(NULL,"",Variant::OBJECT,graph->cubemap_input_node_get_value(type,p_id),PROPERTY_HINT_RESOURCE_TYPE,"CubeMap"); } @@ -1260,6 +1294,97 @@ void ShaderGraphView::_delete_nodes_request() } +void ShaderGraphView::_default_changed(int p_id, Node *p_button, int p_param, int v_type, String p_hint) +{ + ToolButton *tb = p_button->cast_to(); + ped_popup->set_pos(tb->get_global_pos()+Vector2(0,tb->get_size().height)); + ped_popup->set_size(tb->get_size()); + edited_id=p_id; + edited_def=p_param; + Variant::Type vt = (Variant::Type)v_type; + Variant v = graph->default_get_value(type,p_id,edited_def); + int h=PROPERTY_HINT_NONE; + if (v.get_type() == Variant::NIL) + switch (vt) { + case Variant::VECTOR3: + v=Vector3(); + break; + case Variant::REAL: + h=PROPERTY_HINT_RANGE; + v=0.0; + break; + case Variant::TRANSFORM: + v=Transform(); + break; + case Variant::COLOR: + h=PROPERTY_HINT_COLOR_NO_ALPHA; + v=Color(); + break; + } + + ped_popup->edit(NULL,"",vt,v,h,p_hint); + + ped_popup->popup(); +} + +ToolButton *ShaderGraphView::make_label(String text, Variant::Type v_type) { + ToolButton *l = memnew( ToolButton ); + l->set_text(text); + l->set_text_align(ToolButton::ALIGN_LEFT); + l->add_style_override("hover", l->get_stylebox("normal", "ToolButton")); + l->add_style_override("pressed", l->get_stylebox("normal", "ToolButton")); + l->add_style_override("focus", l->get_stylebox("normal", "ToolButton")); + switch (v_type) { + case Variant::REAL: + l->set_icon(ped_popup->get_icon("Real", "EditorIcons")); + break; + case Variant::VECTOR3: + l->set_icon(ped_popup->get_icon("Vector", "EditorIcons")); + break; + case Variant::TRANSFORM: + l->set_icon(ped_popup->get_icon("Matrix", "EditorIcons")); + break; + case Variant::COLOR: + l->set_icon(ped_popup->get_icon("Color", "EditorIcons")); + } + return l; +} + +ToolButton *ShaderGraphView::make_editor(String text,GraphNode* gn,int p_id,int param,Variant::Type v_type, String p_hint) { + ToolButton *edit = memnew( ToolButton ); + edit->set_text(text); + edit->set_text_align(ToolButton::ALIGN_LEFT); + edit->set_flat(false); + edit->add_style_override("normal", gn->get_stylebox("defaultframe", "GraphNode")); + edit->add_style_override("hover", gn->get_stylebox("defaultframe", "GraphNode")); + edit->add_style_override("pressed", gn->get_stylebox("defaultframe", "GraphNode")); + edit->add_style_override("focus", gn->get_stylebox("defaultfocus", "GraphNode")); + edit->connect("pressed",this,"_default_changed",varray(p_id,edit,param,v_type,p_hint)); + + switch (v_type) { + case Variant::REAL: + edit->set_icon(ped_popup->get_icon("Real", "EditorIcons")); + break; + case Variant::VECTOR3: + edit->set_icon(ped_popup->get_icon("Vector", "EditorIcons")); + break; + case Variant::TRANSFORM: + edit->set_icon(ped_popup->get_icon("Matrix", "EditorIcons")); + break; + case Variant::COLOR: + Image icon_color = Image(15,15,false,Image::FORMAT_RGB); + Color c = graph->default_get_value(type,p_id,param); + for (int x=1;x<14;x++) + for (int y=1;y<14;y++) + icon_color.put_pixel(x,y,c); + Ref t; + t.instance(); + t->create_from_image(icon_color); + edit->set_icon(t); + break; + } + return edit; +} void ShaderGraphView::_create_node(int p_id) { @@ -1273,6 +1398,9 @@ void ShaderGraphView::_create_node(int p_id) { Color(0,1,1) }; + const String hint_spin = "-65536,65535,0.001"; + const String hint_slider = "0.0,1.0,0.01,slider"; + switch(graph->node_get_type(type,p_id)) { @@ -1377,7 +1505,12 @@ void ShaderGraphView::_create_node(int p_id) { gn->set_title("ScreenTex"); HBoxContainer *hbc = memnew( HBoxContainer ); hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("UV"))); + if (!graph->is_slot_connected(type,p_id,0)) { + Vector3 v = graph->default_get_value(type, p_id, 0); + hbc->add_child(make_editor("UV: " + v,gn,p_id,0,Variant::VECTOR3)); + } else { + hbc->add_child(make_label("UV",Variant::VECTOR3)); + } hbc->add_spacer(); hbc->add_child( memnew(Label("RGB"))); gn->add_child(hbc); @@ -1411,11 +1544,21 @@ void ShaderGraphView::_create_node(int p_id) { HBoxContainer *hbc = memnew( HBoxContainer ); hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("a"))); + if (graph->is_slot_connected(type, p_id, 0)) { + hbc->add_child(make_label("a",Variant::REAL)); + } else { + float v = graph->default_get_value(type,p_id,0); + hbc->add_child(make_editor(String("a: ")+Variant(v),gn,p_id,0,Variant::REAL,hint_spin)); + } hbc->add_spacer(); hbc->add_child( memnew(Label("out"))); gn->add_child(hbc); - gn->add_child( memnew(Label("b"))); + if (graph->is_slot_connected(type, p_id, 1)) { + gn->add_child(make_label("b",Variant::REAL)); + } else { + float v = graph->default_get_value(type,p_id,1); + gn->add_child(make_editor(String("b: ")+Variant(v),gn,p_id,1,Variant::REAL,hint_spin)); + } gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); @@ -1449,11 +1592,21 @@ void ShaderGraphView::_create_node(int p_id) { HBoxContainer *hbc = memnew( HBoxContainer ); hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("a"))); + if (graph->is_slot_connected(type, p_id, 0)) { + hbc->add_child(make_label("a",Variant::VECTOR3)); + } else { + Vector3 v = graph->default_get_value(type,p_id,0); + hbc->add_child(make_editor(String("a: ")+v,gn,p_id,0,Variant::VECTOR3)); + } hbc->add_spacer(); hbc->add_child( memnew(Label("out"))); gn->add_child(hbc); - gn->add_child( memnew(Label("b"))); + if (graph->is_slot_connected(type, p_id, 1)) { + gn->add_child(make_label("b",Variant::VECTOR3)); + } else { + Vector3 v = graph->default_get_value(type,p_id,1); + gn->add_child(make_editor(String("b: ")+v,gn,p_id,1,Variant::VECTOR3)); + } gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); @@ -1481,12 +1634,22 @@ void ShaderGraphView::_create_node(int p_id) { HBoxContainer *hbc = memnew( HBoxContainer ); hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("a"))); + if (graph->is_slot_connected(type, p_id, 0)) { + hbc->add_child(make_label("a",Variant::VECTOR3)); + } else { + Vector3 v = graph->default_get_value(type,p_id,0); + hbc->add_child(make_editor(String("a: ")+v,gn,p_id,0,Variant::VECTOR3)); + } hbc->add_spacer(); hbc->add_child( memnew(Label("out"))); gn->add_child(hbc); - gn->add_child( memnew(Label("b"))); + if (graph->is_slot_connected(type, p_id, 1)) { + gn->add_child(make_label("b",Variant::REAL)); + } else { + float v = graph->default_get_value(type,p_id,1); + gn->add_child(make_editor(String("b: ")+Variant(v),gn,p_id,1,Variant::REAL,hint_spin)); + } gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); @@ -1519,11 +1682,19 @@ void ShaderGraphView::_create_node(int p_id) { HBoxContainer *hbc = memnew( HBoxContainer ); hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("a"))); + if (graph->is_slot_connected(type, p_id, 0)) { + hbc->add_child(make_label("a",Variant::COLOR)); + } else { + hbc->add_child(make_editor(String("a: "),gn,p_id,0,Variant::COLOR)); + } hbc->add_spacer(); hbc->add_child( memnew(Label("out"))); gn->add_child(hbc); - gn->add_child( memnew(Label("b"))); + if (graph->is_slot_connected(type, p_id, 1)) { + gn->add_child(make_label("b",Variant::COLOR)); + } else { + gn->add_child(make_editor(String("b: "),gn,p_id,1,Variant::COLOR)); + } gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); @@ -1533,11 +1704,19 @@ void ShaderGraphView::_create_node(int p_id) { gn->set_title("XFMult"); HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_child( memnew(Label("a"))); + if (graph->is_slot_connected(type, p_id, 0)) { + hbc->add_child(make_label("a",Variant::TRANSFORM)); + } else { + hbc->add_child(make_editor(String("a: edit..."),gn,p_id,0,Variant::TRANSFORM)); + } hbc->add_spacer(); hbc->add_child( memnew(Label("out"))); gn->add_child(hbc); - gn->add_child( memnew(Label("b"))); + if (graph->is_slot_connected(type, p_id, 1)) { + gn->add_child(make_label("b",Variant::TRANSFORM)); + } else { + gn->add_child(make_editor(String("b: edit..."),gn,p_id,1,Variant::TRANSFORM)); + } gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM],true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM]); gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM],false,0,Color()); @@ -1548,8 +1727,7 @@ void ShaderGraphView::_create_node(int p_id) { gn->set_title("XFVecMult"); - Button *button = memnew( Button("RotOnly")); - button->set_toggle_mode(true); + CheckBox *button = memnew (CheckBox("RotOnly")); button->set_pressed(graph->xform_vec_mult_node_get_no_translation(type,p_id)); button->connect("toggled",this,"_xform_inv_rev_changed",varray(p_id)); @@ -1557,13 +1735,22 @@ void ShaderGraphView::_create_node(int p_id) { HBoxContainer *hbc = memnew( HBoxContainer ); hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("xf"))); + if (graph->is_slot_connected(type, p_id, 0)) { + hbc->add_child(make_label("xf",Variant::TRANSFORM)); + } else { + hbc->add_child(make_editor(String("xf: edit..."),gn,p_id,0,Variant::TRANSFORM)); + } hbc->add_spacer(); Label *l = memnew(Label("out")); l->set_align(Label::ALIGN_RIGHT); hbc->add_child( l); gn->add_child(hbc); - gn->add_child( memnew(Label("vec"))); + if (graph->is_slot_connected(type, p_id, 1)) { + gn->add_child(make_label("a",Variant::VECTOR3)); + } else { + Vector3 v = graph->default_get_value(type,p_id,1); + gn->add_child(make_editor(String("a: ")+v,gn,p_id,1,Variant::VECTOR3)); + } gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); @@ -1574,17 +1761,25 @@ void ShaderGraphView::_create_node(int p_id) { gn->set_title("XFVecInvMult"); - Button *button = memnew( Button("RotOnly")); - button->set_toggle_mode(true); + CheckBox *button = memnew( CheckBox("RotOnly")); button->set_pressed(graph->xform_vec_mult_node_get_no_translation(type,p_id)); button->connect("toggled",this,"_xform_inv_rev_changed",varray(p_id)); gn->add_child(button); - gn->add_child( memnew(Label("vec"))); + if (graph->is_slot_connected(type, p_id, 0)) { + gn->add_child(make_label("a",Variant::VECTOR3)); + } else { + Vector3 v = graph->default_get_value(type,p_id,0); + gn->add_child(make_editor(String("a: ")+v,gn,p_id,0,Variant::VECTOR3)); + } HBoxContainer *hbc = memnew( HBoxContainer ); hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("xf"))); + if (graph->is_slot_connected(type, p_id, 1)) { + hbc->add_child(make_label("xf", Variant::TRANSFORM)); + } else { + hbc->add_child(make_editor(String("xf: edit..."),gn,p_id,1,Variant::TRANSFORM)); + } hbc->add_spacer(); Label *l = memnew(Label("out")); l->set_align(Label::ALIGN_RIGHT); @@ -1633,7 +1828,12 @@ void ShaderGraphView::_create_node(int p_id) { gn->add_child(ob); HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_child( memnew(Label("in"))); + if (graph->is_slot_connected(type, p_id, 0)) { + hbc->add_child(make_label("in", Variant::REAL)); + } else { + float v = graph->default_get_value(type,p_id,0); + hbc->add_child(make_editor(String("in: ")+Variant(v),gn,p_id,0,Variant::REAL,hint_spin)); + } hbc->add_spacer(); hbc->add_child( memnew(Label("out"))); gn->add_child(hbc); @@ -1668,7 +1868,12 @@ void ShaderGraphView::_create_node(int p_id) { HBoxContainer *hbc = memnew( HBoxContainer ); hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("in"))); + if (graph->is_slot_connected(type, p_id, 0)) { + hbc->add_child(make_label("in", Variant::VECTOR3)); + } else { + Vector3 v = graph->default_get_value(type,p_id,0); + hbc->add_child(make_editor(String("in: ")+v,gn,p_id,0,Variant::VECTOR3)); + } hbc->add_spacer(); hbc->add_child( memnew(Label("out"))); gn->add_child(hbc); @@ -1679,7 +1884,12 @@ void ShaderGraphView::_create_node(int p_id) { case ShaderGraph::NODE_VEC_LEN: { gn->set_title("VecLength"); HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_child( memnew(Label("in"))); + if (graph->is_slot_connected(type, p_id, 0)) { + hbc->add_child(make_label("in", Variant::VECTOR3)); + } else { + Vector3 v = graph->default_get_value(type,p_id,0); + hbc->add_child(make_editor(String("in: ")+v,gn,p_id,0,Variant::VECTOR3)); + } hbc->add_spacer(); hbc->add_child( memnew(Label("len"))); gn->add_child(hbc); @@ -1692,11 +1902,21 @@ void ShaderGraphView::_create_node(int p_id) { gn->set_title("DotProduct"); HBoxContainer *hbc = memnew( HBoxContainer ); hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("a"))); + if (graph->is_slot_connected(type, p_id, 0)) { + hbc->add_child(make_label("a", Variant::VECTOR3)); + } else { + Vector3 v = graph->default_get_value(type,p_id,0); + hbc->add_child(make_editor(String("a: ")+v,gn,p_id,0,Variant::VECTOR3)); + } hbc->add_spacer(); hbc->add_child( memnew(Label("dp"))); gn->add_child(hbc); - gn->add_child( memnew(Label("b"))); + if (graph->is_slot_connected(type, p_id, 1)) { + gn->add_child(make_label("b", Variant::VECTOR3)); + } else { + Vector3 v = graph->default_get_value(type,p_id,1); + gn->add_child(make_editor(String("b: ")+v,gn,p_id,1,Variant::VECTOR3)); + } gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); @@ -1707,7 +1927,12 @@ void ShaderGraphView::_create_node(int p_id) { gn->set_title("Vec2Scalar"); HBoxContainer *hbc = memnew( HBoxContainer ); hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("vec"))); + if (graph->is_slot_connected(type, p_id, 0)) { + hbc->add_child(make_label("vec", Variant::VECTOR3)); + } else { + Vector3 v = graph->default_get_value(type,p_id,0); + hbc->add_child(make_editor(String("vec: ")+v,gn,p_id,0,Variant::VECTOR3)); + } hbc->add_spacer(); Label *l=memnew(Label("x")); l->set_align(Label::ALIGN_RIGHT); @@ -1732,12 +1957,27 @@ void ShaderGraphView::_create_node(int p_id) { gn->set_title("Scalar2Vec"); HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_child( memnew(Label("x"))); + if (graph->is_slot_connected(type, p_id, 0)) { + hbc->add_child(make_label("x", Variant::REAL)); + } else { + float v = graph->default_get_value(type,p_id,0); + hbc->add_child(make_editor(String("x: ")+Variant(v),gn,p_id,0,Variant::REAL)); + } hbc->add_spacer(); hbc->add_child( memnew(Label("vec"))); gn->add_child(hbc); - gn->add_child( memnew(Label("y"))); - gn->add_child( memnew(Label("z"))); + if (graph->is_slot_connected(type, p_id, 1)) { + gn->add_child(make_label("y", Variant::REAL)); + } else { + float v = graph->default_get_value(type,p_id,1); + gn->add_child(make_editor(String("y: ")+Variant(v),gn,p_id,1,Variant::REAL)); + } + if (graph->is_slot_connected(type, p_id, 2)) { + gn->add_child(make_label("in", Variant::REAL)); + } else { + float v = graph->default_get_value(type,p_id,2); + gn->add_child(make_editor(String("in: ")+Variant(v),gn,p_id,2,Variant::REAL)); + } gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); @@ -1749,13 +1989,33 @@ void ShaderGraphView::_create_node(int p_id) { gn->set_title("Vec2XForm"); HBoxContainer *hbc = memnew( HBoxContainer ); hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("x"))); + if (graph->is_slot_connected(type, p_id, 0)) { + hbc->add_child(make_label("x", Variant::VECTOR3)); + } else { + Vector3 v = graph->default_get_value(type,p_id,0); + hbc->add_child(make_editor(String("x: ")+v,gn,p_id,0,Variant::VECTOR3)); + } hbc->add_spacer(); hbc->add_child( memnew(Label("xf"))); gn->add_child(hbc); - gn->add_child( memnew(Label("y"))); - gn->add_child( memnew(Label("z"))); - gn->add_child( memnew(Label("ofs"))); + if (graph->is_slot_connected(type, p_id, 1)) { + gn->add_child(make_label("y", Variant::VECTOR3)); + } else { + Vector3 v = graph->default_get_value(type,p_id,1); + gn->add_child(make_editor(String("y: ")+v,gn,p_id,1,Variant::VECTOR3)); + } + if (graph->is_slot_connected(type, p_id, 2)) { + gn->add_child(make_label("z", Variant::VECTOR3)); + } else { + Vector3 v = graph->default_get_value(type,p_id,2); + gn->add_child(make_editor(String("z: ")+v,gn,p_id,2,Variant::VECTOR3)); + } + if (graph->is_slot_connected(type, p_id, 3)) { + gn->add_child(make_label("ofs", Variant::VECTOR3)); + } else { + Vector3 v = graph->default_get_value(type,p_id,3); + gn->add_child(make_editor(String("ofs: ")+v,gn,p_id,3,Variant::VECTOR3)); + } gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM]); gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); @@ -1769,7 +2029,11 @@ void ShaderGraphView::_create_node(int p_id) { HBoxContainer *hbc = memnew( HBoxContainer ); hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("xf"))); + if (graph->is_slot_connected(type, p_id, 0)) { + hbc->add_child(make_label("fx", Variant::TRANSFORM)); + } else { + hbc->add_child(make_editor(String("fx: edit..."),gn,p_id,0,Variant::TRANSFORM)); + } hbc->add_spacer(); Label *l=memnew(Label("x")); l->set_align(Label::ALIGN_RIGHT); @@ -1796,12 +2060,27 @@ void ShaderGraphView::_create_node(int p_id) { gn->set_title("ScalarInterp"); HBoxContainer *hbc = memnew( HBoxContainer ); hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("a"))); + if (graph->is_slot_connected(type, p_id, 0)) { + hbc->add_child(make_label("a", Variant::REAL)); + } else { + float v = graph->default_get_value(type,p_id,0); + hbc->add_child(make_editor(String("a: ")+Variant(v),gn,p_id,0,Variant::REAL,hint_spin)); + } hbc->add_spacer(); hbc->add_child( memnew(Label("interp"))); gn->add_child(hbc); - gn->add_child( memnew(Label("b"))); - gn->add_child( memnew(Label("c"))); + if (graph->is_slot_connected(type, p_id, 1)) { + gn->add_child(make_label("b", Variant::REAL)); + } else { + float v = graph->default_get_value(type,p_id,1); + gn->add_child(make_editor(String("b: ")+Variant(v),gn,p_id,1,Variant::REAL,hint_spin)); + } + if (graph->is_slot_connected(type, p_id, 2)) { + gn->add_child(make_label("c", Variant::REAL)); + } else { + float v = graph->default_get_value(type,p_id,2); + gn->add_child(make_editor(String("c: ")+Variant(v),gn,p_id,2,Variant::REAL,hint_slider)); + } gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); @@ -1813,12 +2092,27 @@ void ShaderGraphView::_create_node(int p_id) { gn->set_title("VecInterp"); HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_child( memnew(Label("a"))); + if (graph->is_slot_connected(type, p_id, 0)) { + hbc->add_child(make_label("a", Variant::VECTOR3)); + } else { + Vector3 v = graph->default_get_value(type,p_id,0); + hbc->add_child(make_editor(String("a: ")+v,gn,p_id,0,Variant::VECTOR3)); + } hbc->add_spacer(); hbc->add_child( memnew(Label("interp"))); gn->add_child(hbc); - gn->add_child( memnew(Label("b"))); - gn->add_child( memnew(Label("c"))); + if (graph->is_slot_connected(type, p_id, 1)) { + gn->add_child(make_label("b", Variant::VECTOR3)); + } else { + Vector3 v = graph->default_get_value(type,p_id,1); + gn->add_child(make_editor(String("b: ")+v,gn,p_id,1,Variant::VECTOR3)); + } + if (graph->is_slot_connected(type, p_id, 2)) { + gn->add_child(make_label("c", Variant::REAL)); + } else { + float v = graph->default_get_value(type,p_id,2); + gn->add_child(make_editor(String("c: ")+Variant(v),gn,p_id,2,Variant::REAL,hint_slider)); + } gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); @@ -1857,7 +2151,12 @@ void ShaderGraphView::_create_node(int p_id) { HBoxContainer *hbc = memnew( HBoxContainer ); hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("c"))); + if (graph->is_slot_connected(type, p_id, 0)) { + hbc->add_child(make_label("c", Variant::REAL)); + } else { + float v = graph->default_get_value(type,p_id,0); + hbc->add_child(make_editor(String("c: ")+Variant(v),gn,p_id,0,Variant::REAL,hint_slider)); + } hbc->add_spacer(); Label *l=memnew(Label("rgb")); l->set_align(Label::ALIGN_RIGHT); @@ -1902,7 +2201,12 @@ void ShaderGraphView::_create_node(int p_id) { HBoxContainer *hbc = memnew( HBoxContainer ); hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("c"))); + if (graph->is_slot_connected(type, p_id, 0)) { + hbc->add_child(make_label("c", Variant::REAL)); + } else { + float v = graph->default_get_value(type,p_id,0); + hbc->add_child(make_editor(String("c: ")+Variant(v),gn,p_id,0,Variant::REAL,hint_slider)); + } hbc->add_spacer(); Label *l=memnew(Label("cmap")); l->set_align(Label::ALIGN_RIGHT); @@ -2016,7 +2320,12 @@ void ShaderGraphView::_create_node(int p_id) { HBoxContainer *hbc = memnew( HBoxContainer ); hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("UV"))); + if (graph->is_slot_connected(type, p_id, 0)) { + hbc->add_child(make_label("UV", Variant::VECTOR3)); + } else { + Vector3 v = graph->default_get_value(type,p_id,0); + hbc->add_child(make_editor(String("UV: ")+v,gn,p_id,0,Variant::VECTOR3)); + } hbc->add_spacer(); Label *l=memnew(Label("RGB")); l->set_align(Label::ALIGN_RIGHT); @@ -2047,7 +2356,12 @@ void ShaderGraphView::_create_node(int p_id) { HBoxContainer *hbc = memnew( HBoxContainer ); hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("UV"))); + if (graph->is_slot_connected(type, p_id, 0)) { + hbc->add_child(make_label("UV", Variant::VECTOR3)); + } else { + Vector3 v = graph->default_get_value(type,p_id,0); + hbc->add_child(make_editor(String("UV: ")+v,gn,p_id,0,Variant::VECTOR3)); + } hbc->add_spacer(); Label *l=memnew(Label("RGB")); l->set_align(Label::ALIGN_RIGHT); @@ -2067,7 +2381,12 @@ void ShaderGraphView::_create_node(int p_id) { gn->set_title("CanvasItemTex"); HBoxContainer *hbc = memnew( HBoxContainer ); hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("UV"))); + if (graph->is_slot_connected(type, p_id, 0)) { + hbc->add_child(make_label("UV", Variant::VECTOR3)); + } else { + Vector3 v = graph->default_get_value(type,p_id,0); + hbc->add_child(make_editor(String("UV: ")+v,gn,p_id,0,Variant::VECTOR3)); + } hbc->add_spacer(); Label *l=memnew(Label("RGB")); l->set_align(Label::ALIGN_RIGHT); @@ -2091,15 +2410,34 @@ void ShaderGraphView::_create_node(int p_id) { List si; ShaderGraph::get_input_output_node_slot_info(graph->get_mode(),type,&si); + Array colors; + colors.push_back("Color"); + colors.push_back("LightColor"); + Array reals; + reals.push_back("Alpha"); + reals.push_back("NormapMapDepth"); + reals.push_back("LightAlpha"); + reals.push_back("PointSize"); + Array vectors; + vectors.push_back("Normal"); + vectors.push_back("NormalMap"); + vectors.push_back("Vertex"); + vectors.push_back("UV"); + vectors.push_back("Var1"); + vectors.push_back("Var2"); + int idx=0; for (List::Element *E=si.front();E;E=E->next()) { ShaderGraph::SlotInfo& s=E->get(); if (s.dir==ShaderGraph::SLOT_OUT) { - - Label *l= memnew( Label ); - l->set_text(s.name); - l->set_align(Label::ALIGN_LEFT); - gn->add_child(l); + Variant::Type v; + if (colors.find(s.name)>=0) + v=Variant::COLOR; + else if (reals.find(s.name)>=0) + v=Variant::REAL; + else if (vectors.find(s.name)>=0) + v=Variant::VECTOR3; + gn->add_child(make_label(s.name, v)); gn->set_slot(idx,true,s.type,typecol[s.type],false,0,Color()); idx++; } @@ -2256,6 +2594,7 @@ void ShaderGraphView::_bind_methods() { ObjectTypeDB::bind_method("_duplicate_nodes", &ShaderGraphView::_duplicate_nodes); ObjectTypeDB::bind_method("_delete_nodes_request", &ShaderGraphView::_delete_nodes_request); + ObjectTypeDB::bind_method("_default_changed",&ShaderGraphView::_default_changed); ObjectTypeDB::bind_method("_scalar_const_changed",&ShaderGraphView::_scalar_const_changed); ObjectTypeDB::bind_method("_vec_const_changed",&ShaderGraphView::_vec_const_changed); ObjectTypeDB::bind_method("_rgb_const_changed",&ShaderGraphView::_rgb_const_changed); diff --git a/tools/editor/plugins/shader_graph_editor_plugin.h b/tools/editor/plugins/shader_graph_editor_plugin.h index 36443efeb057..800fdf1fea19 100644 --- a/tools/editor/plugins/shader_graph_editor_plugin.h +++ b/tools/editor/plugins/shader_graph_editor_plugin.h @@ -129,6 +129,7 @@ class ShaderGraphView : public Node { GraphEdit *graph_edit; Ref graph; int edited_id; + int edited_def; ShaderGraph::ShaderType type; @@ -136,6 +137,8 @@ class ShaderGraphView : public Node { void _create_node(int p_id); + ToolButton *make_label(String text, Variant::Type v_type = Variant::NIL); + ToolButton *make_editor(String text, GraphNode* gn, int p_id, int param, Variant::Type type, String p_hint=""); void _connection_request(const String& p_from, int p_from_slot,const String& p_to,int p_to_slot); void _disconnection_request(const String& p_from, int p_from_slot,const String& p_to,int p_to_slot); @@ -149,6 +152,9 @@ class ShaderGraphView : public Node { void _duplicate_nodes(Array &p_nodes); void _delete_nodes_request(); + + void _default_changed(int p_id, Node* p_button, int p_param, int v_type, String p_hint); + void _scalar_const_changed(double p_value,int p_id); void _vec_const_changed(double p_value, int p_id, Array p_arr); void _rgb_const_changed(const Color& p_color, int p_id); diff --git a/tools/editor/property_editor.cpp b/tools/editor/property_editor.cpp index 78a1f0ad15ca..ae0975c89679 100644 --- a/tools/editor/property_editor.cpp +++ b/tools/editor/property_editor.cpp @@ -42,15 +42,15 @@ #include "multi_node_edit.h" void CustomPropertyEditor::_notification(int p_what) { - + if (p_what==NOTIFICATION_DRAW) { - + RID ci = get_canvas_item(); - get_stylebox("panel","PopupMenu")->draw(ci,Rect2(Point2(),get_size())); + get_stylebox("panel","PopupMenu")->draw(ci,Rect2(Point2(),get_size())); /* if (v.get_type()==Variant::COLOR) { - + VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2( 10,10,60, get_size().height-20 ), v ); }*/ } @@ -211,11 +211,11 @@ void CustomPropertyEditor::_menu_option(int p_which) { } Variant CustomPropertyEditor::get_variant() const { - - return v; + + return v; } String CustomPropertyEditor::get_name() const { - + return name; } @@ -233,9 +233,11 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty inheritors_array.clear(); text_edit->hide(); easing_draw->hide(); - + spinbox->hide(); + slider->hide(); + for (int i=0;ihide(); value_label[i]->hide(); if (i<4) @@ -243,8 +245,8 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty } for (int i=0;ihide(); + + action_buttons[i]->hide(); } for(int i=0;i<20;i++) @@ -254,11 +256,49 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty switch(type) { - + case Variant::INT: case Variant::REAL: { - if (hint==PROPERTY_HINT_ALL_FLAGS) { + if (hint==PROPERTY_HINT_RANGE) { + + int c = hint_text.get_slice_count(","); + float min=0,max=100,step=1; + if (c>=1) { + + if (!hint_text.get_slice(",",0).empty()) + min=hint_text.get_slice(",",0).to_double(); + } + if (c>=2) { + + if (!hint_text.get_slice(",",1).empty()) + max=hint_text.get_slice(",",1).to_double(); + } + + if (type==Variant::REAL && c>=3) { + + if (!hint_text.get_slice(",",2).empty()) + step= hint_text.get_slice(",",2).to_double(); + } + + if (c>=4 && hint_text.get_slice(",",3)=="slider") { + slider->set_min(min); + slider->set_max(max); + slider->set_step((type==Variant::REAL) ? step : 1); + slider->set_val(v); + slider->show(); + set_size(Size2(110,30)); + } else { + spinbox->set_min(min); + spinbox->set_max(max); + spinbox->set_step((type==Variant::REAL) ? step : 1); + spinbox->set_val(v); + spinbox->show(); + set_size(Size2(70,35)); + } + + + } else if (hint==PROPERTY_HINT_ALL_FLAGS) { uint32_t flgs = v; for(int i=0;i<2;i++) { @@ -406,7 +446,7 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty value_editor[3]->set_text( String::num( r.size.y) ); } break; case Variant::VECTOR3: { - + List names; names.push_back("x"); names.push_back("y"); @@ -418,7 +458,7 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty value_editor[2]->set_text( String::num( vec.z) ); } break; case Variant::PLANE: { - + List names; names.push_back("x"); names.push_back("y"); @@ -430,10 +470,10 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty value_editor[1]->set_text( String::num( plane.normal.y ) ); value_editor[2]->set_text( String::num( plane.normal.z ) ); value_editor[3]->set_text( String::num( plane.d ) ); - + } break; case Variant::QUAT: { - + List names; names.push_back("x"); names.push_back("y"); @@ -448,7 +488,7 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty } break; case Variant::_AABB: { - + List names; names.push_back("px"); names.push_back("py"); @@ -457,7 +497,7 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty names.push_back("sy"); names.push_back("sz"); config_value_editors(6,3,16,names); - + AABB aabb=v; value_editor[0]->set_text( String::num( aabb.pos.x ) ); value_editor[1]->set_text( String::num( aabb.pos.y ) ); @@ -465,7 +505,7 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty value_editor[3]->set_text( String::num( aabb.size.x ) ); value_editor[4]->set_text( String::num( aabb.size.y ) ); value_editor[5]->set_text( String::num( aabb.size.z ) ); - + } break; case Variant::MATRIX32: { @@ -486,7 +526,7 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty } break; case Variant::MATRIX3: { - + List names; names.push_back("xx"); names.push_back("xy"); @@ -498,17 +538,17 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty names.push_back("zy"); names.push_back("zz"); config_value_editors(9,3,16,names); - + Matrix3 basis=v; for(int i=0;i<9;i++) { - + value_editor[i]->set_text( String::num( basis.elements[i/3][i%3] ) ); } - + } break; case Variant::TRANSFORM: { - - + + List names; names.push_back("xx"); names.push_back("xy"); @@ -523,20 +563,20 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty names.push_back("zz"); names.push_back("zo"); config_value_editors(12,4,16,names); - + Transform tr=v; for(int i=0;i<9;i++) { - + value_editor[(i/3)*4+i%3]->set_text( String::num( tr.basis.elements[i/3][i%3] ) ); } - + value_editor[3]->set_text( String::num( tr.origin.x ) ); value_editor[7]->set_text( String::num( tr.origin.y ) ); value_editor[11]->set_text( String::num( tr.origin.z ) ); - + } break; case Variant::COLOR: { - + color_picker->show(); color_picker->set_edit_alpha(hint!=PROPERTY_HINT_COLOR_NO_ALPHA); @@ -550,13 +590,13 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty float values[4]={c.r,c.g,c.b,c.a}; for (int i=0;i<4;i++) { int y=m+i*h; - + value_editor[i]->show(); - value_label[i]->show(); + value_label[i]->show(); value_label[i]->set_pos(Point2(ofs,y)); scroll[i]->set_min(0); scroll[i]->set_max(1.0); - scroll[i]->set_page(0); + scroll[i]->set_page(0); scroll[i]->set_pos(Point2(ofs+15,y+Math::floor((h-scroll[i]->get_minimum_size().height)/2.0))); scroll[i]->set_val(values[i]); scroll[i]->set_size(Size2(120,1)); @@ -564,30 +604,30 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty value_editor[i]->set_pos(Point2(ofs+140,y)); value_editor[i]->set_size(Size2(40,h)); value_editor[i]->set_text( String::num(values[i],2 )); - + } - + value_label[0]->set_text("R"); value_label[1]->set_text("G"); value_label[2]->set_text("B"); value_label[3]->set_text("A"); - + Size2 new_size = value_editor[3]->get_pos() + value_editor[3]->get_size() + Point2(10,10); set_size( new_size ); */ - + } break; case Variant::IMAGE: { - + List names; names.push_back("New"); names.push_back("Load"); names.push_back("Clear"); config_action_buttons(names); - + } break; case Variant::NODE_PATH: { - + List names; names.push_back("Assign"); names.push_back("Clear"); @@ -595,7 +635,7 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty } break; case Variant::OBJECT: { - + if (hint!=PROPERTY_HINT_RESOURCE_TYPE) break; @@ -701,40 +741,40 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty } break; case Variant::INPUT_EVENT: { - - + + } break; case Variant::DICTIONARY: { - - + + } break; case Variant::RAW_ARRAY: { - - + + } break; case Variant::INT_ARRAY: { - - + + } break; case Variant::REAL_ARRAY: { - - + + } break; case Variant::STRING_ARRAY: { - - + + } break; case Variant::VECTOR3_ARRAY: { - - + + } break; case Variant::COLOR_ARRAY: { - - + + } break; default: {} - } - + } + updating=false; return true; } @@ -742,7 +782,7 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty void CustomPropertyEditor::_file_selected(String p_file) { switch(type) { - + case Variant::STRING: { if (hint==PROPERTY_HINT_FILE || hint==PROPERTY_HINT_DIR) { @@ -880,9 +920,9 @@ void CustomPropertyEditor::_node_path_selected(NodePath p_path) { void CustomPropertyEditor::_action_pressed(int p_which) { - if (updating) + if (updating) return; - + switch(type) { case Variant::INT: { @@ -965,7 +1005,7 @@ void CustomPropertyEditor::_action_pressed(int p_which) { } break; case Variant::NODE_PATH: { - + if (p_which==0) { @@ -976,60 +1016,60 @@ void CustomPropertyEditor::_action_pressed(int p_which) { v=NodePath(); emit_signal("variant_changed"); - } + } } break; case Variant::OBJECT: { - + if (p_which==0) { - + ERR_FAIL_COND( inheritors_array.empty() ); String intype=inheritors_array[0]; - + if (hint==PROPERTY_HINT_RESOURCE_TYPE) { - + Object *obj = ObjectTypeDB::instance(intype); ERR_BREAK( !obj ); Resource *res=obj->cast_to(); ERR_BREAK( !res ); - + v=Ref(res).get_ref_ptr(); emit_signal("variant_changed"); hide(); - + } } else if (p_which==1) { - + file->set_access(EditorFileDialog::ACCESS_RESOURCES); file->set_mode(EditorFileDialog::MODE_OPEN_FILE); List extensions; String type=(hint==PROPERTY_HINT_RESOURCE_TYPE)?hint_text:String(); - + ResourceLoader::get_recognized_extensions_for_type(type,&extensions); file->clear_filters(); for (List::Element *E=extensions.front();E;E=E->next()) { - + file->add_filter("*."+E->get()+" ; "+E->get().to_upper() ); - + } - + file->popup_centered_ratio(); - + } else if (p_which==2) { - + RefPtr RefPtr=v; if (!RefPtr.is_null()) { emit_signal("resource_edit_request"); - hide(); + hide(); } - + } else if (p_which==3) { - - + + v=Variant(); emit_signal("variant_changed"); hide(); @@ -1072,7 +1112,7 @@ void CustomPropertyEditor::_action_pressed(int p_which) { emit_signal("variant_changed"); hide(); } - + } break; case Variant::IMAGE: { @@ -1111,16 +1151,16 @@ void CustomPropertyEditor::_action_pressed(int p_which) { } void CustomPropertyEditor::_scroll_modified(double p_value) { - - if (updating) + + if (updating) return; /* switch(type) { - + case Variant::COLOR: { - + for (int i=0;i<4;i++) { - + value_editor[i]->set_text( String::num(scroll[i]->get_val(),2) ); } Color c; @@ -1145,7 +1185,7 @@ void CustomPropertyEditor::_drag_easing(const InputEvent& p_ev) { float rel = p_ev.mouse_motion.relative_x; if (rel==0) - return; + return; bool flip=hint_text=="attenuation"; @@ -1228,7 +1268,7 @@ void CustomPropertyEditor::_text_edit_changed() { } void CustomPropertyEditor::_modified(String p_string) { - + if (updating) return; updating=true; @@ -1269,17 +1309,17 @@ void CustomPropertyEditor::_modified(String p_string) { } break; case Variant::VECTOR3: { - + Vector3 vec; vec.x=value_editor[0]->get_text().to_double(); vec.y=value_editor[1]->get_text().to_double(); vec.z=value_editor[2]->get_text().to_double(); v=vec; emit_signal("variant_changed"); - + } break; case Variant::PLANE: { - + Plane pl; pl.normal.x=value_editor[0]->get_text().to_double(); pl.normal.y=value_editor[1]->get_text().to_double(); @@ -1287,10 +1327,10 @@ void CustomPropertyEditor::_modified(String p_string) { pl.d=value_editor[3]->get_text().to_double(); v=pl; emit_signal("variant_changed"); - + } break; case Variant::QUAT: { - + Quat q; q.x=value_editor[0]->get_text().to_double(); q.y=value_editor[1]->get_text().to_double(); @@ -1298,10 +1338,10 @@ void CustomPropertyEditor::_modified(String p_string) { q.w=value_editor[3]->get_text().to_double(); v=q; emit_signal("variant_changed"); - + } break; case Variant::_AABB: { - + Vector3 pos; pos.x=value_editor[0]->get_text().to_double(); pos.y=value_editor[1]->get_text().to_double(); @@ -1310,10 +1350,10 @@ void CustomPropertyEditor::_modified(String p_string) { size.x=value_editor[3]->get_text().to_double(); size.y=value_editor[4]->get_text().to_double(); size.z=value_editor[5]->get_text().to_double(); - + v=AABB(pos,size); emit_signal("variant_changed"); - + } break; case Variant::MATRIX32: { @@ -1328,39 +1368,39 @@ void CustomPropertyEditor::_modified(String p_string) { } break; case Variant::MATRIX3: { - + Matrix3 m; for(int i=0;i<9;i++) { - + m.elements[i/3][i%3]=value_editor[i]->get_text().to_double(); } - + v=m; emit_signal("variant_changed"); - + } break; case Variant::TRANSFORM: { - + Matrix3 basis; for(int i=0;i<9;i++) { - + basis.elements[i/3][i%3]=value_editor[(i/3)*4+i%3]->get_text().to_double(); } - + Vector3 origin; origin.x=value_editor[3]->get_text().to_double(); origin.y=value_editor[7]->get_text().to_double(); origin.z=value_editor[11]->get_text().to_double(); - + v=Transform(basis,origin); emit_signal("variant_changed"); - - + + } break; case Variant::COLOR: { /* for (int i=0;i<4;i++) { - + scroll[i]->set_val( value_editor[i]->get_text().to_double() ); } Color c; @@ -1374,51 +1414,57 @@ void CustomPropertyEditor::_modified(String p_string) { */ } break; case Variant::IMAGE: { - - + + } break; case Variant::NODE_PATH: { - - - } break; + + + } break; case Variant::INPUT_EVENT: { - - + + } break; case Variant::DICTIONARY: { - - + + } break; case Variant::RAW_ARRAY: { - - + + } break; case Variant::INT_ARRAY: { - - + + } break; case Variant::REAL_ARRAY: { - - + + } break; case Variant::STRING_ARRAY: { - - + + } break; case Variant::VECTOR3_ARRAY: { - - + + } break; case Variant::COLOR_ARRAY: { - - + + } break; default: {} - } - + } + updating=false; } +void CustomPropertyEditor::_range_modified(double p_value) +{ + v=p_value; + emit_signal("variant_changed"); +} + void CustomPropertyEditor::_focus_enter() { switch(type) { case Variant::REAL: @@ -1475,10 +1521,10 @@ void CustomPropertyEditor::config_action_buttons(const List& p_strings) set_size( Size2( w, m*2+(h+m)*p_strings.size() ) ); for (int i=0;ishow(); - action_buttons[i]->set_text(p_strings[i]); + action_buttons[i]->set_text(p_strings[i]); action_buttons[i]->set_pos( Point2( m, m+i*(h+m) )); action_buttons[i]->set_size( Size2( w-m*2, h ) ); action_buttons[i]->set_flat(true); @@ -1486,29 +1532,29 @@ void CustomPropertyEditor::config_action_buttons(const List& p_strings) action_buttons[i]->hide(); } } - - + + } void CustomPropertyEditor::config_value_editors(int p_amount, int p_columns,int p_label_w,const List& p_strings) { - + int w=80; int h=20; int m=10; - + int rows=((p_amount-1)/p_columns)+1; - + set_size( Size2( m*(1+p_columns)+(w+p_label_w)*p_columns, m*(1+rows)+h*rows ) ); - + for (int i=0;ishow(); value_label[i]->show(); - value_label[i]->set_text(iset_text(iset_pos( Point2( m+p_label_w+c*(w+m+p_label_w), m+r*(h+m) )); value_editor[i]->set_size( Size2( w, h ) ); value_label[i]->set_pos( Point2( m+c*(w+m+p_label_w), m+r*(h+m) ) ); @@ -1518,16 +1564,17 @@ void CustomPropertyEditor::config_value_editors(int p_amount, int p_columns,int value_label[i]->hide(); } } - - - + + + } void CustomPropertyEditor::_bind_methods() { - + ObjectTypeDB::bind_method("_focus_enter", &CustomPropertyEditor::_focus_enter); ObjectTypeDB::bind_method("_focus_exit", &CustomPropertyEditor::_focus_exit); ObjectTypeDB::bind_method("_modified",&CustomPropertyEditor::_modified); + ObjectTypeDB::bind_method("_range_modified", &CustomPropertyEditor::_range_modified); ObjectTypeDB::bind_method("_scroll_modified",&CustomPropertyEditor::_scroll_modified); ObjectTypeDB::bind_method("_action_pressed",&CustomPropertyEditor::_action_pressed); ObjectTypeDB::bind_method("_file_selected",&CustomPropertyEditor::_file_selected); @@ -1544,13 +1591,13 @@ void CustomPropertyEditor::_bind_methods() { ADD_SIGNAL( MethodInfo("resource_edit_request") ); } CustomPropertyEditor::CustomPropertyEditor() { - - + + read_only=false; updating=false; - + for (int i=0;iconnect("focus_enter", this, "_focus_enter"); value_editor[i]->connect("focus_exit", this, "_focus_exit"); } - + for(int i=0;i<4;i++) { - + scroll[i] = memnew( HScrollBar ); scroll[i]->hide(); scroll[i]->set_min(0); scroll[i]->set_max(1.0); - scroll[i]->set_step(0.01); + scroll[i]->set_step(0.01); add_child(scroll[i]); scroll[i]->connect("value_changed", this,"_scroll_modified"); - + } for(int i=0;i<20;i++) { @@ -1595,15 +1642,15 @@ CustomPropertyEditor::CustomPropertyEditor() { text_edit->connect("text_changed",this,"_text_edit_changed"); for (int i=0;ihide(); + action_buttons[i]->hide(); add_child(action_buttons[i]); Vector binds; binds.push_back(i); action_buttons[i]->connect("pressed", this,"_action_pressed",binds); } - + color_picker = memnew( ColorPicker ); add_child(color_picker); color_picker->hide(); @@ -1616,7 +1663,7 @@ CustomPropertyEditor::CustomPropertyEditor() { file = memnew ( EditorFileDialog ); add_child(file); file->hide(); - + file->connect("file_selected", this,"_file_selected"); file->connect("dir_selected", this,"_file_selected"); @@ -1624,12 +1671,12 @@ CustomPropertyEditor::CustomPropertyEditor() { error->set_title("Error!"); add_child(error); //error->get_cancel()->hide(); - + type_button = memnew( MenuButton ); add_child(type_button); type_button->hide(); type_button->get_popup()->connect("item_pressed", this,"_type_create_selected"); - + scene_tree = memnew( SceneTreeDialog ); add_child(scene_tree); @@ -1651,6 +1698,16 @@ CustomPropertyEditor::CustomPropertyEditor() { menu = memnew(PopupMenu); add_child(menu); menu->connect("item_pressed",this,"_menu_option"); + + spinbox = memnew ( SpinBox ); + add_child(spinbox); + spinbox->set_area_as_parent_rect(5); + spinbox->connect("value_changed",this,"_range_modified"); + + slider = memnew ( HSlider ); + add_child(slider); + slider->set_area_as_parent_rect(5); + slider->connect("value_changed",this,"_range_modified"); } @@ -1675,28 +1732,28 @@ Node *PropertyEditor::get_instanced_node() { } TreeItem *PropertyEditor::find_item(TreeItem *p_item,const String& p_name) { - - + + if (!p_item) return NULL; - + String name = p_item->get_metadata(1); - + if (name==p_name) { - + return p_item; } - + TreeItem *c=p_item->get_children(); - + while (c) { - + TreeItem *found = find_item(c,p_name); if (found) return found; c=c->get_next(); } - + return NULL; } @@ -1719,9 +1776,9 @@ void PropertyEditor::_changed_callbacks(Object *p_changed,const String& p_prop) if (p_prop==String()) update_tree_pending=true; else { - + pending[p_prop]=p_prop; - + } } @@ -1733,7 +1790,7 @@ void PropertyEditor::update_property(const String& p_prop) { void PropertyEditor::set_item_text(TreeItem *p_item, int p_type, const String& p_name, int p_hint, const String& p_hint_text) { - + switch( p_type ) { case Variant::BOOL: { @@ -1826,7 +1883,7 @@ void PropertyEditor::set_item_text(TreeItem *p_item, int p_type, const String& p } break; case Variant::IMAGE: { - + Image img = obj->get( p_name ); if (img.empty()) p_item->set_text(1,"[Image (empty)]"); @@ -1905,7 +1962,7 @@ void PropertyEditor::set_item_text(TreeItem *p_item, int p_type, const String& p } break; default: {}; } - + } void PropertyEditor::_notification(int p_what) { @@ -1920,10 +1977,10 @@ void PropertyEditor::_notification(int p_what) { edit(NULL); } - + if (p_what==NOTIFICATION_FIXED_PROCESS) { - - + + if (refresh_countdown>0) { refresh_countdown-=get_fixed_process_delta_time(); if (refresh_countdown<=0) { @@ -1933,21 +1990,21 @@ void PropertyEditor::_notification(int p_what) { } changing=true; - + if (update_tree_pending) { update_tree(); update_tree_pending=false; - + } else { - - const String *k=NULL; + + const String *k=NULL; while ((k=pending.next(k))) { - + TreeItem * item = find_item(tree->get_root(),*k); if (!item) continue; - + if (get_instanced_node()) { Dictionary d = get_instanced_node()->get_instance_state(); @@ -1981,15 +2038,15 @@ void PropertyEditor::_notification(int p_what) { } } - Dictionary d=item->get_metadata(0); + Dictionary d=item->get_metadata(0); set_item_text(item,d["type"],d["name"],d["hint"],d["hint_text"]); - } + } } - + pending.clear(); - + changing=false; - + } } @@ -2271,20 +2328,20 @@ void PropertyEditor::update_tree() { d["type"]=(int)p.type; d["hint"]=(int)p.hint; d["hint_text"]=p.hint_string; - + item->set_metadata( 0, d ); item->set_metadata( 1, p.name ); if (draw_red) item->set_custom_color(0,Color(0.8,0.4,0.20)); - + if (p.name==selected_property) { item->select(1); } - + //printf("property %s type %i\n",p.name.ascii().get_data(),p.type); switch( p.type ) { @@ -2365,8 +2422,8 @@ void PropertyEditor::update_tree() { if (p.type==Variant::REAL && c>=3) { step= p.hint_string.get_slice(",",2).to_double(); - } - + } + item->set_range_config(1,min,max,step,p.hint==PROPERTY_HINT_EXP_RANGE); } else if (p.hint==PROPERTY_HINT_ENUM) { @@ -2549,7 +2606,7 @@ void PropertyEditor::update_tree() { } break; case Variant::IMAGE: { - + item->set_cell_mode( 1, TreeItem::CELL_MODE_CUSTOM ); item->set_editable( 1, !read_only ); Image img = obj->get( p.name ); @@ -2558,7 +2615,7 @@ void PropertyEditor::update_tree() { else item->set_text(1,"[Image "+itos(img.get_width())+"x"+itos(img.get_height())+"]"); item->set_icon( 0,get_icon("Image","EditorIcons") ); - + } break; case Variant::NODE_PATH: { @@ -2709,10 +2766,10 @@ void PropertyEditor::_edit_set(const String& p_name, const Variant& p_value) { void PropertyEditor::_item_edited() { - - TreeItem * item = tree->get_edited(); + + TreeItem * item = tree->get_edited(); Dictionary d = item->get_metadata(0); - + String name=d["name"]; if (tree->get_edited_column()==0) { @@ -2741,12 +2798,12 @@ void PropertyEditor::_item_edited() { int hint= d["hint"]; String hint_text=d["hint_text"]; switch(type) { - + case Variant::NIL: { - - } break; + + } break; case Variant::BOOL: { - + _edit_set(name,item->is_checked(1)); } break; case Variant::INT: @@ -2765,7 +2822,7 @@ void PropertyEditor::_item_edited() { _edit_set(name,item->get_range(1)); } break; case Variant::STRING: { - + if (hint==PROPERTY_HINT_ENUM) { int idx= item->get_range(1); @@ -2783,64 +2840,64 @@ void PropertyEditor::_item_edited() { } } break; // math types - + case Variant::VECTOR3: { - + } break; case Variant::PLANE: { - + } break; case Variant::QUAT: { - + } break; case Variant::_AABB: { - + } break; case Variant::MATRIX3: { - + } break; case Variant::TRANSFORM: { - + } break; - + case Variant::COLOR: { //_edit_set(name,item->get_custom_bg_color(0)); } break; case Variant::IMAGE: { - + } break; case Variant::NODE_PATH: { - + } break; case Variant::INPUT_EVENT: { - + } break; case Variant::DICTIONARY: { - + } break; - + // arrays case Variant::RAW_ARRAY: { - + } break; case Variant::INT_ARRAY: { - + } break; case Variant::REAL_ARRAY: { - + } break; case Variant::STRING_ARRAY: { - + } break; case Variant::VECTOR3_ARRAY: { - + } break; case Variant::COLOR_ARRAY: { - + } break; - - + + }; } @@ -2891,24 +2948,24 @@ void PropertyEditor::_custom_editor_request(bool p_arrow) { } void PropertyEditor::edit(Object* p_object) { - + if (obj==p_object) return; if (obj) { - + obj->remove_change_receptor(this); } obj=p_object; update_tree(); - + if (obj) { - + obj->add_change_receptor(this); } - - + + } void PropertyEditor::_set_range_def(Object *p_item, String prop,float p_frame) { @@ -3003,9 +3060,9 @@ void PropertyEditor::_edit_button(Object *p_item, int p_column, int p_button) { void PropertyEditor::_node_removed(Node *p_node) { - + if (p_node==obj) { - + edit(NULL); } } @@ -3065,9 +3122,9 @@ void PropertyEditor::_bind_methods() { ObjectTypeDB::bind_method( "_item_edited",&PropertyEditor::_item_edited); ObjectTypeDB::bind_method( "_item_selected",&PropertyEditor::_item_selected); ObjectTypeDB::bind_method( "_custom_editor_request",&PropertyEditor::_custom_editor_request); - ObjectTypeDB::bind_method( "_custom_editor_edited",&PropertyEditor::_custom_editor_edited); - ObjectTypeDB::bind_method( "_resource_edit_request",&PropertyEditor::_resource_edit_request); - ObjectTypeDB::bind_method( "_node_removed",&PropertyEditor::_node_removed); + ObjectTypeDB::bind_method( "_custom_editor_edited",&PropertyEditor::_custom_editor_edited); + ObjectTypeDB::bind_method( "_resource_edit_request",&PropertyEditor::_resource_edit_request); + ObjectTypeDB::bind_method( "_node_removed",&PropertyEditor::_node_removed); ObjectTypeDB::bind_method( "_edit_button",&PropertyEditor::_edit_button); ObjectTypeDB::bind_method( "_changed_callback",&PropertyEditor::_changed_callbacks); ObjectTypeDB::bind_method( "_draw_flags",&PropertyEditor::_draw_flags); @@ -3127,29 +3184,29 @@ void PropertyEditor::set_show_categories(bool p_show) { } PropertyEditor::PropertyEditor() { - + _prop_edited="property_edited"; _prop_edited_name.push_back(String()); undo_redo=NULL; obj=NULL; changing=false; update_tree_pending=false; - + top_label = memnew( Label ); top_label->set_text("Properties:"); top_label->set_anchor( MARGIN_RIGHT, ANCHOR_END ); top_label->set_begin( Point2( 10,0) ); - top_label->set_end( Point2( 0,12) ); - - add_child(top_label); + top_label->set_end( Point2( 0,12) ); + + add_child(top_label); + - tree = memnew( Tree ); tree->set_anchor( MARGIN_RIGHT, ANCHOR_END ); - tree->set_anchor( MARGIN_BOTTOM, ANCHOR_END ); + tree->set_anchor( MARGIN_BOTTOM, ANCHOR_END ); tree->set_begin( Point2(0,19 )); tree->set_end( Point2(0,0 )); - + tree->set_columns(2); tree->set_column_expand(0,true); tree->set_column_min_width(0,30); @@ -3157,21 +3214,21 @@ PropertyEditor::PropertyEditor() { tree->set_column_min_width(1,18); //tree->set_hide_root(true); - add_child( tree ); - + add_child( tree ); + tree->connect("item_edited", this,"_item_edited",varray(),CONNECT_DEFERRED); tree->connect("cell_selected", this,"_item_selected"); - + set_fixed_process(true); - + custom_editor = memnew( CustomPropertyEditor ); add_child(custom_editor); - + tree->connect("custom_popup_edited", this,"_custom_editor_request"); tree->connect("button_pressed", this,"_edit_button"); custom_editor->connect("variant_changed", this,"_custom_editor_edited"); custom_editor->connect("resource_edit_request", this,"_resource_edit_request",make_binds(),CONNECT_DEFERRED); - + capitalize_paths=true; autoclear=false; tree->set_column_title(0,"Property"); @@ -3182,7 +3239,7 @@ PropertyEditor::PropertyEditor() { read_only=false; show_categories=false; refresh_countdown=0; - + } diff --git a/tools/editor/property_editor.h b/tools/editor/property_editor.h index de5cac871107..f6e2dfcf509c 100644 --- a/tools/editor/property_editor.h +++ b/tools/editor/property_editor.h @@ -46,9 +46,9 @@ */ class CustomPropertyEditor : public Popup { - + OBJ_TYPE( CustomPropertyEditor, Popup ); - + enum { MAX_VALUE_EDITORS=12, MAX_ACTION_BUTTONS=5, @@ -93,7 +93,8 @@ class CustomPropertyEditor : public Popup { TextEdit *text_edit; bool read_only; Button *checks20[20]; - + SpinBox *spinbox; + HSlider *slider; Control *easing_draw; @@ -105,6 +106,7 @@ class CustomPropertyEditor : public Popup { void _file_selected(String p_file); void _scroll_modified(double p_value); void _modified(String p_string); + void _range_modified(double p_value); void _focus_enter(); void _focus_exit(); void _action_pressed(int p_which); @@ -113,7 +115,7 @@ class CustomPropertyEditor : public Popup { void _color_changed(const Color& p_color); void _draw_easing(); void _menu_option(int p_which); - + void _drag_easing(const InputEvent& p_ev); void _node_path_selected(NodePath p_path); @@ -123,23 +125,23 @@ class CustomPropertyEditor : public Popup { protected: void _notification(int p_what); - static void _bind_methods(); - -public: + static void _bind_methods(); + +public: Variant get_variant() const; String get_name() const; - + void set_read_only(bool p_read_only) { read_only=p_read_only; } bool edit(Object* p_owner,const String& p_name,Variant::Type p_type, const Variant& p_variant,int p_hint,String p_hint_text); - + CustomPropertyEditor(); }; class PropertyEditor : public Control { - + OBJ_TYPE( PropertyEditor, Control ); - + Tree *tree; Label *top_label; //Object *object; @@ -160,27 +162,27 @@ class PropertyEditor : public Control { HashMap pending; String selected_property; - + CustomPropertyEditor *custom_editor; - + void _resource_edit_request(); void _custom_editor_edited(); void _custom_editor_request(bool p_arrow); - + void _item_selected(); void _item_edited(); TreeItem *get_parent_node(String p_path,HashMap& item_paths,TreeItem *root); - + void set_item_text(TreeItem *p_item, int p_type, const String& p_name, int p_hint=PROPERTY_HINT_NONE, const String& p_hint_text=""); - + TreeItem *find_item(TreeItem *p_item,const String& p_name); - - + + virtual void _changed_callback(Object *p_changed,const char * p_what); virtual void _changed_callbacks(Object *p_changed,const String& p_callback); void _edit_button(Object *p_item, int p_column, int p_button); - + void _node_removed(Node *p_node); void _edit_set(const String& p_name, const Variant& p_value); void _draw_flags(Object *ti,const Rect2& p_rect); @@ -191,7 +193,7 @@ class PropertyEditor : public Control { UndoRedo *undo_redo; protected: - + void _notification(int p_what); static void _bind_methods(); public: @@ -217,8 +219,8 @@ class PropertyEditor : public Control { void set_autoclear(bool p_enable); void set_show_categories(bool p_show); - - PropertyEditor(); + + PropertyEditor(); ~PropertyEditor(); }; From a19a653e2cae50f43b8de5d4ba69170c7d2fa800 Mon Sep 17 00:00:00 2001 From: Mariano Javier Suligoy Date: Sun, 30 Aug 2015 02:44:49 -0300 Subject: [PATCH 09/11] Compile shaders using default values. --- scene/resources/shader_graph.cpp | 87 ++++++++++++++++--- .../plugins/shader_graph_editor_plugin.cpp | 10 +-- 2 files changed, 79 insertions(+), 18 deletions(-) diff --git a/scene/resources/shader_graph.cpp b/scene/resources/shader_graph.cpp index fbc76c5143f5..4604c42de111 100644 --- a/scene/resources/shader_graph.cpp +++ b/scene/resources/shader_graph.cpp @@ -1849,17 +1849,17 @@ void ShaderGraph::_update_shader() { Vector inputs; int max = get_node_input_slot_count(get_mode(),ShaderType(i),n->type); for(int k=0;kconnections.has(k)) { - shader[i].error=GRAPH_ERROR_MISSING_CONNECTIONS; - failed=true; - break; + iname="nd"+itos(n->id)+"sl"+itos(k)+"def"; + } else { + iname="nd"+itos(n->connections[k].id)+"sl"+itos(n->connections[k].slot); + if (node_get_type(ShaderType(i),n->connections[k].id)==NODE_INPUT) { + inputs_used.insert(iname); + } + } - String iname="nd"+itos(n->connections[k].id)+"sl"+itos(n->connections[k].slot); inputs.push_back(iname); - if (node_get_type(ShaderType(i),n->connections[k].id)==NODE_INPUT) { - inputs_used.insert(iname); - } - } if (failed) @@ -2065,6 +2065,31 @@ void ShaderGraph::_add_node_code(ShaderType p_type,Node *p_node,const Vectortype,slot)])+" "+("nd"+itos(id)+"sl"+itos(slot))) #define OUTVAR(id,slot) ("nd"+itos(id)+"sl"+itos(slot)) +#define DEF_VEC(slot)\ + if (p_inputs[slot].ends_with("def")){\ + Vector3 v = p_node->defaults[slot];\ + code+=String(typestr[1])+" "+p_inputs[slot]+"=vec3("+v+");\n";\ + } +#define DEF_SCALAR(slot)\ + if (p_inputs[slot].ends_with("def")){\ + double v = p_node->defaults[slot];\ + code+=String(typestr[0])+" "+p_inputs[slot]+"="+rtos(v)+";\n";\ + } +#define DEF_COLOR(slot)\ + if (p_inputs[slot].ends_with("def")){\ + Color col = p_node->defaults[slot];\ + code+=String(typestr[1])+" "+p_inputs[slot]+"=vec3("+rtos(col.r)+","+rtos(col.g)+","+rtos(col.b)+");\n";\ + } +#define DEF_MATRIX(slot) \ + if (p_inputs[slot].ends_with("def")){\ + Transform xf = p_node->defaults[slot]; \ + code+=String(typestr[3])+" "+p_inputs[slot]+"=mat4(\n";\ + code+="\tvec4(vec3("+rtos(xf.basis.get_axis(0).x)+","+rtos(xf.basis.get_axis(0).y)+","+rtos(xf.basis.get_axis(0).z)+"),0),\n";\ + code+="\tvec4(vec3("+rtos(xf.basis.get_axis(1).x)+","+rtos(xf.basis.get_axis(1).y)+","+rtos(xf.basis.get_axis(1).z)+"),0),\n";\ + code+="\tvec4(vec3("+rtos(xf.basis.get_axis(2).x)+","+rtos(xf.basis.get_axis(2).y)+","+rtos(xf.basis.get_axis(2).z)+"),0),\n";\ + code+="\tvec4(vec3("+rtos(xf.origin.x)+","+rtos(xf.origin.y)+","+rtos(xf.origin.z)+"),1)\n";\ + code+=");\n";\ + } switch(p_node->type) { @@ -2101,9 +2126,12 @@ void ShaderGraph::_add_node_code(ShaderType p_type,Node *p_node,const Vectorid,0)+"=TIME;\n"; }break; case NODE_SCREEN_TEX: { + DEF_VEC(0); code+=OUTNAME(p_node->id,0)+"=texscreen("+p_inputs[0]+".xy);\n"; }break; case NODE_SCALAR_OP: { + DEF_SCALAR(0); + DEF_SCALAR(1); int op = p_node->param1; String optxt; switch(op) { @@ -2123,6 +2151,8 @@ void ShaderGraph::_add_node_code(ShaderType p_type,Node *p_node,const Vectorparam1; String optxt; switch(op) { @@ -2140,6 +2170,8 @@ void ShaderGraph::_add_node_code(ShaderType p_type,Node *p_node,const Vectorparam1; String optxt; switch(op) { @@ -2151,6 +2183,8 @@ void ShaderGraph::_add_node_code(ShaderType p_type,Node *p_node,const Vectorparam1; static const char*axisn[3]={"x","y","z"}; @@ -2162,7 +2196,7 @@ void ShaderGraph::_add_node_code(ShaderType p_type,Node *p_node,const Vectorid,0)+"=abs("+p_inputs[0]+"-"+p_inputs[1]+");\n"; - + print_line(OUTNAME(p_node->id,0)+"=abs("+p_inputs[0]+"-"+p_inputs[1]+");\n"); } break; case RGB_OP_DARKEN: { @@ -2233,11 +2267,15 @@ void ShaderGraph::_add_node_code(ShaderType p_type,Node *p_node,const Vectorid,0)+"="+p_inputs[0]+"*"+p_inputs[1]+";\n"; }break; case NODE_XFORM_VEC_MULT: { + DEF_MATRIX(0); + DEF_VEC(1); bool no_translation = p_node->param1; if (no_translation) { @@ -2248,6 +2286,8 @@ void ShaderGraph::_add_node_code(ShaderType p_type,Node *p_node,const Vectorparam1; if (no_translation) { code += OUTNAME(p_node->id,0)+"=("+p_inputs[1]+"*vec4("+p_inputs[0]+",0)).xyz;\n"; @@ -2256,6 +2296,7 @@ void ShaderGraph::_add_node_code(ShaderType p_type,Node *p_node,const Vectorid,0)+"=length("+p_inputs[0]+");\n"; }break; case NODE_DOT_PROD: { + DEF_VEC(0); + DEF_VEC(1); code += OUTNAME(p_node->id,0)+"=dot("+p_inputs[1]+","+p_inputs[0]+");\n"; }break; case NODE_VEC_TO_SCALAR: { + DEF_VEC(0); code += OUTNAME(p_node->id,0)+"="+p_inputs[0]+".x;\n"; code += OUTNAME(p_node->id,1)+"="+p_inputs[0]+".y;\n"; code += OUTNAME(p_node->id,2)+"="+p_inputs[0]+".z;\n"; }break; case NODE_SCALAR_TO_VEC: { + DEF_SCALAR(0); + DEF_SCALAR(1); + DEF_SCALAR(2); code += OUTNAME(p_node->id,0)+"=vec3("+p_inputs[0]+","+p_inputs[1]+","+p_inputs[2]+""+");\n"; }break; case NODE_VEC_TO_XFORM: { + DEF_VEC(0); + DEF_VEC(1); + DEF_VEC(2); + DEF_VEC(3); code += OUTNAME(p_node->id,0)+"=xform("+p_inputs[0]+","+p_inputs[1]+","+p_inputs[2]+","+","+p_inputs[3]+");\n"; }break; case NODE_XFORM_TO_VEC: { + DEF_MATRIX(0); code += OUTNAME(p_node->id,0)+"="+p_inputs[0]+".x;\n"; code += OUTNAME(p_node->id,1)+"="+p_inputs[0]+".y;\n"; code += OUTNAME(p_node->id,2)+"="+p_inputs[0]+".z;\n"; code += OUTNAME(p_node->id,3)+"="+p_inputs[0]+".o;\n"; }break; case NODE_SCALAR_INTERP: { + DEF_SCALAR(0); + DEF_SCALAR(1); + DEF_SCALAR(2); code += OUTNAME(p_node->id,0)+"=mix("+p_inputs[0]+","+p_inputs[1]+","+p_inputs[2]+");\n"; }break; case NODE_VEC_INTERP: { + DEF_VEC(0); + DEF_VEC(1); + DEF_SCALAR(2); code += OUTNAME(p_node->id,0)+"=mix("+p_inputs[0]+","+p_inputs[1]+","+p_inputs[2]+");\n"; }break; case NODE_COLOR_RAMP: { + DEF_SCALAR(0); static const int color_ramp_len=512; DVector cramp; @@ -2416,6 +2477,7 @@ void ShaderGraph::_add_node_code(ShaderType p_type,Node *p_node,const Vectorparam1; float dv=p_node->param2; code +="uniform float "+name+"="+rtos(dv)+";\n"; @@ -2520,6 +2585,7 @@ void ShaderGraph::_add_node_code(ShaderType p_type,Node *p_node,const Vectorparam1; String rname="rt_read_tex"+itos(p_node->id); code +="uniform texture "+name+";"; @@ -2529,7 +2595,7 @@ void ShaderGraph::_add_node_code(ShaderType p_type,Node *p_node,const Vectorparam1; code +="uniform cubemap "+name+";"; String rname="rt_read_tex"+itos(p_node->id); @@ -2538,6 +2604,7 @@ void ShaderGraph::_add_node_code(ShaderType p_type,Node *p_node,const Vectorid,1)+"="+rname+".a;\n"; }break; case NODE_DEFAULT_TEXTURE: { + DEF_VEC(0); if (get_mode()==MODE_CANVAS_ITEM && p_type==SHADER_TYPE_FRAGMENT) { diff --git a/tools/editor/plugins/shader_graph_editor_plugin.cpp b/tools/editor/plugins/shader_graph_editor_plugin.cpp index 12a9dce6b737..5da287aa69ad 100644 --- a/tools/editor/plugins/shader_graph_editor_plugin.cpp +++ b/tools/editor/plugins/shader_graph_editor_plugin.cpp @@ -2416,15 +2416,9 @@ void ShaderGraphView::_create_node(int p_id) { Array reals; reals.push_back("Alpha"); reals.push_back("NormapMapDepth"); + reals.push_back("SpecExp"); reals.push_back("LightAlpha"); reals.push_back("PointSize"); - Array vectors; - vectors.push_back("Normal"); - vectors.push_back("NormalMap"); - vectors.push_back("Vertex"); - vectors.push_back("UV"); - vectors.push_back("Var1"); - vectors.push_back("Var2"); int idx=0; for (List::Element *E=si.front();E;E=E->next()) { @@ -2435,7 +2429,7 @@ void ShaderGraphView::_create_node(int p_id) { v=Variant::COLOR; else if (reals.find(s.name)>=0) v=Variant::REAL; - else if (vectors.find(s.name)>=0) + else v=Variant::VECTOR3; gn->add_child(make_label(s.name, v)); gn->set_slot(idx,true,s.type,typecol[s.type],false,0,Color()); From 680402cebf63066abcc93e7e8035e457c6305874 Mon Sep 17 00:00:00 2001 From: Mariano Javier Suligoy Date: Sun, 30 Aug 2015 19:37:23 -0300 Subject: [PATCH 10/11] Add missing icons, also make MSVC2010 happy --- scene/gui/spin_box.cpp | 2 +- scene/gui/tree.cpp | 344 +++++++++--------- .../plugins/shader_graph_editor_plugin.cpp | 15 +- 3 files changed, 184 insertions(+), 177 deletions(-) diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp index 2478e3204cd6..aa20bc6f2288 100644 --- a/scene/gui/spin_box.cpp +++ b/scene/gui/spin_box.cpp @@ -125,7 +125,7 @@ void SpinBox::_input_event(const InputEvent& p_event) { if (drag.enabled) { float diff_y = drag.mouse_pos.y - cpos.y; - diff_y=pow(ABS(diff_y),1.8)*SGN(diff_y); + diff_y=pow((float)ABS(diff_y),(float)1.8)*SGN(diff_y); diff_y*=0.1; drag.mouse_pos=cpos; diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 252414cb3e05..7941ff36145f 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -121,7 +121,7 @@ void TreeItem::set_cell_mode( int p_column, TreeCellMode p_mode ) { c.val=0; c.checked=false; c.icon=Ref(); - c.text=""; + c.text=""; c.icon_max_w=0; _changed_notify(p_column); } @@ -153,9 +153,9 @@ void TreeItem::set_text(int p_column,String p_text) { ERR_FAIL_INDEX( p_column, cells.size() ); cells[p_column].text=p_text; - + if (cells[p_column].mode==TreeItem::CELL_MODE_RANGE) { - + cells[p_column].min=0; cells[p_column].max=p_text.get_slice_count(","); cells[p_column].step=0; @@ -225,7 +225,7 @@ void TreeItem::set_range(int p_column,double p_value) { p_value=cells[p_column].min; if (p_value>cells[p_column].max) p_value=cells[p_column].max; - + cells[p_column].val=p_value; _changed_notify(p_column); @@ -237,7 +237,7 @@ double TreeItem::get_range(int p_column) const { return cells[p_column].val; } - + bool TreeItem::is_range_exponential(int p_column) const { ERR_FAIL_INDEX_V( p_column, cells.size(), false); @@ -304,7 +304,7 @@ void TreeItem::set_collapsed(bool p_collapsed) { if (tree->select_mode==Tree::SELECT_MULTI) { - tree->selected_item=this; + tree->selected_item=this; emit_signal("cell_selected"); } else { @@ -337,11 +337,11 @@ TreeItem *TreeItem::get_prev() { if (!parent || parent->childs==this) return NULL; - + TreeItem *prev = parent->childs; while(prev && prev->next!=this) prev=prev->next; - + return prev; } @@ -636,14 +636,14 @@ void TreeItem::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_range","column"),&TreeItem::get_range); ObjectTypeDB::bind_method(_MD("set_range_config","column","min","max","step","expr"),&TreeItem::set_range_config,DEFVAL(false)); ObjectTypeDB::bind_method(_MD("get_range_config","column"),&TreeItem::_get_range_config); - + ObjectTypeDB::bind_method(_MD("set_metadata","column","meta"),&TreeItem::set_metadata); ObjectTypeDB::bind_method(_MD("get_metadata","column"),&TreeItem::get_metadata); ObjectTypeDB::bind_method(_MD("set_custom_draw","column","object","callback"),&TreeItem::set_custom_draw); ObjectTypeDB::bind_method(_MD("set_collapsed","enable"),&TreeItem::set_collapsed); - ObjectTypeDB::bind_method(_MD("is_collapsed"),&TreeItem::is_collapsed); + ObjectTypeDB::bind_method(_MD("is_collapsed"),&TreeItem::is_collapsed); ObjectTypeDB::bind_method(_MD("get_next:TreeItem"),&TreeItem::get_next); ObjectTypeDB::bind_method(_MD("get_prev:TreeItem"),&TreeItem::get_prev); @@ -654,17 +654,17 @@ void TreeItem::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_prev_visible:TreeItem"),&TreeItem::get_prev_visible); ObjectTypeDB::bind_method(_MD("remove_child:TreeItem","child"),&TreeItem::_remove_child); - + ObjectTypeDB::bind_method(_MD("set_selectable","column","selectable"),&TreeItem::set_selectable); ObjectTypeDB::bind_method(_MD("is_selectable","column"),&TreeItem::is_selectable); ObjectTypeDB::bind_method(_MD("is_selected","column"),&TreeItem::is_selected); ObjectTypeDB::bind_method(_MD("select","column"),&TreeItem::select); ObjectTypeDB::bind_method(_MD("deselect","column"),&TreeItem::deselect); - + ObjectTypeDB::bind_method(_MD("set_editable","column","enabled"),&TreeItem::set_editable); ObjectTypeDB::bind_method(_MD("is_editable","column"),&TreeItem::is_editable); - + ObjectTypeDB::bind_method(_MD("set_custom_color","column","color"),&TreeItem::set_custom_color); ObjectTypeDB::bind_method(_MD("clear_custom_color","column"),&TreeItem::clear_custom_color); @@ -688,7 +688,7 @@ void TreeItem::_bind_methods() { BIND_CONSTANT( CELL_MODE_RANGE ); BIND_CONSTANT( CELL_MODE_ICON ); BIND_CONSTANT( CELL_MODE_CUSTOM ); - + } @@ -774,7 +774,7 @@ void Tree::update_cache() { cache.arrow =get_icon("arrow"); cache.select_arrow =get_icon("select_arrow"); cache.updown=get_icon("updown"); - + cache.font_color=get_color("font_color"); cache.font_color_selected=get_color("font_color_selected"); cache.guide_color=get_color("guide_color"); @@ -802,10 +802,10 @@ int Tree::compute_item_height(TreeItem *p_item) const { if (p_item==root && hide_root) return 0; - + int height=cache.font->get_height(); - + for (int i=0;icells[i].mode) { - + case TreeItem::CELL_MODE_CHECK: { - + int check_icon_h = cache.checked->get_height(); if (height icon = p_item->cells[i].icon; if (!icon.is_null()) { - + Size2i s = p_item->cells[i].get_icon_size(); if (p_item->cells[i].icon_max_w>0 && s.width > p_item->cells[i].icon_max_w ) { s.height=s.height * p_item->cells[i].icon_max_w / s.width; @@ -843,15 +843,15 @@ int Tree::compute_item_height(TreeItem *p_item) const { if (s.height > height ) height=s.height; } - + } break; default: {} } } - - + + height += cache.vseparation; - + return height; } @@ -927,7 +927,7 @@ void Tree::draw_item_text(String p_text,const Ref& p_icon,int p_icon_ma p_rect.size.x-=Math::floor(p_rect.size.y/2); Ref font = cache.font; - + p_rect.pos.y+=Math::floor((p_rect.size.y-font->get_height())/2.0) +font->get_ascent(); font->draw(ci,p_rect.pos,p_text,p_color,p_rect.size.x); } @@ -950,13 +950,13 @@ int Tree::draw_item(const Point2i& p_pos,const Point2& p_draw_ofs, const Size2& Point2i guide_from; - bool skip=(p_item==root && hide_root); + bool skip=(p_item==root && hide_root); // printf("skip (%p == %p && %i) %i\n",p_item,root,hide_root,skip); if (!skip && (p_pos.y+label_h-cache.offset.y)>0) { - // printf("entering\n"); + // printf("entering\n"); int height=label_h; @@ -965,7 +965,7 @@ int Tree::draw_item(const Point2i& p_pos,const Point2& p_draw_ofs, const Size2& if (p_item->childs) { //has childs, draw the guide box Ref arrow; - + if (p_item->collapsed) { arrow=cache.arrow_collapsed; @@ -983,7 +983,7 @@ int Tree::draw_item(const Point2i& p_pos,const Point2& p_draw_ofs, const Size2& // if (p_item->get_parent()!=root || !hide_root) Ref font = cache.font; - + int font_ascent=font->get_ascent(); int ofs = p_pos.x + cache.item_margin; @@ -1066,7 +1066,7 @@ int Tree::draw_item(const Point2i& p_pos,const Point2& p_draw_ofs, const Size2& } Color col=p_item->cells[i].custom_color?p_item->cells[i].color:get_color( p_item->cells[i].selected?"font_color_selected":"font_color"); - + Point2i text_pos=item_rect.pos; text_pos.y+=Math::floor((item_rect.size.y-font->get_height())/2) + font_ascent; @@ -1104,7 +1104,7 @@ int Tree::draw_item(const Point2i& p_pos,const Point2& p_draw_ofs, const Size2& } break; case TreeItem::CELL_MODE_RANGE: { - + if (p_item->cells[i].text!="") { if (!p_item->cells[i].editable) @@ -1128,7 +1128,7 @@ int Tree::draw_item(const Point2i& p_pos,const Point2& p_draw_ofs, const Size2& } else { Ref updown = cache.updown; - + String valtext = String::num( p_item->cells[i].val, Math::decimals( p_item->cells[i].step ) ); font->draw( ci, text_pos, valtext, col, item_rect.size.x-updown->get_width()); @@ -1185,7 +1185,7 @@ int Tree::draw_item(const Point2i& p_pos,const Point2& p_draw_ofs, const Size2& Rect2i ir=item_rect; ir.size.width-=downarrow->get_width(); draw_item_rect(p_item->cells[i],ir,col); - + Point2i arrow_pos=item_rect.pos; arrow_pos.x+=item_rect.size.x-downarrow->get_width(); arrow_pos.y+=Math::floor(((item_rect.size.y-downarrow->get_height()))/2.0); @@ -1227,7 +1227,7 @@ int Tree::draw_item(const Point2i& p_pos,const Point2& p_draw_ofs, const Size2& children_pos.x+=cache.item_margin; htotal+=label_h; children_pos.y+=htotal; - + } @@ -1272,12 +1272,12 @@ void Tree::select_single_item(TreeItem *p_selected,TreeItem *p_current,int p_col continue; if (select_mode==SELECT_ROW) { - + if (p_selected==p_current) { - + if (!c.selected) { - + c.selected=true; selected_item=p_selected; selected_col=0; @@ -1286,26 +1286,26 @@ void Tree::select_single_item(TreeItem *p_selected,TreeItem *p_current,int p_col //if (p_col==i) // p_current->selected_signal.call(p_col); } - + } else { - + if (c.selected) { - - c.selected=false; + + c.selected=false; //p_current->deselected_signal.call(p_col); } - + } - + } else if (select_mode==SELECT_SINGLE || select_mode==SELECT_MULTI) { - + if (!r_in_range && &selected_cell==&c) { - + if (!selected_cell.selected) { - + selected_cell.selected=true; - + selected_item=p_selected; selected_col=i; @@ -1321,7 +1321,7 @@ void Tree::select_single_item(TreeItem *p_selected,TreeItem *p_current,int p_col } } else { - + if (r_in_range && *r_in_range) { @@ -1372,7 +1372,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos,int x_ofs,int y_ofs,bool p_ int item_h=compute_item_height( p_item )+cache.vseparation; bool skip=(p_item==root && hide_root); - + if (!skip && p_pos.y checked = cache.checked; bring_up_editor=false; //checkboxes are not edited with editor if (x>=0 && x<= checked->get_width()+cache.hseparation ) { - + p_item->set_checked(col,!c.checked); - item_edited(col,p_item); + item_edited(col,p_item); click_handled=true; //p_item->edited_signal.call(col); } @@ -1549,37 +1549,37 @@ int Tree::propagate_mouse_event(const Point2i &p_pos,int x_ofs,int y_ofs,bool p_ //} bring_up_editor=false; } else { - + Ref updown = cache.updown; - - + + if (x >= (col_width-item_h/2)) { - + /* touching the combo */ bool up=p_pos.y < (item_h /2); - + if (p_button==BUTTON_LEFT) { p_item->set_range( col, c.val + (up?1.0:-1.0) * c.step ); - - item_edited(col,p_item); + + item_edited(col,p_item); } else if (p_button==BUTTON_RIGHT) { - + p_item->set_range( col, (up?c.max:c.min) ); - item_edited(col,p_item); + item_edited(col,p_item); } else if (p_button==BUTTON_WHEEL_UP) { - + p_item->set_range( col, c.val + c.step ); - item_edited(col,p_item); + item_edited(col,p_item); } else if (p_button==BUTTON_WHEEL_DOWN) { - + p_item->set_range( col, c.val - c.step ); - item_edited(col,p_item); + item_edited(col,p_item); } - - //p_item->edited_signal.call(col); + + //p_item->edited_signal.call(col); bring_up_editor=false; - - + + } else { editor_text=String::num( p_item->cells[col].val, Math::decimals( p_item->cells[col].step ) ); @@ -1587,7 +1587,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos,int x_ofs,int y_ofs,bool p_ if (select_mode==SELECT_MULTI && get_tree()->get_last_event_id() == focus_in_id) bring_up_editor=false; - } + } } click_handled=true; @@ -1598,12 +1598,12 @@ int Tree::propagate_mouse_event(const Point2i &p_pos,int x_ofs,int y_ofs,bool p_ } break; case TreeItem::CELL_MODE_CUSTOM: { edited_item=p_item; - edited_col=col; + edited_col=col; custom_popup_rect=Rect2i(get_global_pos() + Point2i(col_ofs,_get_title_button_height()+y_ofs+item_h-cache.offset.y), Size2(get_column_width(col),item_h)); emit_signal("custom_popup_edited",((bool)(x >= (col_width-item_h/2)))); bring_up_editor=false; - item_edited(col,p_item); + item_edited(col,p_item); click_handled=true; return -1; } break; @@ -1615,7 +1615,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos,int x_ofs,int y_ofs,bool p_ - click_handled=true; + click_handled=true; popup_edited_item=p_item; popup_edited_item_col=col; @@ -1627,14 +1627,14 @@ int Tree::propagate_mouse_event(const Point2i &p_pos,int x_ofs,int y_ofs,bool p_ } else { Point2i new_pos=p_pos; - + if (!skip) { x_ofs+=cache.item_margin; //new_pos.x-=cache.item_margin; y_ofs+=item_h; new_pos.y-=item_h; } - + if (!p_item->collapsed) { /* if not collapsed, check the childs */ @@ -1697,7 +1697,7 @@ void Tree::text_editor_enter(String p_text) { default: { ERR_FAIL(); } } - item_edited(popup_edited_item_col,popup_edited_item); + item_edited(popup_edited_item_col,popup_edited_item); update(); } @@ -1725,19 +1725,19 @@ void Tree::popup_select(int p_option) { if (popup_edited_item_col<0 || popup_edited_item_col>columns.size()) return; - + popup_edited_item->cells[popup_edited_item_col].val=p_option; //popup_edited_item->edited_signal.call( popup_edited_item_col ); update(); - item_edited(popup_edited_item_col,popup_edited_item); + item_edited(popup_edited_item_col,popup_edited_item); } void Tree::_input_event(InputEvent p_event) { - + switch (p_event.type) { - + case InputEvent::KEY: { if (!p_event.key.pressed) @@ -2070,7 +2070,7 @@ void Tree::_input_event(InputEvent p_event) { TreeItem::Cell &c=popup_edited_item->cells[popup_edited_item_col]; float diff_y = -b.relative_y; - diff_y=pow(ABS(diff_y),1.8)*SGN(diff_y); + diff_y=pow((float)ABS(diff_y),(float)1.8)*SGN(diff_y); diff_y*=0.1; range_drag_base=CLAMP(range_drag_base + c.step * diff_y, c.min, c.max); @@ -2091,12 +2091,12 @@ void Tree::_input_event(InputEvent p_event) { } } break; case InputEvent::MOUSE_BUTTON: { - + if (cache.font.is_null()) // avoid a strange case that may fuckup stuff update_cache(); - const InputEventMouseButton& b=p_event.mouse_button; + const InputEventMouseButton& b=p_event.mouse_button; if (!b.pressed) { @@ -2160,7 +2160,7 @@ void Tree::_input_event(InputEvent p_event) { switch(b.button_index) { case BUTTON_LEFT: { Ref bg = cache.bg; - + Point2 pos = Point2(b.x,b.y) - bg->get_offset(); cache.click_type=Cache::CLICK_NONE; if (show_column_titles) { @@ -2222,18 +2222,18 @@ void Tree::_input_event(InputEvent p_event) { } break; - case BUTTON_WHEEL_UP: { + case BUTTON_WHEEL_UP: { v_scroll->set_val( v_scroll->get_val()-v_scroll->get_page()/8 ); } break; case BUTTON_WHEEL_DOWN: { - + v_scroll->set_val( v_scroll->get_val()+v_scroll->get_page()/8 ); } break; } - + } break; } - + } @@ -2331,10 +2331,10 @@ Size2 Tree::get_internal_min_size() const { if (root) size.height+=get_item_height(root); for (int i=0;iget_combined_minimum_size(); - + v_scroll->set_begin( Point2(size.width - vmin.width , cache.bg->get_margin(MARGIN_TOP)) ); v_scroll->set_end( Point2(size.width, size.height-cache.bg->get_margin(MARGIN_TOP)-cache.bg->get_margin(MARGIN_BOTTOM)) ); - + h_scroll->set_begin( Point2( 0, size.height - hmin.height) ); h_scroll->set_end( Point2(size.width-vmin.width, size.height) ); - - + + Size2 min = get_internal_min_size(); - + if (min.height < size.height - hmin.height) { - + v_scroll->hide(); cache.offset.y=0; } else { - + v_scroll->show(); v_scroll->set_max(min.height); v_scroll->set_page(size.height - hmin.height - tbh); cache.offset.y=v_scroll->get_val(); } - + if (min.width < size.width - vmin.width) { - + h_scroll->hide(); cache.offset.x=0; } else { - + h_scroll->show(); h_scroll->set_max(min.width); h_scroll->set_page(size.width - vmin.width); cache.offset.x=h_scroll->get_val(); - } + } } @@ -2464,16 +2464,16 @@ void Tree::_notification(int p_what) { } if (p_what==NOTIFICATION_DRAW) { - + update_cache(); update_scrollbars(); - RID ci = get_canvas_item(); - + RID ci = get_canvas_item(); + VisualServer::get_singleton()->canvas_item_set_clip(ci,true); - + Ref bg = cache.bg; Ref bg_focus = get_stylebox("bg_focus"); - + Point2 draw_ofs; draw_ofs+=bg->get_offset(); Size2 draw_size=get_size()-bg->get_minimum_size(); @@ -2491,7 +2491,7 @@ void Tree::_notification(int p_what) { draw_size.y-=tbh; if (root) { - + draw_item( Point2(),draw_ofs,draw_size,root); @@ -2502,10 +2502,10 @@ void Tree::_notification(int p_what) { // int size_y=exposed.size.height-bg->get_minimum_size().height; for (int i=0;i<(columns.size()-1-1);i++) { - + ofs+=get_column_width(i); //get_painter()->draw_fill_rect( Point2(ofs+cache.hseparation/2, from_y), Size2( 1, size_y ),color( COLOR_TREE_GRID) ); - } + } if (show_column_titles) { @@ -2605,7 +2605,7 @@ TreeItem* Tree::get_last_item() { } void Tree::item_edited(int p_column,TreeItem *p_item) { - + edited_item=p_item; edited_col=p_column; emit_signal("item_edited"); @@ -2613,14 +2613,14 @@ void Tree::item_edited(int p_column,TreeItem *p_item) { void Tree::item_changed(int p_column,TreeItem *p_item) { - update(); + update(); } void Tree::item_selected(int p_column,TreeItem *p_item) { if (select_mode==SELECT_MULTI) { - + if (!p_item->cells[p_column].selectable) return; @@ -2636,16 +2636,16 @@ void Tree::item_selected(int p_column,TreeItem *p_item) { void Tree::item_deselected(int p_column,TreeItem *p_item) { if (select_mode==SELECT_MULTI) { - + p_item->cells[p_column].selected=false; - } + } update(); } void Tree::set_select_mode(SelectMode p_mode) { - select_mode=p_mode; + select_mode=p_mode; } void Tree::clear() { @@ -2675,15 +2675,15 @@ void Tree::set_hide_root(bool p_enabled) { - hide_root=p_enabled; - update(); + hide_root=p_enabled; + update(); } void Tree::set_column_min_width(int p_column,int p_min_width) { ERR_FAIL_INDEX(p_column,columns.size()); - + if (p_min_width<1) return; columns[p_column].min_width=p_min_width; @@ -2693,8 +2693,8 @@ void Tree::set_column_min_width(int p_column,int p_min_width) { void Tree::set_column_expand(int p_column,bool p_expand) { ERR_FAIL_INDEX(p_column,columns.size()); - - columns[p_column].expand=p_expand; + + columns[p_column].expand=p_expand; update(); } @@ -2709,78 +2709,78 @@ int Tree::get_selected_column() const { } TreeItem *Tree::get_edited() const { - + return edited_item; } int Tree::get_edited_column() const { - + return edited_col; } TreeItem* Tree::get_next_selected( TreeItem* p_item) { - + //if (!p_item) // return NULL; if (!root) - return NULL; - + return NULL; + while(true) { - - + + if (!p_item) { p_item=root; } else { - + if (p_item->childs) { - + p_item=p_item->childs; - + } else if (p_item->next) { - - p_item=p_item->next; + + p_item=p_item->next; } else { - + while(!p_item->next) { - + p_item=p_item->parent; if (p_item==NULL) return NULL; } - + p_item=p_item->next; } - + } - + for (int i=0;icells[i].selected) return p_item; } - + return NULL; } int Tree::get_column_width(int p_column) const { - + ERR_FAIL_INDEX_V(p_column,columns.size(),-1); - - + + if (!columns[p_column].expand) return columns[p_column].min_width; - + Ref bg = cache.bg; - + int expand_area=get_size().width-(bg->get_margin(MARGIN_LEFT)+bg->get_margin(MARGIN_RIGHT)); - + if (v_scroll->is_visible()) expand_area-=v_scroll->get_combined_minimum_size().width; - + int expanding_columns=0; int expanding_total=0; - + for (int i=0;icells.resize( columns.size() ); - + TreeItem *c = p_item->get_children(); while(c) { - + propagate_set_columns(c); c=c->get_next(); } } void Tree::set_columns(int p_columns) { - + ERR_FAIL_COND(p_columns<1); ERR_FAIL_COND(blocked>0); columns.resize(p_columns); - + if (root) propagate_set_columns(root); if (selected_col>=p_columns) @@ -2824,17 +2824,17 @@ void Tree::set_columns(int p_columns) { } int Tree::get_columns() const { - + return columns.size(); } void Tree::_scroll_moved(float) { - + update(); } Rect2 Tree::get_custom_popup_rect() const { - + return custom_popup_rect; } @@ -3116,7 +3116,7 @@ bool Tree::can_cursor_exit_tree() const { void Tree::_bind_methods() { - + ObjectTypeDB::bind_method(_MD("_input_event"),&Tree::_input_event); ObjectTypeDB::bind_method(_MD("_popup_select"),&Tree::popup_select); ObjectTypeDB::bind_method(_MD("_text_editor_enter"),&Tree::text_editor_enter); @@ -3140,7 +3140,7 @@ void Tree::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_columns","amount"),&Tree::set_columns); ObjectTypeDB::bind_method(_MD("get_columns"),&Tree::get_columns); - + ObjectTypeDB::bind_method(_MD("get_edited:TreeItem"),&Tree::get_edited); ObjectTypeDB::bind_method(_MD("get_edited_column"),&Tree::get_edited_column); ObjectTypeDB::bind_method(_MD("get_custom_popup_rect"),&Tree::get_custom_popup_rect); @@ -3179,7 +3179,7 @@ Tree::Tree() { edited_item=NULL; selected_col=-1; edited_col=-1; - + hide_root=false; select_mode=SELECT_SINGLE; root=0; @@ -3187,8 +3187,8 @@ Tree::Tree() { popup_edited_item=NULL; text_editor=NULL; set_focus_mode(FOCUS_ALL); - - + + popup_menu = memnew( PopupMenu ); popup_menu->hide(); add_child(popup_menu); @@ -3204,7 +3204,7 @@ Tree::Tree() { h_scroll = memnew( HScrollBar ); v_scroll = memnew( VScrollBar ); - + add_child(h_scroll); add_child(v_scroll); @@ -3250,6 +3250,6 @@ Tree::~Tree() { if (root) { memdelete( root ); } - + } diff --git a/tools/editor/plugins/shader_graph_editor_plugin.cpp b/tools/editor/plugins/shader_graph_editor_plugin.cpp index 5da287aa69ad..1997b268a7d2 100644 --- a/tools/editor/plugins/shader_graph_editor_plugin.cpp +++ b/tools/editor/plugins/shader_graph_editor_plugin.cpp @@ -2413,12 +2413,21 @@ void ShaderGraphView::_create_node(int p_id) { Array colors; colors.push_back("Color"); colors.push_back("LightColor"); + colors.push_back("Light"); + colors.push_back("Diffuse"); + colors.push_back("Specular"); + colors.push_back("Emmision"); Array reals; reals.push_back("Alpha"); - reals.push_back("NormapMapDepth"); + reals.push_back("DiffuseAlpha"); + reals.push_back("NormalMapDepth"); reals.push_back("SpecExp"); + reals.push_back("Glow"); + reals.push_back("ShadeParam"); + reals.push_back("SpecularExp"); reals.push_back("LightAlpha"); reals.push_back("PointSize"); + reals.push_back("Discard"); int idx=0; for (List::Element *E=si.front();E;E=E->next()) { @@ -2739,10 +2748,8 @@ const char* ShaderGraphEditor::node_names[ShaderGraph::NODE_TYPE_MAX]={ ShaderGraphEditor::ShaderGraphEditor(bool p_2d) { _2d=p_2d; - HBoxContainer *hbc = memnew( HBoxContainer ); popup = memnew( PopupMenu ); - hbc->add_child(popup); - add_child(hbc); + add_child(popup); tabs = memnew(TabContainer); From 25324aa5061b07df6da877e94c8c23fbe7f34f6e Mon Sep 17 00:00:00 2001 From: MarianoGNU Date: Sat, 17 Oct 2015 15:27:36 -0300 Subject: [PATCH 11/11] Fix crash when using a Scalar Uniform node to GraphShader --- scene/resources/shader_graph.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scene/resources/shader_graph.cpp b/scene/resources/shader_graph.cpp index 4604c42de111..49a1bdccb1ed 100644 --- a/scene/resources/shader_graph.cpp +++ b/scene/resources/shader_graph.cpp @@ -2196,7 +2196,6 @@ void ShaderGraph::_add_node_code(ShaderType p_type,Node *p_node,const Vectorid,0)+"=abs("+p_inputs[0]+"-"+p_inputs[1]+");\n"; - print_line(OUTNAME(p_node->id,0)+"=abs("+p_inputs[0]+"-"+p_inputs[1]+");\n"); } break; case RGB_OP_DARKEN: { @@ -2545,9 +2544,6 @@ void ShaderGraph::_add_node_code(ShaderType p_type,Node *p_node,const Vectorparam1; float dv=p_node->param2; code +="uniform float "+name+"="+rtos(dv)+";\n"; @@ -2631,4 +2627,8 @@ void ShaderGraph::_add_node_code(ShaderType p_type,Node *p_node,const Vector