2016-06-18 14:46:12 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/* graph_node.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2016-06-18 14:46:12 +02:00
|
|
|
/*************************************************************************/
|
2021-01-01 20:13:46 +01:00
|
|
|
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
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. */
|
|
|
|
/*************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2014-12-20 16:32:14 +01:00
|
|
|
#include "graph_node.h"
|
2018-09-11 18:13:45 +02:00
|
|
|
|
2020-09-03 13:22:16 +02:00
|
|
|
#include "core/string/translation.h"
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool GraphNode::_set(const StringName &p_name, const Variant &p_value) {
|
2020-09-03 13:22:16 +02:00
|
|
|
String str = p_name;
|
|
|
|
if (str.begins_with("opentype_features/")) {
|
|
|
|
String name = str.get_slicec('/', 1);
|
|
|
|
int32_t tag = TS->name_to_tag(name);
|
|
|
|
double value = p_value;
|
|
|
|
if (value == -1) {
|
|
|
|
if (opentype_features.has(tag)) {
|
|
|
|
opentype_features.erase(tag);
|
|
|
|
_shape();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ((double)opentype_features[tag] != value) {
|
|
|
|
opentype_features[tag] = value;
|
|
|
|
_shape();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_change_notify();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!str.begins_with("slot/")) {
|
2015-07-21 03:15:06 +02:00
|
|
|
return false;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-12-21 15:42:44 +01:00
|
|
|
|
2020-09-03 13:22:16 +02:00
|
|
|
int idx = str.get_slice("/", 1).to_int();
|
|
|
|
String what = str.get_slice("/", 2);
|
2014-12-21 15:42:44 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
Slot si;
|
2020-05-14 16:41:43 +02:00
|
|
|
if (slot_info.has(idx)) {
|
2017-03-05 16:44:50 +01:00
|
|
|
si = slot_info[idx];
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (what == "left_enabled") {
|
2017-03-05 16:44:50 +01:00
|
|
|
si.enable_left = p_value;
|
2020-05-14 16:41:43 +02:00
|
|
|
} else if (what == "left_type") {
|
2017-03-05 16:44:50 +01:00
|
|
|
si.type_left = p_value;
|
2021-01-26 08:21:27 +01:00
|
|
|
} else if (what == "left_icon") {
|
|
|
|
si.custom_slot_left = p_value;
|
2020-05-14 16:41:43 +02:00
|
|
|
} else if (what == "left_color") {
|
2017-03-05 16:44:50 +01:00
|
|
|
si.color_left = p_value;
|
2020-05-14 16:41:43 +02:00
|
|
|
} else if (what == "right_enabled") {
|
2017-03-05 16:44:50 +01:00
|
|
|
si.enable_right = p_value;
|
2020-05-14 16:41:43 +02:00
|
|
|
} else if (what == "right_type") {
|
2017-03-05 16:44:50 +01:00
|
|
|
si.type_right = p_value;
|
2020-05-14 16:41:43 +02:00
|
|
|
} else if (what == "right_color") {
|
2017-03-05 16:44:50 +01:00
|
|
|
si.color_right = p_value;
|
2021-01-26 08:21:27 +01:00
|
|
|
} else if (what == "right_icon") {
|
|
|
|
si.custom_slot_right = p_value;
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2015-07-21 03:15:06 +02:00
|
|
|
return false;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-12-21 15:42:44 +01:00
|
|
|
|
2021-01-26 08:21:27 +01:00
|
|
|
set_slot(idx, si.enable_left, si.type_left, si.color_left, si.enable_right, si.type_right, si.color_right, si.custom_slot_left, si.custom_slot_right);
|
2015-07-21 03:15:06 +02:00
|
|
|
update();
|
|
|
|
return true;
|
2014-12-21 15:42:44 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool GraphNode::_get(const StringName &p_name, Variant &r_ret) const {
|
2020-09-03 13:22:16 +02:00
|
|
|
String str = p_name;
|
|
|
|
if (str.begins_with("opentype_features/")) {
|
|
|
|
String name = str.get_slicec('/', 1);
|
|
|
|
int32_t tag = TS->name_to_tag(name);
|
|
|
|
if (opentype_features.has(tag)) {
|
|
|
|
r_ret = opentype_features[tag];
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
r_ret = -1;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!str.begins_with("slot/")) {
|
2015-07-21 03:15:06 +02:00
|
|
|
return false;
|
|
|
|
}
|
2014-12-21 15:42:44 +01:00
|
|
|
|
2020-09-03 13:22:16 +02:00
|
|
|
int idx = str.get_slice("/", 1).to_int();
|
|
|
|
String what = str.get_slice("/", 2);
|
2014-12-21 15:42:44 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
Slot si;
|
2020-05-14 16:41:43 +02:00
|
|
|
if (slot_info.has(idx)) {
|
2017-03-05 16:44:50 +01:00
|
|
|
si = slot_info[idx];
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (what == "left_enabled") {
|
2017-03-05 16:44:50 +01:00
|
|
|
r_ret = si.enable_left;
|
2020-05-14 16:41:43 +02:00
|
|
|
} else if (what == "left_type") {
|
2017-03-05 16:44:50 +01:00
|
|
|
r_ret = si.type_left;
|
2020-05-14 16:41:43 +02:00
|
|
|
} else if (what == "left_color") {
|
2017-03-05 16:44:50 +01:00
|
|
|
r_ret = si.color_left;
|
2021-01-26 08:21:27 +01:00
|
|
|
} else if (what == "left_icon") {
|
|
|
|
r_ret = si.custom_slot_left;
|
2020-05-14 16:41:43 +02:00
|
|
|
} else if (what == "right_enabled") {
|
2017-03-05 16:44:50 +01:00
|
|
|
r_ret = si.enable_right;
|
2020-05-14 16:41:43 +02:00
|
|
|
} else if (what == "right_type") {
|
2017-03-05 16:44:50 +01:00
|
|
|
r_ret = si.type_right;
|
2020-05-14 16:41:43 +02:00
|
|
|
} else if (what == "right_color") {
|
2017-03-05 16:44:50 +01:00
|
|
|
r_ret = si.color_right;
|
2021-01-26 08:21:27 +01:00
|
|
|
} else if (what == "right_icon") {
|
|
|
|
r_ret = si.custom_slot_right;
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2015-07-21 03:15:06 +02:00
|
|
|
return false;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
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
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void GraphNode::_get_property_list(List<PropertyInfo> *p_list) const {
|
2020-09-03 13:22:16 +02:00
|
|
|
for (const Variant *ftr = opentype_features.next(nullptr); ftr != nullptr; ftr = opentype_features.next(ftr)) {
|
|
|
|
String name = TS->tag_to_name(*ftr);
|
|
|
|
p_list->push_back(PropertyInfo(Variant::FLOAT, "opentype_features/" + name));
|
|
|
|
}
|
|
|
|
p_list->push_back(PropertyInfo(Variant::NIL, "opentype_features/_new", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR));
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int idx = 0;
|
|
|
|
for (int i = 0; i < get_child_count(); i++) {
|
2017-08-24 22:58:51 +02:00
|
|
|
Control *c = Object::cast_to<Control>(get_child(i));
|
2020-10-01 09:17:33 +02:00
|
|
|
if (!c || c->is_set_as_top_level()) {
|
2015-07-21 03:15:06 +02:00
|
|
|
continue;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-12-21 15:42:44 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
String base = "slot/" + itos(idx) + "/";
|
2014-12-21 15:42:44 +01:00
|
|
|
|
2017-03-05 16:44:50 +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"));
|
2021-01-26 08:21:27 +01:00
|
|
|
p_list->push_back(PropertyInfo(Variant::OBJECT, base + "left_icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_STORE_IF_NULL));
|
2017-03-05 16:44:50 +01:00
|
|
|
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"));
|
2021-01-26 08:21:27 +01:00
|
|
|
p_list->push_back(PropertyInfo(Variant::OBJECT, base + "right_icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_STORE_IF_NULL));
|
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() {
|
2020-03-12 13:37:40 +01:00
|
|
|
int sep = get_theme_constant("separation");
|
|
|
|
Ref<StyleBox> sb = get_theme_stylebox("frame");
|
2017-03-05 16:44:50 +01:00
|
|
|
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-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < get_child_count(); i++) {
|
2017-08-24 22:58:51 +02:00
|
|
|
Control *c = Object::cast_to<Control>(get_child(i));
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!c) {
|
2015-07-21 03:15:06 +02:00
|
|
|
continue;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2020-10-01 09:17:33 +02:00
|
|
|
if (c->is_set_as_top_level()) {
|
2015-07-21 03:15:06 +02:00
|
|
|
continue;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Size2i size = c->get_combined_minimum_size();
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
minsize.y += size.y;
|
|
|
|
minsize.x = MAX(minsize.x, size.x);
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (first) {
|
2017-03-05 16:44:50 +01:00
|
|
|
first = false;
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
minsize.y += sep;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-07-21 03:15:06 +02:00
|
|
|
}
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2017-03-05 16:44:50 +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-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < get_child_count(); i++) {
|
2017-08-24 22:58:51 +02:00
|
|
|
Control *c = Object::cast_to<Control>(get_child(i));
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!c) {
|
2015-07-21 03:15:06 +02:00
|
|
|
continue;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2020-10-01 09:17:33 +02:00
|
|
|
if (c->is_set_as_top_level()) {
|
2015-07-21 03:15:06 +02:00
|
|
|
continue;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Size2i size = c->get_combined_minimum_size();
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2020-12-22 17:24:29 +01:00
|
|
|
Rect2 r(sb->get_margin(SIDE_LEFT), sb->get_margin(SIDE_TOP) + vofs, w, size.y);
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2017-03-05 16:44:50 +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
|
|
|
|
2019-06-04 15:05:23 +02:00
|
|
|
vofs += size.y + sep;
|
2015-07-21 03:15:06 +02:00
|
|
|
}
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
update();
|
2017-03-05 16:44:50 +01:00
|
|
|
connpos_dirty = true;
|
2014-12-20 16:32:14 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool GraphNode::has_point(const Point2 &p_point) const {
|
2016-09-02 16:55:12 +02:00
|
|
|
if (comment) {
|
2020-03-12 13:37:40 +01:00
|
|
|
Ref<StyleBox> comment = get_theme_stylebox("comment");
|
|
|
|
Ref<Texture2D> resizer = get_theme_icon("resizer");
|
2016-09-02 16:55:12 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (Rect2(get_size() - resizer->get_size(), resizer->get_size()).has_point(p_point)) {
|
2016-09-02 16:55:12 +02:00
|
|
|
return true;
|
|
|
|
}
|
2017-08-08 15:57:33 +02:00
|
|
|
|
2020-12-22 17:24:29 +01:00
|
|
|
if (Rect2(0, 0, get_size().width, comment->get_margin(SIDE_TOP)).has_point(p_point)) {
|
2016-09-02 16:55:12 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
return Control::has_point(p_point);
|
|
|
|
}
|
|
|
|
}
|
2014-12-20 16:32:14 +01:00
|
|
|
|
|
|
|
void GraphNode::_notification(int p_what) {
|
2019-01-24 22:31:33 +01:00
|
|
|
switch (p_what) {
|
|
|
|
case NOTIFICATION_DRAW: {
|
|
|
|
Ref<StyleBox> sb;
|
2016-09-02 16:55:12 +02:00
|
|
|
|
2019-01-24 22:31:33 +01:00
|
|
|
if (comment) {
|
2020-03-12 13:37:40 +01:00
|
|
|
sb = get_theme_stylebox(selected ? "commentfocus" : "comment");
|
2016-09-02 16:55:12 +02:00
|
|
|
|
2019-01-24 22:31:33 +01:00
|
|
|
} else {
|
2020-03-12 13:37:40 +01:00
|
|
|
sb = get_theme_stylebox(selected ? "selectedframe" : "frame");
|
2019-01-24 22:31:33 +01:00
|
|
|
}
|
2016-08-25 22:45:20 +02:00
|
|
|
|
2019-01-24 22:31:33 +01:00
|
|
|
//sb=sb->duplicate();
|
|
|
|
//sb->call("set_modulate",modulate);
|
2020-03-12 13:37:40 +01:00
|
|
|
Ref<Texture2D> port = get_theme_icon("port");
|
|
|
|
Ref<Texture2D> close = get_theme_icon("close");
|
|
|
|
Ref<Texture2D> resizer = get_theme_icon("resizer");
|
|
|
|
int close_offset = get_theme_constant("close_offset");
|
|
|
|
int close_h_offset = get_theme_constant("close_h_offset");
|
|
|
|
Color close_color = get_theme_color("close_color");
|
|
|
|
Color resizer_color = get_theme_color("resizer_color");
|
|
|
|
int title_offset = get_theme_constant("title_offset");
|
|
|
|
int title_h_offset = get_theme_constant("title_h_offset");
|
|
|
|
Color title_color = get_theme_color("title_color");
|
2019-01-24 22:31:33 +01:00
|
|
|
Point2i icofs = -port->get_size() * 0.5;
|
2020-03-12 13:37:40 +01:00
|
|
|
int edgeofs = get_theme_constant("port_offset");
|
2020-12-22 17:24:29 +01:00
|
|
|
icofs.y += sb->get_margin(SIDE_TOP);
|
2019-01-24 22:31:33 +01:00
|
|
|
|
|
|
|
draw_style_box(sb, Rect2(Point2(), get_size()));
|
|
|
|
|
|
|
|
switch (overlay) {
|
|
|
|
case OVERLAY_DISABLED: {
|
|
|
|
} break;
|
|
|
|
case OVERLAY_BREAKPOINT: {
|
2020-03-12 13:37:40 +01:00
|
|
|
draw_style_box(get_theme_stylebox("breakpoint"), Rect2(Point2(), get_size()));
|
2019-01-24 22:31:33 +01:00
|
|
|
} break;
|
|
|
|
case OVERLAY_POSITION: {
|
2020-03-12 13:37:40 +01:00
|
|
|
draw_style_box(get_theme_stylebox("position"), Rect2(Point2(), get_size()));
|
2019-01-24 22:31:33 +01:00
|
|
|
|
|
|
|
} break;
|
|
|
|
}
|
2016-08-07 00:00:54 +02:00
|
|
|
|
2019-01-24 22:31:33 +01:00
|
|
|
int w = get_size().width - sb->get_minimum_size().x;
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (show_close) {
|
2019-01-24 22:31:33 +01:00
|
|
|
w -= close->get_width();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2020-09-03 13:22:16 +02:00
|
|
|
title_buf->set_width(w);
|
2020-12-22 17:24:29 +01:00
|
|
|
title_buf->draw(get_canvas_item(), Point2(sb->get_margin(SIDE_LEFT) + title_h_offset, -title_buf->get_size().y + title_offset), title_color);
|
2019-01-24 22:31:33 +01:00
|
|
|
if (show_close) {
|
2020-12-22 17:24:29 +01:00
|
|
|
Vector2 cpos = Point2(w + sb->get_margin(SIDE_LEFT) + close_h_offset, -close->get_height() + close_offset);
|
2019-01-24 22:31:33 +01:00
|
|
|
draw_texture(close, cpos, close_color);
|
|
|
|
close_rect.position = cpos;
|
|
|
|
close_rect.size = close->get_size();
|
|
|
|
} else {
|
|
|
|
close_rect = Rect2();
|
|
|
|
}
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2019-01-24 22:31:33 +01:00
|
|
|
for (Map<int, Slot>::Element *E = slot_info.front(); E; E = E->next()) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (E->key() < 0 || E->key() >= cache_y.size()) {
|
2019-01-24 22:31:33 +01:00
|
|
|
continue;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
|
|
|
if (!slot_info.has(E->key())) {
|
2019-01-24 22:31:33 +01:00
|
|
|
continue;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2019-01-24 22:31:33 +01:00
|
|
|
const Slot &s = slot_info[E->key()];
|
|
|
|
//left
|
|
|
|
if (s.enable_left) {
|
2019-06-11 20:43:37 +02:00
|
|
|
Ref<Texture2D> p = port;
|
2019-01-24 22:31:33 +01:00
|
|
|
if (s.custom_slot_left.is_valid()) {
|
|
|
|
p = s.custom_slot_left;
|
|
|
|
}
|
|
|
|
p->draw(get_canvas_item(), icofs + Point2(edgeofs, cache_y[E->key()]), s.color_left);
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
2019-01-24 22:31:33 +01:00
|
|
|
if (s.enable_right) {
|
2019-06-11 20:43:37 +02:00
|
|
|
Ref<Texture2D> p = port;
|
2019-01-24 22:31:33 +01:00
|
|
|
if (s.custom_slot_right.is_valid()) {
|
|
|
|
p = s.custom_slot_right;
|
|
|
|
}
|
|
|
|
p->draw(get_canvas_item(), icofs + Point2(get_size().x - edgeofs, cache_y[E->key()]), s.color_right);
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
}
|
2016-08-25 22:45:20 +02:00
|
|
|
|
2019-01-24 22:31:33 +01:00
|
|
|
if (resizable) {
|
2019-09-01 07:57:56 +02:00
|
|
|
draw_texture(resizer, get_size() - resizer->get_size(), resizer_color);
|
2019-01-24 22:31:33 +01:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case NOTIFICATION_SORT_CHILDREN: {
|
|
|
|
_resort();
|
|
|
|
} break;
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2020-09-03 13:22:16 +02:00
|
|
|
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED:
|
|
|
|
case NOTIFICATION_TRANSLATION_CHANGED:
|
2019-01-24 22:31:33 +01:00
|
|
|
case NOTIFICATION_THEME_CHANGED: {
|
2020-09-03 13:22:16 +02:00
|
|
|
_shape();
|
|
|
|
|
2019-01-24 22:31:33 +01:00
|
|
|
minimum_size_changed();
|
2020-09-03 13:22:16 +02:00
|
|
|
update();
|
2019-01-24 22:31:33 +01:00
|
|
|
} break;
|
2015-07-21 03:15:06 +02:00
|
|
|
}
|
2014-12-20 16:32:14 +01:00
|
|
|
}
|
|
|
|
|
2020-09-03 13:22:16 +02:00
|
|
|
void GraphNode::_shape() {
|
|
|
|
Ref<Font> font = get_theme_font("title_font");
|
|
|
|
int font_size = get_theme_font_size("title_font_size");
|
|
|
|
|
|
|
|
title_buf->clear();
|
|
|
|
if (text_direction == Control::TEXT_DIRECTION_INHERITED) {
|
|
|
|
title_buf->set_direction(is_layout_rtl() ? TextServer::DIRECTION_RTL : TextServer::DIRECTION_LTR);
|
|
|
|
} else {
|
|
|
|
title_buf->set_direction((TextServer::Direction)text_direction);
|
|
|
|
}
|
|
|
|
title_buf->add_string(title, font, font_size, opentype_features, (language != "") ? language : TranslationServer::get_singleton()->get_tool_locale());
|
|
|
|
}
|
|
|
|
|
2019-06-11 20:43:37 +02: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, const Ref<Texture2D> &p_custom_left, const Ref<Texture2D> &p_custom_right) {
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND(p_idx < 0);
|
2014-12-21 15:42:44 +01:00
|
|
|
|
2021-01-26 08:21:27 +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) &&
|
|
|
|
!p_custom_left.is_valid() && !p_custom_right.is_valid()) {
|
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-05 16:44:50 +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;
|
|
|
|
s.custom_slot_left = p_custom_left;
|
|
|
|
s.custom_slot_right = p_custom_right;
|
|
|
|
slot_info[p_idx] = s;
|
2015-07-21 03:15:06 +02:00
|
|
|
update();
|
2017-03-05 16:44:50 +01:00
|
|
|
connpos_dirty = true;
|
2014-12-20 16:32:14 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void GraphNode::clear_slot(int p_idx) {
|
2015-07-21 03:15:06 +02:00
|
|
|
slot_info.erase(p_idx);
|
|
|
|
update();
|
2017-03-05 16:44:50 +01:00
|
|
|
connpos_dirty = true;
|
2014-12-20 16:32:14 +01:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void GraphNode::clear_all_slots() {
|
2015-07-21 03:15:06 +02:00
|
|
|
slot_info.clear();
|
|
|
|
update();
|
2017-03-05 16:44:50 +01:00
|
|
|
connpos_dirty = true;
|
2014-12-20 16:32:14 +01:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool GraphNode::is_slot_enabled_left(int p_idx) const {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!slot_info.has(p_idx)) {
|
2015-07-21 03:15:06 +02:00
|
|
|
return false;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-07-21 03:15:06 +02:00
|
|
|
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-05 16:44:50 +01:00
|
|
|
int GraphNode::get_slot_type_left(int p_idx) const {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!slot_info.has(p_idx)) {
|
2015-07-21 03:15:06 +02:00
|
|
|
return 0;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-07-21 03:15:06 +02:00
|
|
|
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-05 16:44:50 +01:00
|
|
|
Color GraphNode::get_slot_color_left(int p_idx) const {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!slot_info.has(p_idx)) {
|
2017-03-05 16:44:50 +01:00
|
|
|
return Color(1, 1, 1, 1);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
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-05 16:44:50 +01:00
|
|
|
bool GraphNode::is_slot_enabled_right(int p_idx) const {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!slot_info.has(p_idx)) {
|
2015-07-21 03:15:06 +02:00
|
|
|
return false;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-07-21 03:15:06 +02:00
|
|
|
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-05 16:44:50 +01:00
|
|
|
int GraphNode::get_slot_type_right(int p_idx) const {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!slot_info.has(p_idx)) {
|
2015-07-21 03:15:06 +02:00
|
|
|
return 0;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-07-21 03:15:06 +02:00
|
|
|
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-05 16:44:50 +01:00
|
|
|
Color GraphNode::get_slot_color_right(int p_idx) const {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!slot_info.has(p_idx)) {
|
2017-03-05 16:44:50 +01:00
|
|
|
return Color(1, 1, 1, 1);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
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 {
|
2020-03-12 13:37:40 +01:00
|
|
|
int sep = get_theme_constant("separation");
|
|
|
|
Ref<StyleBox> sb = get_theme_stylebox("frame");
|
2017-03-05 16:44:50 +01:00
|
|
|
bool first = true;
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
Size2 minsize;
|
2020-09-03 13:22:16 +02:00
|
|
|
minsize.x = title_buf->get_size().x;
|
2015-07-21 03:15:06 +02:00
|
|
|
if (show_close) {
|
2020-03-12 13:37:40 +01:00
|
|
|
Ref<Texture2D> close = get_theme_icon("close");
|
2017-03-05 16:44:50 +01:00
|
|
|
minsize.x += sep + close->get_width();
|
2015-07-21 03:15:06 +02:00
|
|
|
}
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < get_child_count(); i++) {
|
2017-08-24 22:58:51 +02:00
|
|
|
Control *c = Object::cast_to<Control>(get_child(i));
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!c) {
|
2015-07-21 03:15:06 +02:00
|
|
|
continue;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2020-10-01 09:17:33 +02:00
|
|
|
if (c->is_set_as_top_level()) {
|
2015-07-21 03:15:06 +02:00
|
|
|
continue;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Size2i size = c->get_combined_minimum_size();
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
minsize.y += size.y;
|
|
|
|
minsize.x = MAX(minsize.x, size.x);
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (first) {
|
2017-03-05 16:44:50 +01:00
|
|
|
first = false;
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
minsize.y += sep;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-07-21 03:15:06 +02:00
|
|
|
}
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
return minsize + sb->get_minimum_size();
|
2014-12-20 16:32:14 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void GraphNode::set_title(const String &p_title) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (title == p_title) {
|
2019-03-10 11:22:15 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
title = p_title;
|
2020-09-03 13:22:16 +02:00
|
|
|
_shape();
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
update();
|
2019-03-10 11:22:15 +01:00
|
|
|
_change_notify("title");
|
|
|
|
minimum_size_changed();
|
2015-01-03 20:52:37 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
String GraphNode::get_title() const {
|
2015-07-21 03:15:06 +02:00
|
|
|
return title;
|
2015-01-03 20:52:37 +01:00
|
|
|
}
|
|
|
|
|
2020-09-03 13:22:16 +02:00
|
|
|
void GraphNode::set_text_direction(Control::TextDirection p_text_direction) {
|
|
|
|
ERR_FAIL_COND((int)p_text_direction < -1 || (int)p_text_direction > 3);
|
|
|
|
if (text_direction != p_text_direction) {
|
|
|
|
text_direction = p_text_direction;
|
|
|
|
_shape();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Control::TextDirection GraphNode::get_text_direction() const {
|
|
|
|
return text_direction;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphNode::clear_opentype_features() {
|
|
|
|
opentype_features.clear();
|
|
|
|
_shape();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphNode::set_opentype_feature(const String &p_name, int p_value) {
|
|
|
|
int32_t tag = TS->name_to_tag(p_name);
|
|
|
|
if (!opentype_features.has(tag) || (int)opentype_features[tag] != p_value) {
|
|
|
|
opentype_features[tag] = p_value;
|
|
|
|
_shape();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int GraphNode::get_opentype_feature(const String &p_name) const {
|
|
|
|
int32_t tag = TS->name_to_tag(p_name);
|
|
|
|
if (!opentype_features.has(tag)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return opentype_features[tag];
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphNode::set_language(const String &p_language) {
|
|
|
|
if (language != p_language) {
|
|
|
|
language = p_language;
|
|
|
|
_shape();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String GraphNode::get_language() const {
|
|
|
|
return language;
|
|
|
|
}
|
|
|
|
|
2020-12-22 17:24:29 +01:00
|
|
|
void GraphNode::set_position_offset(const Vector2 &p_offset) {
|
|
|
|
position_offset = p_offset;
|
|
|
|
emit_signal("position_offset_changed");
|
2015-07-21 03:15:06 +02:00
|
|
|
update();
|
2015-01-03 20:52:37 +01:00
|
|
|
}
|
|
|
|
|
2020-12-22 17:24:29 +01:00
|
|
|
Vector2 GraphNode::get_position_offset() const {
|
|
|
|
return position_offset;
|
2015-01-03 20:52:37 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +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-05 16:44:50 +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-05 16:44:50 +01:00
|
|
|
void GraphNode::set_drag(bool p_drag) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (p_drag) {
|
2020-12-22 17:24:29 +01:00
|
|
|
drag_from = get_position_offset();
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2020-12-22 17:24:29 +01:00
|
|
|
emit_signal("dragged", drag_from, get_position_offset()); //useful for undo/redo
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-07-19 06:48:46 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +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-05 16:44:50 +01:00
|
|
|
void GraphNode::set_show_close_button(bool p_enable) {
|
|
|
|
show_close = p_enable;
|
2015-07-21 03:15:06 +02:00
|
|
|
update();
|
2015-01-03 20:52:37 +01:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool GraphNode::is_close_button_visible() const {
|
2015-07-21 03:15:06 +02:00
|
|
|
return show_close;
|
2015-01-03 20:52:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void GraphNode::_connpos_update() {
|
2020-03-12 13:37:40 +01:00
|
|
|
int edgeofs = get_theme_constant("port_offset");
|
|
|
|
int sep = get_theme_constant("separation");
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2020-03-12 13:37:40 +01:00
|
|
|
Ref<StyleBox> sb = get_theme_stylebox("frame");
|
2015-07-21 03:15:06 +02:00
|
|
|
conn_input_cache.clear();
|
|
|
|
conn_output_cache.clear();
|
2017-03-05 16:44:50 +01:00
|
|
|
int vofs = 0;
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int idx = 0;
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < get_child_count(); i++) {
|
2017-08-24 22:58:51 +02:00
|
|
|
Control *c = Object::cast_to<Control>(get_child(i));
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!c) {
|
2015-07-21 03:15:06 +02:00
|
|
|
continue;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2020-10-01 09:17:33 +02:00
|
|
|
if (c->is_set_as_top_level()) {
|
2015-07-21 03:15:06 +02:00
|
|
|
continue;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Size2i size = c->get_combined_minimum_size();
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2020-12-22 17:24:29 +01:00
|
|
|
int y = sb->get_margin(SIDE_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)) {
|
|
|
|
if (slot_info[idx].enable_left) {
|
|
|
|
ConnCache cc;
|
2017-03-05 16:44:50 +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-05 16:44:50 +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
|
|
|
|
2020-03-21 22:09:48 +01:00
|
|
|
vofs += sep;
|
2017-03-05 16:44:50 +01:00
|
|
|
vofs += size.y;
|
2015-07-21 03:15:06 +02:00
|
|
|
idx++;
|
|
|
|
}
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
connpos_dirty = false;
|
2015-01-03 20:52:37 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int GraphNode::get_connection_input_count() {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (connpos_dirty) {
|
2015-07-21 03:15:06 +02:00
|
|
|
_connpos_update();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
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
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2015-01-03 20:52:37 +01:00
|
|
|
int GraphNode::get_connection_output_count() {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (connpos_dirty) {
|
2015-07-21 03:15:06 +02:00
|
|
|
_connpos_update();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2017-09-10 15:37:49 +02:00
|
|
|
Vector2 GraphNode::get_connection_input_position(int p_idx) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (connpos_dirty) {
|
2015-07-21 03:15:06 +02:00
|
|
|
_connpos_update();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2017-03-05 16:44:50 +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) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (connpos_dirty) {
|
2015-07-21 03:15:06 +02:00
|
|
|
_connpos_update();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2017-03-05 16:44:50 +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) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (connpos_dirty) {
|
2015-07-21 03:15:06 +02:00
|
|
|
_connpos_update();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2017-03-05 16:44:50 +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-09-10 15:37:49 +02:00
|
|
|
Vector2 GraphNode::get_connection_output_position(int p_idx) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (connpos_dirty) {
|
2015-07-21 03:15:06 +02:00
|
|
|
_connpos_update();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2017-03-05 16:44:50 +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) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (connpos_dirty) {
|
2015-07-21 03:15:06 +02:00
|
|
|
_connpos_update();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2017-03-05 16:44:50 +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) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (connpos_dirty) {
|
2015-07-21 03:15:06 +02:00
|
|
|
_connpos_update();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2017-03-05 16:44:50 +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-05-20 17:38:03 +02:00
|
|
|
void GraphNode::_gui_input(const Ref<InputEvent> &p_ev) {
|
|
|
|
Ref<InputEventMouseButton> mb = p_ev;
|
|
|
|
if (mb.is_valid()) {
|
2020-04-02 01:20:12 +02:00
|
|
|
ERR_FAIL_COND_MSG(get_parent_control() == nullptr, "GraphNode must be the child of a GraphEdit node.");
|
2016-07-23 23:59:24 +02:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
|
2017-06-03 10:54:24 +02:00
|
|
|
Vector2 mpos = Vector2(mb->get_position().x, mb->get_position().y);
|
2017-03-05 16:44:50 +01:00
|
|
|
if (close_rect.size != Size2() && close_rect.has_point(mpos)) {
|
2019-07-11 07:58:43 +02:00
|
|
|
//send focus to parent
|
|
|
|
get_parent_control()->grab_focus();
|
2015-07-26 02:16:07 +02:00
|
|
|
emit_signal("close_request");
|
2016-08-25 22:45:20 +02:00
|
|
|
accept_event();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-12 13:37:40 +01:00
|
|
|
Ref<Texture2D> resizer = get_theme_icon("resizer");
|
2016-08-25 22:45:20 +02:00
|
|
|
|
2017-09-03 20:10:43 +02:00
|
|
|
if (resizable && mpos.x > get_size().x - resizer->get_width() && mpos.y > get_size().y - resizer->get_height()) {
|
2017-03-05 16:44:50 +01:00
|
|
|
resizing = true;
|
|
|
|
resizing_from = mpos;
|
|
|
|
resizing_from_size = get_size();
|
2016-08-25 22:45:20 +02:00
|
|
|
accept_event();
|
2015-07-26 02:16:07 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-08-25 22:45:20 +02:00
|
|
|
|
2015-07-26 02:16:07 +02:00
|
|
|
emit_signal("raise_request");
|
2015-07-21 03:15:06 +02:00
|
|
|
}
|
2016-08-25 22:45:20 +02:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (!mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
|
2017-03-05 16:44:50 +01:00
|
|
|
resizing = false;
|
2016-08-25 22:45:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
Ref<InputEventMouseMotion> mm = p_ev;
|
|
|
|
if (resizing && mm.is_valid()) {
|
2017-06-03 10:54:24 +02:00
|
|
|
Vector2 mpos = mm->get_position();
|
2016-08-25 22:45:20 +02:00
|
|
|
|
|
|
|
Vector2 diff = mpos - resizing_from;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
emit_signal("resize_request", resizing_from_size + diff);
|
2015-07-21 03:15:06 +02:00
|
|
|
}
|
2015-01-03 20:52:37 +01:00
|
|
|
}
|
|
|
|
|
2016-08-07 00:00:54 +02:00
|
|
|
void GraphNode::set_overlay(Overlay p_overlay) {
|
2017-03-05 16:44:50 +01:00
|
|
|
overlay = p_overlay;
|
2016-08-07 00:00:54 +02:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
GraphNode::Overlay GraphNode::get_overlay() const {
|
2016-08-07 00:00:54 +02:00
|
|
|
return overlay;
|
|
|
|
}
|
2014-12-20 16:32:14 +01:00
|
|
|
|
2016-08-25 22:45:20 +02:00
|
|
|
void GraphNode::set_comment(bool p_enable) {
|
2017-03-05 16:44:50 +01:00
|
|
|
comment = p_enable;
|
2016-08-25 22:45:20 +02:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool GraphNode::is_comment() const {
|
2016-08-25 22:45:20 +02:00
|
|
|
return comment;
|
|
|
|
}
|
|
|
|
|
2017-09-03 20:10:43 +02:00
|
|
|
void GraphNode::set_resizable(bool p_enable) {
|
|
|
|
resizable = p_enable;
|
2016-08-25 22:45:20 +02:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2017-09-03 20:10:43 +02:00
|
|
|
bool GraphNode::is_resizable() const {
|
|
|
|
return resizable;
|
2016-08-25 22:45:20 +02:00
|
|
|
}
|
|
|
|
|
2014-12-20 16:32:14 +01:00
|
|
|
void GraphNode::_bind_methods() {
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_title", "title"), &GraphNode::set_title);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_title"), &GraphNode::get_title);
|
2020-09-03 13:22:16 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_text_direction", "direction"), &GraphNode::set_text_direction);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_text_direction"), &GraphNode::get_text_direction);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_opentype_feature", "tag", "value"), &GraphNode::set_opentype_feature);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_opentype_feature", "tag"), &GraphNode::get_opentype_feature);
|
|
|
|
ClassDB::bind_method(D_METHOD("clear_opentype_features"), &GraphNode::clear_opentype_features);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_language", "language"), &GraphNode::set_language);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_language"), &GraphNode::get_language);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("_gui_input"), &GraphNode::_gui_input);
|
2017-02-13 12:47:24 +01:00
|
|
|
|
2019-06-11 20:43:37 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_slot", "idx", "enable_left", "type_left", "color_left", "enable_right", "type_right", "color_right", "custom_left", "custom_right"), &GraphNode::set_slot, DEFVAL(Ref<Texture2D>()), DEFVAL(Ref<Texture2D>()));
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("clear_slot", "idx"), &GraphNode::clear_slot);
|
2017-08-09 13:54:55 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("clear_all_slots"), &GraphNode::clear_all_slots);
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("is_slot_enabled_left", "idx"), &GraphNode::is_slot_enabled_left);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_slot_type_left", "idx"), &GraphNode::get_slot_type_left);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_slot_color_left", "idx"), &GraphNode::get_slot_color_left);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_slot_enabled_right", "idx"), &GraphNode::is_slot_enabled_right);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_slot_type_right", "idx"), &GraphNode::get_slot_type_right);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_slot_color_right", "idx"), &GraphNode::get_slot_color_right);
|
2017-02-13 12:47:24 +01:00
|
|
|
|
2020-12-22 17:24:29 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_position_offset", "offset"), &GraphNode::set_position_offset);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_position_offset"), &GraphNode::get_position_offset);
|
2017-02-13 12:47:24 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_comment", "comment"), &GraphNode::set_comment);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_comment"), &GraphNode::is_comment);
|
2017-02-13 12:47:24 +01:00
|
|
|
|
2017-09-03 20:10:43 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_resizable", "resizable"), &GraphNode::set_resizable);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_resizable"), &GraphNode::is_resizable);
|
2017-02-13 12:47:24 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_selected", "selected"), &GraphNode::set_selected);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_selected"), &GraphNode::is_selected);
|
2017-02-13 12:47:24 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_connection_output_count"), &GraphNode::get_connection_output_count);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_connection_input_count"), &GraphNode::get_connection_input_count);
|
2017-02-13 12:47:24 +01:00
|
|
|
|
2017-09-10 15:37:49 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_connection_output_position", "idx"), &GraphNode::get_connection_output_position);
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_connection_output_type", "idx"), &GraphNode::get_connection_output_type);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_connection_output_color", "idx"), &GraphNode::get_connection_output_color);
|
2017-09-10 15:37:49 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_connection_input_position", "idx"), &GraphNode::get_connection_input_position);
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_connection_input_type", "idx"), &GraphNode::get_connection_input_type);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_connection_input_color", "idx"), &GraphNode::get_connection_input_color);
|
2017-02-13 12:47:24 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_show_close_button", "show"), &GraphNode::set_show_close_button);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_close_button_visible"), &GraphNode::is_close_button_visible);
|
2017-02-13 12:47:24 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_overlay", "overlay"), &GraphNode::set_overlay);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_overlay"), &GraphNode::get_overlay);
|
2016-08-07 00:00:54 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::STRING, "title"), "set_title", "get_title");
|
2020-09-03 13:22:16 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "text_direction", PROPERTY_HINT_ENUM, "Auto,LTR,RTL,Inherited"), "set_text_direction", "get_text_direction");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::STRING, "language"), "set_language", "get_language");
|
2020-12-22 17:24:29 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position_offset"), "set_position_offset", "get_position_offset");
|
2017-03-05 16:44:50 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_close"), "set_show_close_button", "is_close_button_visible");
|
2017-09-03 20:10:43 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "resizable"), "set_resizable", "is_resizable");
|
2018-01-11 23:35:12 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "selected"), "set_selected", "is_selected");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "comment"), "set_comment", "is_comment");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "overlay", PROPERTY_HINT_ENUM, "Disabled,Breakpoint,Position"), "set_overlay", "get_overlay");
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2020-12-22 17:24:29 +01:00
|
|
|
ADD_SIGNAL(MethodInfo("position_offset_changed"));
|
2017-03-05 16:44:50 +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"));
|
2017-03-05 16:44:50 +01:00
|
|
|
ADD_SIGNAL(MethodInfo("resize_request", PropertyInfo(Variant::VECTOR2, "new_minsize")));
|
2016-08-07 00:00:54 +02:00
|
|
|
|
2017-08-20 17:45:01 +02:00
|
|
|
BIND_ENUM_CONSTANT(OVERLAY_DISABLED);
|
|
|
|
BIND_ENUM_CONSTANT(OVERLAY_BREAKPOINT);
|
|
|
|
BIND_ENUM_CONSTANT(OVERLAY_POSITION);
|
2014-12-20 16:32:14 +01:00
|
|
|
}
|
|
|
|
|
2014-12-21 15:42:44 +01:00
|
|
|
GraphNode::GraphNode() {
|
2020-09-03 13:22:16 +02:00
|
|
|
title_buf.instance();
|
2017-03-05 16:44:50 +01:00
|
|
|
overlay = OVERLAY_DISABLED;
|
|
|
|
show_close = false;
|
|
|
|
connpos_dirty = true;
|
2017-08-08 15:57:33 +02:00
|
|
|
set_mouse_filter(MOUSE_FILTER_STOP);
|
2017-03-05 16:44:50 +01:00
|
|
|
comment = false;
|
2017-09-03 20:10:43 +02:00
|
|
|
resizable = false;
|
2017-03-05 16:44:50 +01:00
|
|
|
resizing = false;
|
|
|
|
selected = false;
|
2014-12-20 16:32:14 +01:00
|
|
|
}
|