You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-05 12:10:55 +00:00
Clean up/refactor GraphNode and make it more flexible
Split GraphNode into GraphElement and GraphNode, add custom titlebar, and adjust theming.
This commit is contained in:
@@ -295,16 +295,16 @@ void GraphEdit::_update_scroll_offset() {
|
||||
set_block_minimum_size_adjust(true);
|
||||
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
GraphNode *graph_node = Object::cast_to<GraphNode>(get_child(i));
|
||||
if (!graph_node) {
|
||||
GraphElement *graph_element = Object::cast_to<GraphElement>(get_child(i));
|
||||
if (!graph_element) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Point2 pos = graph_node->get_position_offset() * zoom;
|
||||
Point2 pos = graph_element->get_position_offset() * zoom;
|
||||
pos -= Point2(h_scrollbar->get_value(), v_scrollbar->get_value());
|
||||
graph_node->set_position(pos);
|
||||
if (graph_node->get_scale() != Vector2(zoom, zoom)) {
|
||||
graph_node->set_scale(Vector2(zoom, zoom));
|
||||
graph_element->set_position(pos);
|
||||
if (graph_element->get_scale() != Vector2(zoom, zoom)) {
|
||||
graph_element->set_scale(Vector2(zoom, zoom));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -328,14 +328,14 @@ void GraphEdit::_update_scroll() {
|
||||
|
||||
Rect2 screen_rect;
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
GraphNode *graph_node = Object::cast_to<GraphNode>(get_child(i));
|
||||
if (!graph_node) {
|
||||
GraphElement *graph_element = Object::cast_to<GraphElement>(get_child(i));
|
||||
if (!graph_element) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Rect2 node_rect;
|
||||
node_rect.position = graph_node->get_position_offset() * zoom;
|
||||
node_rect.size = graph_node->get_size() * zoom;
|
||||
node_rect.position = graph_element->get_position_offset() * zoom;
|
||||
node_rect.size = graph_element->get_size() * zoom;
|
||||
screen_rect = screen_rect.merge(node_rect);
|
||||
}
|
||||
|
||||
@@ -378,46 +378,48 @@ void GraphEdit::_update_scroll() {
|
||||
updating = false;
|
||||
}
|
||||
|
||||
void GraphEdit::_graph_node_moved_to_front(Node *p_gn) {
|
||||
GraphNode *graph_node = Object::cast_to<GraphNode>(p_gn);
|
||||
ERR_FAIL_NULL(graph_node);
|
||||
void GraphEdit::_graph_element_moved_to_front(Node *p_node) {
|
||||
GraphElement *graph_element = Object::cast_to<GraphElement>(p_node);
|
||||
ERR_FAIL_NULL(graph_element);
|
||||
|
||||
graph_node->move_to_front();
|
||||
graph_element->move_to_front();
|
||||
}
|
||||
|
||||
void GraphEdit::_graph_node_selected(Node *p_gn) {
|
||||
GraphNode *graph_node = Object::cast_to<GraphNode>(p_gn);
|
||||
ERR_FAIL_NULL(graph_node);
|
||||
void GraphEdit::_graph_element_selected(Node *p_node) {
|
||||
GraphElement *graph_element = Object::cast_to<GraphElement>(p_node);
|
||||
ERR_FAIL_NULL(graph_element);
|
||||
|
||||
emit_signal(SNAME("node_selected"), graph_node);
|
||||
emit_signal(SNAME("node_selected"), graph_element);
|
||||
}
|
||||
|
||||
void GraphEdit::_graph_node_deselected(Node *p_gn) {
|
||||
GraphNode *graph_node = Object::cast_to<GraphNode>(p_gn);
|
||||
ERR_FAIL_NULL(graph_node);
|
||||
void GraphEdit::_graph_element_deselected(Node *p_node) {
|
||||
GraphElement *graph_element = Object::cast_to<GraphElement>(p_node);
|
||||
ERR_FAIL_NULL(graph_element);
|
||||
|
||||
emit_signal(SNAME("node_deselected"), graph_node);
|
||||
emit_signal(SNAME("node_deselected"), graph_element);
|
||||
}
|
||||
|
||||
void GraphEdit::_graph_node_resized(Vector2 p_new_minsize, Node *p_gn) {
|
||||
GraphNode *graph_node = Object::cast_to<GraphNode>(p_gn);
|
||||
ERR_FAIL_NULL(graph_node);
|
||||
void GraphEdit::_graph_element_resized(Vector2 p_new_minsize, Node *p_node) {
|
||||
GraphElement *graph_element = Object::cast_to<GraphElement>(p_node);
|
||||
ERR_FAIL_NULL(graph_element);
|
||||
|
||||
graph_node->set_custom_minimum_size(p_new_minsize);
|
||||
graph_element->set_size(p_new_minsize);
|
||||
}
|
||||
|
||||
void GraphEdit::_graph_node_moved(Node *p_gn) {
|
||||
GraphNode *graph_node = Object::cast_to<GraphNode>(p_gn);
|
||||
ERR_FAIL_NULL(graph_node);
|
||||
void GraphEdit::_graph_element_moved(Node *p_node) {
|
||||
GraphElement *graph_element = Object::cast_to<GraphElement>(p_node);
|
||||
ERR_FAIL_NULL(graph_element);
|
||||
|
||||
top_layer->queue_redraw();
|
||||
minimap->queue_redraw();
|
||||
queue_redraw();
|
||||
connections_layer->queue_redraw();
|
||||
}
|
||||
|
||||
void GraphEdit::_graph_node_slot_updated(int p_index, Node *p_gn) {
|
||||
GraphNode *graph_node = Object::cast_to<GraphNode>(p_gn);
|
||||
void GraphEdit::_graph_node_slot_updated(int p_index, Node *p_node) {
|
||||
GraphNode *graph_node = Object::cast_to<GraphNode>(p_node);
|
||||
ERR_FAIL_NULL(graph_node);
|
||||
|
||||
top_layer->queue_redraw();
|
||||
minimap->queue_redraw();
|
||||
queue_redraw();
|
||||
@@ -430,19 +432,25 @@ void GraphEdit::add_child_notify(Node *p_child) {
|
||||
// Keep the top layer always on top!
|
||||
callable_mp((CanvasItem *)top_layer, &CanvasItem::move_to_front).call_deferred();
|
||||
|
||||
GraphNode *graph_node = Object::cast_to<GraphNode>(p_child);
|
||||
if (graph_node) {
|
||||
graph_node->set_scale(Vector2(zoom, zoom));
|
||||
graph_node->connect("position_offset_changed", callable_mp(this, &GraphEdit::_graph_node_moved).bind(graph_node));
|
||||
graph_node->connect("node_selected", callable_mp(this, &GraphEdit::_graph_node_selected).bind(graph_node));
|
||||
graph_node->connect("node_deselected", callable_mp(this, &GraphEdit::_graph_node_deselected).bind(graph_node));
|
||||
graph_node->connect("slot_updated", callable_mp(this, &GraphEdit::_graph_node_slot_updated).bind(graph_node));
|
||||
graph_node->connect("raise_request", callable_mp(this, &GraphEdit::_graph_node_moved_to_front).bind(graph_node));
|
||||
graph_node->connect("resize_request", callable_mp(this, &GraphEdit::_graph_node_resized).bind(graph_node));
|
||||
graph_node->connect("item_rect_changed", callable_mp((CanvasItem *)connections_layer, &CanvasItem::queue_redraw));
|
||||
graph_node->connect("item_rect_changed", callable_mp((CanvasItem *)minimap, &GraphEditMinimap::queue_redraw));
|
||||
_graph_node_moved(graph_node);
|
||||
graph_node->set_mouse_filter(MOUSE_FILTER_PASS);
|
||||
GraphElement *graph_element = Object::cast_to<GraphElement>(p_child);
|
||||
if (graph_element) {
|
||||
graph_element->connect("position_offset_changed", callable_mp(this, &GraphEdit::_graph_element_moved).bind(graph_element));
|
||||
graph_element->connect("node_selected", callable_mp(this, &GraphEdit::_graph_element_selected).bind(graph_element));
|
||||
graph_element->connect("node_deselected", callable_mp(this, &GraphEdit::_graph_element_deselected).bind(graph_element));
|
||||
|
||||
GraphNode *graph_node = Object::cast_to<GraphNode>(graph_element);
|
||||
if (graph_node) {
|
||||
graph_element->connect("slot_updated", callable_mp(this, &GraphEdit::_graph_node_slot_updated).bind(graph_element));
|
||||
}
|
||||
|
||||
graph_element->connect("raise_request", callable_mp(this, &GraphEdit::_graph_element_moved_to_front).bind(graph_element));
|
||||
graph_element->connect("resize_request", callable_mp(this, &GraphEdit::_graph_element_resized).bind(graph_element));
|
||||
graph_element->connect("item_rect_changed", callable_mp((CanvasItem *)connections_layer, &CanvasItem::queue_redraw));
|
||||
graph_element->connect("item_rect_changed", callable_mp((CanvasItem *)minimap, &GraphEditMinimap::queue_redraw));
|
||||
|
||||
graph_element->set_scale(Vector2(zoom, zoom));
|
||||
_graph_element_moved(graph_element);
|
||||
graph_element->set_mouse_filter(MOUSE_FILTER_PASS);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -461,20 +469,26 @@ void GraphEdit::remove_child_notify(Node *p_child) {
|
||||
callable_mp((CanvasItem *)top_layer, &CanvasItem::move_to_front).call_deferred();
|
||||
}
|
||||
|
||||
GraphNode *graph_node = Object::cast_to<GraphNode>(p_child);
|
||||
if (graph_node) {
|
||||
graph_node->disconnect("position_offset_changed", callable_mp(this, &GraphEdit::_graph_node_moved));
|
||||
graph_node->disconnect("node_selected", callable_mp(this, &GraphEdit::_graph_node_selected));
|
||||
graph_node->disconnect("node_deselected", callable_mp(this, &GraphEdit::_graph_node_deselected));
|
||||
graph_node->disconnect("slot_updated", callable_mp(this, &GraphEdit::_graph_node_slot_updated));
|
||||
graph_node->disconnect("raise_request", callable_mp(this, &GraphEdit::_graph_node_moved_to_front));
|
||||
GraphElement *graph_element = Object::cast_to<GraphElement>(p_child);
|
||||
if (graph_element) {
|
||||
graph_element->disconnect("position_offset_changed", callable_mp(this, &GraphEdit::_graph_element_moved));
|
||||
graph_element->disconnect("node_selected", callable_mp(this, &GraphEdit::_graph_element_selected));
|
||||
graph_element->disconnect("node_deselected", callable_mp(this, &GraphEdit::_graph_element_deselected));
|
||||
|
||||
GraphNode *graph_node = Object::cast_to<GraphNode>(graph_element);
|
||||
if (graph_node) {
|
||||
graph_element->disconnect("slot_updated", callable_mp(this, &GraphEdit::_graph_node_slot_updated));
|
||||
}
|
||||
|
||||
graph_element->disconnect("raise_request", callable_mp(this, &GraphEdit::_graph_element_moved_to_front));
|
||||
graph_element->disconnect("resize_request", callable_mp(this, &GraphEdit::_graph_element_resized));
|
||||
|
||||
// In case of the whole GraphEdit being destroyed these references can already be freed.
|
||||
if (connections_layer != nullptr && connections_layer->is_inside_tree()) {
|
||||
graph_node->disconnect("item_rect_changed", callable_mp((CanvasItem *)connections_layer, &CanvasItem::queue_redraw));
|
||||
graph_element->disconnect("item_rect_changed", callable_mp((CanvasItem *)connections_layer, &CanvasItem::queue_redraw));
|
||||
}
|
||||
if (minimap != nullptr && minimap->is_inside_tree()) {
|
||||
graph_node->disconnect("item_rect_changed", callable_mp((CanvasItem *)minimap, &GraphEditMinimap::queue_redraw));
|
||||
graph_element->disconnect("item_rect_changed", callable_mp((CanvasItem *)minimap, &GraphEditMinimap::queue_redraw));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -572,11 +586,11 @@ bool GraphEdit::_filter_input(const Point2 &p_point) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int j = 0; j < graph_node->get_connection_input_count(); j++) {
|
||||
for (int j = 0; j < graph_node->get_input_port_count(); j++) {
|
||||
Vector2i port_size = Vector2i(port_icon->get_width(), port_icon->get_height());
|
||||
|
||||
// Determine slot height.
|
||||
int slot_index = graph_node->get_connection_input_slot(j);
|
||||
int slot_index = graph_node->get_input_port_slot(j);
|
||||
Control *child = Object::cast_to<Control>(graph_node->get_child(slot_index));
|
||||
|
||||
port_size.height = MAX(port_size.height, child ? child->get_size().y : 0);
|
||||
@@ -586,11 +600,11 @@ bool GraphEdit::_filter_input(const Point2 &p_point) {
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = 0; j < graph_node->get_connection_output_count(); j++) {
|
||||
for (int j = 0; j < graph_node->get_output_port_count(); j++) {
|
||||
Vector2i port_size = Vector2i(port_icon->get_width(), port_icon->get_height());
|
||||
|
||||
// Determine slot height.
|
||||
int slot_index = graph_node->get_connection_output_slot(j);
|
||||
int slot_index = graph_node->get_output_port_slot(j);
|
||||
Control *child = Object::cast_to<Control>(graph_node->get_child(slot_index));
|
||||
port_size.height = MAX(port_size.height, child ? child->get_size().y : 0);
|
||||
|
||||
@@ -616,17 +630,17 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int j = 0; j < graph_node->get_connection_output_count(); j++) {
|
||||
Vector2 pos = graph_node->get_connection_output_position(j) * zoom + graph_node->get_position();
|
||||
for (int j = 0; j < graph_node->get_output_port_count(); j++) {
|
||||
Vector2 pos = graph_node->get_output_port_position(j) * zoom + graph_node->get_position();
|
||||
Vector2i port_size = Vector2i(port_icon->get_width(), port_icon->get_height());
|
||||
|
||||
// Determine slot height.
|
||||
int slot_index = graph_node->get_connection_output_slot(j);
|
||||
int slot_index = graph_node->get_output_port_slot(j);
|
||||
Control *child = Object::cast_to<Control>(graph_node->get_child(slot_index));
|
||||
port_size.height = MAX(port_size.height, child ? child->get_size().y : 0);
|
||||
|
||||
if (is_in_output_hotzone(graph_node, j, click_pos, port_size)) {
|
||||
if (valid_left_disconnect_types.has(graph_node->get_connection_output_type(j))) {
|
||||
if (valid_left_disconnect_types.has(graph_node->get_output_port_type(j))) {
|
||||
// Check disconnect.
|
||||
for (const Connection &E : connections) {
|
||||
if (E.from_node == graph_node->get_name() && E.from_port == j) {
|
||||
@@ -635,8 +649,8 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
|
||||
connecting_from = E.to_node;
|
||||
connecting_index = E.to_port;
|
||||
connecting_out = false;
|
||||
connecting_type = Object::cast_to<GraphNode>(to)->get_connection_input_type(E.to_port);
|
||||
connecting_color = Object::cast_to<GraphNode>(to)->get_connection_input_color(E.to_port);
|
||||
connecting_type = Object::cast_to<GraphNode>(to)->get_input_port_type(E.to_port);
|
||||
connecting_color = Object::cast_to<GraphNode>(to)->get_input_port_color(E.to_port);
|
||||
connecting_target = false;
|
||||
connecting_to = pos;
|
||||
|
||||
@@ -659,8 +673,8 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
|
||||
connecting_from = graph_node->get_name();
|
||||
connecting_index = j;
|
||||
connecting_out = true;
|
||||
connecting_type = graph_node->get_connection_output_type(j);
|
||||
connecting_color = graph_node->get_connection_output_color(j);
|
||||
connecting_type = graph_node->get_output_port_type(j);
|
||||
connecting_color = graph_node->get_output_port_color(j);
|
||||
connecting_target = false;
|
||||
connecting_to = pos;
|
||||
if (connecting_type >= 0) {
|
||||
@@ -672,18 +686,18 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = 0; j < graph_node->get_connection_input_count(); j++) {
|
||||
Vector2 pos = graph_node->get_connection_input_position(j) + graph_node->get_position();
|
||||
for (int j = 0; j < graph_node->get_input_port_count(); j++) {
|
||||
Vector2 pos = graph_node->get_input_port_position(j) * zoom + graph_node->get_position();
|
||||
|
||||
Vector2i port_size = Vector2i(port_icon->get_width(), port_icon->get_height());
|
||||
|
||||
// Determine slot height.
|
||||
int slot_index = graph_node->get_connection_input_slot(j);
|
||||
int slot_index = graph_node->get_input_port_slot(j);
|
||||
Control *child = Object::cast_to<Control>(graph_node->get_child(slot_index));
|
||||
port_size.height = MAX(port_size.height, child ? child->get_size().y : 0);
|
||||
|
||||
if (is_in_input_hotzone(graph_node, j, click_pos, port_size)) {
|
||||
if (right_disconnects || valid_right_disconnect_types.has(graph_node->get_connection_input_type(j))) {
|
||||
if (right_disconnects || valid_right_disconnect_types.has(graph_node->get_input_port_type(j))) {
|
||||
// Check disconnect.
|
||||
for (const Connection &E : connections) {
|
||||
if (E.to_node == graph_node->get_name() && E.to_port == j) {
|
||||
@@ -692,8 +706,8 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
|
||||
connecting_from = E.from_node;
|
||||
connecting_index = E.from_port;
|
||||
connecting_out = true;
|
||||
connecting_type = Object::cast_to<GraphNode>(fr)->get_connection_output_type(E.from_port);
|
||||
connecting_color = Object::cast_to<GraphNode>(fr)->get_connection_output_color(E.from_port);
|
||||
connecting_type = Object::cast_to<GraphNode>(fr)->get_output_port_type(E.from_port);
|
||||
connecting_color = Object::cast_to<GraphNode>(fr)->get_output_port_color(E.from_port);
|
||||
connecting_target = false;
|
||||
connecting_to = pos;
|
||||
just_disconnected = true;
|
||||
@@ -715,8 +729,8 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
|
||||
connecting_from = graph_node->get_name();
|
||||
connecting_index = j;
|
||||
connecting_out = false;
|
||||
connecting_type = graph_node->get_connection_input_type(j);
|
||||
connecting_color = graph_node->get_connection_input_color(j);
|
||||
connecting_type = graph_node->get_input_port_type(j);
|
||||
connecting_color = graph_node->get_input_port_color(j);
|
||||
connecting_target = false;
|
||||
connecting_to = pos;
|
||||
if (connecting_type >= 0) {
|
||||
@@ -749,16 +763,16 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
|
||||
}
|
||||
|
||||
if (!connecting_out) {
|
||||
for (int j = 0; j < graph_node->get_connection_output_count(); j++) {
|
||||
Vector2 pos = graph_node->get_connection_output_position(j) + graph_node->get_position();
|
||||
for (int j = 0; j < graph_node->get_output_port_count(); j++) {
|
||||
Vector2 pos = graph_node->get_output_port_position(j) * zoom + graph_node->get_position();
|
||||
Vector2i port_size = Vector2i(port_icon->get_width(), port_icon->get_height());
|
||||
|
||||
// Determine slot height.
|
||||
int slot_index = graph_node->get_connection_output_slot(j);
|
||||
int slot_index = graph_node->get_output_port_slot(j);
|
||||
Control *child = Object::cast_to<Control>(graph_node->get_child(slot_index));
|
||||
port_size.height = MAX(port_size.height, child ? child->get_size().y : 0);
|
||||
|
||||
int type = graph_node->get_connection_output_type(j);
|
||||
int type = graph_node->get_output_port_type(j);
|
||||
if ((type == connecting_type ||
|
||||
valid_connection_types.has(ConnectionType(connecting_type, type))) &&
|
||||
is_in_output_hotzone(graph_node, j, mpos, port_size)) {
|
||||
@@ -773,16 +787,16 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int j = 0; j < graph_node->get_connection_input_count(); j++) {
|
||||
Vector2 pos = graph_node->get_connection_input_position(j) + graph_node->get_position();
|
||||
for (int j = 0; j < graph_node->get_input_port_count(); j++) {
|
||||
Vector2 pos = graph_node->get_input_port_position(j) * zoom + graph_node->get_position();
|
||||
Vector2i port_size = Vector2i(port_icon->get_width(), port_icon->get_height());
|
||||
|
||||
// Determine slot height.
|
||||
int slot_index = graph_node->get_connection_input_slot(j);
|
||||
int slot_index = graph_node->get_input_port_slot(j);
|
||||
Control *child = Object::cast_to<Control>(graph_node->get_child(slot_index));
|
||||
port_size.height = MAX(port_size.height, child ? child->get_size().y : 0);
|
||||
|
||||
int type = graph_node->get_connection_input_type(j);
|
||||
int type = graph_node->get_input_port_type(j);
|
||||
if ((type == connecting_type || valid_connection_types.has(ConnectionType(connecting_type, type))) &&
|
||||
is_in_input_hotzone(graph_node, j, mpos, port_size)) {
|
||||
if (!is_node_hover_valid(connecting_from, connecting_index, graph_node->get_name(), j)) {
|
||||
@@ -851,17 +865,17 @@ bool GraphEdit::_check_clickable_control(Control *p_control, const Vector2 &mpos
|
||||
}
|
||||
}
|
||||
|
||||
bool GraphEdit::is_in_input_hotzone(GraphNode *p_graph_node, int p_port, const Vector2 &p_mouse_pos, const Vector2i &p_port_size) {
|
||||
bool GraphEdit::is_in_input_hotzone(GraphNode *p_graph_node, int p_port_idx, const Vector2 &p_mouse_pos, const Vector2i &p_port_size) {
|
||||
bool success;
|
||||
if (GDVIRTUAL_CALL(_is_in_input_hotzone, p_graph_node, p_port, p_mouse_pos, success)) {
|
||||
if (GDVIRTUAL_CALL(_is_in_input_hotzone, p_graph_node, p_port_idx, p_mouse_pos, success)) {
|
||||
return success;
|
||||
} else {
|
||||
Vector2 pos = p_graph_node->get_connection_input_position(p_port) + p_graph_node->get_position();
|
||||
Vector2 pos = p_graph_node->get_input_port_position(p_port_idx) * zoom + p_graph_node->get_position();
|
||||
return is_in_port_hotzone(pos / zoom, p_mouse_pos, p_port_size, true);
|
||||
}
|
||||
}
|
||||
|
||||
bool GraphEdit::is_in_output_hotzone(GraphNode *p_graph_node, int p_port, const Vector2 &p_mouse_pos, const Vector2i &p_port_size) {
|
||||
bool GraphEdit::is_in_output_hotzone(GraphNode *p_graph_node, int p_port_idx, const Vector2 &p_mouse_pos, const Vector2i &p_port_size) {
|
||||
if (p_graph_node->is_resizable()) {
|
||||
Ref<Texture2D> resizer = p_graph_node->get_theme_icon(SNAME("resizer"));
|
||||
Rect2 resizer_rect = Rect2(p_graph_node->get_position() / zoom + p_graph_node->get_size() - resizer->get_size(), resizer->get_size());
|
||||
@@ -871,10 +885,10 @@ bool GraphEdit::is_in_output_hotzone(GraphNode *p_graph_node, int p_port, const
|
||||
}
|
||||
|
||||
bool success;
|
||||
if (GDVIRTUAL_CALL(_is_in_output_hotzone, p_graph_node, p_port, p_mouse_pos, success)) {
|
||||
if (GDVIRTUAL_CALL(_is_in_output_hotzone, p_graph_node, p_port_idx, p_mouse_pos, success)) {
|
||||
return success;
|
||||
} else {
|
||||
Vector2 pos = p_graph_node->get_connection_output_position(p_port) + p_graph_node->get_position();
|
||||
Vector2 pos = p_graph_node->get_output_port_position(p_port_idx) * zoom + p_graph_node->get_position();
|
||||
return is_in_port_hotzone(pos / zoom, p_mouse_pos, p_port_size, false);
|
||||
}
|
||||
}
|
||||
@@ -978,10 +992,10 @@ void GraphEdit::_connections_layer_draw() {
|
||||
continue;
|
||||
}
|
||||
|
||||
Vector2 frompos = gnode_from->get_connection_output_position(c.from_port) + gnode_from->get_position_offset() * zoom;
|
||||
Color color = gnode_from->get_connection_output_color(c.from_port);
|
||||
Vector2 topos = gnode_to->get_connection_input_position(c.to_port) + gnode_to->get_position_offset() * zoom;
|
||||
Color tocolor = gnode_to->get_connection_input_color(c.to_port);
|
||||
Vector2 frompos = gnode_from->get_output_port_position(c.from_port) * zoom + gnode_from->get_position_offset() * zoom;
|
||||
Color color = gnode_from->get_output_port_color(c.from_port);
|
||||
Vector2 topos = gnode_to->get_input_port_position(c.to_port) * zoom + gnode_to->get_position_offset() * zoom;
|
||||
Color tocolor = gnode_to->get_input_port_color(c.to_port);
|
||||
|
||||
if (c.activity > 0) {
|
||||
color = color.lerp(activity_color, c.activity);
|
||||
@@ -1005,9 +1019,9 @@ void GraphEdit::_top_layer_draw() {
|
||||
ERR_FAIL_NULL(graph_node_from);
|
||||
Vector2 pos;
|
||||
if (connecting_out) {
|
||||
pos = graph_node_from->get_connection_output_position(connecting_index);
|
||||
pos = graph_node_from->get_output_port_position(connecting_index) * zoom;
|
||||
} else {
|
||||
pos = graph_node_from->get_connection_input_position(connecting_index);
|
||||
pos = graph_node_from->get_input_port_position(connecting_index) * zoom;
|
||||
}
|
||||
pos += graph_node_from->get_position();
|
||||
|
||||
@@ -1061,7 +1075,7 @@ void GraphEdit::_minimap_draw() {
|
||||
Ref<StyleBoxFlat> sb_minimap = minimap->get_theme_stylebox(SNAME("node"))->duplicate();
|
||||
|
||||
// Override default values with colors provided by the GraphNode's stylebox, if possible.
|
||||
Ref<StyleBoxFlat> sb_frame = graph_node->get_theme_stylebox(graph_node->is_selected() ? "selected_frame" : "frame");
|
||||
Ref<StyleBoxFlat> sb_frame = graph_node->get_theme_stylebox(graph_node->is_selected() ? "panel_selected" : "panel");
|
||||
if (sb_frame.is_valid()) {
|
||||
Color node_color = sb_frame->get_bg_color();
|
||||
sb_minimap->set_bg_color(node_color);
|
||||
@@ -1085,12 +1099,12 @@ void GraphEdit::_minimap_draw() {
|
||||
continue;
|
||||
}
|
||||
|
||||
Vector2 from_port_position = graph_node_from->get_position_offset() + graph_node_from->get_connection_output_position(E.from_port);
|
||||
Vector2 from_port_position = graph_node_from->get_position_offset() * zoom + graph_node_from->get_output_port_position(E.from_port) * zoom;
|
||||
Vector2 from_position = minimap->_convert_from_graph_position(from_port_position - graph_offset) + minimap_offset;
|
||||
Color from_color = graph_node_from->get_connection_output_color(E.from_port);
|
||||
Vector2 to_port_position = graph_node_to->get_position_offset() + graph_node_to->get_connection_input_position(E.to_port);
|
||||
Color from_color = graph_node_from->get_output_port_color(E.from_port);
|
||||
Vector2 to_port_position = graph_node_to->get_position_offset() * zoom + graph_node_to->get_input_port_position(E.to_port) * zoom;
|
||||
Vector2 to_position = minimap->_convert_from_graph_position(to_port_position - graph_offset) + minimap_offset;
|
||||
Color to_color = graph_node_to->get_connection_input_color(E.to_port);
|
||||
Color to_color = graph_node_to->get_input_port_color(E.to_port);
|
||||
|
||||
if (E.activity > 0) {
|
||||
from_color = from_color.lerp(activity_color, E.activity);
|
||||
@@ -1137,9 +1151,9 @@ void GraphEdit::gui_input(const Ref<InputEvent> &p_ev) {
|
||||
just_selected = true;
|
||||
drag_accum += mm->get_relative();
|
||||
for (int i = get_child_count() - 1; i >= 0; i--) {
|
||||
GraphNode *graph_node = Object::cast_to<GraphNode>(get_child(i));
|
||||
if (graph_node && graph_node->is_selected() && graph_node->is_draggable()) {
|
||||
Vector2 pos = (graph_node->get_drag_from() * zoom + drag_accum) / zoom;
|
||||
GraphElement *graph_element = Object::cast_to<GraphElement>(get_child(i));
|
||||
if (graph_element && graph_element->is_selected() && graph_element->is_draggable()) {
|
||||
Vector2 pos = (graph_element->get_drag_from() * zoom + drag_accum) / zoom;
|
||||
|
||||
// Snapping can be toggled temporarily by holding down Ctrl.
|
||||
// This is done here as to not toggle the grid when holding down Ctrl.
|
||||
@@ -1147,7 +1161,7 @@ void GraphEdit::gui_input(const Ref<InputEvent> &p_ev) {
|
||||
pos = pos.snapped(Vector2(snapping_distance, snapping_distance));
|
||||
}
|
||||
|
||||
graph_node->set_position_offset(pos);
|
||||
graph_element->set_position_offset(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1158,18 +1172,18 @@ void GraphEdit::gui_input(const Ref<InputEvent> &p_ev) {
|
||||
box_selecting_rect = Rect2(box_selecting_from.min(box_selecting_to), (box_selecting_from - box_selecting_to).abs());
|
||||
|
||||
for (int i = get_child_count() - 1; i >= 0; i--) {
|
||||
GraphNode *graph_node = Object::cast_to<GraphNode>(get_child(i));
|
||||
if (!graph_node) {
|
||||
GraphElement *graph_element = Object::cast_to<GraphElement>(get_child(i));
|
||||
if (!graph_element) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Rect2 r = graph_node->get_rect();
|
||||
Rect2 r = graph_element->get_rect();
|
||||
bool in_box = r.intersects(box_selecting_rect);
|
||||
|
||||
if (in_box) {
|
||||
graph_node->set_selected(box_selection_mode_additive);
|
||||
graph_element->set_selected(box_selection_mode_additive);
|
||||
} else {
|
||||
graph_node->set_selected(prev_selected.find(graph_node) != nullptr);
|
||||
graph_element->set_selected(prev_selected.find(graph_element) != nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1183,12 +1197,12 @@ void GraphEdit::gui_input(const Ref<InputEvent> &p_ev) {
|
||||
if (box_selecting) {
|
||||
box_selecting = false;
|
||||
for (int i = get_child_count() - 1; i >= 0; i--) {
|
||||
GraphNode *graph_node = Object::cast_to<GraphNode>(get_child(i));
|
||||
if (!graph_node) {
|
||||
GraphElement *graph_element = Object::cast_to<GraphElement>(get_child(i));
|
||||
if (!graph_element) {
|
||||
continue;
|
||||
}
|
||||
|
||||
graph_node->set_selected(prev_selected.find(graph_node) != nullptr);
|
||||
graph_element->set_selected(prev_selected.find(graph_element) != nullptr);
|
||||
}
|
||||
top_layer->queue_redraw();
|
||||
minimap->queue_redraw();
|
||||
@@ -1205,12 +1219,12 @@ void GraphEdit::gui_input(const Ref<InputEvent> &p_ev) {
|
||||
if (!just_selected && drag_accum == Vector2() && Input::get_singleton()->is_key_pressed(Key::CTRL)) {
|
||||
// Deselect current node.
|
||||
for (int i = get_child_count() - 1; i >= 0; i--) {
|
||||
GraphNode *graph_node = Object::cast_to<GraphNode>(get_child(i));
|
||||
GraphElement *graph_element = Object::cast_to<GraphElement>(get_child(i));
|
||||
|
||||
if (graph_node) {
|
||||
Rect2 r = graph_node->get_rect();
|
||||
if (graph_element) {
|
||||
Rect2 r = graph_element->get_rect();
|
||||
if (r.has_point(mb->get_position())) {
|
||||
graph_node->set_selected(false);
|
||||
graph_element->set_selected(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1218,9 +1232,9 @@ void GraphEdit::gui_input(const Ref<InputEvent> &p_ev) {
|
||||
|
||||
if (drag_accum != Vector2()) {
|
||||
for (int i = get_child_count() - 1; i >= 0; i--) {
|
||||
GraphNode *graph_node = Object::cast_to<GraphNode>(get_child(i));
|
||||
if (graph_node && graph_node->is_selected()) {
|
||||
graph_node->set_drag(false);
|
||||
GraphElement *graph_element = Object::cast_to<GraphElement>(get_child(i));
|
||||
if (graph_element && graph_element->is_selected()) {
|
||||
graph_element->set_drag(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1240,27 +1254,27 @@ void GraphEdit::gui_input(const Ref<InputEvent> &p_ev) {
|
||||
|
||||
// Node selection logic.
|
||||
if (mb->get_button_index() == MouseButton::LEFT && mb->is_pressed()) {
|
||||
GraphNode *graph_node = nullptr;
|
||||
GraphElement *graph_element = nullptr;
|
||||
|
||||
// Find node which was clicked on.
|
||||
for (int i = get_child_count() - 1; i >= 0; i--) {
|
||||
GraphNode *selected_gcontrol = Object::cast_to<GraphNode>(get_child(i));
|
||||
GraphElement *selected_element = Object::cast_to<GraphElement>(get_child(i));
|
||||
|
||||
if (!selected_gcontrol) {
|
||||
if (!selected_element) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (selected_gcontrol->is_resizing()) {
|
||||
if (selected_element->is_resizing()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (selected_gcontrol->has_point((mb->get_position() - selected_gcontrol->get_position()) / zoom)) {
|
||||
graph_node = selected_gcontrol;
|
||||
if (selected_element->has_point((mb->get_position() - selected_element->get_position()) / zoom)) {
|
||||
graph_element = selected_element;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (graph_node) {
|
||||
if (graph_element) {
|
||||
if (_filter_input(mb->get_position())) {
|
||||
return;
|
||||
}
|
||||
@@ -1268,26 +1282,26 @@ void GraphEdit::gui_input(const Ref<InputEvent> &p_ev) {
|
||||
// Left-clicked on a node, select it.
|
||||
dragging = true;
|
||||
drag_accum = Vector2();
|
||||
just_selected = !graph_node->is_selected();
|
||||
if (!graph_node->is_selected() && !Input::get_singleton()->is_key_pressed(Key::CTRL)) {
|
||||
just_selected = !graph_element->is_selected();
|
||||
if (!graph_element->is_selected() && !Input::get_singleton()->is_key_pressed(Key::CTRL)) {
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
GraphNode *o_gn = Object::cast_to<GraphNode>(get_child(i));
|
||||
if (!o_gn) {
|
||||
GraphElement *child_element = Object::cast_to<GraphElement>(get_child(i));
|
||||
if (!child_element) {
|
||||
continue;
|
||||
}
|
||||
|
||||
o_gn->set_selected(o_gn == graph_node);
|
||||
child_element->set_selected(child_element == graph_element);
|
||||
}
|
||||
}
|
||||
|
||||
graph_node->set_selected(true);
|
||||
graph_element->set_selected(true);
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
GraphNode *o_gn = Object::cast_to<GraphNode>(get_child(i));
|
||||
if (!o_gn) {
|
||||
GraphElement *child_element = Object::cast_to<GraphElement>(get_child(i));
|
||||
if (!child_element) {
|
||||
continue;
|
||||
}
|
||||
if (o_gn->is_selected()) {
|
||||
o_gn->set_drag(true);
|
||||
if (child_element->is_selected()) {
|
||||
child_element->set_drag(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1306,34 +1320,34 @@ void GraphEdit::gui_input(const Ref<InputEvent> &p_ev) {
|
||||
box_selection_mode_additive = true;
|
||||
prev_selected.clear();
|
||||
for (int i = get_child_count() - 1; i >= 0; i--) {
|
||||
GraphNode *gn2 = Object::cast_to<GraphNode>(get_child(i));
|
||||
if (!gn2 || !gn2->is_selected()) {
|
||||
GraphElement *child_element = Object::cast_to<GraphElement>(get_child(i));
|
||||
if (!child_element || !child_element->is_selected()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
prev_selected.push_back(gn2);
|
||||
prev_selected.push_back(child_element);
|
||||
}
|
||||
} else if (mb->is_shift_pressed()) {
|
||||
box_selection_mode_additive = false;
|
||||
prev_selected.clear();
|
||||
for (int i = get_child_count() - 1; i >= 0; i--) {
|
||||
GraphNode *gn2 = Object::cast_to<GraphNode>(get_child(i));
|
||||
if (!gn2 || !gn2->is_selected()) {
|
||||
GraphElement *child_element = Object::cast_to<GraphElement>(get_child(i));
|
||||
if (!child_element || !child_element->is_selected()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
prev_selected.push_back(gn2);
|
||||
prev_selected.push_back(child_element);
|
||||
}
|
||||
} else {
|
||||
box_selection_mode_additive = true;
|
||||
prev_selected.clear();
|
||||
for (int i = get_child_count() - 1; i >= 0; i--) {
|
||||
GraphNode *gn2 = Object::cast_to<GraphNode>(get_child(i));
|
||||
if (!gn2) {
|
||||
GraphElement *child_element = Object::cast_to<GraphElement>(get_child(i));
|
||||
if (!child_element) {
|
||||
continue;
|
||||
}
|
||||
|
||||
gn2->set_selected(false);
|
||||
child_element->set_selected(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1372,7 +1386,7 @@ void GraphEdit::gui_input(const Ref<InputEvent> &p_ev) {
|
||||
}
|
||||
}
|
||||
|
||||
emit_signal(SNAME("delete_nodes_request"), nodes);
|
||||
emit_signal(SNAME("close_nodes_request"), nodes);
|
||||
accept_event();
|
||||
}
|
||||
}
|
||||
@@ -1886,7 +1900,7 @@ void GraphEdit::_bind_methods() {
|
||||
ADD_SIGNAL(MethodInfo("node_deselected", PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "Node")));
|
||||
ADD_SIGNAL(MethodInfo("connection_to_empty", PropertyInfo(Variant::STRING_NAME, "from_node"), PropertyInfo(Variant::INT, "from_port"), PropertyInfo(Variant::VECTOR2, "release_position")));
|
||||
ADD_SIGNAL(MethodInfo("connection_from_empty", PropertyInfo(Variant::STRING_NAME, "to_node"), PropertyInfo(Variant::INT, "to_port"), PropertyInfo(Variant::VECTOR2, "release_position")));
|
||||
ADD_SIGNAL(MethodInfo("delete_nodes_request", PropertyInfo(Variant::ARRAY, "nodes", PROPERTY_HINT_ARRAY_TYPE, "StringName")));
|
||||
ADD_SIGNAL(MethodInfo("close_nodes_request", PropertyInfo(Variant::ARRAY, "nodes", PROPERTY_HINT_ARRAY_TYPE, "StringName")));
|
||||
ADD_SIGNAL(MethodInfo("begin_node_move"));
|
||||
ADD_SIGNAL(MethodInfo("end_node_move"));
|
||||
ADD_SIGNAL(MethodInfo("scroll_offset_changed", PropertyInfo(Variant::VECTOR2, "offset")));
|
||||
|
||||
Reference in New Issue
Block a user