2016-06-18 14:46:12 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/* graph_edit.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/*************************************************************************/
|
2015-01-03 20:52:37 +01:00
|
|
|
#include "graph_edit.h"
|
2015-01-08 04:41:34 +01:00
|
|
|
#include "os/input.h"
|
|
|
|
#include "os/keyboard.h"
|
2016-01-19 02:10:44 +01:00
|
|
|
#include "scene/gui/box_container.h"
|
2016-01-23 22:49:26 +01:00
|
|
|
|
|
|
|
|
2016-02-08 20:28:12 +01:00
|
|
|
#define ZOOM_SCALE 1.2
|
|
|
|
|
|
|
|
#define MIN_ZOOM (((1/ZOOM_SCALE)/ZOOM_SCALE)/ZOOM_SCALE)
|
|
|
|
#define MAX_ZOOM (1*ZOOM_SCALE*ZOOM_SCALE*ZOOM_SCALE)
|
|
|
|
|
|
|
|
|
2015-01-03 20:52:37 +01:00
|
|
|
bool GraphEditFilter::has_point(const Point2& p_point) const {
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
return ge->_filter_input(p_point);
|
2015-01-03 20:52:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GraphEditFilter::GraphEditFilter(GraphEdit *p_edit) {
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
ge=p_edit;
|
2015-01-03 20:52:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Error GraphEdit::connect_node(const StringName& p_from, int p_from_port,const StringName& p_to,int p_to_port) {
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
if (is_node_connected(p_from,p_from_port,p_to,p_to_port))
|
|
|
|
return OK;
|
|
|
|
Connection c;
|
|
|
|
c.from=p_from;
|
|
|
|
c.from_port=p_from_port;
|
|
|
|
c.to=p_to;
|
|
|
|
c.to_port=p_to_port;
|
|
|
|
connections.push_back(c);
|
|
|
|
top_layer->update();
|
2016-08-23 15:15:47 +02:00
|
|
|
update();
|
2016-08-31 04:44:14 +02:00
|
|
|
connections_layer->update();
|
2015-07-21 03:15:06 +02:00
|
|
|
|
|
|
|
return OK;
|
2015-01-03 20:52:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GraphEdit::is_node_connected(const StringName& p_from, int p_from_port,const StringName& p_to,int p_to_port) {
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
for(List<Connection>::Element *E=connections.front();E;E=E->next()) {
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02: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)
|
|
|
|
return true;
|
|
|
|
}
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
return false;
|
2015-01-03 20:52:37 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphEdit::disconnect_node(const StringName& p_from, int p_from_port,const StringName& p_to,int p_to_port){
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
for(List<Connection>::Element *E=connections.front();E;E=E->next()) {
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02: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-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
connections.erase(E);
|
|
|
|
top_layer->update();
|
2016-08-23 15:15:47 +02:00
|
|
|
update();
|
2016-08-31 04:44:14 +02:00
|
|
|
connections_layer->update();
|
2015-07-21 03:15:06 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2015-01-03 20:52:37 +01:00
|
|
|
}
|
|
|
|
|
2016-01-23 22:49:26 +01:00
|
|
|
bool GraphEdit::clips_input() const {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-08 04:41:34 +01:00
|
|
|
void GraphEdit::get_connection_list(List<Connection> *r_connections) const {
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
*r_connections=connections;
|
2015-01-03 20:52:37 +01:00
|
|
|
}
|
|
|
|
|
2016-08-07 00:00:54 +02:00
|
|
|
void GraphEdit::set_scroll_ofs(const Vector2& p_ofs) {
|
|
|
|
|
|
|
|
setting_scroll_ofs=true;
|
|
|
|
h_scroll->set_val(p_ofs.x);
|
|
|
|
v_scroll->set_val(p_ofs.y);
|
|
|
|
_update_scroll();
|
|
|
|
setting_scroll_ofs=false;
|
|
|
|
}
|
|
|
|
|
2016-01-17 22:26:32 +01:00
|
|
|
Vector2 GraphEdit::get_scroll_ofs() const{
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2016-01-17 22:26:32 +01:00
|
|
|
return Vector2(h_scroll->get_val(),v_scroll->get_val());
|
|
|
|
}
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2016-01-17 22:26:32 +01:00
|
|
|
void GraphEdit::_scroll_moved(double) {
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2016-08-31 04:44:14 +02:00
|
|
|
|
|
|
|
if (!awaiting_scroll_offset_update) {
|
|
|
|
call_deferred("_update_scroll_offset");
|
|
|
|
awaiting_scroll_offset_update=true;
|
|
|
|
}
|
2015-07-21 03:15:06 +02:00
|
|
|
top_layer->update();
|
2016-08-23 15:15:47 +02:00
|
|
|
update();
|
2016-08-07 00:00:54 +02:00
|
|
|
|
|
|
|
if (!setting_scroll_ofs) {//in godot, signals on change value are avoided as a convention
|
|
|
|
emit_signal("scroll_offset_changed",get_scroll_ofs());
|
|
|
|
}
|
2015-01-03 20:52:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void GraphEdit::_update_scroll_offset() {
|
|
|
|
|
2016-08-31 04:44:14 +02:00
|
|
|
set_block_minimum_size_adjust(true);
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
for(int i=0;i<get_child_count();i++) {
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
GraphNode *gn=get_child(i)->cast_to<GraphNode>();
|
|
|
|
if (!gn)
|
|
|
|
continue;
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2016-02-08 20:28:12 +01:00
|
|
|
Point2 pos=gn->get_offset()*zoom;
|
2015-07-21 03:15:06 +02:00
|
|
|
pos-=Point2(h_scroll->get_val(),v_scroll->get_val());
|
|
|
|
gn->set_pos(pos);
|
2016-08-31 04:44:14 +02:00
|
|
|
if (gn->get_scale()!=Vector2(zoom,zoom)) {
|
|
|
|
gn->set_scale(Vector2(zoom,zoom));
|
|
|
|
}
|
2015-07-21 03:15:06 +02:00
|
|
|
}
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2016-10-13 05:11:29 +02:00
|
|
|
connections_layer->set_pos(-Point2(h_scroll->get_val(),v_scroll->get_val()));
|
2016-08-31 04:44:14 +02:00
|
|
|
set_block_minimum_size_adjust(false);
|
|
|
|
awaiting_scroll_offset_update=false;
|
|
|
|
|
2015-01-03 20:52:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void GraphEdit::_update_scroll() {
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
if (updating)
|
|
|
|
return;
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
updating=true;
|
2016-08-31 04:44:14 +02:00
|
|
|
|
|
|
|
set_block_minimum_size_adjust(true);
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
Rect2 screen;
|
|
|
|
for(int i=0;i<get_child_count();i++) {
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
GraphNode *gn=get_child(i)->cast_to<GraphNode>();
|
|
|
|
if (!gn)
|
|
|
|
continue;
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
Rect2 r;
|
2016-02-08 20:28:12 +01:00
|
|
|
r.pos=gn->get_offset()*zoom;
|
|
|
|
r.size=gn->get_size()*zoom;
|
2015-07-21 03:15:06 +02:00
|
|
|
screen = screen.merge(r);
|
|
|
|
}
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
screen.pos-=get_size();
|
|
|
|
screen.size+=get_size()*2.0;
|
2015-01-08 04:41:34 +01:00
|
|
|
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
h_scroll->set_min(screen.pos.x);
|
|
|
|
h_scroll->set_max(screen.pos.x+screen.size.x);
|
|
|
|
h_scroll->set_page(get_size().x);
|
|
|
|
if (h_scroll->get_max() - h_scroll->get_min() <= h_scroll->get_page())
|
|
|
|
h_scroll->hide();
|
|
|
|
else
|
|
|
|
h_scroll->show();
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
v_scroll->set_min(screen.pos.y);
|
|
|
|
v_scroll->set_max(screen.pos.y+screen.size.y);
|
|
|
|
v_scroll->set_page(get_size().y);
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
if (v_scroll->get_max() - v_scroll->get_min() <= v_scroll->get_page())
|
|
|
|
v_scroll->hide();
|
|
|
|
else
|
|
|
|
v_scroll->show();
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2016-08-31 04:44:14 +02:00
|
|
|
set_block_minimum_size_adjust(false);
|
|
|
|
|
|
|
|
if (!awaiting_scroll_offset_update) {
|
|
|
|
call_deferred("_update_scroll_offset");
|
|
|
|
awaiting_scroll_offset_update=true;
|
|
|
|
}
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
updating=false;
|
2015-01-03 20:52:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GraphEdit::_graph_node_raised(Node* p_gn) {
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
GraphNode *gn=p_gn->cast_to<GraphNode>();
|
|
|
|
ERR_FAIL_COND(!gn);
|
|
|
|
gn->raise();
|
2016-08-25 22:45:20 +02:00
|
|
|
if (gn->is_comment()) {
|
|
|
|
move_child(gn,0);
|
|
|
|
}
|
2016-08-31 04:44:14 +02:00
|
|
|
int first_not_comment=0;
|
|
|
|
for(int i=0;i<get_child_count();i++) {
|
|
|
|
GraphNode *gn=get_child(i)->cast_to<GraphNode>();
|
|
|
|
if (gn && !gn->is_comment()) {
|
|
|
|
first_not_comment=i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
move_child(connections_layer,first_not_comment);
|
2015-07-21 03:15:06 +02:00
|
|
|
top_layer->raise();
|
2016-08-03 00:11:05 +02:00
|
|
|
emit_signal("node_selected",p_gn);
|
2015-01-03 20:52:37 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GraphEdit::_graph_node_moved(Node *p_gn) {
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
GraphNode *gn=p_gn->cast_to<GraphNode>();
|
|
|
|
ERR_FAIL_COND(!gn);
|
|
|
|
top_layer->update();
|
2016-08-23 15:15:47 +02:00
|
|
|
update();
|
2016-08-31 04:44:14 +02:00
|
|
|
connections_layer->update();
|
2015-01-03 20:52:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void GraphEdit::add_child_notify(Node *p_child) {
|
|
|
|
|
2016-08-06 03:46:45 +02:00
|
|
|
Control::add_child_notify(p_child);
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
top_layer->call_deferred("raise"); //top layer always on top!
|
|
|
|
GraphNode *gn = p_child->cast_to<GraphNode>();
|
|
|
|
if (gn) {
|
2016-01-19 00:32:37 +01:00
|
|
|
gn->set_scale(Vector2(zoom,zoom));
|
2015-07-21 03:15:06 +02:00
|
|
|
gn->connect("offset_changed",this,"_graph_node_moved",varray(gn));
|
|
|
|
gn->connect("raise_request",this,"_graph_node_raised",varray(gn));
|
2016-10-14 20:11:26 +02:00
|
|
|
gn->connect("item_rect_changed",connections_layer,"update");
|
2015-07-21 03:15:06 +02:00
|
|
|
_graph_node_moved(gn);
|
|
|
|
gn->set_stop_mouse(false);
|
|
|
|
}
|
2016-08-06 03:46:45 +02:00
|
|
|
|
|
|
|
|
2015-01-03 20:52:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void GraphEdit::remove_child_notify(Node *p_child) {
|
|
|
|
|
2016-08-06 03:46:45 +02:00
|
|
|
Control::remove_child_notify(p_child);
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
top_layer->call_deferred("raise"); //top layer always on top!
|
|
|
|
GraphNode *gn = p_child->cast_to<GraphNode>();
|
|
|
|
if (gn) {
|
|
|
|
gn->disconnect("offset_changed",this,"_graph_node_moved");
|
|
|
|
gn->disconnect("raise_request",this,"_graph_node_raised");
|
|
|
|
}
|
2015-01-03 20:52:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void GraphEdit::_notification(int p_what) {
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
if (p_what==NOTIFICATION_READY) {
|
|
|
|
Size2 hmin = h_scroll->get_combined_minimum_size();
|
|
|
|
Size2 vmin = v_scroll->get_combined_minimum_size();
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
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);
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
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);
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2016-08-04 05:05:35 +02:00
|
|
|
|
|
|
|
zoom_minus->set_icon(get_icon("minus"));
|
|
|
|
zoom_reset->set_icon(get_icon("reset"));
|
|
|
|
zoom_plus->set_icon(get_icon("more"));
|
|
|
|
snap_button->set_icon(get_icon("snap"));
|
2016-02-08 20:28:12 +01:00
|
|
|
// zoom_icon->set_texture( get_icon("Zoom", "EditorIcons"));
|
2016-01-19 02:10:44 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
}
|
|
|
|
if (p_what==NOTIFICATION_DRAW) {
|
2016-08-25 22:45:20 +02:00
|
|
|
|
2016-08-31 04:44:14 +02:00
|
|
|
|
2016-02-08 20:28:12 +01:00
|
|
|
draw_style_box( get_stylebox("bg"),Rect2(Point2(),get_size()) );
|
2015-07-21 03:15:06 +02:00
|
|
|
VS::get_singleton()->canvas_item_set_clip(get_canvas_item(),true);
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2016-08-04 05:05:35 +02:00
|
|
|
if (is_using_snap()) {
|
|
|
|
//draw grid
|
|
|
|
|
|
|
|
int snap = get_snap();
|
|
|
|
|
|
|
|
Vector2 offset = get_scroll_ofs()/zoom;
|
|
|
|
Size2 size = get_size()/zoom;
|
|
|
|
|
|
|
|
Point2i from = (offset/float(snap)).floor();
|
|
|
|
Point2i len = (size/float(snap)).floor()+Vector2(1,1);
|
|
|
|
|
|
|
|
Color grid_minor = get_color("grid_minor");
|
|
|
|
Color grid_major = get_color("grid_major");
|
|
|
|
|
|
|
|
for(int i=from.x;i<from.x+len.x;i++) {
|
|
|
|
|
|
|
|
Color color;
|
|
|
|
|
|
|
|
if (ABS(i)%10==0)
|
|
|
|
color=grid_major;
|
|
|
|
else
|
|
|
|
color=grid_minor;
|
|
|
|
|
|
|
|
float base_ofs = i*snap*zoom - offset.x*zoom;
|
|
|
|
draw_line(Vector2(base_ofs,0),Vector2(base_ofs,get_size().height),color);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int i=from.y;i<from.y+len.y;i++) {
|
|
|
|
|
|
|
|
Color color;
|
|
|
|
|
|
|
|
if (ABS(i)%10==0)
|
|
|
|
color=grid_major;
|
|
|
|
else
|
|
|
|
color=grid_minor;
|
|
|
|
|
|
|
|
float base_ofs = i*snap*zoom - offset.y*zoom;
|
|
|
|
draw_line(Vector2(0,base_ofs),Vector2(get_size().width,base_ofs),color);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-08-23 15:15:47 +02:00
|
|
|
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
}
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
if (p_what==NOTIFICATION_RESIZED) {
|
|
|
|
_update_scroll();
|
|
|
|
top_layer->update();
|
2016-08-23 15:15:47 +02:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
}
|
2015-01-03 20:52:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GraphEdit::_filter_input(const Point2& p_point) {
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
Ref<Texture> port =get_icon("port","GraphNode");
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2016-09-07 00:55:22 +02:00
|
|
|
float grab_r_extend = 2.0;
|
|
|
|
float grab_r=port->get_width()*0.5*grab_r_extend;
|
2015-07-21 03:15:06 +02:00
|
|
|
for(int i=get_child_count()-1;i>=0;i--) {
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
GraphNode *gn=get_child(i)->cast_to<GraphNode>();
|
|
|
|
if (!gn)
|
|
|
|
continue;
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
for(int j=0;j<gn->get_connection_output_count();j++) {
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
Vector2 pos = gn->get_connection_output_pos(j)+gn->get_pos();
|
|
|
|
if (pos.distance_to(p_point)<grab_r)
|
|
|
|
return true;
|
2015-01-03 20:52:37 +01:00
|
|
|
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
}
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
for(int j=0;j<gn->get_connection_input_count();j++) {
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
Vector2 pos = gn->get_connection_input_pos(j)+gn->get_pos();
|
2016-09-07 00:55:22 +02:00
|
|
|
if (pos.distance_to(p_point)<grab_r) {
|
2015-07-21 03:15:06 +02:00
|
|
|
return true;
|
2016-09-07 00:55:22 +02:00
|
|
|
}
|
2015-01-03 20:52:37 +01:00
|
|
|
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
}
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
}
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
return false;
|
2015-01-03 20:52:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void GraphEdit::_top_layer_input(const InputEvent& p_ev) {
|
|
|
|
|
2016-09-07 00:55:22 +02:00
|
|
|
|
|
|
|
float grab_r_extend = 2.0;
|
2015-07-21 03:15:06 +02:00
|
|
|
if (p_ev.type==InputEvent::MOUSE_BUTTON && p_ev.mouse_button.button_index==BUTTON_LEFT && p_ev.mouse_button.pressed) {
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
Ref<Texture> port =get_icon("port","GraphNode");
|
|
|
|
Vector2 mpos(p_ev.mouse_button.x,p_ev.mouse_button.y);
|
2016-09-07 00:55:22 +02:00
|
|
|
float grab_r=port->get_width()*0.5*grab_r_extend;
|
2015-07-21 03:15:06 +02:00
|
|
|
for(int i=get_child_count()-1;i>=0;i--) {
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
GraphNode *gn=get_child(i)->cast_to<GraphNode>();
|
|
|
|
if (!gn)
|
|
|
|
continue;
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
for(int j=0;j<gn->get_connection_output_count();j++) {
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
Vector2 pos = gn->get_connection_output_pos(j)+gn->get_pos();
|
|
|
|
if (pos.distance_to(mpos)<grab_r) {
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2016-08-03 00:11:05 +02:00
|
|
|
|
|
|
|
if (valid_left_disconnect_types.has(gn->get_connection_output_type(j))) {
|
|
|
|
//check disconnect
|
|
|
|
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));
|
|
|
|
if (to && to->cast_to<GraphNode>()) {
|
|
|
|
|
|
|
|
connecting_from=E->get().to;
|
|
|
|
connecting_index=E->get().to_port;
|
|
|
|
connecting_out=false;
|
|
|
|
connecting_type=to->cast_to<GraphNode>()->get_connection_input_type(E->get().to_port);
|
|
|
|
connecting_color=to->cast_to<GraphNode>()->get_connection_input_color(E->get().to_port);
|
|
|
|
connecting_target=false;
|
|
|
|
connecting_to=pos;
|
2016-09-03 19:58:23 +02:00
|
|
|
just_disconected=true;
|
2016-08-03 00:11:05 +02:00
|
|
|
|
|
|
|
emit_signal("disconnection_request",E->get().from,E->get().from_port,E->get().to,E->get().to_port);
|
|
|
|
to = get_node(String(connecting_from)); //maybe it was erased
|
|
|
|
if (to && to->cast_to<GraphNode>()) {
|
|
|
|
connecting=true;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-21 03:15:06 +02: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;
|
2016-09-03 19:58:23 +02:00
|
|
|
just_disconected=false;
|
2015-07-21 03:15:06 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-01-03 20:52:37 +01:00
|
|
|
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
}
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
for(int j=0;j<gn->get_connection_input_count();j++) {
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
Vector2 pos = gn->get_connection_input_pos(j)+gn->get_pos();
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
if (pos.distance_to(mpos)<grab_r) {
|
2015-01-07 05:45:46 +01:00
|
|
|
|
2016-08-03 00:11:05 +02:00
|
|
|
if (right_disconnects || valid_right_disconnect_types.has(gn->get_connection_input_type(j))) {
|
2015-07-21 03:15:06 +02:00
|
|
|
//check disconnect
|
|
|
|
for (List<Connection>::Element*E=connections.front();E;E=E->next()) {
|
2015-01-07 05:45:46 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
if (E->get().to==gn->get_name() && E->get().to_port==j) {
|
2015-01-07 05:45:46 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
Node*fr = get_node(String(E->get().from));
|
|
|
|
if (fr && fr->cast_to<GraphNode>()) {
|
2015-01-07 05:45:46 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
connecting_from=E->get().from;
|
|
|
|
connecting_index=E->get().from_port;
|
|
|
|
connecting_out=true;
|
|
|
|
connecting_type=fr->cast_to<GraphNode>()->get_connection_output_type(E->get().from_port);
|
|
|
|
connecting_color=fr->cast_to<GraphNode>()->get_connection_output_color(E->get().from_port);
|
|
|
|
connecting_target=false;
|
|
|
|
connecting_to=pos;
|
2016-09-03 19:58:23 +02:00
|
|
|
just_disconected=true;
|
2015-01-07 05:45:46 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
emit_signal("disconnection_request",E->get().from,E->get().from_port,E->get().to,E->get().to_port);
|
|
|
|
fr = get_node(String(connecting_from)); //maybe it was erased
|
|
|
|
if (fr && fr->cast_to<GraphNode>()) {
|
|
|
|
connecting=true;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2015-01-07 05:45:46 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-01-07 05:45:46 +01:00
|
|
|
|
|
|
|
|
2015-07-21 03:15:06 +02: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;
|
2016-09-03 19:58:23 +02:00
|
|
|
just_disconected=true;
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-01-03 20:52:37 +01:00
|
|
|
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
if (p_ev.type==InputEvent::MOUSE_MOTION && connecting) {
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
connecting_to=Vector2(p_ev.mouse_motion.x,p_ev.mouse_motion.y);
|
|
|
|
connecting_target=false;
|
2016-08-23 15:15:47 +02:00
|
|
|
top_layer->update();
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
Ref<Texture> port =get_icon("port","GraphNode");
|
|
|
|
Vector2 mpos(p_ev.mouse_button.x,p_ev.mouse_button.y);
|
2016-09-07 00:55:22 +02:00
|
|
|
float grab_r=port->get_width()*0.5*grab_r_extend;
|
2015-07-21 03:15:06 +02:00
|
|
|
for(int i=get_child_count()-1;i>=0;i--) {
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
GraphNode *gn=get_child(i)->cast_to<GraphNode>();
|
|
|
|
if (!gn)
|
|
|
|
continue;
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
if (!connecting_out) {
|
|
|
|
for(int j=0;j<gn->get_connection_output_count();j++) {
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
Vector2 pos = gn->get_connection_output_pos(j)+gn->get_pos();
|
|
|
|
int type =gn->get_connection_output_type(j);
|
2016-08-03 00:11:05 +02:00
|
|
|
if ((type==connecting_type ||valid_connection_types.has(ConnType(type,connecting_type))) && pos.distance_to(mpos)<grab_r) {
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
connecting_target=true;
|
|
|
|
connecting_to=pos;
|
|
|
|
connecting_target_to=gn->get_name();
|
|
|
|
connecting_target_index=j;
|
|
|
|
return;
|
|
|
|
}
|
2015-01-03 20:52:37 +01:00
|
|
|
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
}
|
|
|
|
} else {
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
for(int j=0;j<gn->get_connection_input_count();j++) {
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
Vector2 pos = gn->get_connection_input_pos(j)+gn->get_pos();
|
|
|
|
int type =gn->get_connection_input_type(j);
|
2016-08-03 00:11:05 +02:00
|
|
|
if ((type==connecting_type ||valid_connection_types.has(ConnType(type,connecting_type))) && pos.distance_to(mpos)<grab_r) {
|
2015-07-21 03:15:06 +02:00
|
|
|
connecting_target=true;
|
|
|
|
connecting_to=pos;
|
|
|
|
connecting_target_to=gn->get_name();
|
|
|
|
connecting_target_index=j;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
if (p_ev.type==InputEvent::MOUSE_BUTTON && p_ev.mouse_button.button_index==BUTTON_LEFT && !p_ev.mouse_button.pressed) {
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
if (connecting && connecting_target) {
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
String from = connecting_from;
|
|
|
|
int from_slot = connecting_index;
|
|
|
|
String to =connecting_target_to;
|
|
|
|
int to_slot = connecting_target_index;
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
if (!connecting_out) {
|
|
|
|
SWAP(from,to);
|
|
|
|
SWAP(from_slot,to_slot);
|
|
|
|
}
|
|
|
|
emit_signal("connection_request",from,from_slot,to,to_slot);
|
|
|
|
|
2016-09-03 19:58:23 +02:00
|
|
|
} else if (!just_disconected) {
|
2016-08-24 00:29:07 +02:00
|
|
|
String from = connecting_from;
|
|
|
|
int from_slot = connecting_index;
|
|
|
|
Vector2 ofs = Vector2(p_ev.mouse_button.x,p_ev.mouse_button.y);
|
|
|
|
emit_signal("connection_to_empty",from,from_slot,ofs);
|
2015-07-21 03:15:06 +02:00
|
|
|
}
|
|
|
|
connecting=false;
|
|
|
|
top_layer->update();
|
2016-08-23 15:15:47 +02:00
|
|
|
update();
|
2016-08-31 04:44:14 +02:00
|
|
|
connections_layer->update();
|
2015-07-19 06:48:46 +02:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
}
|
2015-01-03 20:52:37 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-08-23 15:15:47 +02:00
|
|
|
|
|
|
|
template<class Vector2>
|
|
|
|
static _FORCE_INLINE_ Vector2 _bezier_interp(real_t t, Vector2 start, Vector2 control_1, Vector2 control_2, Vector2 end) {
|
|
|
|
/* Formula from Wikipedia article on Bezier curves. */
|
|
|
|
real_t omt = (1.0 - t);
|
|
|
|
real_t omt2 = omt*omt;
|
|
|
|
real_t omt3 = omt2*omt;
|
|
|
|
real_t t2 = t*t;
|
|
|
|
real_t t3 = t2*t;
|
|
|
|
|
|
|
|
return start * omt3
|
|
|
|
+ control_1 * omt2 * t * 3.0
|
|
|
|
+ control_2 * omt * t2 * 3.0
|
|
|
|
+ end * t3;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GraphEdit::_bake_segment2d(CanvasItem* p_where,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 {
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
Vector2 na = (mid-beg).normalized();
|
|
|
|
Vector2 nb = (end-mid).normalized();
|
|
|
|
float dp = Math::rad2deg(Math::acos(na.dot(nb)));
|
|
|
|
|
|
|
|
if (p_depth>=p_min_depth && ( dp<p_tol || p_depth>=p_max_depth)) {
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-08-31 04:44:14 +02:00
|
|
|
p_where->draw_line(beg,end,p_color.linear_interpolate(p_to_color,mp),2,true);
|
2016-08-23 15:15:47 +02:00
|
|
|
lines++;
|
|
|
|
} else {
|
|
|
|
_bake_segment2d(p_where,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(p_where,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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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-31 04:44:14 +02:00
|
|
|
|
2016-08-23 15:15:47 +02:00
|
|
|
#if 1
|
|
|
|
|
|
|
|
//cubic bezier code
|
|
|
|
float diff = p_to.x-p_from.x;
|
|
|
|
float cp_offset;
|
|
|
|
int cp_len = get_constant("bezier_len_pos");
|
|
|
|
int cp_neg_len = get_constant("bezier_len_neg");
|
|
|
|
|
|
|
|
if (diff>0) {
|
|
|
|
cp_offset=MAX(cp_len,diff*0.5);
|
|
|
|
} else {
|
|
|
|
cp_offset=MAX(MIN(cp_len-diff,cp_neg_len),-diff*0.5);
|
|
|
|
}
|
|
|
|
|
2016-10-13 05:11:29 +02:00
|
|
|
Vector2 c1 = Vector2(cp_offset*zoom,0);
|
|
|
|
Vector2 c2 = Vector2(-cp_offset*zoom,0);
|
2016-08-23 15:15:47 +02:00
|
|
|
|
|
|
|
int lines=0;
|
2016-08-31 04:44:14 +02:00
|
|
|
_bake_segment2d(p_where,0,1,p_from,c1,p_to,c2,0,3,9,8,p_color,p_to_color,lines);
|
2016-08-23 15:15:47 +02:00
|
|
|
|
|
|
|
|
|
|
|
#else
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
static const int steps = 20;
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2016-08-23 15:15:47 +02:00
|
|
|
//old cosine code
|
2015-07-21 03:15:06 +02:00
|
|
|
Rect2 r;
|
|
|
|
r.pos=p_from;
|
|
|
|
r.expand_to(p_to);
|
|
|
|
Vector2 sign=Vector2((p_from.x < p_to.x) ? 1 : -1,(p_from.y < p_to.y) ? 1 : -1);
|
|
|
|
bool flip = sign.x * sign.y < 0;
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
Vector2 prev;
|
|
|
|
for(int i=0;i<=steps;i++) {
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2016-08-23 15:15:47 +02:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
float d = i/float(steps);
|
|
|
|
float c=-Math::cos(d*Math_PI) * 0.5+0.5;
|
|
|
|
if (flip)
|
|
|
|
c=1.0-c;
|
|
|
|
Vector2 p = r.pos+Vector2(d*r.size.width,c*r.size.height);
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
if (i>0) {
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2016-08-23 15:15:47 +02:00
|
|
|
p_where->draw_line(prev,p,p_color.linear_interpolate(p_to_color,d),2);
|
2015-07-21 03:15:06 +02:00
|
|
|
}
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
prev=p;
|
|
|
|
}
|
2016-08-23 15:15:47 +02:00
|
|
|
#endif
|
2015-01-03 20:52:37 +01:00
|
|
|
}
|
|
|
|
|
2016-08-31 04:44:14 +02:00
|
|
|
|
|
|
|
void GraphEdit::_connections_layer_draw() {
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
//draw connections
|
|
|
|
List<List<Connection>::Element* > to_erase;
|
|
|
|
for(List<Connection>::Element *E=connections.front();E;E=E->next()) {
|
|
|
|
|
|
|
|
NodePath fromnp(E->get().from);
|
|
|
|
|
|
|
|
Node * from = get_node(fromnp);
|
|
|
|
if (!from) {
|
|
|
|
to_erase.push_back(E);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
GraphNode *gfrom = from->cast_to<GraphNode>();
|
|
|
|
|
|
|
|
if (!gfrom) {
|
|
|
|
to_erase.push_back(E);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
NodePath tonp(E->get().to);
|
|
|
|
Node * to = get_node(tonp);
|
|
|
|
if (!to) {
|
|
|
|
to_erase.push_back(E);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
GraphNode *gto = to->cast_to<GraphNode>();
|
|
|
|
|
|
|
|
if (!gto) {
|
|
|
|
to_erase.push_back(E);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-10-13 05:11:29 +02:00
|
|
|
Vector2 frompos=gfrom->get_connection_output_pos(E->get().from_port)+gfrom->get_offset()*zoom;
|
2016-08-31 04:44:14 +02:00
|
|
|
Color color = gfrom->get_connection_output_color(E->get().from_port);
|
2016-10-13 05:11:29 +02:00
|
|
|
Vector2 topos=gto->get_connection_input_pos(E->get().to_port)+gto->get_offset()*zoom;
|
2016-08-31 04:44:14 +02:00
|
|
|
Color tocolor = gto->get_connection_input_color(E->get().to_port);
|
|
|
|
_draw_cos_line(connections_layer,frompos,topos,color,tocolor);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
while(to_erase.size()) {
|
|
|
|
connections.erase(to_erase.front()->get());
|
|
|
|
to_erase.pop_front();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-03 20:52:37 +01:00
|
|
|
void GraphEdit::_top_layer_draw() {
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
_update_scroll();
|
|
|
|
|
|
|
|
if (connecting) {
|
|
|
|
|
|
|
|
Node *fromn = get_node(connecting_from);
|
|
|
|
ERR_FAIL_COND(!fromn);
|
|
|
|
GraphNode *from = fromn->cast_to<GraphNode>();
|
|
|
|
ERR_FAIL_COND(!from);
|
|
|
|
Vector2 pos;
|
|
|
|
if (connecting_out)
|
|
|
|
pos=from->get_connection_output_pos(connecting_index);
|
|
|
|
else
|
|
|
|
pos=from->get_connection_input_pos(connecting_index);
|
|
|
|
pos+=from->get_pos();
|
|
|
|
|
|
|
|
Vector2 topos;
|
|
|
|
topos=connecting_to;
|
|
|
|
|
|
|
|
Color col=connecting_color;
|
|
|
|
|
|
|
|
if (connecting_target) {
|
|
|
|
col.r+=0.4;
|
|
|
|
col.g+=0.4;
|
|
|
|
col.b+=0.4;
|
|
|
|
}
|
2016-08-25 22:45:20 +02:00
|
|
|
|
|
|
|
if (!connecting_out) {
|
|
|
|
SWAP(pos,topos);
|
|
|
|
}
|
2016-08-23 15:15:47 +02:00
|
|
|
_draw_cos_line(top_layer,pos,topos,col,col);
|
2015-07-21 03:15:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-25 02:59:48 +02:00
|
|
|
if (box_selecting)
|
|
|
|
top_layer->draw_rect(box_selecting_rect,Color(0.7,0.7,1.0,0.3));
|
2015-01-03 20:52:37 +01:00
|
|
|
}
|
|
|
|
|
2016-08-03 00:11:05 +02:00
|
|
|
void GraphEdit::set_selected(Node* p_child) {
|
|
|
|
|
|
|
|
for(int i=get_child_count()-1;i>=0;i--) {
|
|
|
|
|
|
|
|
GraphNode *gn=get_child(i)->cast_to<GraphNode>();
|
|
|
|
if (!gn)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
gn->set_selected(gn==p_child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-03 20:52:37 +01:00
|
|
|
void GraphEdit::_input_event(const InputEvent& p_ev) {
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
if (p_ev.type==InputEvent::MOUSE_MOTION && (p_ev.mouse_motion.button_mask&BUTTON_MASK_MIDDLE || (p_ev.mouse_motion.button_mask&BUTTON_MASK_LEFT && Input::get_singleton()->is_key_pressed(KEY_SPACE)))) {
|
|
|
|
h_scroll->set_val( h_scroll->get_val() - p_ev.mouse_motion.relative_x );
|
|
|
|
v_scroll->set_val( v_scroll->get_val() - p_ev.mouse_motion.relative_y );
|
|
|
|
}
|
2015-07-19 06:48:46 +02:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
if (p_ev.type==InputEvent::MOUSE_MOTION && dragging) {
|
2015-07-19 06:48:46 +02:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
just_selected=true;
|
2016-07-26 23:19:41 +02:00
|
|
|
// TODO: Remove local mouse pos hack if/when InputEventMouseMotion is fixed to support floats
|
|
|
|
//drag_accum+=Vector2(p_ev.mouse_motion.relative_x,p_ev.mouse_motion.relative_y);
|
|
|
|
drag_accum = get_local_mouse_pos() - drag_origin;
|
2015-07-21 03:15:06 +02:00
|
|
|
for(int i=get_child_count()-1;i>=0;i--) {
|
|
|
|
GraphNode *gn=get_child(i)->cast_to<GraphNode>();
|
2016-08-04 05:05:35 +02:00
|
|
|
if (gn && gn->is_selected()) {
|
|
|
|
|
|
|
|
Vector2 pos = (gn->get_drag_from()*zoom+drag_accum)/zoom;
|
|
|
|
if (is_using_snap()) {
|
|
|
|
int snap = get_snap();
|
|
|
|
pos = pos.snapped(Vector2(snap,snap));
|
|
|
|
}
|
|
|
|
|
|
|
|
gn->set_offset(pos);
|
|
|
|
}
|
2015-07-21 03:15:06 +02:00
|
|
|
}
|
|
|
|
}
|
2015-07-19 06:48:46 +02:00
|
|
|
|
2015-07-25 02:59:48 +02:00
|
|
|
if (p_ev.type==InputEvent::MOUSE_MOTION && box_selecting) {
|
|
|
|
box_selecting_to = get_local_mouse_pos();
|
|
|
|
|
|
|
|
box_selecting_rect = Rect2(MIN(box_selecting_from.x,box_selecting_to.x),
|
|
|
|
MIN(box_selecting_from.y,box_selecting_to.y),
|
|
|
|
ABS(box_selecting_from.x-box_selecting_to.x),
|
|
|
|
ABS(box_selecting_from.y-box_selecting_to.y));
|
|
|
|
|
|
|
|
for(int i=get_child_count()-1;i>=0;i--) {
|
|
|
|
|
|
|
|
GraphNode *gn=get_child(i)->cast_to<GraphNode>();
|
|
|
|
if (!gn)
|
|
|
|
continue;
|
|
|
|
|
2016-01-19 00:32:37 +01:00
|
|
|
Rect2 r = gn->get_rect();
|
|
|
|
r.size*=zoom;
|
|
|
|
bool in_box = r.intersects(box_selecting_rect);
|
2015-07-25 02:59:48 +02:00
|
|
|
|
|
|
|
if (in_box)
|
|
|
|
gn->set_selected(box_selection_mode_aditive);
|
|
|
|
else
|
|
|
|
gn->set_selected(previus_selected.find(gn)!=NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
top_layer->update();
|
|
|
|
}
|
|
|
|
|
2015-07-26 02:16:07 +02:00
|
|
|
if (p_ev.type==InputEvent::MOUSE_BUTTON) {
|
2015-07-17 03:38:12 +02:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
const InputEventMouseButton &b=p_ev.mouse_button;
|
2015-07-17 03:38:12 +02:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
if (b.button_index==BUTTON_RIGHT && b.pressed)
|
|
|
|
{
|
2015-07-25 02:59:48 +02:00
|
|
|
if (box_selecting) {
|
|
|
|
box_selecting = false;
|
|
|
|
for(int i=get_child_count()-1;i>=0;i--) {
|
|
|
|
|
|
|
|
GraphNode *gn=get_child(i)->cast_to<GraphNode>();
|
|
|
|
if (!gn)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
gn->set_selected(previus_selected.find(gn)!=NULL);
|
|
|
|
}
|
|
|
|
top_layer->update();
|
|
|
|
} else {
|
2016-01-19 00:32:37 +01:00
|
|
|
if (connecting) {
|
|
|
|
connecting = false;
|
|
|
|
top_layer->update();
|
|
|
|
} else {
|
|
|
|
emit_signal("popup_request", Vector2(b.global_x, b.global_y));
|
|
|
|
}
|
2015-07-25 02:59:48 +02:00
|
|
|
}
|
2015-07-21 03:15:06 +02:00
|
|
|
}
|
2015-07-19 06:48:46 +02:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
if (b.button_index==BUTTON_LEFT && !b.pressed && dragging) {
|
|
|
|
if (!just_selected && drag_accum==Vector2() && Input::get_singleton()->is_key_pressed(KEY_CONTROL)) {
|
|
|
|
//deselect current node
|
|
|
|
for(int i=get_child_count()-1;i>=0;i--) {
|
|
|
|
GraphNode *gn=get_child(i)->cast_to<GraphNode>();
|
2015-07-19 06:48:46 +02:00
|
|
|
|
2016-01-19 00:32:37 +01:00
|
|
|
if (gn) {
|
|
|
|
Rect2 r = gn->get_rect();
|
|
|
|
r.size*=zoom;
|
|
|
|
if (r.has_point(get_local_mouse_pos()))
|
|
|
|
gn->set_selected(false);
|
|
|
|
}
|
2015-07-21 03:15:06 +02:00
|
|
|
}
|
|
|
|
}
|
2015-07-19 06:48:46 +02:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
if (drag_accum!=Vector2()) {
|
2015-07-19 06:48:46 +02:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
emit_signal("_begin_node_move");
|
2015-07-19 06:48:46 +02:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
for(int i=get_child_count()-1;i>=0;i--) {
|
|
|
|
GraphNode *gn=get_child(i)->cast_to<GraphNode>();
|
|
|
|
if (gn && gn->is_selected())
|
|
|
|
gn->set_drag(false);
|
|
|
|
}
|
2015-07-19 06:48:46 +02:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
emit_signal("_end_node_move");
|
|
|
|
}
|
2015-07-19 06:48:46 +02:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
dragging = false;
|
2015-07-19 06:48:46 +02:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
top_layer->update();
|
2016-08-23 15:15:47 +02:00
|
|
|
update();
|
2016-08-31 04:44:14 +02:00
|
|
|
connections_layer->update();
|
2015-07-21 03:15:06 +02:00
|
|
|
}
|
2015-07-19 06:48:46 +02:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
if (b.button_index==BUTTON_LEFT && b.pressed) {
|
2015-07-19 06:48:46 +02:00
|
|
|
|
2016-02-29 23:36:19 +01:00
|
|
|
GraphNode *gn = NULL;
|
2016-10-04 18:10:49 +02:00
|
|
|
GraphNode *gn_selected = NULL;
|
2015-07-21 03:15:06 +02:00
|
|
|
for(int i=get_child_count()-1;i>=0;i--) {
|
2015-07-19 06:48:46 +02:00
|
|
|
|
2016-10-04 18:10:49 +02:00
|
|
|
gn_selected=get_child(i)->cast_to<GraphNode>();
|
2015-07-19 06:48:46 +02:00
|
|
|
|
2016-10-04 18:10:49 +02:00
|
|
|
if (gn_selected) {
|
2016-08-25 22:45:20 +02:00
|
|
|
|
2016-10-04 18:10:49 +02:00
|
|
|
if (gn_selected->is_resizing())
|
2016-08-25 22:45:20 +02:00
|
|
|
continue;
|
|
|
|
|
2016-10-04 18:10:49 +02:00
|
|
|
Rect2 r = gn_selected->get_rect();
|
2016-01-19 00:32:37 +01:00
|
|
|
r.size*=zoom;
|
|
|
|
if (r.has_point(get_local_mouse_pos()))
|
2016-10-04 18:10:49 +02:00
|
|
|
gn = gn_selected;
|
2016-01-19 00:32:37 +01:00
|
|
|
break;
|
|
|
|
}
|
2015-07-21 03:15:06 +02:00
|
|
|
}
|
2015-07-19 06:48:46 +02:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
if (gn) {
|
2015-07-19 06:48:46 +02:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
if (_filter_input(Vector2(b.x,b.y)))
|
|
|
|
return;
|
2015-07-19 06:48:46 +02:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
dragging = true;
|
|
|
|
drag_accum = Vector2();
|
2016-07-26 23:19:41 +02:00
|
|
|
drag_origin = get_local_mouse_pos();
|
2015-07-21 03:15:06 +02:00
|
|
|
just_selected = !gn->is_selected();
|
|
|
|
if(!gn->is_selected() && !Input::get_singleton()->is_key_pressed(KEY_CONTROL)) {
|
|
|
|
for (int i = 0; i < get_child_count(); i++) {
|
|
|
|
GraphNode *o_gn = get_child(i)->cast_to<GraphNode>();
|
|
|
|
if (o_gn)
|
|
|
|
o_gn->set_selected(o_gn == gn);
|
|
|
|
}
|
|
|
|
}
|
2015-07-19 06:48:46 +02:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
gn->set_selected(true);
|
|
|
|
for (int i = 0; i < get_child_count(); i++) {
|
|
|
|
GraphNode *o_gn = get_child(i)->cast_to<GraphNode>();
|
|
|
|
if (!o_gn)
|
|
|
|
continue;
|
|
|
|
if (o_gn->is_selected())
|
|
|
|
o_gn->set_drag(true);
|
|
|
|
}
|
2015-07-19 06:48:46 +02:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
} else {
|
2016-01-19 00:32:37 +01:00
|
|
|
if (_filter_input(Vector2(b.x,b.y)))
|
|
|
|
return;
|
2016-02-08 20:28:12 +01:00
|
|
|
if (Input::get_singleton()->is_key_pressed(KEY_SPACE))
|
|
|
|
return;
|
2016-01-19 00:32:37 +01:00
|
|
|
|
2015-07-25 02:59:48 +02:00
|
|
|
box_selecting = true;
|
|
|
|
box_selecting_from = get_local_mouse_pos();
|
|
|
|
if (b.mod.control) {
|
|
|
|
box_selection_mode_aditive = true;
|
|
|
|
previus_selected.clear();
|
|
|
|
for(int i=get_child_count()-1;i>=0;i--) {
|
|
|
|
|
|
|
|
GraphNode *gn=get_child(i)->cast_to<GraphNode>();
|
|
|
|
if (!gn || !gn->is_selected())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
previus_selected.push_back(gn);
|
|
|
|
}
|
|
|
|
} else if (b.mod.shift) {
|
|
|
|
box_selection_mode_aditive = false;
|
|
|
|
previus_selected.clear();
|
|
|
|
for(int i=get_child_count()-1;i>=0;i--) {
|
2015-07-19 06:48:46 +02:00
|
|
|
|
2015-07-25 02:59:48 +02:00
|
|
|
GraphNode *gn=get_child(i)->cast_to<GraphNode>();
|
|
|
|
if (!gn || !gn->is_selected())
|
|
|
|
continue;
|
2015-07-19 06:48:46 +02:00
|
|
|
|
2015-07-25 02:59:48 +02:00
|
|
|
previus_selected.push_back(gn);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
box_selection_mode_aditive = true;
|
|
|
|
previus_selected.clear();
|
|
|
|
for(int i=get_child_count()-1;i>=0;i--) {
|
|
|
|
|
|
|
|
GraphNode *gn=get_child(i)->cast_to<GraphNode>();
|
|
|
|
if (!gn)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
gn->set_selected(false);
|
|
|
|
}
|
2015-07-21 03:15:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-07-25 02:59:48 +02:00
|
|
|
|
|
|
|
if (b.button_index==BUTTON_LEFT && !b.pressed && box_selecting) {
|
|
|
|
box_selecting = false;
|
|
|
|
previus_selected.clear();
|
|
|
|
top_layer->update();
|
|
|
|
}
|
2016-01-19 00:32:37 +01:00
|
|
|
|
|
|
|
if (b.button_index==BUTTON_WHEEL_UP && b.pressed) {
|
2016-02-08 20:28:12 +01:00
|
|
|
//too difficult to get right
|
|
|
|
//set_zoom(zoom*ZOOM_SCALE);
|
2016-01-19 00:32:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (b.button_index==BUTTON_WHEEL_DOWN && b.pressed) {
|
2016-02-08 20:28:12 +01:00
|
|
|
//too difficult to get right
|
|
|
|
//set_zoom(zoom/ZOOM_SCALE);
|
2016-01-19 00:32:37 +01:00
|
|
|
}
|
2015-07-21 03:15:06 +02:00
|
|
|
}
|
2015-07-26 02:16:07 +02:00
|
|
|
|
|
|
|
if (p_ev.type==InputEvent::KEY && p_ev.key.scancode==KEY_D && p_ev.key.pressed && p_ev.key.mod.command) {
|
|
|
|
emit_signal("duplicate_nodes_request");
|
|
|
|
accept_event();
|
|
|
|
}
|
2015-07-27 02:57:27 +02:00
|
|
|
|
|
|
|
if (p_ev.type==InputEvent::KEY && p_ev.key.scancode==KEY_DELETE && p_ev.key.pressed) {
|
|
|
|
emit_signal("delete_nodes_request");
|
|
|
|
accept_event();
|
|
|
|
}
|
|
|
|
|
2015-01-03 20:52:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void GraphEdit::clear_connections() {
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
connections.clear();
|
|
|
|
update();
|
2016-08-31 04:44:14 +02:00
|
|
|
connections_layer->update();
|
2015-01-03 20:52:37 +01:00
|
|
|
}
|
|
|
|
|
2016-01-19 00:32:37 +01:00
|
|
|
void GraphEdit::set_zoom(float p_zoom) {
|
|
|
|
|
2016-02-08 20:28:12 +01:00
|
|
|
p_zoom=CLAMP(p_zoom,MIN_ZOOM,MAX_ZOOM);
|
2016-01-19 00:32:37 +01:00
|
|
|
if (zoom == p_zoom)
|
|
|
|
return;
|
|
|
|
|
2016-02-08 20:28:12 +01:00
|
|
|
zoom_minus->set_disabled(zoom==MIN_ZOOM);
|
|
|
|
zoom_plus->set_disabled(zoom==MAX_ZOOM);
|
|
|
|
|
|
|
|
Vector2 sbofs = (Vector2( h_scroll->get_val(), v_scroll->get_val() ) + get_size()/2)/zoom;
|
|
|
|
|
2016-01-19 00:32:37 +01:00
|
|
|
zoom = p_zoom;
|
2016-02-08 20:28:12 +01:00
|
|
|
top_layer->update();
|
|
|
|
|
|
|
|
_update_scroll();
|
2016-10-13 05:11:29 +02:00
|
|
|
connections_layer->update();
|
2016-02-08 20:28:12 +01:00
|
|
|
|
|
|
|
if (is_visible()) {
|
|
|
|
|
|
|
|
Vector2 ofs = sbofs*zoom - get_size()/2;
|
|
|
|
h_scroll->set_val( ofs.x );
|
|
|
|
v_scroll->set_val( ofs.y );
|
2016-01-19 00:32:37 +01:00
|
|
|
}
|
2016-02-08 20:28:12 +01:00
|
|
|
|
|
|
|
|
2016-01-19 00:32:37 +01:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
float GraphEdit::get_zoom() const {
|
|
|
|
return zoom;
|
|
|
|
}
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-01-07 05:45:46 +01:00
|
|
|
void GraphEdit::set_right_disconnects(bool p_enable) {
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
right_disconnects=p_enable;
|
2015-01-07 05:45:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GraphEdit::is_right_disconnects_enabled() const{
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
return right_disconnects;
|
2015-01-07 05:45:46 +01:00
|
|
|
}
|
|
|
|
|
2016-08-03 00:11:05 +02:00
|
|
|
void GraphEdit::add_valid_right_disconnect_type(int p_type) {
|
|
|
|
|
|
|
|
valid_right_disconnect_types.insert(p_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphEdit::remove_valid_right_disconnect_type(int p_type){
|
|
|
|
|
|
|
|
valid_right_disconnect_types.erase(p_type);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphEdit::add_valid_left_disconnect_type(int p_type){
|
|
|
|
|
|
|
|
valid_left_disconnect_types.insert(p_type);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphEdit::remove_valid_left_disconnect_type(int p_type){
|
|
|
|
|
|
|
|
valid_left_disconnect_types.erase(p_type);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-01-08 04:41:34 +01:00
|
|
|
Array GraphEdit::_get_connection_list() const {
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
List<Connection> conns;
|
|
|
|
get_connection_list(&conns);
|
|
|
|
Array arr;
|
|
|
|
for(List<Connection>::Element *E=conns.front();E;E=E->next()) {
|
|
|
|
Dictionary d;
|
|
|
|
d["from"]=E->get().from;
|
|
|
|
d["from_port"]=E->get().from_port;
|
|
|
|
d["to"]=E->get().to;
|
|
|
|
d["to_port"]=E->get().to_port;
|
|
|
|
arr.push_back(d);
|
|
|
|
}
|
|
|
|
return arr;
|
2015-01-08 04:41:34 +01:00
|
|
|
}
|
2016-02-08 20:28:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GraphEdit::_zoom_minus() {
|
|
|
|
|
|
|
|
|
|
|
|
set_zoom(zoom/ZOOM_SCALE);
|
|
|
|
}
|
|
|
|
void GraphEdit::_zoom_reset() {
|
|
|
|
|
|
|
|
|
|
|
|
set_zoom(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphEdit::_zoom_plus() {
|
|
|
|
|
|
|
|
set_zoom(zoom*ZOOM_SCALE);
|
|
|
|
}
|
|
|
|
|
2016-08-03 00:11:05 +02:00
|
|
|
void GraphEdit::add_valid_connection_type(int p_type,int p_with_type) {
|
|
|
|
|
|
|
|
ConnType ct;
|
|
|
|
ct.type_a=p_type;
|
|
|
|
ct.type_b=p_with_type;
|
|
|
|
|
|
|
|
valid_connection_types.insert(ct);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphEdit::remove_valid_connection_type(int p_type,int p_with_type) {
|
|
|
|
|
|
|
|
ConnType ct;
|
|
|
|
ct.type_a=p_type;
|
|
|
|
ct.type_b=p_with_type;
|
|
|
|
|
|
|
|
valid_connection_types.erase(ct);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GraphEdit::is_valid_connection_type(int p_type,int p_with_type) const {
|
|
|
|
|
|
|
|
ConnType ct;
|
|
|
|
ct.type_a=p_type;
|
|
|
|
ct.type_b=p_with_type;
|
|
|
|
|
|
|
|
return valid_connection_types.has(ct);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-08-04 05:05:35 +02:00
|
|
|
void GraphEdit::set_use_snap(bool p_enable) {
|
|
|
|
|
|
|
|
snap_button->set_pressed(p_enable);
|
|
|
|
update();
|
2016-08-31 04:44:14 +02:00
|
|
|
|
2016-08-04 05:05:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GraphEdit::is_using_snap() const{
|
|
|
|
|
|
|
|
return snap_button->is_pressed();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int GraphEdit::get_snap() const{
|
|
|
|
|
|
|
|
return snap_amount->get_val();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphEdit::set_snap(int p_snap) {
|
|
|
|
|
|
|
|
ERR_FAIL_COND(p_snap<5);
|
|
|
|
snap_amount->set_val(p_snap);
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
void GraphEdit::_snap_toggled() {
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphEdit::_snap_value_changed(double) {
|
|
|
|
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2016-02-08 20:28:12 +01:00
|
|
|
|
2015-01-03 20:52:37 +01:00
|
|
|
void GraphEdit::_bind_methods() {
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
ObjectTypeDB::bind_method(_MD("connect_node:Error","from","from_port","to","to_port"),&GraphEdit::connect_node);
|
|
|
|
ObjectTypeDB::bind_method(_MD("is_node_connected","from","from_port","to","to_port"),&GraphEdit::is_node_connected);
|
|
|
|
ObjectTypeDB::bind_method(_MD("disconnect_node","from","from_port","to","to_port"),&GraphEdit::disconnect_node);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_connection_list"),&GraphEdit::_get_connection_list);
|
2016-01-17 22:26:32 +01:00
|
|
|
ObjectTypeDB::bind_method(_MD("get_scroll_ofs"),&GraphEdit::get_scroll_ofs);
|
2016-08-07 00:00:54 +02:00
|
|
|
ObjectTypeDB::bind_method(_MD("set_scroll_ofs","ofs"),&GraphEdit::set_scroll_ofs);
|
2015-01-07 05:45:46 +01:00
|
|
|
|
2016-01-19 00:32:37 +01:00
|
|
|
ObjectTypeDB::bind_method(_MD("set_zoom","p_zoom"),&GraphEdit::set_zoom);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_zoom"),&GraphEdit::get_zoom);
|
|
|
|
|
2016-08-04 05:05:35 +02:00
|
|
|
ObjectTypeDB::bind_method(_MD("set_snap","pixels"),&GraphEdit::set_snap);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_snap"),&GraphEdit::get_snap);
|
|
|
|
|
|
|
|
ObjectTypeDB::bind_method(_MD("set_use_snap","enable"),&GraphEdit::set_use_snap);
|
|
|
|
ObjectTypeDB::bind_method(_MD("is_using_snap"),&GraphEdit::is_using_snap);
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
ObjectTypeDB::bind_method(_MD("set_right_disconnects","enable"),&GraphEdit::set_right_disconnects);
|
|
|
|
ObjectTypeDB::bind_method(_MD("is_right_disconnects_enabled"),&GraphEdit::is_right_disconnects_enabled);
|
2015-01-07 05:45:46 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
ObjectTypeDB::bind_method(_MD("_graph_node_moved"),&GraphEdit::_graph_node_moved);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_graph_node_raised"),&GraphEdit::_graph_node_raised);
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
ObjectTypeDB::bind_method(_MD("_top_layer_input"),&GraphEdit::_top_layer_input);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_top_layer_draw"),&GraphEdit::_top_layer_draw);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_scroll_moved"),&GraphEdit::_scroll_moved);
|
2016-02-08 20:28:12 +01:00
|
|
|
ObjectTypeDB::bind_method(_MD("_zoom_minus"),&GraphEdit::_zoom_minus);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_zoom_reset"),&GraphEdit::_zoom_reset);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_zoom_plus"),&GraphEdit::_zoom_plus);
|
2016-08-04 05:05:35 +02:00
|
|
|
ObjectTypeDB::bind_method(_MD("_snap_toggled"),&GraphEdit::_snap_toggled);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_snap_value_changed"),&GraphEdit::_snap_value_changed);
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
ObjectTypeDB::bind_method(_MD("_input_event"),&GraphEdit::_input_event);
|
2016-08-31 04:44:14 +02:00
|
|
|
ObjectTypeDB::bind_method(_MD("_update_scroll_offset"),&GraphEdit::_update_scroll_offset);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_connections_layer_draw"),&GraphEdit::_connections_layer_draw);
|
|
|
|
|
|
|
|
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2016-08-03 00:11:05 +02:00
|
|
|
ObjectTypeDB::bind_method(_MD("set_selected","node"),&GraphEdit::set_selected);
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
ADD_SIGNAL(MethodInfo("connection_request",PropertyInfo(Variant::STRING,"from"),PropertyInfo(Variant::INT,"from_slot"),PropertyInfo(Variant::STRING,"to"),PropertyInfo(Variant::INT,"to_slot")));
|
|
|
|
ADD_SIGNAL(MethodInfo("disconnection_request",PropertyInfo(Variant::STRING,"from"),PropertyInfo(Variant::INT,"from_slot"),PropertyInfo(Variant::STRING,"to"),PropertyInfo(Variant::INT,"to_slot")));
|
|
|
|
ADD_SIGNAL(MethodInfo("popup_request", PropertyInfo(Variant::VECTOR2,"p_position")));
|
2015-07-26 02:16:07 +02:00
|
|
|
ADD_SIGNAL(MethodInfo("duplicate_nodes_request"));
|
2016-08-03 00:11:05 +02:00
|
|
|
ADD_SIGNAL(MethodInfo("node_selected",PropertyInfo(Variant::OBJECT,"node")));
|
2016-08-24 00:29:07 +02:00
|
|
|
ADD_SIGNAL(MethodInfo("connection_to_empty",PropertyInfo(Variant::STRING,"from"),PropertyInfo(Variant::INT,"from_slot"),PropertyInfo(Variant::VECTOR2,"release_pos")));
|
2015-07-27 02:57:27 +02:00
|
|
|
ADD_SIGNAL(MethodInfo("delete_nodes_request"));
|
2015-07-21 03:15:06 +02:00
|
|
|
ADD_SIGNAL(MethodInfo("_begin_node_move"));
|
|
|
|
ADD_SIGNAL(MethodInfo("_end_node_move"));
|
2016-08-07 00:00:54 +02:00
|
|
|
ADD_SIGNAL(MethodInfo("scroll_offset_changed",PropertyInfo(Variant::VECTOR2,"ofs")));
|
2015-01-03 20:52:37 +01:00
|
|
|
}
|
|
|
|
|
2015-01-07 05:45:46 +01:00
|
|
|
|
|
|
|
|
2015-01-03 20:52:37 +01:00
|
|
|
GraphEdit::GraphEdit() {
|
2015-07-26 02:16:07 +02:00
|
|
|
set_focus_mode(FOCUS_ALL);
|
|
|
|
|
2016-08-31 04:44:14 +02:00
|
|
|
awaiting_scroll_offset_update=false;
|
2015-07-21 03:15:06 +02:00
|
|
|
top_layer=NULL;
|
|
|
|
top_layer=memnew(GraphEditFilter(this));
|
|
|
|
add_child(top_layer);
|
2015-01-03 20:52:37 +01:00
|
|
|
top_layer->set_stop_mouse(false);
|
2015-07-21 03:15:06 +02:00
|
|
|
top_layer->set_area_as_parent_rect();
|
|
|
|
top_layer->connect("draw",this,"_top_layer_draw");
|
|
|
|
top_layer->set_stop_mouse(false);
|
|
|
|
top_layer->connect("input_event",this,"_top_layer_input");
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2016-08-31 04:44:14 +02:00
|
|
|
connections_layer = memnew( Control );
|
|
|
|
add_child(connections_layer);
|
|
|
|
connections_layer->connect("draw",this,"_connections_layer_draw");
|
|
|
|
connections_layer->set_name("CLAYER");
|
|
|
|
connections_layer->set_disable_visibility_clip(true); // so it can draw freely and be offseted
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
h_scroll = memnew(HScrollBar);
|
|
|
|
h_scroll->set_name("_h_scroll");
|
|
|
|
top_layer->add_child(h_scroll);
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
v_scroll = memnew(VScrollBar);
|
|
|
|
v_scroll->set_name("_v_scroll");
|
|
|
|
top_layer->add_child(v_scroll);
|
|
|
|
updating=false;
|
|
|
|
connecting=false;
|
|
|
|
right_disconnects=false;
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-25 02:59:48 +02:00
|
|
|
box_selecting = false;
|
|
|
|
dragging = false;
|
|
|
|
|
2016-08-07 00:00:54 +02: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);
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
h_scroll->connect("value_changed", this,"_scroll_moved");
|
|
|
|
v_scroll->connect("value_changed", this,"_scroll_moved");
|
2016-01-19 00:32:37 +01:00
|
|
|
|
|
|
|
zoom = 1;
|
2016-01-19 02:10:44 +01:00
|
|
|
|
2016-02-08 20:28:12 +01:00
|
|
|
HBoxContainer *zoom_hb = memnew( HBoxContainer );
|
|
|
|
top_layer->add_child(zoom_hb);
|
|
|
|
zoom_hb->set_pos(Vector2(10,10));
|
|
|
|
|
|
|
|
|
|
|
|
zoom_minus = memnew( ToolButton );
|
|
|
|
zoom_hb->add_child(zoom_minus);
|
|
|
|
zoom_minus->connect("pressed",this,"_zoom_minus");
|
2016-08-04 05:05:35 +02:00
|
|
|
zoom_minus->set_focus_mode(FOCUS_NONE);
|
2016-02-08 20:28:12 +01:00
|
|
|
|
|
|
|
zoom_reset = memnew( ToolButton );
|
|
|
|
zoom_hb->add_child(zoom_reset);
|
|
|
|
zoom_reset->connect("pressed",this,"_zoom_reset");
|
2016-08-04 05:05:35 +02:00
|
|
|
zoom_reset->set_focus_mode(FOCUS_NONE);
|
2016-02-08 20:28:12 +01:00
|
|
|
|
|
|
|
zoom_plus = memnew( ToolButton );
|
|
|
|
zoom_hb->add_child(zoom_plus);
|
|
|
|
zoom_plus->connect("pressed",this,"_zoom_plus");
|
2016-08-04 05:05:35 +02:00
|
|
|
zoom_plus->set_focus_mode(FOCUS_NONE);
|
|
|
|
|
|
|
|
snap_button = memnew( ToolButton );
|
|
|
|
snap_button->set_toggle_mode(true);
|
|
|
|
snap_button->connect("pressed",this,"_snap_toggled");
|
|
|
|
snap_button->set_pressed(true);
|
|
|
|
snap_button->set_focus_mode(FOCUS_NONE);
|
|
|
|
zoom_hb->add_child(snap_button);
|
|
|
|
|
|
|
|
snap_amount = memnew( SpinBox );
|
|
|
|
snap_amount->set_min(5);
|
|
|
|
snap_amount->set_max(100);
|
|
|
|
snap_amount->set_step(1);
|
|
|
|
snap_amount->set_val(20);
|
|
|
|
snap_amount->connect("value_changed",this,"_snap_value_changed");
|
|
|
|
zoom_hb->add_child(snap_amount);
|
|
|
|
|
2016-08-07 00:00:54 +02:00
|
|
|
setting_scroll_ofs=false;
|
2016-09-03 19:58:23 +02:00
|
|
|
just_disconected=false;
|
2016-01-19 02:10:44 +01:00
|
|
|
|
2016-08-23 15:15:47 +02:00
|
|
|
|
|
|
|
|
2015-01-03 20:52:37 +01:00
|
|
|
}
|