void GraphEdit::_connections_layer_draw() { Color activity_color = get_color("activity"); //draw connections List<List<Connection>::Element *> to_erase; for (List<Connection>::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 = Object::cast_to<GraphNode>(from); 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 = Object::cast_to<GraphNode>(to); if (!gto) { to_erase.push_back(E); continue; } Vector2 frompos = gfrom->get_connection_output_position(E->get().from_port) + gfrom->get_offset() * zoom; Color color = gfrom->get_connection_output_color(E->get().from_port); Vector2 topos = gto->get_connection_input_position(E->get().to_port) + gto->get_offset() * zoom; Color tocolor = gto->get_connection_input_color(E->get().to_port); if (E->get().activity > 0) { color = color.linear_interpolate(activity_color, E->get().activity); tocolor = tocolor.linear_interpolate(activity_color, E->get().activity); } _draw_cos_line(connections_layer, frompos, topos, color, tocolor); } while (to_erase.size()) { connections.erase(to_erase.front()->get()); to_erase.pop_front(); } }
void GraphEdit::_update_scroll() { if (updating) return; updating = true; set_block_minimum_size_adjust(true); Rect2 screen; for (int i = 0; i < get_child_count(); i++) { GraphNode *gn = Object::cast_to<GraphNode>(get_child(i)); if (!gn) continue; Rect2 r; r.position = gn->get_offset() * zoom; r.size = gn->get_size() * zoom; screen = screen.merge(r); } screen.position -= get_size(); screen.size += get_size() * 2.0; h_scroll->set_min(screen.position.x); h_scroll->set_max(screen.position.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.position.y); v_scroll->set_max(screen.position.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(); set_block_minimum_size_adjust(false); if (!awaiting_scroll_offset_update) { call_deferred("_update_scroll_offset"); awaiting_scroll_offset_update = true; } updating = false; }
void GraphEdit::_update_scroll_offset() { set_block_minimum_size_adjust(true); for (int i = 0; i < get_child_count(); i++) { GraphNode *gn = Object::cast_to<GraphNode>(get_child(i)); if (!gn) continue; Point2 pos = gn->get_offset() * zoom; pos -= Point2(h_scroll->get_value(), v_scroll->get_value()); gn->set_position(pos); if (gn->get_scale() != Vector2(zoom, zoom)) { gn->set_scale(Vector2(zoom, zoom)); } } connections_layer->set_position(-Point2(h_scroll->get_value(), v_scroll->get_value())); set_block_minimum_size_adjust(false); awaiting_scroll_offset_update = false; }