diff options
Diffstat (limited to 'scene/gui/graph_edit_arranger.cpp')
-rw-r--r-- | scene/gui/graph_edit_arranger.cpp | 68 |
1 files changed, 33 insertions, 35 deletions
diff --git a/scene/gui/graph_edit_arranger.cpp b/scene/gui/graph_edit_arranger.cpp index 345421db31..49998beb42 100644 --- a/scene/gui/graph_edit_arranger.cpp +++ b/scene/gui/graph_edit_arranger.cpp @@ -65,8 +65,7 @@ void GraphEditArranger::arrange_nodes() { float gap_v = 100.0f; float gap_h = 100.0f; - List<GraphEdit::Connection> connection_list; - graph_edit->get_connection_list(&connection_list); + List<Ref<GraphEdit::Connection>> connection_list = graph_edit->get_connection_list(); for (int i = graph_edit->get_child_count() - 1; i >= 0; i--) { GraphNode *graph_element = Object::cast_to<GraphNode>(graph_edit->get_child(i)); @@ -77,15 +76,16 @@ void GraphEditArranger::arrange_nodes() { if (graph_element->is_selected() || arrange_entire_graph) { selected_nodes.insert(graph_element->get_name()); HashSet<StringName> s; - for (List<GraphEdit::Connection>::Element *E = connection_list.front(); E; E = E->next()) { - GraphNode *p_from = Object::cast_to<GraphNode>(node_names[E->get().from_node]); - if (E->get().to_node == graph_element->get_name() && (p_from->is_selected() || arrange_entire_graph) && E->get().to_node != E->get().from_node) { + + for (const Ref<GraphEdit::Connection> &connection : connection_list) { + GraphNode *p_from = Object::cast_to<GraphNode>(node_names[connection->from_node]); + if (connection->to_node == graph_element->get_name() && (p_from->is_selected() || arrange_entire_graph) && connection->to_node != connection->from_node) { if (!s.has(p_from->get_name())) { s.insert(p_from->get_name()); } - String s_connection = String(p_from->get_name()) + " " + String(E->get().to_node); + String s_connection = String(p_from->get_name()) + " " + String(connection->to_node); StringName _connection(s_connection); - Pair<int, int> ports(E->get().from_port, E->get().to_port); + Pair<int, int> ports(connection->from_port, connection->to_port); port_info.insert(_connection, ports); } } @@ -421,7 +421,7 @@ void GraphEditArranger::_calculate_inner_shifts(Dictionary &r_inner_shifts, cons } } -float GraphEditArranger::_calculate_threshold(StringName p_v, StringName p_w, const Dictionary &r_node_names, const HashMap<int, Vector<StringName>> &r_layers, const Dictionary &r_root, const Dictionary &r_align, const Dictionary &r_inner_shift, real_t p_current_threshold, const HashMap<StringName, Vector2> &r_node_positions) { +float GraphEditArranger::_calculate_threshold(const StringName &p_v, const StringName &p_w, const Dictionary &r_node_names, const HashMap<int, Vector<StringName>> &r_layers, const Dictionary &r_root, const Dictionary &r_align, const Dictionary &r_inner_shift, real_t p_current_threshold, const HashMap<StringName, Vector2> &r_node_positions) { #define MAX_ORDER 2147483647 #define ORDER(node, layers) \ for (unsigned int i = 0; i < layers.size(); i++) { \ @@ -437,31 +437,30 @@ float GraphEditArranger::_calculate_threshold(StringName p_v, StringName p_w, co float threshold = p_current_threshold; if (p_v == p_w) { int min_order = MAX_ORDER; - GraphEdit::Connection incoming; - List<GraphEdit::Connection> connection_list; - graph_edit->get_connection_list(&connection_list); - for (List<GraphEdit::Connection>::Element *E = connection_list.front(); E; E = E->next()) { - if (E->get().to_node == p_w) { - ORDER(E->get().from_node, r_layers); + Ref<GraphEdit::Connection> incoming; + List<Ref<GraphEdit::Connection>> connection_list = graph_edit->get_connection_list(); + for (const Ref<GraphEdit::Connection> &connection : connection_list) { + if (connection->to_node == p_w) { + ORDER(connection->from_node, r_layers); if (min_order > order) { min_order = order; - incoming = E->get(); + incoming = connection; } } } - if (incoming.from_node != StringName()) { - GraphNode *gnode_from = Object::cast_to<GraphNode>(r_node_names[incoming.from_node]); + if (incoming.is_valid()) { + GraphNode *gnode_from = Object::cast_to<GraphNode>(r_node_names[incoming->from_node]); GraphNode *gnode_to = Object::cast_to<GraphNode>(r_node_names[p_w]); - Vector2 pos_from = gnode_from->get_output_port_position(incoming.from_port) * graph_edit->get_zoom(); - Vector2 pos_to = gnode_to->get_input_port_position(incoming.to_port) * graph_edit->get_zoom(); + Vector2 pos_from = gnode_from->get_output_port_position(incoming->from_port) * graph_edit->get_zoom(); + Vector2 pos_to = gnode_to->get_input_port_position(incoming->to_port) * graph_edit->get_zoom(); // If connected block node is selected, calculate thershold or add current block to list. if (gnode_from->is_selected()) { - Vector2 connected_block_pos = r_node_positions[r_root[incoming.from_node]]; + Vector2 connected_block_pos = r_node_positions[r_root[incoming->from_node]]; if (connected_block_pos.y != FLT_MAX) { //Connected block is placed, calculate threshold. - threshold = connected_block_pos.y + (real_t)r_inner_shift[incoming.from_node] - (real_t)r_inner_shift[p_w] + pos_from.y - pos_to.y; + threshold = connected_block_pos.y + (real_t)r_inner_shift[incoming->from_node] - (real_t)r_inner_shift[p_w] + pos_from.y - pos_to.y; } } } @@ -469,31 +468,30 @@ float GraphEditArranger::_calculate_threshold(StringName p_v, StringName p_w, co if (threshold == FLT_MIN && (StringName)r_align[p_w] == p_v) { // This time, pick an outgoing edge and repeat as above! int min_order = MAX_ORDER; - GraphEdit::Connection outgoing; - List<GraphEdit::Connection> connection_list; - graph_edit->get_connection_list(&connection_list); - for (List<GraphEdit::Connection>::Element *E = connection_list.front(); E; E = E->next()) { - if (E->get().from_node == p_w) { - ORDER(E->get().to_node, r_layers); + Ref<GraphEdit::Connection> outgoing; + List<Ref<GraphEdit::Connection>> connection_list = graph_edit->get_connection_list(); + for (const Ref<GraphEdit::Connection> &connection : connection_list) { + if (connection->from_node == p_w) { + ORDER(connection->to_node, r_layers); if (min_order > order) { min_order = order; - outgoing = E->get(); + outgoing = connection; } } } - if (outgoing.to_node != StringName()) { + if (outgoing.is_valid()) { GraphNode *gnode_from = Object::cast_to<GraphNode>(r_node_names[p_w]); - GraphNode *gnode_to = Object::cast_to<GraphNode>(r_node_names[outgoing.to_node]); - Vector2 pos_from = gnode_from->get_output_port_position(outgoing.from_port) * graph_edit->get_zoom(); - Vector2 pos_to = gnode_to->get_input_port_position(outgoing.to_port) * graph_edit->get_zoom(); + GraphNode *gnode_to = Object::cast_to<GraphNode>(r_node_names[outgoing->to_node]); + Vector2 pos_from = gnode_from->get_output_port_position(outgoing->from_port) * graph_edit->get_zoom(); + Vector2 pos_to = gnode_to->get_input_port_position(outgoing->to_port) * graph_edit->get_zoom(); // If connected block node is selected, calculate thershold or add current block to list. if (gnode_to->is_selected()) { - Vector2 connected_block_pos = r_node_positions[r_root[outgoing.to_node]]; + Vector2 connected_block_pos = r_node_positions[r_root[outgoing->to_node]]; if (connected_block_pos.y != FLT_MAX) { //Connected block is placed. Calculate threshold - threshold = connected_block_pos.y + (real_t)r_inner_shift[outgoing.to_node] - (real_t)r_inner_shift[p_w] + pos_from.y - pos_to.y; + threshold = connected_block_pos.y + (real_t)r_inner_shift[outgoing->to_node] - (real_t)r_inner_shift[p_w] + pos_from.y - pos_to.y; } } } @@ -503,7 +501,7 @@ float GraphEditArranger::_calculate_threshold(StringName p_v, StringName p_w, co return threshold; } -void GraphEditArranger::_place_block(StringName p_v, float p_delta, const HashMap<int, Vector<StringName>> &r_layers, const Dictionary &r_root, const Dictionary &r_align, const Dictionary &r_node_name, const Dictionary &r_inner_shift, Dictionary &r_sink, Dictionary &r_shift, HashMap<StringName, Vector2> &r_node_positions) { +void GraphEditArranger::_place_block(const StringName &p_v, float p_delta, const HashMap<int, Vector<StringName>> &r_layers, const Dictionary &r_root, const Dictionary &r_align, const Dictionary &r_node_name, const Dictionary &r_inner_shift, Dictionary &r_sink, Dictionary &r_shift, HashMap<StringName, Vector2> &r_node_positions) { #define PRED(node, layers) \ for (unsigned int i = 0; i < layers.size(); i++) { \ int index = layers[i].find(node); \ |