2016-06-18 14:46:12 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/* graph_node.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2017-01-01 22:01:57 +01:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2016-06-18 14:46:12 +02: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. */
|
|
|
|
/*************************************************************************/
|
2014-12-20 16:32:14 +01:00
|
|
|
#include "graph_node.h"
|
2015-01-08 04:41:34 +01:00
|
|
|
#include "method_bind_ext.inc"
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
bool GraphNode::_set(const StringName &p_name, const Variant &p_value) {
|
2014-12-21 15:42:44 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
if (!p_name.operator String().begins_with("slot/"))
|
|
|
|
return false;
|
2014-12-21 15:42:44 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
int idx = p_name.operator String().get_slice("/", 1).to_int();
|
|
|
|
String what = p_name.operator String().get_slice("/", 2);
|
2014-12-21 15:42:44 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
Slot si;
|
|
|
|
if (slot_info.has(idx))
|
2017-03-19 00:36:26 +01:00
|
|
|
si = slot_info[idx];
|
|
|
|
|
|
|
|
if (what == "left_enabled")
|
|
|
|
si.enable_left = p_value;
|
|
|
|
else if (what == "left_type")
|
|
|
|
si.type_left = p_value;
|
|
|
|
else if (what == "left_color")
|
|
|
|
si.color_left = p_value;
|
|
|
|
else if (what == "right_enabled")
|
|
|
|
si.enable_right = p_value;
|
|
|
|
else if (what == "right_type")
|
|
|
|
si.type_right = p_value;
|
|
|
|
else if (what == "right_color")
|
|
|
|
si.color_right = p_value;
|
2015-07-21 03:15:06 +02:00
|
|
|
else
|
|
|
|
return false;
|
2014-12-21 15:42:44 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
set_slot(idx, si.enable_left, si.type_left, si.color_left, si.enable_right, si.type_right, si.color_right);
|
2015-07-21 03:15:06 +02:00
|
|
|
update();
|
|
|
|
return true;
|
2014-12-21 15:42:44 +01:00
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
bool GraphNode::_get(const StringName &p_name, Variant &r_ret) const {
|
2015-01-08 04:41:34 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
if (!p_name.operator String().begins_with("slot/")) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-12-21 15:42:44 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
int idx = p_name.operator String().get_slice("/", 1).to_int();
|
|
|
|
String what = p_name.operator String().get_slice("/", 2);
|
2014-12-21 15:42:44 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
Slot si;
|
|
|
|
if (slot_info.has(idx))
|
2017-03-19 00:36:26 +01:00
|
|
|
si = slot_info[idx];
|
|
|
|
|
|
|
|
if (what == "left_enabled")
|
|
|
|
r_ret = si.enable_left;
|
|
|
|
else if (what == "left_type")
|
|
|
|
r_ret = si.type_left;
|
|
|
|
else if (what == "left_color")
|
|
|
|
r_ret = si.color_left;
|
|
|
|
else if (what == "right_enabled")
|
|
|
|
r_ret = si.enable_right;
|
|
|
|
else if (what == "right_type")
|
|
|
|
r_ret = si.type_right;
|
|
|
|
else if (what == "right_color")
|
|
|
|
r_ret = si.color_right;
|
2015-07-21 03:15:06 +02:00
|
|
|
else
|
|
|
|
return false;
|
2014-12-21 15:42:44 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
return true;
|
2014-12-21 15:42:44 +01:00
|
|
|
}
|
2017-03-19 00:36:26 +01:00
|
|
|
void GraphNode::_get_property_list(List<PropertyInfo> *p_list) const {
|
2014-12-21 15:42:44 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
int idx = 0;
|
|
|
|
for (int i = 0; i < get_child_count(); i++) {
|
|
|
|
Control *c = get_child(i)->cast_to<Control>();
|
|
|
|
if (!c || c->is_set_as_toplevel())
|
2015-07-21 03:15:06 +02:00
|
|
|
continue;
|
2014-12-21 15:42:44 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
String base = "slot/" + itos(idx) + "/";
|
2014-12-21 15:42:44 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
p_list->push_back(PropertyInfo(Variant::BOOL, base + "left_enabled"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, base + "left_type"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::COLOR, base + "left_color"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::BOOL, base + "right_enabled"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, base + "right_type"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::COLOR, base + "right_color"));
|
2014-12-21 15:42:44 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
idx++;
|
|
|
|
}
|
2014-12-21 15:42:44 +01:00
|
|
|
}
|
|
|
|
|
2014-12-20 16:32:14 +01:00
|
|
|
void GraphNode::_resort() {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
int sep = get_constant("separation");
|
|
|
|
Ref<StyleBox> sb = get_stylebox("frame");
|
|
|
|
bool first = true;
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
Size2 minsize;
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
for (int i = 0; i < get_child_count(); i++) {
|
|
|
|
Control *c = get_child(i)->cast_to<Control>();
|
2015-07-21 03:15:06 +02:00
|
|
|
if (!c)
|
|
|
|
continue;
|
|
|
|
if (c->is_set_as_toplevel())
|
|
|
|
continue;
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
Size2i size = c->get_combined_minimum_size();
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
minsize.y += size.y;
|
|
|
|
minsize.x = MAX(minsize.x, size.x);
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
if (first)
|
2017-03-19 00:36:26 +01:00
|
|
|
first = false;
|
2015-07-21 03:15:06 +02:00
|
|
|
else
|
2017-03-19 00:36:26 +01:00
|
|
|
minsize.y += sep;
|
2015-07-21 03:15:06 +02:00
|
|
|
}
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
int vofs = 0;
|
2015-07-21 03:15:06 +02:00
|
|
|
int w = get_size().x - sb->get_minimum_size().x;
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
cache_y.clear();
|
2017-03-19 00:36:26 +01:00
|
|
|
for (int i = 0; i < get_child_count(); i++) {
|
|
|
|
Control *c = get_child(i)->cast_to<Control>();
|
2015-07-21 03:15:06 +02:00
|
|
|
if (!c)
|
|
|
|
continue;
|
|
|
|
if (c->is_set_as_toplevel())
|
|
|
|
continue;
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
Size2i size = c->get_combined_minimum_size();
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
Rect2 r(sb->get_margin(MARGIN_LEFT), sb->get_margin(MARGIN_TOP) + vofs, w, size.y);
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
fit_child_in_rect(c, r);
|
|
|
|
cache_y.push_back(vofs + size.y * 0.5);
|
2014-12-21 15:42:44 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (vofs > 0)
|
|
|
|
vofs += sep;
|
|
|
|
vofs += size.y;
|
2015-07-21 03:15:06 +02:00
|
|
|
}
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
_change_notify();
|
|
|
|
update();
|
2017-03-19 00:36:26 +01:00
|
|
|
connpos_dirty = true;
|
2014-12-20 16:32:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void GraphNode::_notification(int p_what) {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (p_what == NOTIFICATION_DRAW) {
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
Ref<StyleBox> sb = get_stylebox(selected ? "selectedframe" : "frame");
|
|
|
|
Ref<Texture> port = get_icon("port");
|
|
|
|
Ref<Texture> close = get_icon("close");
|
2015-07-21 03:15:06 +02:00
|
|
|
int close_offset = get_constant("close_offset");
|
|
|
|
Ref<Font> title_font = get_font("title_font");
|
|
|
|
int title_offset = get_constant("title_offset");
|
|
|
|
Color title_color = get_color("title_color");
|
2017-03-19 00:36:26 +01:00
|
|
|
Point2i icofs = -port->get_size() * 0.5;
|
|
|
|
int edgeofs = get_constant("port_offset");
|
|
|
|
icofs.y += sb->get_margin(MARGIN_TOP);
|
|
|
|
draw_style_box(sb, Rect2(Point2(), get_size()));
|
2014-12-21 15:42:44 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
int w = get_size().width - sb->get_minimum_size().x;
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
if (show_close)
|
2017-03-19 00:36:26 +01:00
|
|
|
w -= close->get_width();
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
draw_string(title_font, Point2(sb->get_margin(MARGIN_LEFT), -title_font->get_height() + title_font->get_ascent() + title_offset), title, title_color, w);
|
2015-07-21 03:15:06 +02:00
|
|
|
if (show_close) {
|
2017-03-19 00:36:26 +01:00
|
|
|
Vector2 cpos = Point2(w + sb->get_margin(MARGIN_LEFT), -close->get_height() + close_offset);
|
|
|
|
draw_texture(close, cpos);
|
|
|
|
close_rect.pos = cpos;
|
|
|
|
close_rect.size = close->get_size();
|
2015-07-21 03:15:06 +02:00
|
|
|
} else {
|
2017-03-19 00:36:26 +01:00
|
|
|
close_rect = Rect2();
|
2015-07-21 03:15:06 +02:00
|
|
|
}
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
for (Map<int, Slot>::Element *E = slot_info.front(); E; E = E->next()) {
|
2014-12-21 15:42:44 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (E->key() < 0 || E->key() >= cache_y.size())
|
2015-07-21 03:15:06 +02:00
|
|
|
continue;
|
|
|
|
if (!slot_info.has(E->key()))
|
|
|
|
continue;
|
2017-03-19 00:36:26 +01:00
|
|
|
const Slot &s = slot_info[E->key()];
|
2015-07-21 03:15:06 +02:00
|
|
|
//left
|
|
|
|
if (s.enable_left)
|
2017-03-19 00:36:26 +01:00
|
|
|
port->draw(get_canvas_item(), icofs + Point2(edgeofs, cache_y[E->key()]), s.color_left);
|
2015-07-21 03:15:06 +02:00
|
|
|
if (s.enable_right)
|
2017-03-19 00:36:26 +01:00
|
|
|
port->draw(get_canvas_item(), icofs + Point2(get_size().x - edgeofs, cache_y[E->key()]), s.color_right);
|
2015-07-21 03:15:06 +02:00
|
|
|
}
|
|
|
|
}
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (p_what == NOTIFICATION_SORT_CHILDREN) {
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
_resort();
|
|
|
|
}
|
2014-12-20 16:32:14 +01:00
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
void GraphNode::set_slot(int p_idx, bool p_enable_left, int p_type_left, const Color &p_color_left, bool p_enable_right, int p_type_right, const Color &p_color_right) {
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
ERR_FAIL_COND(p_idx < 0);
|
2014-12-21 15:42:44 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (!p_enable_left && p_type_left == 0 && p_color_left == Color(1, 1, 1, 1) && !p_enable_right && p_type_right == 0 && p_color_right == Color(1, 1, 1, 1)) {
|
2015-07-21 03:15:06 +02:00
|
|
|
slot_info.erase(p_idx);
|
|
|
|
return;
|
|
|
|
}
|
2014-12-21 15:42:44 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
Slot s;
|
2017-03-19 00:36:26 +01:00
|
|
|
s.enable_left = p_enable_left;
|
|
|
|
s.type_left = p_type_left;
|
|
|
|
s.color_left = p_color_left;
|
|
|
|
s.enable_right = p_enable_right;
|
|
|
|
s.type_right = p_type_right;
|
|
|
|
s.color_right = p_color_right;
|
|
|
|
slot_info[p_idx] = s;
|
2015-07-21 03:15:06 +02:00
|
|
|
update();
|
2017-03-19 00:36:26 +01:00
|
|
|
connpos_dirty = true;
|
2014-12-20 16:32:14 +01:00
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
void GraphNode::clear_slot(int p_idx) {
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
slot_info.erase(p_idx);
|
|
|
|
update();
|
2017-03-19 00:36:26 +01:00
|
|
|
connpos_dirty = true;
|
2014-12-20 16:32:14 +01:00
|
|
|
}
|
2017-03-19 00:36:26 +01:00
|
|
|
void GraphNode::clear_all_slots() {
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
slot_info.clear();
|
|
|
|
update();
|
2017-03-19 00:36:26 +01:00
|
|
|
connpos_dirty = true;
|
2014-12-20 16:32:14 +01:00
|
|
|
}
|
2017-03-19 00:36:26 +01:00
|
|
|
bool GraphNode::is_slot_enabled_left(int p_idx) const {
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
if (!slot_info.has(p_idx))
|
|
|
|
return false;
|
|
|
|
return slot_info[p_idx].enable_left;
|
2014-12-20 16:32:14 +01:00
|
|
|
}
|
2014-12-21 15:42:44 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
int GraphNode::get_slot_type_left(int p_idx) const {
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
if (!slot_info.has(p_idx))
|
|
|
|
return 0;
|
|
|
|
return slot_info[p_idx].type_left;
|
2014-12-20 16:32:14 +01:00
|
|
|
}
|
2014-12-21 15:42:44 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
Color GraphNode::get_slot_color_left(int p_idx) const {
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
if (!slot_info.has(p_idx))
|
2017-03-19 00:36:26 +01:00
|
|
|
return Color(1, 1, 1, 1);
|
2015-07-21 03:15:06 +02:00
|
|
|
return slot_info[p_idx].color_left;
|
2014-12-20 16:32:14 +01:00
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
bool GraphNode::is_slot_enabled_right(int p_idx) const {
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
if (!slot_info.has(p_idx))
|
|
|
|
return false;
|
|
|
|
return slot_info[p_idx].enable_right;
|
2014-12-20 16:32:14 +01:00
|
|
|
}
|
2014-12-21 15:42:44 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
int GraphNode::get_slot_type_right(int p_idx) const {
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
if (!slot_info.has(p_idx))
|
|
|
|
return 0;
|
|
|
|
return slot_info[p_idx].type_right;
|
2014-12-20 16:32:14 +01:00
|
|
|
}
|
2014-12-21 15:42:44 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
Color GraphNode::get_slot_color_right(int p_idx) const {
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
if (!slot_info.has(p_idx))
|
2017-03-19 00:36:26 +01:00
|
|
|
return Color(1, 1, 1, 1);
|
2015-07-21 03:15:06 +02:00
|
|
|
return slot_info[p_idx].color_right;
|
2014-12-20 16:32:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Size2 GraphNode::get_minimum_size() const {
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
Ref<Font> title_font = get_font("title_font");
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
int sep = get_constant("separation");
|
|
|
|
Ref<StyleBox> sb = get_stylebox("frame");
|
|
|
|
bool first = true;
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
Size2 minsize;
|
2017-03-19 00:36:26 +01:00
|
|
|
minsize.x = title_font->get_string_size(title).x;
|
2015-07-21 03:15:06 +02:00
|
|
|
if (show_close) {
|
2017-03-19 00:36:26 +01:00
|
|
|
Ref<Texture> close = get_icon("close");
|
|
|
|
minsize.x += sep + close->get_width();
|
2015-07-21 03:15:06 +02:00
|
|
|
}
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
for (int i = 0; i < get_child_count(); i++) {
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
Control *c = get_child(i)->cast_to<Control>();
|
2015-07-21 03:15:06 +02:00
|
|
|
if (!c)
|
|
|
|
continue;
|
|
|
|
if (c->is_set_as_toplevel())
|
|
|
|
continue;
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
Size2i size = c->get_combined_minimum_size();
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
minsize.y += size.y;
|
|
|
|
minsize.x = MAX(minsize.x, size.x);
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
if (first)
|
2017-03-19 00:36:26 +01:00
|
|
|
first = false;
|
2015-07-21 03:15:06 +02:00
|
|
|
else
|
2017-03-19 00:36:26 +01:00
|
|
|
minsize.y += sep;
|
2015-07-21 03:15:06 +02:00
|
|
|
}
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
return minsize + sb->get_minimum_size();
|
2014-12-20 16:32:14 +01:00
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
void GraphNode::set_title(const String &p_title) {
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
title = p_title;
|
2015-07-21 03:15:06 +02:00
|
|
|
minimum_size_changed();
|
|
|
|
update();
|
2015-01-03 20:52:37 +01:00
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
String GraphNode::get_title() const {
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
return title;
|
2015-01-03 20:52:37 +01:00
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
void GraphNode::set_offset(const Vector2 &p_offset) {
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
offset = p_offset;
|
2015-07-21 03:15:06 +02:00
|
|
|
emit_signal("offset_changed");
|
|
|
|
update();
|
2015-01-03 20:52:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Vector2 GraphNode::get_offset() const {
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
return offset;
|
2015-01-03 20:52:37 +01:00
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
void GraphNode::set_selected(bool p_selected) {
|
2015-07-21 03:15:06 +02:00
|
|
|
selected = p_selected;
|
|
|
|
update();
|
2015-07-19 06:48:46 +02:00
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
bool GraphNode::is_selected() {
|
2015-07-21 03:15:06 +02:00
|
|
|
return selected;
|
2015-07-19 06:48:46 +02:00
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
void GraphNode::set_drag(bool p_drag) {
|
2015-07-21 03:15:06 +02:00
|
|
|
if (p_drag)
|
2017-03-19 00:36:26 +01:00
|
|
|
drag_from = get_offset();
|
2015-07-21 03:15:06 +02:00
|
|
|
else
|
2017-03-19 00:36:26 +01:00
|
|
|
emit_signal("dragged", drag_from, get_offset()); //useful for undo/redo
|
2015-07-19 06:48:46 +02:00
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
Vector2 GraphNode::get_drag_from() {
|
2015-07-21 03:15:06 +02:00
|
|
|
return drag_from;
|
2015-07-19 06:48:46 +02:00
|
|
|
}
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
void GraphNode::set_show_close_button(bool p_enable) {
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
show_close = p_enable;
|
2015-07-21 03:15:06 +02:00
|
|
|
update();
|
2015-01-03 20:52:37 +01:00
|
|
|
}
|
2017-03-19 00:36:26 +01:00
|
|
|
bool GraphNode::is_close_button_visible() const {
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
return show_close;
|
2015-01-03 20:52:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void GraphNode::_connpos_update() {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
int edgeofs = get_constant("port_offset");
|
|
|
|
int sep = get_constant("separation");
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
Ref<StyleBox> sb = get_stylebox("frame");
|
2015-07-21 03:15:06 +02:00
|
|
|
conn_input_cache.clear();
|
|
|
|
conn_output_cache.clear();
|
2017-03-19 00:36:26 +01:00
|
|
|
int vofs = 0;
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
int idx = 0;
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
for (int i = 0; i < get_child_count(); i++) {
|
|
|
|
Control *c = get_child(i)->cast_to<Control>();
|
2015-07-21 03:15:06 +02:00
|
|
|
if (!c)
|
|
|
|
continue;
|
|
|
|
if (c->is_set_as_toplevel())
|
|
|
|
continue;
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
Size2i size = c->get_combined_minimum_size();
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
int y = sb->get_margin(MARGIN_TOP) + vofs;
|
2015-07-21 03:15:06 +02:00
|
|
|
int h = size.y;
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
if (slot_info.has(idx)) {
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
if (slot_info[idx].enable_left) {
|
|
|
|
ConnCache cc;
|
2017-03-19 00:36:26 +01:00
|
|
|
cc.pos = Point2i(edgeofs, y + h / 2);
|
|
|
|
cc.type = slot_info[idx].type_left;
|
|
|
|
cc.color = slot_info[idx].color_left;
|
2015-07-21 03:15:06 +02:00
|
|
|
conn_input_cache.push_back(cc);
|
|
|
|
}
|
|
|
|
if (slot_info[idx].enable_right) {
|
|
|
|
ConnCache cc;
|
2017-03-19 00:36:26 +01:00
|
|
|
cc.pos = Point2i(get_size().width - edgeofs, y + h / 2);
|
|
|
|
cc.type = slot_info[idx].type_right;
|
|
|
|
cc.color = slot_info[idx].color_right;
|
2015-07-21 03:15:06 +02:00
|
|
|
conn_output_cache.push_back(cc);
|
|
|
|
}
|
|
|
|
}
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (vofs > 0)
|
|
|
|
vofs += sep;
|
|
|
|
vofs += size.y;
|
2015-07-21 03:15:06 +02:00
|
|
|
idx++;
|
|
|
|
}
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
connpos_dirty = false;
|
2015-01-03 20:52:37 +01:00
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
int GraphNode::get_connection_input_count() {
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
if (connpos_dirty)
|
|
|
|
_connpos_update();
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
return conn_input_cache.size();
|
2015-01-03 20:52:37 +01:00
|
|
|
}
|
|
|
|
int GraphNode::get_connection_output_count() {
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
if (connpos_dirty)
|
|
|
|
_connpos_update();
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
return conn_output_cache.size();
|
2015-01-03 20:52:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Vector2 GraphNode::get_connection_input_pos(int p_idx) {
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
if (connpos_dirty)
|
|
|
|
_connpos_update();
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
ERR_FAIL_INDEX_V(p_idx, conn_input_cache.size(), Vector2());
|
2016-01-19 00:32:37 +01:00
|
|
|
Vector2 pos = conn_input_cache[p_idx].pos;
|
|
|
|
pos.x *= get_scale().x;
|
|
|
|
pos.y *= get_scale().y;
|
|
|
|
return pos;
|
2015-01-03 20:52:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int GraphNode::get_connection_input_type(int p_idx) {
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
if (connpos_dirty)
|
|
|
|
_connpos_update();
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
ERR_FAIL_INDEX_V(p_idx, conn_input_cache.size(), 0);
|
2015-07-21 03:15:06 +02:00
|
|
|
return conn_input_cache[p_idx].type;
|
2015-01-03 20:52:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Color GraphNode::get_connection_input_color(int p_idx) {
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
if (connpos_dirty)
|
|
|
|
_connpos_update();
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
ERR_FAIL_INDEX_V(p_idx, conn_input_cache.size(), Color());
|
2015-07-21 03:15:06 +02:00
|
|
|
return conn_input_cache[p_idx].color;
|
2015-01-03 20:52:37 +01:00
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
Vector2 GraphNode::get_connection_output_pos(int p_idx) {
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
if (connpos_dirty)
|
|
|
|
_connpos_update();
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
ERR_FAIL_INDEX_V(p_idx, conn_output_cache.size(), Vector2());
|
2016-01-19 00:32:37 +01:00
|
|
|
Vector2 pos = conn_output_cache[p_idx].pos;
|
|
|
|
pos.x *= get_scale().x;
|
|
|
|
pos.y *= get_scale().y;
|
|
|
|
return pos;
|
2015-01-03 20:52:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int GraphNode::get_connection_output_type(int p_idx) {
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
if (connpos_dirty)
|
|
|
|
_connpos_update();
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
ERR_FAIL_INDEX_V(p_idx, conn_output_cache.size(), 0);
|
2015-07-21 03:15:06 +02:00
|
|
|
return conn_output_cache[p_idx].type;
|
2015-01-03 20:52:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Color GraphNode::get_connection_output_color(int p_idx) {
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
if (connpos_dirty)
|
|
|
|
_connpos_update();
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
ERR_FAIL_INDEX_V(p_idx, conn_output_cache.size(), Color());
|
2015-07-21 03:15:06 +02:00
|
|
|
return conn_output_cache[p_idx].color;
|
2015-01-03 20:52:37 +01:00
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
void GraphNode::_input_event(const InputEvent &p_ev) {
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (p_ev.type == InputEvent::MOUSE_BUTTON) {
|
2016-07-23 23:59:24 +02:00
|
|
|
|
|
|
|
ERR_EXPLAIN("GraphNode must be the child of a GraphEdit node.");
|
|
|
|
ERR_FAIL_COND(get_parent_control() == NULL);
|
|
|
|
|
2015-07-26 02:16:07 +02:00
|
|
|
get_parent_control()->grab_focus();
|
2016-07-23 23:59:24 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (p_ev.mouse_button.pressed && p_ev.mouse_button.button_index == BUTTON_LEFT) {
|
2015-07-26 02:16:07 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
Vector2 mpos = Vector2(p_ev.mouse_button.x, p_ev.mouse_button.y);
|
|
|
|
if (close_rect.size != Size2() && close_rect.has_point(mpos)) {
|
2015-07-26 02:16:07 +02:00
|
|
|
emit_signal("close_request");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
emit_signal("raise_request");
|
2015-07-21 03:15:06 +02:00
|
|
|
}
|
|
|
|
}
|
2015-01-03 20:52:37 +01:00
|
|
|
}
|
|
|
|
|
2014-12-20 16:32:14 +01:00
|
|
|
void GraphNode::_bind_methods() {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
ObjectTypeDB::bind_method(_MD("set_title", "title"), &GraphNode::set_title);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_title"), &GraphNode::get_title);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_input_event"), &GraphNode::_input_event);
|
2015-01-08 04:41:34 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
ObjectTypeDB::bind_method(_MD("set_slot", "idx", "enable_left", "type_left", "color_left", "enable_right", "type_right", "color_right"), &GraphNode::set_slot);
|
|
|
|
ObjectTypeDB::bind_method(_MD("clear_slot", "idx"), &GraphNode::clear_slot);
|
|
|
|
ObjectTypeDB::bind_method(_MD("clear_all_slots", "idx"), &GraphNode::clear_all_slots);
|
|
|
|
ObjectTypeDB::bind_method(_MD("is_slot_enabled_left", "idx"), &GraphNode::is_slot_enabled_left);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_slot_type_left", "idx"), &GraphNode::get_slot_type_left);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_slot_color_left", "idx"), &GraphNode::get_slot_color_left);
|
|
|
|
ObjectTypeDB::bind_method(_MD("is_slot_enabled_right", "idx"), &GraphNode::is_slot_enabled_right);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_slot_type_right", "idx"), &GraphNode::get_slot_type_right);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_slot_color_right", "idx"), &GraphNode::get_slot_color_right);
|
2015-01-08 04:41:34 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
ObjectTypeDB::bind_method(_MD("set_offset", "offset"), &GraphNode::set_offset);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_offset"), &GraphNode::get_offset);
|
2015-01-08 04:41:34 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
ObjectTypeDB::bind_method(_MD("get_connection_output_count"), &GraphNode::get_connection_output_count);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_connection_input_count"), &GraphNode::get_connection_input_count);
|
2015-01-08 04:41:34 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
ObjectTypeDB::bind_method(_MD("get_connection_output_pos", "idx"), &GraphNode::get_connection_output_pos);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_connection_output_type", "idx"), &GraphNode::get_connection_output_type);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_connection_output_color", "idx"), &GraphNode::get_connection_output_color);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_connection_input_pos", "idx"), &GraphNode::get_connection_input_pos);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_connection_input_type", "idx"), &GraphNode::get_connection_input_type);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_connection_input_color", "idx"), &GraphNode::get_connection_input_color);
|
2015-01-08 04:41:34 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
ObjectTypeDB::bind_method(_MD("set_show_close_button", "show"), &GraphNode::set_show_close_button);
|
|
|
|
ObjectTypeDB::bind_method(_MD("is_close_button_visible"), &GraphNode::is_close_button_visible);
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::STRING, "title"), _SCS("set_title"), _SCS("get_title"));
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_close"), _SCS("set_show_close_button"), _SCS("is_close_button_visible"));
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
ADD_SIGNAL(MethodInfo("offset_changed"));
|
2017-03-19 00:36:26 +01:00
|
|
|
ADD_SIGNAL(MethodInfo("dragged", PropertyInfo(Variant::VECTOR2, "from"), PropertyInfo(Variant::VECTOR2, "to")));
|
2015-07-21 03:15:06 +02:00
|
|
|
ADD_SIGNAL(MethodInfo("raise_request"));
|
|
|
|
ADD_SIGNAL(MethodInfo("close_request"));
|
2014-12-20 16:32:14 +01:00
|
|
|
}
|
|
|
|
|
2014-12-21 15:42:44 +01:00
|
|
|
GraphNode::GraphNode() {
|
2017-03-19 00:36:26 +01:00
|
|
|
show_close = false;
|
|
|
|
connpos_dirty = true;
|
2016-02-08 20:28:12 +01:00
|
|
|
set_stop_mouse(false);
|
2014-12-20 16:32:14 +01:00
|
|
|
}
|