2016-06-18 12:46:12 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* graph_edit.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:16:55 +00:00
|
|
|
/* https://godotengine.org */
|
2016-06-18 12:46:12 +00:00
|
|
|
/*************************************************************************/
|
2020-01-01 10:16:22 +00:00
|
|
|
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
2016-06-18 12:46:12 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
2015-01-03 19:52:37 +00:00
|
|
|
#include "graph_edit.h"
|
2017-08-27 19:07:15 +00:00
|
|
|
|
2020-04-28 13:19:37 +00:00
|
|
|
#include "core/input/input.h"
|
2018-09-11 16:13:45 +00:00
|
|
|
#include "core/os/keyboard.h"
|
2016-01-19 01:10:44 +00:00
|
|
|
#include "scene/gui/box_container.h"
|
2020-06-19 18:49:04 +00:00
|
|
|
#include "scene/gui/button.h"
|
2016-01-23 21:49:26 +00:00
|
|
|
|
2019-01-02 18:51:07 +00:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
#include "editor/editor_scale.h"
|
|
|
|
#endif
|
|
|
|
|
2016-02-08 19:28:12 +00:00
|
|
|
#define ZOOM_SCALE 1.2
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
#define MIN_ZOOM (((1 / ZOOM_SCALE) / ZOOM_SCALE) / ZOOM_SCALE)
|
|
|
|
#define MAX_ZOOM (1 * ZOOM_SCALE * ZOOM_SCALE * ZOOM_SCALE)
|
2016-02-08 19:28:12 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool GraphEditFilter::has_point(const Point2 &p_point) const {
|
2015-07-21 01:15:06 +00:00
|
|
|
return ge->_filter_input(p_point);
|
2015-01-03 19:52:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GraphEditFilter::GraphEditFilter(GraphEdit *p_edit) {
|
2017-03-05 15:44:50 +00:00
|
|
|
ge = p_edit;
|
2015-01-03 19:52:37 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Error GraphEdit::connect_node(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (is_node_connected(p_from, p_from_port, p_to, p_to_port)) {
|
2015-07-21 01:15:06 +00:00
|
|
|
return OK;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-07-21 01:15:06 +00:00
|
|
|
Connection c;
|
2017-03-05 15:44:50 +00:00
|
|
|
c.from = p_from;
|
|
|
|
c.from_port = p_from_port;
|
|
|
|
c.to = p_to;
|
|
|
|
c.to_port = p_to_port;
|
2018-06-19 01:10:48 +00:00
|
|
|
c.activity = 0;
|
2015-07-21 01:15:06 +00:00
|
|
|
connections.push_back(c);
|
|
|
|
top_layer->update();
|
2016-08-23 13:15:47 +00:00
|
|
|
update();
|
2016-08-31 02:44:14 +00:00
|
|
|
connections_layer->update();
|
2015-07-21 01:15:06 +00:00
|
|
|
|
|
|
|
return OK;
|
2015-01-03 19:52:37 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool GraphEdit::is_node_connected(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port) {
|
|
|
|
for (List<Connection>::Element *E = connections.front(); E; E = E->next()) {
|
2020-05-14 14:41:43 +00:00
|
|
|
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) {
|
2015-07-21 01:15:06 +00:00
|
|
|
return true;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-07-21 01:15:06 +00:00
|
|
|
}
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2015-07-21 01:15:06 +00:00
|
|
|
return false;
|
2015-01-03 19:52:37 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void GraphEdit::disconnect_node(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port) {
|
|
|
|
for (List<Connection>::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) {
|
2015-07-21 01:15:06 +00:00
|
|
|
connections.erase(E);
|
|
|
|
top_layer->update();
|
2016-08-23 13:15:47 +00:00
|
|
|
update();
|
2016-08-31 02:44:14 +00:00
|
|
|
connections_layer->update();
|
2015-07-21 01:15:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2015-01-03 19:52:37 +00:00
|
|
|
}
|
|
|
|
|
2016-01-23 21:49:26 +00:00
|
|
|
bool GraphEdit::clips_input() const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-08 03:41:34 +00:00
|
|
|
void GraphEdit::get_connection_list(List<Connection> *r_connections) const {
|
2017-03-05 15:44:50 +00:00
|
|
|
*r_connections = connections;
|
2015-01-03 19:52:37 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void GraphEdit::set_scroll_ofs(const Vector2 &p_ofs) {
|
|
|
|
setting_scroll_ofs = true;
|
2017-01-04 04:16:14 +00:00
|
|
|
h_scroll->set_value(p_ofs.x);
|
|
|
|
v_scroll->set_value(p_ofs.y);
|
2016-08-06 22:00:54 +00:00
|
|
|
_update_scroll();
|
2017-03-05 15:44:50 +00:00
|
|
|
setting_scroll_ofs = false;
|
2016-08-06 22:00:54 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Vector2 GraphEdit::get_scroll_ofs() const {
|
|
|
|
return Vector2(h_scroll->get_value(), v_scroll->get_value());
|
2016-01-17 21:26:32 +00:00
|
|
|
}
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2016-01-17 21:26:32 +00:00
|
|
|
void GraphEdit::_scroll_moved(double) {
|
2016-08-31 02:44:14 +00:00
|
|
|
if (!awaiting_scroll_offset_update) {
|
|
|
|
call_deferred("_update_scroll_offset");
|
2017-03-05 15:44:50 +00:00
|
|
|
awaiting_scroll_offset_update = true;
|
2016-08-31 02:44:14 +00:00
|
|
|
}
|
2015-07-21 01:15:06 +00:00
|
|
|
top_layer->update();
|
2016-08-23 13:15:47 +00:00
|
|
|
update();
|
2016-08-06 22:00:54 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (!setting_scroll_ofs) { //in godot, signals on change value are avoided as a convention
|
|
|
|
emit_signal("scroll_offset_changed", get_scroll_ofs());
|
2016-08-06 22:00:54 +00:00
|
|
|
}
|
2015-01-03 19:52:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GraphEdit::_update_scroll_offset() {
|
2016-08-31 02:44:14 +00:00
|
|
|
set_block_minimum_size_adjust(true);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < get_child_count(); i++) {
|
2017-08-24 20:58:51 +00:00
|
|
|
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!gn) {
|
2015-07-21 01:15:06 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Point2 pos = gn->get_offset() * zoom;
|
|
|
|
pos -= Point2(h_scroll->get_value(), v_scroll->get_value());
|
2017-03-29 15:29:38 +00:00
|
|
|
gn->set_position(pos);
|
2017-03-05 15:44:50 +00:00
|
|
|
if (gn->get_scale() != Vector2(zoom, zoom)) {
|
|
|
|
gn->set_scale(Vector2(zoom, zoom));
|
2016-08-31 02:44:14 +00:00
|
|
|
}
|
2015-07-21 01:15:06 +00:00
|
|
|
}
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2017-03-29 15:29:38 +00:00
|
|
|
connections_layer->set_position(-Point2(h_scroll->get_value(), v_scroll->get_value()));
|
2016-08-31 02:44:14 +00:00
|
|
|
set_block_minimum_size_adjust(false);
|
2017-03-05 15:44:50 +00:00
|
|
|
awaiting_scroll_offset_update = false;
|
2015-01-03 19:52:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GraphEdit::_update_scroll() {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (updating) {
|
2015-07-21 01:15:06 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
updating = true;
|
2016-08-31 02:44:14 +00:00
|
|
|
|
|
|
|
set_block_minimum_size_adjust(true);
|
|
|
|
|
2015-07-21 01:15:06 +00:00
|
|
|
Rect2 screen;
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < get_child_count(); i++) {
|
2017-08-24 20:58:51 +00:00
|
|
|
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!gn) {
|
2015-07-21 01:15:06 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2015-07-21 01:15:06 +00:00
|
|
|
Rect2 r;
|
2017-06-03 22:25:13 +00:00
|
|
|
r.position = gn->get_offset() * zoom;
|
2017-03-05 15:44:50 +00:00
|
|
|
r.size = gn->get_size() * zoom;
|
2015-07-21 01:15:06 +00:00
|
|
|
screen = screen.merge(r);
|
|
|
|
}
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2017-06-03 22:25:13 +00:00
|
|
|
screen.position -= get_size();
|
2017-03-05 15:44:50 +00:00
|
|
|
screen.size += get_size() * 2.0;
|
2015-01-08 03:41:34 +00:00
|
|
|
|
2017-06-03 22:25:13 +00:00
|
|
|
h_scroll->set_min(screen.position.x);
|
|
|
|
h_scroll->set_max(screen.position.x + screen.size.x);
|
2015-07-21 01:15:06 +00:00
|
|
|
h_scroll->set_page(get_size().x);
|
2020-05-14 14:41:43 +00:00
|
|
|
if (h_scroll->get_max() - h_scroll->get_min() <= h_scroll->get_page()) {
|
2015-07-21 01:15:06 +00:00
|
|
|
h_scroll->hide();
|
2020-05-14 14:41:43 +00:00
|
|
|
} else {
|
2015-07-21 01:15:06 +00:00
|
|
|
h_scroll->show();
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2017-06-03 22:25:13 +00:00
|
|
|
v_scroll->set_min(screen.position.y);
|
|
|
|
v_scroll->set_max(screen.position.y + screen.size.y);
|
2015-07-21 01:15:06 +00:00
|
|
|
v_scroll->set_page(get_size().y);
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (v_scroll->get_max() - v_scroll->get_min() <= v_scroll->get_page()) {
|
2015-07-21 01:15:06 +00:00
|
|
|
v_scroll->hide();
|
2020-05-14 14:41:43 +00:00
|
|
|
} else {
|
2015-07-21 01:15:06 +00:00
|
|
|
v_scroll->show();
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2020-01-14 01:49:17 +00:00
|
|
|
Size2 hmin = h_scroll->get_combined_minimum_size();
|
|
|
|
Size2 vmin = v_scroll->get_combined_minimum_size();
|
|
|
|
|
|
|
|
// Avoid scrollbar overlapping.
|
|
|
|
h_scroll->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, v_scroll->is_visible() ? -vmin.width : 0);
|
|
|
|
v_scroll->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, h_scroll->is_visible() ? -hmin.height : 0);
|
|
|
|
|
2016-08-31 02:44:14 +00:00
|
|
|
set_block_minimum_size_adjust(false);
|
|
|
|
|
|
|
|
if (!awaiting_scroll_offset_update) {
|
|
|
|
call_deferred("_update_scroll_offset");
|
2017-03-05 15:44:50 +00:00
|
|
|
awaiting_scroll_offset_update = true;
|
2016-08-31 02:44:14 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
updating = false;
|
2015-01-03 19:52:37 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void GraphEdit::_graph_node_raised(Node *p_gn) {
|
2017-08-24 20:58:51 +00:00
|
|
|
GraphNode *gn = Object::cast_to<GraphNode>(p_gn);
|
2015-07-21 01:15:06 +00:00
|
|
|
ERR_FAIL_COND(!gn);
|
2016-08-25 20:45:20 +00:00
|
|
|
if (gn->is_comment()) {
|
2017-03-05 15:44:50 +00:00
|
|
|
move_child(gn, 0);
|
2017-08-08 13:57:33 +00:00
|
|
|
} else {
|
|
|
|
gn->raise();
|
2016-08-25 20:45:20 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
int first_not_comment = 0;
|
|
|
|
for (int i = 0; i < get_child_count(); i++) {
|
2019-02-12 20:10:08 +00:00
|
|
|
GraphNode *gn2 = Object::cast_to<GraphNode>(get_child(i));
|
|
|
|
if (gn2 && !gn2->is_comment()) {
|
2017-03-05 15:44:50 +00:00
|
|
|
first_not_comment = i;
|
2016-08-31 02:44:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
move_child(connections_layer, first_not_comment);
|
2015-07-21 01:15:06 +00:00
|
|
|
top_layer->raise();
|
2017-03-05 15:44:50 +00:00
|
|
|
emit_signal("node_selected", p_gn);
|
2015-01-03 19:52:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GraphEdit::_graph_node_moved(Node *p_gn) {
|
2017-08-24 20:58:51 +00:00
|
|
|
GraphNode *gn = Object::cast_to<GraphNode>(p_gn);
|
2015-07-21 01:15:06 +00:00
|
|
|
ERR_FAIL_COND(!gn);
|
|
|
|
top_layer->update();
|
2016-08-23 13:15:47 +00:00
|
|
|
update();
|
2016-08-31 02:44:14 +00:00
|
|
|
connections_layer->update();
|
2015-01-03 19:52:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GraphEdit::add_child_notify(Node *p_child) {
|
2016-08-06 01:46:45 +00:00
|
|
|
Control::add_child_notify(p_child);
|
|
|
|
|
2015-07-21 01:15:06 +00:00
|
|
|
top_layer->call_deferred("raise"); //top layer always on top!
|
2017-08-24 20:58:51 +00:00
|
|
|
GraphNode *gn = Object::cast_to<GraphNode>(p_child);
|
2015-07-21 01:15:06 +00:00
|
|
|
if (gn) {
|
2017-03-05 15:44:50 +00:00
|
|
|
gn->set_scale(Vector2(zoom, zoom));
|
2020-02-21 17:28:45 +00:00
|
|
|
gn->connect("offset_changed", callable_mp(this, &GraphEdit::_graph_node_moved), varray(gn));
|
|
|
|
gn->connect("raise_request", callable_mp(this, &GraphEdit::_graph_node_raised), varray(gn));
|
2020-02-21 22:26:13 +00:00
|
|
|
gn->connect("item_rect_changed", callable_mp((CanvasItem *)connections_layer, &CanvasItem::update));
|
2015-07-21 01:15:06 +00:00
|
|
|
_graph_node_moved(gn);
|
2020-02-07 09:09:39 +00:00
|
|
|
gn->set_mouse_filter(MOUSE_FILTER_PASS);
|
2015-07-21 01:15:06 +00:00
|
|
|
}
|
2015-01-03 19:52:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GraphEdit::remove_child_notify(Node *p_child) {
|
2016-08-06 01:46:45 +00:00
|
|
|
Control::remove_child_notify(p_child);
|
2019-03-01 20:24:57 +00:00
|
|
|
if (is_inside_tree()) {
|
|
|
|
top_layer->call_deferred("raise"); //top layer always on top!
|
|
|
|
}
|
2017-08-24 20:58:51 +00:00
|
|
|
GraphNode *gn = Object::cast_to<GraphNode>(p_child);
|
2015-07-21 01:15:06 +00:00
|
|
|
if (gn) {
|
2020-02-21 17:28:45 +00:00
|
|
|
gn->disconnect("offset_changed", callable_mp(this, &GraphEdit::_graph_node_moved));
|
|
|
|
gn->disconnect("raise_request", callable_mp(this, &GraphEdit::_graph_node_raised));
|
2020-09-11 18:38:28 +00:00
|
|
|
gn->disconnect("item_rect_changed", callable_mp((CanvasItem *)connections_layer, &CanvasItem::update));
|
2015-07-21 01:15:06 +00:00
|
|
|
}
|
2015-01-03 19:52:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GraphEdit::_notification(int p_what) {
|
2018-05-13 03:34:35 +00:00
|
|
|
if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
|
2020-03-12 12:37:40 +00:00
|
|
|
port_grab_distance_horizontal = get_theme_constant("port_grab_distance_horizontal");
|
|
|
|
port_grab_distance_vertical = get_theme_constant("port_grab_distance_vertical");
|
2019-08-30 13:56:56 +00:00
|
|
|
|
2020-03-12 12:37:40 +00:00
|
|
|
zoom_minus->set_icon(get_theme_icon("minus"));
|
|
|
|
zoom_reset->set_icon(get_theme_icon("reset"));
|
|
|
|
zoom_plus->set_icon(get_theme_icon("more"));
|
|
|
|
snap_button->set_icon(get_theme_icon("snap"));
|
2018-05-13 03:34:35 +00:00
|
|
|
}
|
2020-01-16 03:36:31 +00:00
|
|
|
if (p_what == NOTIFICATION_READY) {
|
|
|
|
Size2 hmin = h_scroll->get_combined_minimum_size();
|
|
|
|
Size2 vmin = v_scroll->get_combined_minimum_size();
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_what == NOTIFICATION_DRAW) {
|
2020-03-12 12:37:40 +00:00
|
|
|
draw_style_box(get_theme_stylebox("bg"), Rect2(Point2(), get_size()));
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2016-08-04 03:05:35 +00:00
|
|
|
if (is_using_snap()) {
|
|
|
|
//draw grid
|
|
|
|
|
|
|
|
int snap = get_snap();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Vector2 offset = get_scroll_ofs() / zoom;
|
|
|
|
Size2 size = get_size() / zoom;
|
2016-08-04 03:05:35 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Point2i from = (offset / float(snap)).floor();
|
|
|
|
Point2i len = (size / float(snap)).floor() + Vector2(1, 1);
|
2016-08-04 03:05:35 +00:00
|
|
|
|
2020-03-12 12:37:40 +00:00
|
|
|
Color grid_minor = get_theme_color("grid_minor");
|
|
|
|
Color grid_major = get_theme_color("grid_major");
|
2016-08-04 03:05:35 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = from.x; i < from.x + len.x; i++) {
|
2016-08-04 03:05:35 +00:00
|
|
|
Color color;
|
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (ABS(i) % 10 == 0) {
|
2017-03-05 15:44:50 +00:00
|
|
|
color = grid_major;
|
2020-05-14 14:41:43 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
color = grid_minor;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2016-08-04 03:05:35 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float base_ofs = i * snap * zoom - offset.x * zoom;
|
|
|
|
draw_line(Vector2(base_ofs, 0), Vector2(base_ofs, get_size().height), color);
|
2016-08-04 03:05:35 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = from.y; i < from.y + len.y; i++) {
|
2016-08-04 03:05:35 +00:00
|
|
|
Color color;
|
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (ABS(i) % 10 == 0) {
|
2017-03-05 15:44:50 +00:00
|
|
|
color = grid_major;
|
2020-05-14 14:41:43 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
color = grid_minor;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2016-08-04 03:05:35 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float base_ofs = i * snap * zoom - offset.y * zoom;
|
|
|
|
draw_line(Vector2(0, base_ofs), Vector2(get_size().width, base_ofs), color);
|
2016-08-04 03:05:35 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-21 01:15:06 +00:00
|
|
|
}
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_what == NOTIFICATION_RESIZED) {
|
2015-07-21 01:15:06 +00:00
|
|
|
_update_scroll();
|
|
|
|
top_layer->update();
|
|
|
|
}
|
2015-01-03 19:52:37 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool GraphEdit::_filter_input(const Point2 &p_point) {
|
2020-03-12 12:37:40 +00:00
|
|
|
Ref<Texture2D> port = get_theme_icon("port", "GraphNode");
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = get_child_count() - 1; i >= 0; i--) {
|
2017-08-24 20:58:51 +00:00
|
|
|
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!gn) {
|
2015-07-21 01:15:06 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int j = 0; j < gn->get_connection_output_count(); j++) {
|
2017-09-10 13:37:49 +00:00
|
|
|
Vector2 pos = gn->get_connection_output_position(j) + gn->get_position();
|
2020-05-14 14:41:43 +00:00
|
|
|
if (is_in_hot_zone(pos, p_point)) {
|
2015-07-21 01:15:06 +00:00
|
|
|
return true;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-07-21 01:15:06 +00:00
|
|
|
}
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int j = 0; j < gn->get_connection_input_count(); j++) {
|
2017-09-10 13:37:49 +00:00
|
|
|
Vector2 pos = gn->get_connection_input_position(j) + gn->get_position();
|
2018-08-20 16:38:18 +00:00
|
|
|
if (is_in_hot_zone(pos, p_point)) {
|
2015-07-21 01:15:06 +00:00
|
|
|
return true;
|
2016-09-06 22:55:22 +00:00
|
|
|
}
|
2015-07-21 01:15:06 +00:00
|
|
|
}
|
|
|
|
}
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2015-07-21 01:15:06 +00:00
|
|
|
return false;
|
2015-01-03 19:52:37 +00:00
|
|
|
}
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
|
|
|
|
Ref<InputEventMouseButton> mb = p_ev;
|
|
|
|
if (mb.is_valid() && mb->get_button_index() == BUTTON_LEFT && mb->is_pressed()) {
|
2020-07-04 05:00:17 +00:00
|
|
|
connecting_valid = false;
|
2020-03-12 12:37:40 +00:00
|
|
|
Ref<Texture2D> port = get_theme_icon("port", "GraphNode");
|
2020-07-04 05:00:17 +00:00
|
|
|
click_pos = mb->get_position();
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = get_child_count() - 1; i >= 0; i--) {
|
2017-08-24 20:58:51 +00:00
|
|
|
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!gn) {
|
2015-07-21 01:15:06 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int j = 0; j < gn->get_connection_output_count(); j++) {
|
2017-09-10 13:37:49 +00:00
|
|
|
Vector2 pos = gn->get_connection_output_position(j) + gn->get_position();
|
2020-07-04 05:00:17 +00:00
|
|
|
if (is_in_hot_zone(pos, click_pos)) {
|
2016-08-02 22:11:05 +00:00
|
|
|
if (valid_left_disconnect_types.has(gn->get_connection_output_type(j))) {
|
|
|
|
//check disconnect
|
2017-03-05 15:44:50 +00:00
|
|
|
for (List<Connection>::Element *E = connections.front(); E; E = E->next()) {
|
|
|
|
if (E->get().from == gn->get_name() && E->get().from_port == j) {
|
|
|
|
Node *to = get_node(String(E->get().to));
|
2017-08-24 20:58:51 +00:00
|
|
|
if (Object::cast_to<GraphNode>(to)) {
|
2017-03-05 15:44:50 +00:00
|
|
|
connecting_from = E->get().to;
|
|
|
|
connecting_index = E->get().to_port;
|
|
|
|
connecting_out = false;
|
2017-08-24 20:58:51 +00:00
|
|
|
connecting_type = Object::cast_to<GraphNode>(to)->get_connection_input_type(E->get().to_port);
|
|
|
|
connecting_color = Object::cast_to<GraphNode>(to)->get_connection_input_color(E->get().to_port);
|
2017-03-05 15:44:50 +00:00
|
|
|
connecting_target = false;
|
|
|
|
connecting_to = pos;
|
2018-10-19 11:31:35 +00:00
|
|
|
just_disconnected = true;
|
2016-08-02 22:11:05 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
emit_signal("disconnection_request", E->get().from, E->get().from_port, E->get().to, E->get().to_port);
|
2016-08-02 22:11:05 +00:00
|
|
|
to = get_node(String(connecting_from)); //maybe it was erased
|
2017-08-24 20:58:51 +00:00
|
|
|
if (Object::cast_to<GraphNode>(to)) {
|
2017-03-05 15:44:50 +00:00
|
|
|
connecting = true;
|
2016-08-02 22:11:05 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
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;
|
2018-10-19 11:31:35 +00:00
|
|
|
just_disconnected = false;
|
2015-07-21 01:15:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int j = 0; j < gn->get_connection_input_count(); j++) {
|
2017-09-10 13:37:49 +00:00
|
|
|
Vector2 pos = gn->get_connection_input_position(j) + gn->get_position();
|
2020-07-04 05:00:17 +00:00
|
|
|
if (is_in_hot_zone(pos, click_pos)) {
|
2016-08-02 22:11:05 +00:00
|
|
|
if (right_disconnects || valid_right_disconnect_types.has(gn->get_connection_input_type(j))) {
|
2015-07-21 01:15:06 +00:00
|
|
|
//check disconnect
|
2017-03-05 15:44:50 +00:00
|
|
|
for (List<Connection>::Element *E = connections.front(); E; E = E->next()) {
|
|
|
|
if (E->get().to == gn->get_name() && E->get().to_port == j) {
|
|
|
|
Node *fr = get_node(String(E->get().from));
|
2017-08-24 20:58:51 +00:00
|
|
|
if (Object::cast_to<GraphNode>(fr)) {
|
2017-03-05 15:44:50 +00:00
|
|
|
connecting_from = E->get().from;
|
|
|
|
connecting_index = E->get().from_port;
|
|
|
|
connecting_out = true;
|
2017-08-24 20:58:51 +00:00
|
|
|
connecting_type = Object::cast_to<GraphNode>(fr)->get_connection_output_type(E->get().from_port);
|
|
|
|
connecting_color = Object::cast_to<GraphNode>(fr)->get_connection_output_color(E->get().from_port);
|
2017-03-05 15:44:50 +00:00
|
|
|
connecting_target = false;
|
|
|
|
connecting_to = pos;
|
2018-10-19 11:31:35 +00:00
|
|
|
just_disconnected = true;
|
2015-01-07 04:45:46 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
emit_signal("disconnection_request", E->get().from, E->get().from_port, E->get().to, E->get().to_port);
|
2015-07-21 01:15:06 +00:00
|
|
|
fr = get_node(String(connecting_from)); //maybe it was erased
|
2017-08-24 20:58:51 +00:00
|
|
|
if (Object::cast_to<GraphNode>(fr)) {
|
2017-03-05 15:44:50 +00:00
|
|
|
connecting = true;
|
2015-07-21 01:15:06 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-01-07 04:45:46 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
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;
|
2019-06-26 18:50:38 +00:00
|
|
|
just_disconnected = false;
|
2016-09-03 17:58:23 +00:00
|
|
|
|
2015-07-21 01:15:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
Ref<InputEventMouseMotion> mm = p_ev;
|
|
|
|
if (mm.is_valid() && connecting) {
|
2017-06-03 08:54:24 +00:00
|
|
|
connecting_to = mm->get_position();
|
2017-03-05 15:44:50 +00:00
|
|
|
connecting_target = false;
|
|
|
|
top_layer->update();
|
2020-07-05 06:47:58 +00:00
|
|
|
connecting_valid = just_disconnected || click_pos.distance_to(connecting_to) > 20.0 * zoom;
|
2020-07-04 05:00:17 +00:00
|
|
|
|
|
|
|
if (connecting_valid) {
|
|
|
|
Ref<Texture2D> port = get_theme_icon("port", "GraphNode");
|
|
|
|
Vector2 mpos = mm->get_position();
|
|
|
|
for (int i = get_child_count() - 1; i >= 0; i--) {
|
|
|
|
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
|
|
|
|
if (!gn) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2020-07-04 05:00:17 +00:00
|
|
|
if (!connecting_out) {
|
|
|
|
for (int j = 0; j < gn->get_connection_output_count(); j++) {
|
|
|
|
Vector2 pos = gn->get_connection_output_position(j) + gn->get_position();
|
|
|
|
int type = gn->get_connection_output_type(j);
|
|
|
|
if ((type == connecting_type || valid_connection_types.has(ConnType(type, connecting_type))) && is_in_hot_zone(pos, mpos)) {
|
|
|
|
connecting_target = true;
|
|
|
|
connecting_to = pos;
|
|
|
|
connecting_target_to = gn->get_name();
|
|
|
|
connecting_target_index = j;
|
|
|
|
return;
|
|
|
|
}
|
2015-07-21 01:15:06 +00:00
|
|
|
}
|
2020-07-04 05:00:17 +00:00
|
|
|
} else {
|
|
|
|
for (int j = 0; j < gn->get_connection_input_count(); j++) {
|
|
|
|
Vector2 pos = gn->get_connection_input_position(j) + gn->get_position();
|
|
|
|
int type = gn->get_connection_input_type(j);
|
|
|
|
if ((type == connecting_type || valid_connection_types.has(ConnType(type, connecting_type))) && is_in_hot_zone(pos, mpos)) {
|
|
|
|
connecting_target = true;
|
|
|
|
connecting_to = pos;
|
|
|
|
connecting_target_to = gn->get_name();
|
|
|
|
connecting_target_index = j;
|
|
|
|
return;
|
|
|
|
}
|
2015-07-21 01:15:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (mb.is_valid() && mb->get_button_index() == BUTTON_LEFT && !mb->is_pressed()) {
|
2020-07-04 05:00:17 +00:00
|
|
|
if (connecting_valid) {
|
|
|
|
if (connecting && connecting_target) {
|
|
|
|
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);
|
2015-07-21 01:15:06 +00:00
|
|
|
|
2020-07-04 05:00:17 +00:00
|
|
|
} else if (!just_disconnected) {
|
|
|
|
String from = connecting_from;
|
|
|
|
int from_slot = connecting_index;
|
|
|
|
Vector2 ofs = Vector2(mb->get_position().x, mb->get_position().y);
|
2019-06-26 18:50:38 +00:00
|
|
|
|
2020-07-04 05:00:17 +00:00
|
|
|
if (!connecting_out) {
|
|
|
|
emit_signal("connection_from_empty", from, from_slot, ofs);
|
|
|
|
} else {
|
|
|
|
emit_signal("connection_to_empty", from, from_slot, ofs);
|
|
|
|
}
|
2019-06-26 18:50:38 +00:00
|
|
|
}
|
2015-07-21 01:15:06 +00:00
|
|
|
}
|
2019-06-26 18:50:38 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
connecting = false;
|
2015-07-21 01:15:06 +00:00
|
|
|
top_layer->update();
|
2016-08-23 13:15:47 +00:00
|
|
|
update();
|
2016-08-31 02:44:14 +00:00
|
|
|
connections_layer->update();
|
2015-07-21 01:15:06 +00:00
|
|
|
}
|
2015-01-03 19:52:37 +00:00
|
|
|
}
|
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
bool GraphEdit::_check_clickable_control(Control *p_control, const Vector2 &pos) {
|
2020-10-01 07:17:33 +00:00
|
|
|
if (p_control->is_set_as_top_level() || !p_control->is_visible()) {
|
2018-08-20 16:38:18 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2018-08-20 16:38:18 +00:00
|
|
|
|
|
|
|
if (!p_control->has_point(pos) || p_control->get_mouse_filter() == MOUSE_FILTER_IGNORE) {
|
|
|
|
//test children
|
|
|
|
for (int i = 0; i < p_control->get_child_count(); i++) {
|
|
|
|
Control *subchild = Object::cast_to<Control>(p_control->get_child(i));
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!subchild) {
|
2018-08-20 16:38:18 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2018-08-20 16:38:18 +00:00
|
|
|
if (_check_clickable_control(subchild, pos - subchild->get_position())) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GraphEdit::is_in_hot_zone(const Vector2 &pos, const Vector2 &p_mouse_pos) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!Rect2(pos.x - port_grab_distance_horizontal, pos.y - port_grab_distance_vertical, port_grab_distance_horizontal * 2, port_grab_distance_vertical * 2).has_point(p_mouse_pos)) {
|
2018-08-20 16:38:18 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2018-08-20 16:38:18 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < get_child_count(); i++) {
|
|
|
|
Control *child = Object::cast_to<Control>(get_child(i));
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!child) {
|
2018-08-20 16:38:18 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2018-08-20 16:38:18 +00:00
|
|
|
Rect2 rect = child->get_rect();
|
|
|
|
if (rect.has_point(p_mouse_pos)) {
|
|
|
|
//check sub-controls
|
|
|
|
Vector2 subpos = p_mouse_pos - rect.position;
|
|
|
|
|
|
|
|
for (int j = 0; j < child->get_child_count(); j++) {
|
|
|
|
Control *subchild = Object::cast_to<Control>(child->get_child(j));
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!subchild) {
|
2018-08-20 16:38:18 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2018-08-20 16:38:18 +00:00
|
|
|
|
|
|
|
if (_check_clickable_control(subchild, subpos - subchild->get_position())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2018-05-13 03:34:35 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
template <class Vector2>
|
2016-08-23 13:15:47 +00:00
|
|
|
static _FORCE_INLINE_ Vector2 _bezier_interp(real_t t, Vector2 start, Vector2 control_1, Vector2 control_2, Vector2 end) {
|
2017-03-05 15:44:50 +00:00
|
|
|
/* Formula from Wikipedia article on Bezier curves. */
|
2016-08-23 13:15:47 +00:00
|
|
|
real_t omt = (1.0 - t);
|
2017-03-05 15:44:50 +00:00
|
|
|
real_t omt2 = omt * omt;
|
|
|
|
real_t omt3 = omt2 * omt;
|
|
|
|
real_t t2 = t * t;
|
|
|
|
real_t t3 = t2 * t;
|
2016-08-23 13:15:47 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
return start * omt3 + control_1 * omt2 * t * 3.0 + control_2 * omt * t2 * 3.0 + end * t3;
|
|
|
|
}
|
2016-08-23 13:15:47 +00:00
|
|
|
|
2017-07-01 00:30:17 +00:00
|
|
|
void GraphEdit::_bake_segment2d(Vector<Vector2> &points, Vector<Color> &colors, float p_begin, float p_end, const Vector2 &p_a, const Vector2 &p_out, const Vector2 &p_b, const Vector2 &p_in, int p_depth, int p_min_depth, int p_max_depth, float p_tol, const Color &p_color, const Color &p_to_color, int &lines) const {
|
2017-03-05 15:44:50 +00:00
|
|
|
float mp = p_begin + (p_end - p_begin) * 0.5;
|
|
|
|
Vector2 beg = _bezier_interp(p_begin, p_a, p_a + p_out, p_b + p_in, p_b);
|
|
|
|
Vector2 mid = _bezier_interp(mp, p_a, p_a + p_out, p_b + p_in, p_b);
|
|
|
|
Vector2 end = _bezier_interp(p_end, p_a, p_a + p_out, p_b + p_in, p_b);
|
2016-08-23 13:15:47 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Vector2 na = (mid - beg).normalized();
|
|
|
|
Vector2 nb = (end - mid).normalized();
|
2016-08-23 13:15:47 +00:00
|
|
|
float dp = Math::rad2deg(Math::acos(na.dot(nb)));
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_depth >= p_min_depth && (dp < p_tol || p_depth >= p_max_depth)) {
|
2017-07-01 00:30:17 +00:00
|
|
|
points.push_back((beg + end) * 0.5);
|
2020-03-16 09:07:33 +00:00
|
|
|
colors.push_back(p_color.lerp(p_to_color, mp));
|
2016-08-23 13:15:47 +00:00
|
|
|
lines++;
|
|
|
|
} else {
|
2017-07-01 00:30:17 +00:00
|
|
|
_bake_segment2d(points, colors, p_begin, mp, p_a, p_out, p_b, p_in, p_depth + 1, p_min_depth, p_max_depth, p_tol, p_color, p_to_color, lines);
|
|
|
|
_bake_segment2d(points, colors, mp, p_end, p_a, p_out, p_b, p_in, p_depth + 1, p_min_depth, p_max_depth, p_tol, p_color, p_to_color, lines);
|
2016-08-23 13:15:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void GraphEdit::_draw_cos_line(CanvasItem *p_where, const Vector2 &p_from, const Vector2 &p_to, const Color &p_color, const Color &p_to_color) {
|
2016-08-23 13:15:47 +00:00
|
|
|
//cubic bezier code
|
2017-03-05 15:44:50 +00:00
|
|
|
float diff = p_to.x - p_from.x;
|
2016-08-23 13:15:47 +00:00
|
|
|
float cp_offset;
|
2020-03-12 12:37:40 +00:00
|
|
|
int cp_len = get_theme_constant("bezier_len_pos");
|
|
|
|
int cp_neg_len = get_theme_constant("bezier_len_neg");
|
2016-08-23 13:15:47 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (diff > 0) {
|
2017-07-27 21:39:53 +00:00
|
|
|
cp_offset = MIN(cp_len, diff * 0.5);
|
2016-08-23 13:15:47 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
cp_offset = MAX(MIN(cp_len - diff, cp_neg_len), -diff * 0.5);
|
2016-08-23 13:15:47 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Vector2 c1 = Vector2(cp_offset * zoom, 0);
|
|
|
|
Vector2 c2 = Vector2(-cp_offset * zoom, 0);
|
2016-08-23 13:15:47 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int lines = 0;
|
2017-07-01 00:30:17 +00:00
|
|
|
|
|
|
|
Vector<Point2> points;
|
|
|
|
Vector<Color> colors;
|
|
|
|
points.push_back(p_from);
|
|
|
|
colors.push_back(p_color);
|
2019-01-02 18:51:07 +00:00
|
|
|
_bake_segment2d(points, colors, 0, 1, p_from, c1, p_to, c2, 0, 3, 9, 3, p_color, p_to_color, lines);
|
2017-07-01 00:30:17 +00:00
|
|
|
points.push_back(p_to);
|
|
|
|
colors.push_back(p_to_color);
|
|
|
|
|
2019-01-02 18:51:07 +00:00
|
|
|
#ifdef TOOLS_ENABLED
|
2019-06-25 01:24:07 +00:00
|
|
|
p_where->draw_polyline_colors(points, colors, Math::floor(2 * EDSCALE));
|
2019-01-02 18:51:07 +00:00
|
|
|
#else
|
2019-06-25 01:24:07 +00:00
|
|
|
p_where->draw_polyline_colors(points, colors, 2);
|
2019-01-02 18:51:07 +00:00
|
|
|
#endif
|
2015-01-03 19:52:37 +00:00
|
|
|
}
|
|
|
|
|
2016-08-31 02:44:14 +00:00
|
|
|
void GraphEdit::_connections_layer_draw() {
|
2020-03-12 12:37:40 +00:00
|
|
|
Color activity_color = get_theme_color("activity");
|
2017-08-27 19:07:15 +00:00
|
|
|
//draw connections
|
|
|
|
List<List<Connection>::Element *> to_erase;
|
|
|
|
for (List<Connection>::Element *E = connections.front(); E; E = E->next()) {
|
|
|
|
NodePath fromnp(E->get().from);
|
2016-08-31 02:44:14 +00:00
|
|
|
|
2017-08-27 19:07:15 +00:00
|
|
|
Node *from = get_node(fromnp);
|
|
|
|
if (!from) {
|
|
|
|
to_erase.push_back(E);
|
|
|
|
continue;
|
|
|
|
}
|
2016-08-31 02:44:14 +00:00
|
|
|
|
2017-08-27 19:07:15 +00:00
|
|
|
GraphNode *gfrom = Object::cast_to<GraphNode>(from);
|
2016-08-31 02:44:14 +00:00
|
|
|
|
2017-08-27 19:07:15 +00:00
|
|
|
if (!gfrom) {
|
|
|
|
to_erase.push_back(E);
|
|
|
|
continue;
|
|
|
|
}
|
2016-08-31 02:44:14 +00:00
|
|
|
|
2017-08-27 19:07:15 +00:00
|
|
|
NodePath tonp(E->get().to);
|
|
|
|
Node *to = get_node(tonp);
|
|
|
|
if (!to) {
|
|
|
|
to_erase.push_back(E);
|
|
|
|
continue;
|
|
|
|
}
|
2016-08-31 02:44:14 +00:00
|
|
|
|
2017-08-27 19:07:15 +00:00
|
|
|
GraphNode *gto = Object::cast_to<GraphNode>(to);
|
2016-08-31 02:44:14 +00:00
|
|
|
|
2017-08-27 19:07:15 +00:00
|
|
|
if (!gto) {
|
|
|
|
to_erase.push_back(E);
|
|
|
|
continue;
|
2016-08-31 02:44:14 +00:00
|
|
|
}
|
|
|
|
|
2017-09-10 13:37:49 +00:00
|
|
|
Vector2 frompos = gfrom->get_connection_output_position(E->get().from_port) + gfrom->get_offset() * zoom;
|
2017-08-27 19:07:15 +00:00
|
|
|
Color color = gfrom->get_connection_output_color(E->get().from_port);
|
2017-09-10 13:37:49 +00:00
|
|
|
Vector2 topos = gto->get_connection_input_position(E->get().to_port) + gto->get_offset() * zoom;
|
2017-08-27 19:07:15 +00:00
|
|
|
Color tocolor = gto->get_connection_input_color(E->get().to_port);
|
2018-06-19 01:10:48 +00:00
|
|
|
|
|
|
|
if (E->get().activity > 0) {
|
2020-03-16 09:07:33 +00:00
|
|
|
color = color.lerp(activity_color, E->get().activity);
|
|
|
|
tocolor = tocolor.lerp(activity_color, E->get().activity);
|
2018-06-19 01:10:48 +00:00
|
|
|
}
|
2017-08-27 19:07:15 +00:00
|
|
|
_draw_cos_line(connections_layer, frompos, topos, color, tocolor);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (to_erase.size()) {
|
|
|
|
connections.erase(to_erase.front()->get());
|
|
|
|
to_erase.pop_front();
|
2016-08-31 02:44:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-03 19:52:37 +00:00
|
|
|
void GraphEdit::_top_layer_draw() {
|
2015-07-21 01:15:06 +00:00
|
|
|
_update_scroll();
|
|
|
|
|
|
|
|
if (connecting) {
|
|
|
|
Node *fromn = get_node(connecting_from);
|
|
|
|
ERR_FAIL_COND(!fromn);
|
2017-08-24 20:58:51 +00:00
|
|
|
GraphNode *from = Object::cast_to<GraphNode>(fromn);
|
2015-07-21 01:15:06 +00:00
|
|
|
ERR_FAIL_COND(!from);
|
|
|
|
Vector2 pos;
|
2020-05-14 14:41:43 +00:00
|
|
|
if (connecting_out) {
|
2017-09-10 13:37:49 +00:00
|
|
|
pos = from->get_connection_output_position(connecting_index);
|
2020-05-14 14:41:43 +00:00
|
|
|
} else {
|
2017-09-10 13:37:49 +00:00
|
|
|
pos = from->get_connection_input_position(connecting_index);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-29 15:29:38 +00:00
|
|
|
pos += from->get_position();
|
2015-07-21 01:15:06 +00:00
|
|
|
|
|
|
|
Vector2 topos;
|
2017-03-05 15:44:50 +00:00
|
|
|
topos = connecting_to;
|
2015-07-21 01:15:06 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Color col = connecting_color;
|
2015-07-21 01:15:06 +00:00
|
|
|
|
|
|
|
if (connecting_target) {
|
2017-03-05 15:44:50 +00:00
|
|
|
col.r += 0.4;
|
|
|
|
col.g += 0.4;
|
|
|
|
col.b += 0.4;
|
2015-07-21 01:15:06 +00:00
|
|
|
}
|
2016-08-25 20:45:20 +00:00
|
|
|
|
|
|
|
if (!connecting_out) {
|
2017-03-05 15:44:50 +00:00
|
|
|
SWAP(pos, topos);
|
2016-08-25 20:45:20 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
_draw_cos_line(top_layer, pos, topos, col, col);
|
2015-07-21 01:15:06 +00:00
|
|
|
}
|
|
|
|
|
2019-08-15 20:17:08 +00:00
|
|
|
if (box_selecting) {
|
2020-03-12 12:37:40 +00:00
|
|
|
top_layer->draw_rect(box_selecting_rect, get_theme_color("selection_fill"));
|
|
|
|
top_layer->draw_rect(box_selecting_rect, get_theme_color("selection_stroke"), false);
|
2019-08-15 20:17:08 +00:00
|
|
|
}
|
2015-01-03 19:52:37 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void GraphEdit::set_selected(Node *p_child) {
|
|
|
|
for (int i = get_child_count() - 1; i >= 0; i--) {
|
2017-08-24 20:58:51 +00:00
|
|
|
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!gn) {
|
2016-08-02 22:11:05 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2016-08-02 22:11:05 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
gn->set_selected(gn == p_child);
|
2016-08-02 22:11:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
|
|
|
|
Ref<InputEventMouseMotion> mm = p_ev;
|
2020-04-28 13:19:37 +00:00
|
|
|
if (mm.is_valid() && (mm->get_button_mask() & BUTTON_MASK_MIDDLE || (mm->get_button_mask() & BUTTON_MASK_LEFT && Input::get_singleton()->is_key_pressed(KEY_SPACE)))) {
|
2017-05-20 15:38:03 +00:00
|
|
|
h_scroll->set_value(h_scroll->get_value() - mm->get_relative().x);
|
|
|
|
v_scroll->set_value(v_scroll->get_value() - mm->get_relative().y);
|
2015-07-21 01:15:06 +00:00
|
|
|
}
|
2015-07-19 04:48:46 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (mm.is_valid() && dragging) {
|
2020-10-20 01:25:07 +00:00
|
|
|
if (!moving_selection) {
|
|
|
|
emit_signal("_begin_node_move");
|
|
|
|
moving_selection = true;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
just_selected = true;
|
2020-05-04 18:36:52 +00:00
|
|
|
drag_accum += mm->get_relative();
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = get_child_count() - 1; i >= 0; i--) {
|
2017-08-24 20:58:51 +00:00
|
|
|
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
|
2016-08-04 03:05:35 +00:00
|
|
|
if (gn && gn->is_selected()) {
|
2017-03-05 15:44:50 +00:00
|
|
|
Vector2 pos = (gn->get_drag_from() * zoom + drag_accum) / zoom;
|
2019-11-15 18:34:44 +00:00
|
|
|
|
|
|
|
// Snapping can be toggled temporarily by holding down Ctrl.
|
|
|
|
// This is done here as to not toggle the grid when holding down Ctrl.
|
2020-04-28 13:19:37 +00:00
|
|
|
if (is_using_snap() ^ Input::get_singleton()->is_key_pressed(KEY_CONTROL)) {
|
2019-11-15 18:34:44 +00:00
|
|
|
const int snap = get_snap();
|
2017-03-05 15:44:50 +00:00
|
|
|
pos = pos.snapped(Vector2(snap, snap));
|
2016-08-04 03:05:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gn->set_offset(pos);
|
|
|
|
}
|
2015-07-21 01:15:06 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-19 04:48:46 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (mm.is_valid() && box_selecting) {
|
2020-05-04 18:36:52 +00:00
|
|
|
box_selecting_to = mm->get_position();
|
2015-07-25 00:59:48 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
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));
|
2015-07-25 00:59:48 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = get_child_count() - 1; i >= 0; i--) {
|
2017-08-24 20:58:51 +00:00
|
|
|
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!gn) {
|
2015-07-25 00:59:48 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-07-25 00:59:48 +00:00
|
|
|
|
2016-01-18 23:32:37 +00:00
|
|
|
Rect2 r = gn->get_rect();
|
2017-03-05 15:44:50 +00:00
|
|
|
r.size *= zoom;
|
2016-01-18 23:32:37 +00:00
|
|
|
bool in_box = r.intersects(box_selecting_rect);
|
2015-07-25 00:59:48 +00:00
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (in_box) {
|
2020-07-09 09:47:22 +00:00
|
|
|
if (!gn->is_selected() && box_selection_mode_additive) {
|
|
|
|
emit_signal("node_selected", gn);
|
|
|
|
} else if (gn->is_selected() && !box_selection_mode_additive) {
|
|
|
|
emit_signal("node_unselected", gn);
|
|
|
|
}
|
2020-04-10 20:00:50 +00:00
|
|
|
gn->set_selected(box_selection_mode_additive);
|
2020-05-14 14:41:43 +00:00
|
|
|
} else {
|
2020-07-09 09:47:22 +00:00
|
|
|
bool select = (previus_selected.find(gn) != nullptr);
|
|
|
|
if (gn->is_selected() && !select) {
|
|
|
|
emit_signal("node_unselected", gn);
|
|
|
|
} else if (!gn->is_selected() && select) {
|
|
|
|
emit_signal("node_selected", gn);
|
|
|
|
}
|
|
|
|
gn->set_selected(select);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-07-25 00:59:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
top_layer->update();
|
|
|
|
}
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
Ref<InputEventMouseButton> b = p_ev;
|
|
|
|
if (b.is_valid()) {
|
|
|
|
if (b->get_button_index() == BUTTON_RIGHT && b->is_pressed()) {
|
2015-07-25 00:59:48 +00:00
|
|
|
if (box_selecting) {
|
|
|
|
box_selecting = false;
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = get_child_count() - 1; i >= 0; i--) {
|
2017-08-24 20:58:51 +00:00
|
|
|
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!gn) {
|
2015-07-25 00:59:48 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-07-25 00:59:48 +00:00
|
|
|
|
2020-07-09 09:47:22 +00:00
|
|
|
bool select = (previus_selected.find(gn) != nullptr);
|
|
|
|
if (gn->is_selected() && !select) {
|
|
|
|
emit_signal("node_unselected", gn);
|
|
|
|
} else if (!gn->is_selected() && select) {
|
|
|
|
emit_signal("node_selected", gn);
|
|
|
|
}
|
|
|
|
gn->set_selected(select);
|
2015-07-25 00:59:48 +00:00
|
|
|
}
|
|
|
|
top_layer->update();
|
|
|
|
} else {
|
2016-01-18 23:32:37 +00:00
|
|
|
if (connecting) {
|
|
|
|
connecting = false;
|
|
|
|
top_layer->update();
|
|
|
|
} else {
|
2017-06-03 08:54:24 +00:00
|
|
|
emit_signal("popup_request", b->get_global_position());
|
2016-01-18 23:32:37 +00:00
|
|
|
}
|
2015-07-25 00:59:48 +00:00
|
|
|
}
|
2015-07-21 01:15:06 +00:00
|
|
|
}
|
2015-07-19 04:48:46 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (b->get_button_index() == BUTTON_LEFT && !b->is_pressed() && dragging) {
|
2020-04-28 13:19:37 +00:00
|
|
|
if (!just_selected && drag_accum == Vector2() && Input::get_singleton()->is_key_pressed(KEY_CONTROL)) {
|
2015-07-21 01:15:06 +00:00
|
|
|
//deselect current node
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = get_child_count() - 1; i >= 0; i--) {
|
2017-08-24 20:58:51 +00:00
|
|
|
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
|
2015-07-19 04:48:46 +00:00
|
|
|
|
2016-01-18 23:32:37 +00:00
|
|
|
if (gn) {
|
|
|
|
Rect2 r = gn->get_rect();
|
2017-03-05 15:44:50 +00:00
|
|
|
r.size *= zoom;
|
2020-05-04 18:36:52 +00:00
|
|
|
if (r.has_point(b->get_position())) {
|
2020-07-09 09:47:22 +00:00
|
|
|
emit_signal("node_unselected", gn);
|
2016-01-18 23:32:37 +00:00
|
|
|
gn->set_selected(false);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2016-01-18 23:32:37 +00:00
|
|
|
}
|
2015-07-21 01:15:06 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-19 04:48:46 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (drag_accum != Vector2()) {
|
|
|
|
for (int i = get_child_count() - 1; i >= 0; i--) {
|
2017-08-24 20:58:51 +00:00
|
|
|
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
|
2020-05-14 14:41:43 +00:00
|
|
|
if (gn && gn->is_selected()) {
|
2015-07-21 01:15:06 +00:00
|
|
|
gn->set_drag(false);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-07-21 01:15:06 +00:00
|
|
|
}
|
2020-10-20 01:25:07 +00:00
|
|
|
}
|
2015-07-19 04:48:46 +00:00
|
|
|
|
2020-10-20 01:25:07 +00:00
|
|
|
if (moving_selection) {
|
2015-07-21 01:15:06 +00:00
|
|
|
emit_signal("_end_node_move");
|
2020-10-20 01:25:07 +00:00
|
|
|
moving_selection = false;
|
2015-07-21 01:15:06 +00:00
|
|
|
}
|
2015-07-19 04:48:46 +00:00
|
|
|
|
2015-07-21 01:15:06 +00:00
|
|
|
dragging = false;
|
2015-07-19 04:48:46 +00:00
|
|
|
|
2015-07-21 01:15:06 +00:00
|
|
|
top_layer->update();
|
2016-08-23 13:15:47 +00:00
|
|
|
update();
|
2016-08-31 02:44:14 +00:00
|
|
|
connections_layer->update();
|
2015-07-21 01:15:06 +00:00
|
|
|
}
|
2015-07-19 04:48:46 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (b->get_button_index() == BUTTON_LEFT && b->is_pressed()) {
|
2020-04-01 23:20:12 +00:00
|
|
|
GraphNode *gn = nullptr;
|
2017-08-08 13:57:33 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = get_child_count() - 1; i >= 0; i--) {
|
2017-08-24 20:58:51 +00:00
|
|
|
GraphNode *gn_selected = Object::cast_to<GraphNode>(get_child(i));
|
2015-07-19 04:48:46 +00:00
|
|
|
|
2016-10-04 16:10:49 +00:00
|
|
|
if (gn_selected) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (gn_selected->is_resizing()) {
|
2016-08-25 20:45:20 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2016-08-25 20:45:20 +00:00
|
|
|
|
2020-05-04 18:36:52 +00:00
|
|
|
if (gn_selected->has_point(b->get_position() - gn_selected->get_position())) {
|
2016-10-04 16:10:49 +00:00
|
|
|
gn = gn_selected;
|
2017-08-08 13:57:33 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-01-18 23:32:37 +00:00
|
|
|
}
|
2015-07-21 01:15:06 +00:00
|
|
|
}
|
2015-07-19 04:48:46 +00:00
|
|
|
|
2015-07-21 01:15:06 +00:00
|
|
|
if (gn) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (_filter_input(b->get_position())) {
|
2015-07-21 01:15:06 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-07-19 04:48:46 +00:00
|
|
|
|
2015-07-21 01:15:06 +00:00
|
|
|
dragging = true;
|
|
|
|
drag_accum = Vector2();
|
|
|
|
just_selected = !gn->is_selected();
|
2020-04-28 13:19:37 +00:00
|
|
|
if (!gn->is_selected() && !Input::get_singleton()->is_key_pressed(KEY_CONTROL)) {
|
2015-07-21 01:15:06 +00:00
|
|
|
for (int i = 0; i < get_child_count(); i++) {
|
2017-08-24 20:58:51 +00:00
|
|
|
GraphNode *o_gn = Object::cast_to<GraphNode>(get_child(i));
|
2020-04-10 20:00:50 +00:00
|
|
|
if (o_gn) {
|
|
|
|
if (o_gn == gn) {
|
|
|
|
o_gn->set_selected(true);
|
|
|
|
} else {
|
|
|
|
if (o_gn->is_selected()) {
|
|
|
|
emit_signal("node_unselected", o_gn);
|
|
|
|
}
|
|
|
|
o_gn->set_selected(false);
|
|
|
|
}
|
|
|
|
}
|
2015-07-21 01:15:06 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-19 04:48:46 +00:00
|
|
|
|
2015-07-21 01:15:06 +00:00
|
|
|
gn->set_selected(true);
|
|
|
|
for (int i = 0; i < get_child_count(); i++) {
|
2017-08-24 20:58:51 +00:00
|
|
|
GraphNode *o_gn = Object::cast_to<GraphNode>(get_child(i));
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!o_gn) {
|
2015-07-21 01:15:06 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
|
|
|
if (o_gn->is_selected()) {
|
2015-07-21 01:15:06 +00:00
|
|
|
o_gn->set_drag(true);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-07-21 01:15:06 +00:00
|
|
|
}
|
2015-07-19 04:48:46 +00:00
|
|
|
|
2015-07-21 01:15:06 +00:00
|
|
|
} else {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (_filter_input(b->get_position())) {
|
2016-01-18 23:32:37 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
|
|
|
if (Input::get_singleton()->is_key_pressed(KEY_SPACE)) {
|
2016-02-08 19:28:12 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2016-01-18 23:32:37 +00:00
|
|
|
|
2015-07-25 00:59:48 +00:00
|
|
|
box_selecting = true;
|
2020-05-04 18:36:52 +00:00
|
|
|
box_selecting_from = b->get_position();
|
2017-05-20 15:38:03 +00:00
|
|
|
if (b->get_control()) {
|
2020-04-10 20:00:50 +00:00
|
|
|
box_selection_mode_additive = true;
|
2015-07-25 00:59:48 +00:00
|
|
|
previus_selected.clear();
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = get_child_count() - 1; i >= 0; i--) {
|
2019-02-12 20:10:08 +00:00
|
|
|
GraphNode *gn2 = Object::cast_to<GraphNode>(get_child(i));
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!gn2 || !gn2->is_selected()) {
|
2015-07-25 00:59:48 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-07-25 00:59:48 +00:00
|
|
|
|
2019-02-12 20:10:08 +00:00
|
|
|
previus_selected.push_back(gn2);
|
2015-07-25 00:59:48 +00:00
|
|
|
}
|
2017-05-20 15:38:03 +00:00
|
|
|
} else if (b->get_shift()) {
|
2020-04-10 20:00:50 +00:00
|
|
|
box_selection_mode_additive = false;
|
2015-07-25 00:59:48 +00:00
|
|
|
previus_selected.clear();
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = get_child_count() - 1; i >= 0; i--) {
|
2019-02-12 20:10:08 +00:00
|
|
|
GraphNode *gn2 = Object::cast_to<GraphNode>(get_child(i));
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!gn2 || !gn2->is_selected()) {
|
2015-07-25 00:59:48 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-07-19 04:48:46 +00:00
|
|
|
|
2019-02-12 20:10:08 +00:00
|
|
|
previus_selected.push_back(gn2);
|
2015-07-25 00:59:48 +00:00
|
|
|
}
|
|
|
|
} else {
|
2020-04-10 20:00:50 +00:00
|
|
|
box_selection_mode_additive = true;
|
2015-07-25 00:59:48 +00:00
|
|
|
previus_selected.clear();
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = get_child_count() - 1; i >= 0; i--) {
|
2019-02-12 20:10:08 +00:00
|
|
|
GraphNode *gn2 = Object::cast_to<GraphNode>(get_child(i));
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!gn2) {
|
2015-07-25 00:59:48 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2020-04-10 20:00:50 +00:00
|
|
|
if (gn2->is_selected()) {
|
|
|
|
emit_signal("node_unselected", gn2);
|
|
|
|
}
|
2019-02-12 20:10:08 +00:00
|
|
|
gn2->set_selected(false);
|
2015-07-25 00:59:48 +00:00
|
|
|
}
|
2015-07-21 01:15:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-07-25 00:59:48 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (b->get_button_index() == BUTTON_LEFT && !b->is_pressed() && box_selecting) {
|
2015-07-25 00:59:48 +00:00
|
|
|
box_selecting = false;
|
|
|
|
previus_selected.clear();
|
|
|
|
top_layer->update();
|
|
|
|
}
|
2016-01-18 23:32:37 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (b->get_button_index() == BUTTON_WHEEL_UP && b->is_pressed()) {
|
2016-02-08 19:28:12 +00:00
|
|
|
//too difficult to get right
|
|
|
|
//set_zoom(zoom*ZOOM_SCALE);
|
2016-01-18 23:32:37 +00:00
|
|
|
}
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (b->get_button_index() == BUTTON_WHEEL_DOWN && b->is_pressed()) {
|
2016-02-08 19:28:12 +00:00
|
|
|
//too difficult to get right
|
|
|
|
//set_zoom(zoom/ZOOM_SCALE);
|
2016-01-18 23:32:37 +00:00
|
|
|
}
|
2020-04-28 13:19:37 +00:00
|
|
|
if (b->get_button_index() == BUTTON_WHEEL_UP && !Input::get_singleton()->is_key_pressed(KEY_SHIFT)) {
|
2017-10-01 12:14:42 +00:00
|
|
|
v_scroll->set_value(v_scroll->get_value() - v_scroll->get_page() * b->get_factor() / 8);
|
2017-02-21 22:45:31 +00:00
|
|
|
}
|
2020-04-28 13:19:37 +00:00
|
|
|
if (b->get_button_index() == BUTTON_WHEEL_DOWN && !Input::get_singleton()->is_key_pressed(KEY_SHIFT)) {
|
2017-05-20 15:38:03 +00:00
|
|
|
v_scroll->set_value(v_scroll->get_value() + v_scroll->get_page() * b->get_factor() / 8);
|
2017-02-21 22:45:31 +00:00
|
|
|
}
|
2020-04-28 13:19:37 +00:00
|
|
|
if (b->get_button_index() == BUTTON_WHEEL_RIGHT || (b->get_button_index() == BUTTON_WHEEL_DOWN && Input::get_singleton()->is_key_pressed(KEY_SHIFT))) {
|
2017-10-01 12:14:42 +00:00
|
|
|
h_scroll->set_value(h_scroll->get_value() + h_scroll->get_page() * b->get_factor() / 8);
|
|
|
|
}
|
2020-04-28 13:19:37 +00:00
|
|
|
if (b->get_button_index() == BUTTON_WHEEL_LEFT || (b->get_button_index() == BUTTON_WHEEL_UP && Input::get_singleton()->is_key_pressed(KEY_SHIFT))) {
|
2017-10-01 12:14:42 +00:00
|
|
|
h_scroll->set_value(h_scroll->get_value() - h_scroll->get_page() * b->get_factor() / 8);
|
2017-02-21 22:45:31 +00:00
|
|
|
}
|
2015-07-21 01:15:06 +00:00
|
|
|
}
|
2015-07-26 00:16:07 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
Ref<InputEventKey> k = p_ev;
|
2015-07-27 00:57:27 +00:00
|
|
|
|
2019-07-12 17:36:33 +00:00
|
|
|
if (k.is_valid()) {
|
2018-04-05 17:59:35 +00:00
|
|
|
if (k->get_keycode() == KEY_D && k->is_pressed() && k->get_command()) {
|
2019-07-12 17:36:33 +00:00
|
|
|
emit_signal("duplicate_nodes_request");
|
|
|
|
accept_event();
|
|
|
|
}
|
|
|
|
|
2018-04-05 17:59:35 +00:00
|
|
|
if (k->get_keycode() == KEY_C && k->is_pressed() && k->get_command()) {
|
2019-07-12 17:36:33 +00:00
|
|
|
emit_signal("copy_nodes_request");
|
|
|
|
accept_event();
|
|
|
|
}
|
|
|
|
|
2018-04-05 17:59:35 +00:00
|
|
|
if (k->get_keycode() == KEY_V && k->is_pressed() && k->get_command()) {
|
2019-07-12 17:36:33 +00:00
|
|
|
emit_signal("paste_nodes_request");
|
|
|
|
accept_event();
|
|
|
|
}
|
|
|
|
|
2018-04-05 17:59:35 +00:00
|
|
|
if (k->get_keycode() == KEY_DELETE && k->is_pressed()) {
|
2019-07-12 17:36:33 +00:00
|
|
|
emit_signal("delete_nodes_request");
|
|
|
|
accept_event();
|
|
|
|
}
|
2015-07-27 00:57:27 +00:00
|
|
|
}
|
2017-11-01 20:49:39 +00:00
|
|
|
|
|
|
|
Ref<InputEventMagnifyGesture> magnify_gesture = p_ev;
|
|
|
|
if (magnify_gesture.is_valid()) {
|
|
|
|
set_zoom_custom(zoom * magnify_gesture->get_factor(), magnify_gesture->get_position());
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<InputEventPanGesture> pan_gesture = p_ev;
|
|
|
|
if (pan_gesture.is_valid()) {
|
|
|
|
h_scroll->set_value(h_scroll->get_value() + h_scroll->get_page() * pan_gesture->get_delta().x / 8);
|
|
|
|
v_scroll->set_value(v_scroll->get_value() + v_scroll->get_page() * pan_gesture->get_delta().y / 8);
|
|
|
|
}
|
2015-01-03 19:52:37 +00:00
|
|
|
}
|
|
|
|
|
2018-06-19 01:10:48 +00:00
|
|
|
void GraphEdit::set_connection_activity(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port, float p_activity) {
|
|
|
|
for (List<Connection>::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) {
|
2019-01-16 15:42:53 +00:00
|
|
|
if (Math::is_equal_approx(E->get().activity, p_activity)) {
|
2018-06-19 01:10:48 +00:00
|
|
|
//update only if changed
|
|
|
|
top_layer->update();
|
|
|
|
connections_layer->update();
|
|
|
|
}
|
|
|
|
E->get().activity = p_activity;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-03 19:52:37 +00:00
|
|
|
void GraphEdit::clear_connections() {
|
2015-07-21 01:15:06 +00:00
|
|
|
connections.clear();
|
|
|
|
update();
|
2016-08-31 02:44:14 +00:00
|
|
|
connections_layer->update();
|
2015-01-03 19:52:37 +00:00
|
|
|
}
|
|
|
|
|
2016-01-18 23:32:37 +00:00
|
|
|
void GraphEdit::set_zoom(float p_zoom) {
|
2017-11-01 20:49:39 +00:00
|
|
|
set_zoom_custom(p_zoom, get_size() / 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphEdit::set_zoom_custom(float p_zoom, const Vector2 &p_center) {
|
2017-03-05 15:44:50 +00:00
|
|
|
p_zoom = CLAMP(p_zoom, MIN_ZOOM, MAX_ZOOM);
|
2020-05-14 14:41:43 +00:00
|
|
|
if (zoom == p_zoom) {
|
2016-01-18 23:32:37 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2016-01-18 23:32:37 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
zoom_minus->set_disabled(zoom == MIN_ZOOM);
|
|
|
|
zoom_plus->set_disabled(zoom == MAX_ZOOM);
|
2016-02-08 19:28:12 +00:00
|
|
|
|
2017-11-01 20:49:39 +00:00
|
|
|
Vector2 sbofs = (Vector2(h_scroll->get_value(), v_scroll->get_value()) + p_center) / zoom;
|
2016-02-08 19:28:12 +00:00
|
|
|
|
2016-01-18 23:32:37 +00:00
|
|
|
zoom = p_zoom;
|
2016-02-08 19:28:12 +00:00
|
|
|
top_layer->update();
|
|
|
|
|
|
|
|
_update_scroll();
|
2016-10-13 03:11:29 +00:00
|
|
|
connections_layer->update();
|
2016-02-08 19:28:12 +00:00
|
|
|
|
2017-01-13 13:45:50 +00:00
|
|
|
if (is_visible_in_tree()) {
|
2017-11-01 20:49:39 +00:00
|
|
|
Vector2 ofs = sbofs * zoom - p_center;
|
2017-03-05 15:44:50 +00:00
|
|
|
h_scroll->set_value(ofs.x);
|
|
|
|
v_scroll->set_value(ofs.y);
|
2016-01-18 23:32:37 +00:00
|
|
|
}
|
2016-02-08 19:28:12 +00:00
|
|
|
|
2016-01-18 23:32:37 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
float GraphEdit::get_zoom() const {
|
|
|
|
return zoom;
|
|
|
|
}
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2015-01-07 04:45:46 +00:00
|
|
|
void GraphEdit::set_right_disconnects(bool p_enable) {
|
2017-03-05 15:44:50 +00:00
|
|
|
right_disconnects = p_enable;
|
2015-01-07 04:45:46 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool GraphEdit::is_right_disconnects_enabled() const {
|
2015-07-21 01:15:06 +00:00
|
|
|
return right_disconnects;
|
2015-01-07 04:45:46 +00:00
|
|
|
}
|
|
|
|
|
2016-08-02 22:11:05 +00:00
|
|
|
void GraphEdit::add_valid_right_disconnect_type(int p_type) {
|
|
|
|
valid_right_disconnect_types.insert(p_type);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void GraphEdit::remove_valid_right_disconnect_type(int p_type) {
|
2016-08-02 22:11:05 +00:00
|
|
|
valid_right_disconnect_types.erase(p_type);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void GraphEdit::add_valid_left_disconnect_type(int p_type) {
|
2016-08-02 22:11:05 +00:00
|
|
|
valid_left_disconnect_types.insert(p_type);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void GraphEdit::remove_valid_left_disconnect_type(int p_type) {
|
2016-08-02 22:11:05 +00:00
|
|
|
valid_left_disconnect_types.erase(p_type);
|
|
|
|
}
|
|
|
|
|
2015-01-08 03:41:34 +00:00
|
|
|
Array GraphEdit::_get_connection_list() const {
|
2015-07-21 01:15:06 +00:00
|
|
|
List<Connection> conns;
|
|
|
|
get_connection_list(&conns);
|
|
|
|
Array arr;
|
2017-03-05 15:44:50 +00:00
|
|
|
for (List<Connection>::Element *E = conns.front(); E; E = E->next()) {
|
2015-07-21 01:15:06 +00:00
|
|
|
Dictionary d;
|
2017-03-05 15:44:50 +00:00
|
|
|
d["from"] = E->get().from;
|
|
|
|
d["from_port"] = E->get().from_port;
|
|
|
|
d["to"] = E->get().to;
|
|
|
|
d["to_port"] = E->get().to_port;
|
2015-07-21 01:15:06 +00:00
|
|
|
arr.push_back(d);
|
|
|
|
}
|
|
|
|
return arr;
|
2015-01-08 03:41:34 +00:00
|
|
|
}
|
2016-02-08 19:28:12 +00:00
|
|
|
|
|
|
|
void GraphEdit::_zoom_minus() {
|
2017-03-05 15:44:50 +00:00
|
|
|
set_zoom(zoom / ZOOM_SCALE);
|
2016-02-08 19:28:12 +00:00
|
|
|
}
|
2020-05-14 12:29:06 +00:00
|
|
|
|
2016-02-08 19:28:12 +00:00
|
|
|
void GraphEdit::_zoom_reset() {
|
|
|
|
set_zoom(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphEdit::_zoom_plus() {
|
2017-03-05 15:44:50 +00:00
|
|
|
set_zoom(zoom * ZOOM_SCALE);
|
2016-02-08 19:28:12 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void GraphEdit::add_valid_connection_type(int p_type, int p_with_type) {
|
2016-08-02 22:11:05 +00:00
|
|
|
ConnType ct;
|
2017-03-05 15:44:50 +00:00
|
|
|
ct.type_a = p_type;
|
|
|
|
ct.type_b = p_with_type;
|
2016-08-02 22:11:05 +00:00
|
|
|
|
|
|
|
valid_connection_types.insert(ct);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void GraphEdit::remove_valid_connection_type(int p_type, int p_with_type) {
|
2016-08-02 22:11:05 +00:00
|
|
|
ConnType ct;
|
2017-03-05 15:44:50 +00:00
|
|
|
ct.type_a = p_type;
|
|
|
|
ct.type_b = p_with_type;
|
2016-08-02 22:11:05 +00:00
|
|
|
|
|
|
|
valid_connection_types.erase(ct);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool GraphEdit::is_valid_connection_type(int p_type, int p_with_type) const {
|
2016-08-02 22:11:05 +00:00
|
|
|
ConnType ct;
|
2017-03-05 15:44:50 +00:00
|
|
|
ct.type_a = p_type;
|
|
|
|
ct.type_b = p_with_type;
|
2016-08-02 22:11:05 +00:00
|
|
|
|
|
|
|
return valid_connection_types.has(ct);
|
|
|
|
}
|
|
|
|
|
2016-08-04 03:05:35 +00:00
|
|
|
void GraphEdit::set_use_snap(bool p_enable) {
|
|
|
|
snap_button->set_pressed(p_enable);
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool GraphEdit::is_using_snap() const {
|
2016-08-04 03:05:35 +00:00
|
|
|
return snap_button->is_pressed();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int GraphEdit::get_snap() const {
|
2017-01-04 04:16:14 +00:00
|
|
|
return snap_amount->get_value();
|
2016-08-04 03:05:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GraphEdit::set_snap(int p_snap) {
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND(p_snap < 5);
|
2017-01-04 04:16:14 +00:00
|
|
|
snap_amount->set_value(p_snap);
|
2016-08-04 03:05:35 +00:00
|
|
|
update();
|
|
|
|
}
|
2020-05-14 12:29:06 +00:00
|
|
|
|
2016-08-04 03:05:35 +00:00
|
|
|
void GraphEdit::_snap_toggled() {
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphEdit::_snap_value_changed(double) {
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2018-06-19 01:10:48 +00:00
|
|
|
HBoxContainer *GraphEdit::get_zoom_hbox() {
|
|
|
|
return zoom_hb;
|
|
|
|
}
|
|
|
|
|
2015-01-03 19:52:37 +00:00
|
|
|
void GraphEdit::_bind_methods() {
|
2017-08-09 11:19:41 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("connect_node", "from", "from_port", "to", "to_port"), &GraphEdit::connect_node);
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("is_node_connected", "from", "from_port", "to", "to_port"), &GraphEdit::is_node_connected);
|
|
|
|
ClassDB::bind_method(D_METHOD("disconnect_node", "from", "from_port", "to", "to_port"), &GraphEdit::disconnect_node);
|
2018-06-19 01:10:48 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_connection_activity", "from", "from_port", "to", "to_port", "amount"), &GraphEdit::set_connection_activity);
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_connection_list"), &GraphEdit::_get_connection_list);
|
2018-01-31 00:09:41 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("clear_connections"), &GraphEdit::clear_connections);
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_scroll_ofs"), &GraphEdit::get_scroll_ofs);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_scroll_ofs", "ofs"), &GraphEdit::set_scroll_ofs);
|
2016-01-18 23:32:37 +00:00
|
|
|
|
2018-01-31 00:09:41 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("add_valid_right_disconnect_type", "type"), &GraphEdit::add_valid_right_disconnect_type);
|
|
|
|
ClassDB::bind_method(D_METHOD("remove_valid_right_disconnect_type", "type"), &GraphEdit::remove_valid_right_disconnect_type);
|
|
|
|
ClassDB::bind_method(D_METHOD("add_valid_left_disconnect_type", "type"), &GraphEdit::add_valid_left_disconnect_type);
|
|
|
|
ClassDB::bind_method(D_METHOD("remove_valid_left_disconnect_type", "type"), &GraphEdit::remove_valid_left_disconnect_type);
|
|
|
|
ClassDB::bind_method(D_METHOD("add_valid_connection_type", "from_type", "to_type"), &GraphEdit::add_valid_connection_type);
|
|
|
|
ClassDB::bind_method(D_METHOD("remove_valid_connection_type", "from_type", "to_type"), &GraphEdit::remove_valid_connection_type);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_valid_connection_type", "from_type", "to_type"), &GraphEdit::is_valid_connection_type);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_zoom", "p_zoom"), &GraphEdit::set_zoom);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_zoom"), &GraphEdit::get_zoom);
|
2016-08-04 03:05:35 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_snap", "pixels"), &GraphEdit::set_snap);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_snap"), &GraphEdit::get_snap);
|
2016-08-04 03:05:35 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_use_snap", "enable"), &GraphEdit::set_use_snap);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_using_snap"), &GraphEdit::is_using_snap);
|
2015-01-07 04:45:46 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_right_disconnects", "enable"), &GraphEdit::set_right_disconnects);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_right_disconnects_enabled"), &GraphEdit::is_right_disconnects_enabled);
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("_gui_input"), &GraphEdit::_gui_input);
|
|
|
|
ClassDB::bind_method(D_METHOD("_update_scroll_offset"), &GraphEdit::_update_scroll_offset);
|
2016-08-31 02:44:14 +00:00
|
|
|
|
2018-06-19 01:10:48 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_zoom_hbox"), &GraphEdit::get_zoom_hbox);
|
|
|
|
|
2017-08-09 11:19:41 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_selected", "node"), &GraphEdit::set_selected);
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2018-01-11 22:35:12 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "right_disconnects"), "set_right_disconnects", "is_right_disconnects_enabled");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scroll_offset"), "set_scroll_ofs", "get_scroll_ofs");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "snap_distance"), "set_snap", "get_snap");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_snap"), "set_use_snap", "is_using_snap");
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "zoom"), "set_zoom", "get_zoom");
|
2018-01-11 22:35:12 +00:00
|
|
|
|
2020-02-20 21:58:05 +00:00
|
|
|
ADD_SIGNAL(MethodInfo("connection_request", PropertyInfo(Variant::STRING_NAME, "from"), PropertyInfo(Variant::INT, "from_slot"), PropertyInfo(Variant::STRING_NAME, "to"), PropertyInfo(Variant::INT, "to_slot")));
|
|
|
|
ADD_SIGNAL(MethodInfo("disconnection_request", PropertyInfo(Variant::STRING_NAME, "from"), PropertyInfo(Variant::INT, "from_slot"), PropertyInfo(Variant::STRING_NAME, "to"), PropertyInfo(Variant::INT, "to_slot")));
|
2018-12-27 10:10:09 +00:00
|
|
|
ADD_SIGNAL(MethodInfo("popup_request", PropertyInfo(Variant::VECTOR2, "position")));
|
2015-07-26 00:16:07 +00:00
|
|
|
ADD_SIGNAL(MethodInfo("duplicate_nodes_request"));
|
2019-07-12 17:36:33 +00:00
|
|
|
ADD_SIGNAL(MethodInfo("copy_nodes_request"));
|
|
|
|
ADD_SIGNAL(MethodInfo("paste_nodes_request"));
|
2018-09-01 10:05:51 +00:00
|
|
|
ADD_SIGNAL(MethodInfo("node_selected", PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "Node")));
|
2020-04-10 20:00:50 +00:00
|
|
|
ADD_SIGNAL(MethodInfo("node_unselected", PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "Node")));
|
2020-02-20 21:58:05 +00:00
|
|
|
ADD_SIGNAL(MethodInfo("connection_to_empty", PropertyInfo(Variant::STRING_NAME, "from"), PropertyInfo(Variant::INT, "from_slot"), PropertyInfo(Variant::VECTOR2, "release_position")));
|
|
|
|
ADD_SIGNAL(MethodInfo("connection_from_empty", PropertyInfo(Variant::STRING_NAME, "to"), PropertyInfo(Variant::INT, "to_slot"), PropertyInfo(Variant::VECTOR2, "release_position")));
|
2015-07-27 00:57:27 +00:00
|
|
|
ADD_SIGNAL(MethodInfo("delete_nodes_request"));
|
2015-07-21 01:15:06 +00:00
|
|
|
ADD_SIGNAL(MethodInfo("_begin_node_move"));
|
|
|
|
ADD_SIGNAL(MethodInfo("_end_node_move"));
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_SIGNAL(MethodInfo("scroll_offset_changed", PropertyInfo(Variant::VECTOR2, "ofs")));
|
2015-01-03 19:52:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GraphEdit::GraphEdit() {
|
2015-07-26 00:16:07 +00:00
|
|
|
set_focus_mode(FOCUS_ALL);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
awaiting_scroll_offset_update = false;
|
2020-04-01 23:20:12 +00:00
|
|
|
top_layer = nullptr;
|
2017-03-05 15:44:50 +00:00
|
|
|
top_layer = memnew(GraphEditFilter(this));
|
2015-07-21 01:15:06 +00:00
|
|
|
add_child(top_layer);
|
2017-01-08 22:54:19 +00:00
|
|
|
top_layer->set_mouse_filter(MOUSE_FILTER_PASS);
|
2017-09-21 22:12:33 +00:00
|
|
|
top_layer->set_anchors_and_margins_preset(Control::PRESET_WIDE);
|
2020-02-21 17:28:45 +00:00
|
|
|
top_layer->connect("draw", callable_mp(this, &GraphEdit::_top_layer_draw));
|
|
|
|
top_layer->connect("gui_input", callable_mp(this, &GraphEdit::_top_layer_input));
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
connections_layer = memnew(Control);
|
2016-08-31 02:44:14 +00:00
|
|
|
add_child(connections_layer);
|
2020-02-21 17:28:45 +00:00
|
|
|
connections_layer->connect("draw", callable_mp(this, &GraphEdit::_connections_layer_draw));
|
2016-08-31 02:44:14 +00:00
|
|
|
connections_layer->set_name("CLAYER");
|
2018-09-13 01:38:39 +00:00
|
|
|
connections_layer->set_disable_visibility_clip(true); // so it can draw freely and be offset
|
2017-08-08 13:57:33 +00:00
|
|
|
connections_layer->set_mouse_filter(MOUSE_FILTER_IGNORE);
|
2016-08-31 02:44:14 +00:00
|
|
|
|
2015-07-21 01:15:06 +00:00
|
|
|
h_scroll = memnew(HScrollBar);
|
|
|
|
h_scroll->set_name("_h_scroll");
|
|
|
|
top_layer->add_child(h_scroll);
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2015-07-21 01:15:06 +00:00
|
|
|
v_scroll = memnew(VScrollBar);
|
|
|
|
v_scroll->set_name("_v_scroll");
|
|
|
|
top_layer->add_child(v_scroll);
|
2020-01-14 21:19:12 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
updating = false;
|
|
|
|
connecting = false;
|
|
|
|
right_disconnects = false;
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2015-07-25 00:59:48 +00:00
|
|
|
box_selecting = false;
|
|
|
|
dragging = false;
|
|
|
|
|
2016-08-06 22:00:54 +00:00
|
|
|
//set large minmax so it can scroll even if not resized yet
|
|
|
|
h_scroll->set_min(-10000);
|
|
|
|
h_scroll->set_max(10000);
|
|
|
|
|
|
|
|
v_scroll->set_min(-10000);
|
|
|
|
v_scroll->set_max(10000);
|
|
|
|
|
2020-02-21 17:28:45 +00:00
|
|
|
h_scroll->connect("value_changed", callable_mp(this, &GraphEdit::_scroll_moved));
|
|
|
|
v_scroll->connect("value_changed", callable_mp(this, &GraphEdit::_scroll_moved));
|
2016-01-18 23:32:37 +00:00
|
|
|
|
|
|
|
zoom = 1;
|
2016-01-19 01:10:44 +00:00
|
|
|
|
2018-06-19 01:10:48 +00:00
|
|
|
zoom_hb = memnew(HBoxContainer);
|
2016-02-08 19:28:12 +00:00
|
|
|
top_layer->add_child(zoom_hb);
|
2017-03-29 15:29:38 +00:00
|
|
|
zoom_hb->set_position(Vector2(10, 10));
|
2016-02-08 19:28:12 +00:00
|
|
|
|
2020-06-19 18:49:04 +00:00
|
|
|
zoom_minus = memnew(Button);
|
|
|
|
zoom_minus->set_flat(true);
|
2016-02-08 19:28:12 +00:00
|
|
|
zoom_hb->add_child(zoom_minus);
|
2018-12-04 16:36:42 +00:00
|
|
|
zoom_minus->set_tooltip(RTR("Zoom Out"));
|
2020-02-21 17:28:45 +00:00
|
|
|
zoom_minus->connect("pressed", callable_mp(this, &GraphEdit::_zoom_minus));
|
2016-08-04 03:05:35 +00:00
|
|
|
zoom_minus->set_focus_mode(FOCUS_NONE);
|
2016-02-08 19:28:12 +00:00
|
|
|
|
2020-06-19 18:49:04 +00:00
|
|
|
zoom_reset = memnew(Button);
|
|
|
|
zoom_reset->set_flat(true);
|
2016-02-08 19:28:12 +00:00
|
|
|
zoom_hb->add_child(zoom_reset);
|
2018-12-04 16:36:42 +00:00
|
|
|
zoom_reset->set_tooltip(RTR("Zoom Reset"));
|
2020-02-21 17:28:45 +00:00
|
|
|
zoom_reset->connect("pressed", callable_mp(this, &GraphEdit::_zoom_reset));
|
2016-08-04 03:05:35 +00:00
|
|
|
zoom_reset->set_focus_mode(FOCUS_NONE);
|
2016-02-08 19:28:12 +00:00
|
|
|
|
2020-06-19 18:49:04 +00:00
|
|
|
zoom_plus = memnew(Button);
|
|
|
|
zoom_plus->set_flat(true);
|
2016-02-08 19:28:12 +00:00
|
|
|
zoom_hb->add_child(zoom_plus);
|
2018-12-04 16:36:42 +00:00
|
|
|
zoom_plus->set_tooltip(RTR("Zoom In"));
|
2020-02-21 17:28:45 +00:00
|
|
|
zoom_plus->connect("pressed", callable_mp(this, &GraphEdit::_zoom_plus));
|
2016-08-04 03:05:35 +00:00
|
|
|
zoom_plus->set_focus_mode(FOCUS_NONE);
|
|
|
|
|
2020-06-19 18:49:04 +00:00
|
|
|
snap_button = memnew(Button);
|
|
|
|
snap_button->set_flat(true);
|
2016-08-04 03:05:35 +00:00
|
|
|
snap_button->set_toggle_mode(true);
|
2018-12-04 16:36:42 +00:00
|
|
|
snap_button->set_tooltip(RTR("Enable snap and show grid."));
|
2020-02-21 17:28:45 +00:00
|
|
|
snap_button->connect("pressed", callable_mp(this, &GraphEdit::_snap_toggled));
|
2016-08-04 03:05:35 +00:00
|
|
|
snap_button->set_pressed(true);
|
|
|
|
snap_button->set_focus_mode(FOCUS_NONE);
|
|
|
|
zoom_hb->add_child(snap_button);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
snap_amount = memnew(SpinBox);
|
2016-08-04 03:05:35 +00:00
|
|
|
snap_amount->set_min(5);
|
|
|
|
snap_amount->set_max(100);
|
|
|
|
snap_amount->set_step(1);
|
2017-01-04 04:16:14 +00:00
|
|
|
snap_amount->set_value(20);
|
2020-02-21 17:28:45 +00:00
|
|
|
snap_amount->connect("value_changed", callable_mp(this, &GraphEdit::_snap_value_changed));
|
2016-08-04 03:05:35 +00:00
|
|
|
zoom_hb->add_child(snap_amount);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
setting_scroll_ofs = false;
|
2018-10-19 11:31:35 +00:00
|
|
|
just_disconnected = false;
|
2017-01-09 18:50:08 +00:00
|
|
|
set_clip_contents(true);
|
2015-01-03 19:52:37 +00:00
|
|
|
}
|