From 5b71fc45b703d2ea44cc1aa99830ec3e0966b3e6 Mon Sep 17 00:00:00 2001 From: Mariano Javier Suligoy Date: Thu, 16 Jul 2015 22:38:12 -0300 Subject: Use popup menu to add new nodes to the shader graph editor in the last clicked location. --- scene/gui/graph_edit.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'scene/gui') diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index 3cd0dd3d16..d0ff4e48d3 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"))); } -- cgit v1.2.3 From bdd12744fe340152cef5bf88de9e2d183bff1790 Mon Sep 17 00:00:00 2001 From: Mariano Javier Suligoy Date: Sun, 19 Jul 2015 01:48:46 -0300 Subject: 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 +++---- 4 files changed, 939 insertions(+), 839 deletions(-) (limited to 'scene/gui') diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index d0ff4e48d3..4569c71d0b 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 0a9da73ab6..2f9a5fc954 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 444b37855f..760eb6ceed 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 0d5cbf8dd3..6bece22ac5 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(); }; -- cgit v1.2.3 From 2a43778793ba67c7edb7d96ab30c4c2a8c145c70 Mon Sep 17 00:00:00 2001 From: Mariano Javier Suligoy Date: Mon, 20 Jul 2015 22:15:06 -0300 Subject: 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 +++---- 4 files changed, 909 insertions(+), 909 deletions(-) (limited to 'scene/gui') diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index 4569c71d0b..22a03504c6 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 2f9a5fc954..5ab0f3300e 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 760eb6ceed..f0917aa4d1 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 6bece22ac5..201529380d 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(); }; -- cgit v1.2.3 From bdde79a3f433dbff244e544b72ac8946d8d9b44b Mon Sep 17 00:00:00 2001 From: Mariano Javier Suligoy Date: Fri, 24 Jul 2015 21:59:48 -0300 Subject: Box selection for GraphNodes --- scene/gui/graph_edit.cpp | 91 +++++++++++++++++++++++++++++++++++++++++++----- scene/gui/graph_edit.h | 7 ++++ 2 files changed, 90 insertions(+), 8 deletions(-) (limited to 'scene/gui') diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index 22a03504c6..003486dcf1 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 5ab0f3300e..44f5a369c2 100644 --- a/scene/gui/graph_edit.h +++ b/scene/gui/graph_edit.h @@ -53,6 +53,13 @@ private: 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; -- cgit v1.2.3 From 5ffd818fb195a6e9bea48ec03ad52a77080a8d25 Mon Sep 17 00:00:00 2001 From: Mariano Javier Suligoy Date: Sat, 25 Jul 2015 21:16:07 -0300 Subject: Duplicate GraphNode(s) [Control+D] --- scene/gui/graph_edit.cpp | 10 +++++++++- scene/gui/graph_node.cpp | 18 ++++++++++-------- 2 files changed, 19 insertions(+), 9 deletions(-) (limited to 'scene/gui') diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index 003486dcf1..a81542ea17 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 f0917aa4d1..5efc9757b7 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"); - } } -- cgit v1.2.3 From d7279ddaf2aa98ed962d84d466f21dc2f39522c9 Mon Sep 17 00:00:00 2001 From: Mariano Javier Suligoy Date: Sun, 26 Jul 2015 21:57:27 -0300 Subject: Delete selected nodes with the Delete key --- scene/gui/graph_edit.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'scene/gui') diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index a81542ea17..deb3151798 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")); } -- cgit v1.2.3 From 680402cebf63066abcc93e7e8035e457c6305874 Mon Sep 17 00:00:00 2001 From: Mariano Javier Suligoy Date: Sun, 30 Aug 2015 19:37:23 -0300 Subject: Add missing icons, also make MSVC2010 happy --- scene/gui/spin_box.cpp | 2 +- scene/gui/tree.cpp | 344 ++++++++++++++++++++++++------------------------- 2 files changed, 173 insertions(+), 173 deletions(-) (limited to 'scene/gui') diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp index 2478e3204c..aa20bc6f22 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 252414cb3e..7941ff3614 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 ); } - + } -- cgit v1.2.3