2023-01-05 12:25:55 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
/* graph_node.cpp */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 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. */
|
|
|
|
/**************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
2014-12-20 15:32:14 +00:00
|
|
|
#include "graph_node.h"
|
2018-09-11 16:13:45 +00:00
|
|
|
|
2020-09-03 11:22:16 +00:00
|
|
|
#include "core/string/translation.h"
|
2022-02-15 17:06:48 +00:00
|
|
|
|
2021-09-23 05:23:45 +00:00
|
|
|
#include "graph_edit.h"
|
2020-09-03 11:22:16 +00:00
|
|
|
|
2020-06-24 19:59:41 +00:00
|
|
|
struct _MinSizeCache {
|
|
|
|
int min_size;
|
|
|
|
bool will_stretch;
|
|
|
|
int final_size;
|
|
|
|
};
|
|
|
|
|
2014-12-21 14:42:44 +00:00
|
|
|
bool GraphNode::_set(const StringName &p_name, const Variant &p_value) {
|
2020-09-03 11:22:16 +00:00
|
|
|
String str = p_name;
|
|
|
|
|
|
|
|
if (!str.begins_with("slot/")) {
|
2015-07-21 01:15:06 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-12-21 14:42:44 +00:00
|
|
|
|
2020-09-03 11:22:16 +00:00
|
|
|
int idx = str.get_slice("/", 1).to_int();
|
|
|
|
String what = str.get_slice("/", 2);
|
2014-12-21 14:42:44 +00:00
|
|
|
|
2015-07-21 01:15:06 +00:00
|
|
|
Slot si;
|
2020-05-14 14:41:43 +00:00
|
|
|
if (slot_info.has(idx)) {
|
2015-07-21 01:15:06 +00:00
|
|
|
si = slot_info[idx];
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (what == "left_enabled") {
|
2015-07-21 01:15:06 +00:00
|
|
|
si.enable_left = p_value;
|
2020-05-14 14:41:43 +00:00
|
|
|
} else if (what == "left_type") {
|
2015-07-21 01:15:06 +00:00
|
|
|
si.type_left = p_value;
|
2021-01-26 07:21:27 +00:00
|
|
|
} else if (what == "left_icon") {
|
|
|
|
si.custom_slot_left = p_value;
|
2020-05-14 14:41:43 +00:00
|
|
|
} else if (what == "left_color") {
|
2015-07-21 01:15:06 +00:00
|
|
|
si.color_left = p_value;
|
2020-05-14 14:41:43 +00:00
|
|
|
} else if (what == "right_enabled") {
|
2015-07-21 01:15:06 +00:00
|
|
|
si.enable_right = p_value;
|
2020-05-14 14:41:43 +00:00
|
|
|
} else if (what == "right_type") {
|
2015-07-21 01:15:06 +00:00
|
|
|
si.type_right = p_value;
|
2020-05-14 14:41:43 +00:00
|
|
|
} else if (what == "right_color") {
|
2015-07-21 01:15:06 +00:00
|
|
|
si.color_right = p_value;
|
2021-01-26 07:21:27 +00:00
|
|
|
} else if (what == "right_icon") {
|
|
|
|
si.custom_slot_right = p_value;
|
2022-04-30 01:56:57 +00:00
|
|
|
} else if (what == "draw_stylebox") {
|
|
|
|
si.draw_stylebox = p_value;
|
2020-05-14 14:41:43 +00:00
|
|
|
} else {
|
2015-07-21 01:15:06 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-12-21 14:42:44 +00:00
|
|
|
|
2022-04-30 01:56:57 +00: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, si.draw_stylebox);
|
2022-08-13 21:21:24 +00:00
|
|
|
queue_redraw();
|
2015-07-21 01:15:06 +00:00
|
|
|
return true;
|
2014-12-21 14:42:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GraphNode::_get(const StringName &p_name, Variant &r_ret) const {
|
2020-09-03 11:22:16 +00:00
|
|
|
String str = p_name;
|
|
|
|
if (!str.begins_with("slot/")) {
|
2015-07-21 01:15:06 +00:00
|
|
|
return false;
|
|
|
|
}
|
2014-12-21 14:42:44 +00:00
|
|
|
|
2020-09-03 11:22:16 +00:00
|
|
|
int idx = str.get_slice("/", 1).to_int();
|
|
|
|
String what = str.get_slice("/", 2);
|
2014-12-21 14:42:44 +00:00
|
|
|
|
2015-07-21 01:15:06 +00:00
|
|
|
Slot si;
|
2020-05-14 14:41:43 +00:00
|
|
|
if (slot_info.has(idx)) {
|
2015-07-21 01:15:06 +00:00
|
|
|
si = slot_info[idx];
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (what == "left_enabled") {
|
2015-07-21 01:15:06 +00:00
|
|
|
r_ret = si.enable_left;
|
2020-05-14 14:41:43 +00:00
|
|
|
} else if (what == "left_type") {
|
2015-07-21 01:15:06 +00:00
|
|
|
r_ret = si.type_left;
|
2020-05-14 14:41:43 +00:00
|
|
|
} else if (what == "left_color") {
|
2015-07-21 01:15:06 +00:00
|
|
|
r_ret = si.color_left;
|
2021-01-26 07:21:27 +00:00
|
|
|
} else if (what == "left_icon") {
|
|
|
|
r_ret = si.custom_slot_left;
|
2020-05-14 14:41:43 +00:00
|
|
|
} else if (what == "right_enabled") {
|
2015-07-21 01:15:06 +00:00
|
|
|
r_ret = si.enable_right;
|
2020-05-14 14:41:43 +00:00
|
|
|
} else if (what == "right_type") {
|
2015-07-21 01:15:06 +00:00
|
|
|
r_ret = si.type_right;
|
2020-05-14 14:41:43 +00:00
|
|
|
} else if (what == "right_color") {
|
2015-07-21 01:15:06 +00:00
|
|
|
r_ret = si.color_right;
|
2021-01-26 07:21:27 +00:00
|
|
|
} else if (what == "right_icon") {
|
|
|
|
r_ret = si.custom_slot_right;
|
2022-04-30 01:56:57 +00:00
|
|
|
} else if (what == "draw_stylebox") {
|
|
|
|
r_ret = si.draw_stylebox;
|
2020-05-14 14:41:43 +00:00
|
|
|
} else {
|
2015-07-21 01:15:06 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-12-21 14:42:44 +00:00
|
|
|
|
2015-07-21 01:15:06 +00:00
|
|
|
return true;
|
2014-12-21 14:42:44 +00:00
|
|
|
}
|
2020-05-14 12:29:06 +00:00
|
|
|
|
2014-12-21 14:42:44 +00:00
|
|
|
void GraphNode::_get_property_list(List<PropertyInfo> *p_list) const {
|
2015-07-21 01:15:06 +00:00
|
|
|
int idx = 0;
|
|
|
|
for (int i = 0; i < get_child_count(); i++) {
|
2017-08-24 20:58:51 +00:00
|
|
|
Control *c = Object::cast_to<Control>(get_child(i));
|
2020-10-01 07:17:33 +00:00
|
|
|
if (!c || c->is_set_as_top_level()) {
|
2015-07-21 01:15:06 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-12-21 14:42:44 +00:00
|
|
|
|
2015-07-21 01:15:06 +00:00
|
|
|
String base = "slot/" + itos(idx) + "/";
|
2014-12-21 14:42:44 +00:00
|
|
|
|
2015-07-21 01:15:06 +00: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 07:21:27 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::OBJECT, base + "left_icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_STORE_IF_NULL));
|
2015-07-21 01:15:06 +00: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 07:21:27 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::OBJECT, base + "right_icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_STORE_IF_NULL));
|
2022-04-30 01:56:57 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::BOOL, base + "draw_stylebox"));
|
2015-07-21 01:15:06 +00:00
|
|
|
idx++;
|
|
|
|
}
|
2014-12-21 14:42:44 +00:00
|
|
|
}
|
|
|
|
|
2014-12-20 15:32:14 +00:00
|
|
|
void GraphNode::_resort() {
|
2020-06-24 19:59:41 +00:00
|
|
|
/** First pass, determine minimum size AND amount of stretchable elements */
|
|
|
|
|
|
|
|
Size2i new_size = get_size();
|
2021-07-17 21:22:52 +00:00
|
|
|
Ref<StyleBox> sb = get_theme_stylebox(SNAME("frame"));
|
2022-04-30 01:56:57 +00:00
|
|
|
Ref<StyleBox> sb_slot = get_theme_stylebox(SNAME("slot"));
|
2014-12-20 15:32:14 +00:00
|
|
|
|
2021-07-17 21:22:52 +00:00
|
|
|
int sep = get_theme_constant(SNAME("separation"));
|
2020-06-24 19:59:41 +00:00
|
|
|
|
|
|
|
bool first = true;
|
|
|
|
int children_count = 0;
|
|
|
|
int stretch_min = 0;
|
|
|
|
int stretch_avail = 0;
|
|
|
|
float stretch_ratio_total = 0;
|
2022-05-13 13:04:37 +00:00
|
|
|
HashMap<Control *, _MinSizeCache> min_size_cache;
|
2014-12-20 15:32:14 +00:00
|
|
|
|
2015-07-21 01:15:06 +00:00
|
|
|
for (int i = 0; i < get_child_count(); i++) {
|
2017-08-24 20:58:51 +00:00
|
|
|
Control *c = Object::cast_to<Control>(get_child(i));
|
2020-06-24 19:59:41 +00:00
|
|
|
if (!c || !c->is_visible_in_tree()) {
|
2015-07-21 01:15:06 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2020-10-01 07:17:33 +00:00
|
|
|
if (c->is_set_as_top_level()) {
|
2015-07-21 01:15:06 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-12-20 15:32:14 +00:00
|
|
|
|
2022-04-30 01:56:57 +00:00
|
|
|
Size2i size = c->get_combined_minimum_size() + (slot_info[i].draw_stylebox ? sb_slot->get_minimum_size() : Size2());
|
2020-06-24 19:59:41 +00:00
|
|
|
_MinSizeCache msc;
|
2014-12-20 15:32:14 +00:00
|
|
|
|
2020-06-24 19:59:41 +00:00
|
|
|
stretch_min += size.height;
|
|
|
|
msc.min_size = size.height;
|
2023-01-07 19:37:21 +00:00
|
|
|
msc.will_stretch = c->get_v_size_flags().has_flag(SIZE_EXPAND);
|
2014-12-20 15:32:14 +00:00
|
|
|
|
2020-06-24 19:59:41 +00:00
|
|
|
if (msc.will_stretch) {
|
|
|
|
stretch_avail += msc.min_size;
|
|
|
|
stretch_ratio_total += c->get_stretch_ratio();
|
|
|
|
}
|
|
|
|
msc.final_size = msc.min_size;
|
|
|
|
min_size_cache[c] = msc;
|
|
|
|
children_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (children_count == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int stretch_max = new_size.height - (children_count - 1) * sep;
|
|
|
|
int stretch_diff = stretch_max - stretch_min;
|
|
|
|
if (stretch_diff < 0) {
|
|
|
|
//avoid negative stretch space
|
|
|
|
stretch_diff = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
stretch_avail += stretch_diff - sb->get_margin(SIDE_BOTTOM) - sb->get_margin(SIDE_TOP); //available stretch space.
|
2021-05-20 10:07:26 +00:00
|
|
|
/** Second, pass successively to discard elements that can't be stretched, this will run while stretchable
|
2020-06-24 19:59:41 +00:00
|
|
|
elements exist */
|
|
|
|
|
|
|
|
while (stretch_ratio_total > 0) { // first of all, don't even be here if no stretchable objects exist
|
|
|
|
bool refit_successful = true; //assume refit-test will go well
|
|
|
|
|
|
|
|
for (int i = 0; i < get_child_count(); i++) {
|
|
|
|
Control *c = Object::cast_to<Control>(get_child(i));
|
|
|
|
if (!c || !c->is_visible_in_tree()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (c->is_set_as_top_level()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ERR_FAIL_COND(!min_size_cache.has(c));
|
|
|
|
_MinSizeCache &msc = min_size_cache[c];
|
|
|
|
|
|
|
|
if (msc.will_stretch) { //wants to stretch
|
|
|
|
//let's see if it can really stretch
|
|
|
|
|
|
|
|
int final_pixel_size = stretch_avail * c->get_stretch_ratio() / stretch_ratio_total;
|
|
|
|
if (final_pixel_size < msc.min_size) {
|
|
|
|
//if available stretching area is too small for widget,
|
|
|
|
//then remove it from stretching area
|
|
|
|
msc.will_stretch = false;
|
|
|
|
stretch_ratio_total -= c->get_stretch_ratio();
|
|
|
|
refit_successful = false;
|
|
|
|
stretch_avail -= msc.min_size;
|
|
|
|
msc.final_size = msc.min_size;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
msc.final_size = final_pixel_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (refit_successful) { //uf refit went well, break
|
|
|
|
break;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-07-21 01:15:06 +00:00
|
|
|
}
|
2014-12-20 15:32:14 +00:00
|
|
|
|
2020-06-24 19:59:41 +00:00
|
|
|
/** Final pass, draw and stretch elements **/
|
2014-12-20 15:32:14 +00:00
|
|
|
|
2020-06-24 19:59:41 +00:00
|
|
|
int ofs = sb->get_margin(SIDE_TOP);
|
|
|
|
|
|
|
|
first = true;
|
|
|
|
int idx = 0;
|
2015-07-21 01:15:06 +00:00
|
|
|
cache_y.clear();
|
2020-06-24 19:59:41 +00:00
|
|
|
int w = new_size.width - sb->get_minimum_size().x;
|
|
|
|
|
2015-07-21 01:15:06 +00:00
|
|
|
for (int i = 0; i < get_child_count(); i++) {
|
2017-08-24 20:58:51 +00:00
|
|
|
Control *c = Object::cast_to<Control>(get_child(i));
|
2020-06-24 19:59:41 +00:00
|
|
|
if (!c || !c->is_visible_in_tree()) {
|
2015-07-21 01:15:06 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2020-10-01 07:17:33 +00:00
|
|
|
if (c->is_set_as_top_level()) {
|
2015-07-21 01:15:06 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-12-20 15:32:14 +00:00
|
|
|
|
2020-06-24 19:59:41 +00:00
|
|
|
_MinSizeCache &msc = min_size_cache[c];
|
|
|
|
|
|
|
|
if (first) {
|
|
|
|
first = false;
|
|
|
|
} else {
|
|
|
|
ofs += sep;
|
|
|
|
}
|
|
|
|
|
|
|
|
int from = ofs;
|
|
|
|
int to = ofs + msc.final_size;
|
2014-12-20 15:32:14 +00:00
|
|
|
|
2020-06-24 19:59:41 +00:00
|
|
|
if (msc.will_stretch && idx == children_count - 1) {
|
|
|
|
//adjust so the last one always fits perfect
|
|
|
|
//compensating for numerical imprecision
|
2014-12-20 15:32:14 +00:00
|
|
|
|
2020-06-24 19:59:41 +00:00
|
|
|
to = new_size.height - sb->get_margin(SIDE_BOTTOM);
|
|
|
|
}
|
|
|
|
|
|
|
|
int size = to - from;
|
|
|
|
|
2022-04-30 01:56:57 +00:00
|
|
|
float margin = sb->get_margin(SIDE_LEFT) + (slot_info[i].draw_stylebox ? sb_slot->get_margin(SIDE_LEFT) : 0);
|
|
|
|
float width = w - (slot_info[i].draw_stylebox ? sb_slot->get_minimum_size().x : 0);
|
|
|
|
Rect2 rect(margin, from, width, size);
|
2014-12-21 14:42:44 +00:00
|
|
|
|
2020-06-24 19:59:41 +00:00
|
|
|
fit_child_in_rect(c, rect);
|
|
|
|
cache_y.push_back(from - sb->get_margin(SIDE_TOP) + size * 0.5);
|
|
|
|
|
|
|
|
ofs = to;
|
|
|
|
idx++;
|
2015-07-21 01:15:06 +00:00
|
|
|
}
|
2014-12-20 15:32:14 +00:00
|
|
|
|
2022-08-13 21:21:24 +00:00
|
|
|
queue_redraw();
|
2015-07-21 01:15:06 +00:00
|
|
|
connpos_dirty = true;
|
2014-12-20 15:32:14 +00:00
|
|
|
}
|
|
|
|
|
2016-09-02 14:55:12 +00:00
|
|
|
bool GraphNode::has_point(const Point2 &p_point) const {
|
|
|
|
if (comment) {
|
2022-09-29 09:53:28 +00:00
|
|
|
Ref<StyleBox> comment_sb = get_theme_stylebox(SNAME("comment"));
|
2021-07-17 21:22:52 +00:00
|
|
|
Ref<Texture2D> resizer = get_theme_icon(SNAME("resizer"));
|
2016-09-02 14:55:12 +00:00
|
|
|
|
|
|
|
if (Rect2(get_size() - resizer->get_size(), resizer->get_size()).has_point(p_point)) {
|
|
|
|
return true;
|
|
|
|
}
|
2017-08-08 13:57:33 +00:00
|
|
|
|
2022-09-29 09:53:28 +00:00
|
|
|
if (Rect2(0, 0, get_size().width, comment_sb->get_margin(SIDE_TOP)).has_point(p_point)) {
|
2016-09-02 14:55:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
return Control::has_point(p_point);
|
|
|
|
}
|
|
|
|
}
|
2014-12-20 15:32:14 +00:00
|
|
|
|
|
|
|
void GraphNode::_notification(int p_what) {
|
2019-01-24 21:31:33 +00:00
|
|
|
switch (p_what) {
|
|
|
|
case NOTIFICATION_DRAW: {
|
|
|
|
Ref<StyleBox> sb;
|
2016-09-02 14:55:12 +00:00
|
|
|
|
2019-01-24 21:31:33 +00:00
|
|
|
if (comment) {
|
2022-04-30 01:56:57 +00:00
|
|
|
sb = get_theme_stylebox(selected ? SNAME("comment_focus") : SNAME("comment"));
|
2016-09-02 14:55:12 +00:00
|
|
|
|
2019-01-24 21:31:33 +00:00
|
|
|
} else {
|
2022-04-30 01:56:57 +00:00
|
|
|
sb = get_theme_stylebox(selected ? SNAME("selected_frame") : SNAME("frame"));
|
2019-01-24 21:31:33 +00:00
|
|
|
}
|
2016-08-25 20:45:20 +00:00
|
|
|
|
2022-04-30 01:56:57 +00:00
|
|
|
Ref<StyleBox> sb_slot = get_theme_stylebox(SNAME("slot"));
|
|
|
|
|
2021-07-17 21:22:52 +00:00
|
|
|
Ref<Texture2D> port = get_theme_icon(SNAME("port"));
|
|
|
|
Ref<Texture2D> close = get_theme_icon(SNAME("close"));
|
|
|
|
Ref<Texture2D> resizer = get_theme_icon(SNAME("resizer"));
|
|
|
|
int close_offset = get_theme_constant(SNAME("close_offset"));
|
|
|
|
int close_h_offset = get_theme_constant(SNAME("close_h_offset"));
|
|
|
|
Color close_color = get_theme_color(SNAME("close_color"));
|
|
|
|
Color resizer_color = get_theme_color(SNAME("resizer_color"));
|
|
|
|
int title_offset = get_theme_constant(SNAME("title_offset"));
|
|
|
|
int title_h_offset = get_theme_constant(SNAME("title_h_offset"));
|
|
|
|
Color title_color = get_theme_color(SNAME("title_color"));
|
2019-01-24 21:31:33 +00:00
|
|
|
Point2i icofs = -port->get_size() * 0.5;
|
2021-07-17 21:22:52 +00:00
|
|
|
int edgeofs = get_theme_constant(SNAME("port_offset"));
|
2020-12-22 16:24:29 +00:00
|
|
|
icofs.y += sb->get_margin(SIDE_TOP);
|
2019-01-24 21:31:33 +00:00
|
|
|
|
|
|
|
draw_style_box(sb, Rect2(Point2(), get_size()));
|
|
|
|
|
|
|
|
switch (overlay) {
|
|
|
|
case OVERLAY_DISABLED: {
|
|
|
|
} break;
|
|
|
|
case OVERLAY_BREAKPOINT: {
|
2021-07-17 21:22:52 +00:00
|
|
|
draw_style_box(get_theme_stylebox(SNAME("breakpoint")), Rect2(Point2(), get_size()));
|
2019-01-24 21:31:33 +00:00
|
|
|
} break;
|
|
|
|
case OVERLAY_POSITION: {
|
2021-07-17 21:22:52 +00:00
|
|
|
draw_style_box(get_theme_stylebox(SNAME("position")), Rect2(Point2(), get_size()));
|
2019-01-24 21:31:33 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
}
|
2016-08-06 22:00:54 +00:00
|
|
|
|
2019-01-24 21:31:33 +00:00
|
|
|
int w = get_size().width - sb->get_minimum_size().x;
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2020-12-22 16:24:29 +00: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 21:31:33 +00:00
|
|
|
if (show_close) {
|
2022-04-30 01:56:57 +00:00
|
|
|
Vector2 cpos = Point2(w + sb->get_margin(SIDE_LEFT) + close_h_offset - close->get_width(), -close->get_height() + close_offset);
|
2019-01-24 21:31:33 +00:00
|
|
|
draw_texture(close, cpos, close_color);
|
|
|
|
close_rect.position = cpos;
|
|
|
|
close_rect.size = close->get_size();
|
|
|
|
} else {
|
|
|
|
close_rect = Rect2();
|
|
|
|
}
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2022-11-29 01:10:45 +00:00
|
|
|
if (get_child_count() > 0) {
|
|
|
|
for (const KeyValue<int, Slot> &E : slot_info) {
|
|
|
|
if (E.key < 0 || E.key >= cache_y.size()) {
|
|
|
|
continue;
|
2019-01-24 21:31:33 +00:00
|
|
|
}
|
2022-11-29 01:10:45 +00:00
|
|
|
if (!slot_info.has(E.key)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const Slot &s = slot_info[E.key];
|
|
|
|
// Left port.
|
|
|
|
if (s.enable_left) {
|
|
|
|
Ref<Texture2D> p = port;
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
// Right port.
|
|
|
|
if (s.enable_right) {
|
|
|
|
Ref<Texture2D> p = port;
|
|
|
|
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);
|
2019-01-24 21:31:33 +00:00
|
|
|
}
|
2022-04-30 01:56:57 +00:00
|
|
|
|
2022-11-29 01:10:45 +00:00
|
|
|
// Draw slot stylebox.
|
|
|
|
if (s.draw_stylebox) {
|
|
|
|
Control *c = Object::cast_to<Control>(get_child(E.key));
|
|
|
|
if (!c || !c->is_visible_in_tree()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (c->is_set_as_top_level()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
Rect2 c_rect = c->get_rect();
|
|
|
|
c_rect.position.x = sb->get_margin(SIDE_LEFT);
|
|
|
|
c_rect.size.width = w;
|
|
|
|
draw_style_box(sb_slot, c_rect);
|
|
|
|
}
|
2022-04-30 01:56:57 +00:00
|
|
|
}
|
2016-08-02 22:11:05 +00:00
|
|
|
}
|
2016-08-25 20:45:20 +00:00
|
|
|
|
2019-01-24 21:31:33 +00:00
|
|
|
if (resizable) {
|
2019-09-01 05:57:56 +00:00
|
|
|
draw_texture(resizer, get_size() - resizer->get_size(), resizer_color);
|
2019-01-24 21:31:33 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case NOTIFICATION_SORT_CHILDREN: {
|
|
|
|
_resort();
|
|
|
|
} break;
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2020-09-03 11:22:16 +00:00
|
|
|
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED:
|
|
|
|
case NOTIFICATION_TRANSLATION_CHANGED:
|
2019-01-24 21:31:33 +00:00
|
|
|
case NOTIFICATION_THEME_CHANGED: {
|
2020-09-03 11:22:16 +00:00
|
|
|
_shape();
|
|
|
|
|
2021-12-06 13:02:34 +00:00
|
|
|
update_minimum_size();
|
2022-08-13 21:21:24 +00:00
|
|
|
queue_redraw();
|
2019-01-24 21:31:33 +00:00
|
|
|
} break;
|
2015-07-21 01:15:06 +00:00
|
|
|
}
|
2014-12-20 15:32:14 +00:00
|
|
|
}
|
|
|
|
|
2020-09-03 11:22:16 +00:00
|
|
|
void GraphNode::_shape() {
|
2021-07-17 21:22:52 +00:00
|
|
|
Ref<Font> font = get_theme_font(SNAME("title_font"));
|
|
|
|
int font_size = get_theme_font_size(SNAME("title_font_size"));
|
2020-09-03 11:22:16 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2022-05-09 09:47:10 +00:00
|
|
|
title_buf->add_string(title, font, font_size, language);
|
2020-09-03 11:22:16 +00:00
|
|
|
}
|
|
|
|
|
2021-09-23 05:23:45 +00:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
void GraphNode::_edit_set_position(const Point2 &p_position) {
|
|
|
|
GraphEdit *graph = Object::cast_to<GraphEdit>(get_parent());
|
|
|
|
if (graph) {
|
|
|
|
Point2 offset = (p_position + graph->get_scroll_ofs()) * graph->get_zoom();
|
|
|
|
set_position_offset(offset);
|
|
|
|
}
|
|
|
|
set_position(p_position);
|
|
|
|
}
|
2022-08-24 00:02:24 +00:00
|
|
|
#endif
|
2021-09-23 05:23:45 +00:00
|
|
|
|
2022-08-12 20:57:11 +00:00
|
|
|
void GraphNode::_validate_property(PropertyInfo &p_property) const {
|
2021-09-23 05:23:45 +00:00
|
|
|
GraphEdit *graph = Object::cast_to<GraphEdit>(get_parent());
|
|
|
|
if (graph) {
|
2022-08-12 20:57:11 +00:00
|
|
|
if (p_property.name == "position") {
|
|
|
|
p_property.usage |= PROPERTY_USAGE_READ_ONLY;
|
2021-09-23 05:23:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-30 01:56:57 +00: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, bool p_draw_stylebox) {
|
2021-05-11 07:17:47 +00:00
|
|
|
ERR_FAIL_COND_MSG(p_idx < 0, vformat("Cannot set slot with p_idx (%d) lesser than zero.", p_idx));
|
2014-12-21 14:42:44 +00:00
|
|
|
|
2021-01-26 07:21:27 +00: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 01:15:06 +00:00
|
|
|
slot_info.erase(p_idx);
|
|
|
|
return;
|
|
|
|
}
|
2014-12-21 14:42:44 +00:00
|
|
|
|
2015-07-21 01:15:06 +00:00
|
|
|
Slot s;
|
|
|
|
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;
|
2016-08-02 22:11:05 +00:00
|
|
|
s.custom_slot_left = p_custom_left;
|
|
|
|
s.custom_slot_right = p_custom_right;
|
2022-04-30 01:56:57 +00:00
|
|
|
s.draw_stylebox = p_draw_stylebox;
|
2015-07-21 01:15:06 +00:00
|
|
|
slot_info[p_idx] = s;
|
2022-08-13 21:21:24 +00:00
|
|
|
queue_redraw();
|
2015-07-21 01:15:06 +00:00
|
|
|
connpos_dirty = true;
|
2021-02-10 14:18:34 +00:00
|
|
|
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("slot_updated"), p_idx);
|
2014-12-20 15:32:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GraphNode::clear_slot(int p_idx) {
|
2015-07-21 01:15:06 +00:00
|
|
|
slot_info.erase(p_idx);
|
2022-08-13 21:21:24 +00:00
|
|
|
queue_redraw();
|
2015-07-21 01:15:06 +00:00
|
|
|
connpos_dirty = true;
|
2014-12-20 15:32:14 +00:00
|
|
|
}
|
2020-05-14 12:29:06 +00:00
|
|
|
|
2014-12-20 15:32:14 +00:00
|
|
|
void GraphNode::clear_all_slots() {
|
2015-07-21 01:15:06 +00:00
|
|
|
slot_info.clear();
|
2022-08-13 21:21:24 +00:00
|
|
|
queue_redraw();
|
2015-07-21 01:15:06 +00:00
|
|
|
connpos_dirty = true;
|
2014-12-20 15:32:14 +00:00
|
|
|
}
|
2020-05-14 12:29:06 +00:00
|
|
|
|
2014-12-21 14:42:44 +00:00
|
|
|
bool GraphNode::is_slot_enabled_left(int p_idx) const {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!slot_info.has(p_idx)) {
|
2015-07-21 01:15:06 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-07-21 01:15:06 +00:00
|
|
|
return slot_info[p_idx].enable_left;
|
2014-12-20 15:32:14 +00:00
|
|
|
}
|
2014-12-21 14:42:44 +00:00
|
|
|
|
2021-05-11 07:17:47 +00:00
|
|
|
void GraphNode::set_slot_enabled_left(int p_idx, bool p_enable_left) {
|
|
|
|
ERR_FAIL_COND_MSG(p_idx < 0, vformat("Cannot set enable_left for the slot with p_idx (%d) lesser than zero.", p_idx));
|
|
|
|
|
2022-03-16 07:50:48 +00:00
|
|
|
if (slot_info[p_idx].enable_left == p_enable_left) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-11 07:17:47 +00:00
|
|
|
slot_info[p_idx].enable_left = p_enable_left;
|
2022-08-13 21:21:24 +00:00
|
|
|
queue_redraw();
|
2021-05-11 07:17:47 +00:00
|
|
|
connpos_dirty = true;
|
|
|
|
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("slot_updated"), p_idx);
|
2021-05-11 07:17:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GraphNode::set_slot_type_left(int p_idx, int p_type_left) {
|
|
|
|
ERR_FAIL_COND_MSG(!slot_info.has(p_idx), vformat("Cannot set type_left for the slot '%d' because it hasn't been enabled.", p_idx));
|
|
|
|
|
2022-03-16 07:50:48 +00:00
|
|
|
if (slot_info[p_idx].type_left == p_type_left) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-11 07:17:47 +00:00
|
|
|
slot_info[p_idx].type_left = p_type_left;
|
2022-08-13 21:21:24 +00:00
|
|
|
queue_redraw();
|
2021-05-11 07:17:47 +00:00
|
|
|
connpos_dirty = true;
|
|
|
|
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("slot_updated"), p_idx);
|
2021-05-11 07:17:47 +00:00
|
|
|
}
|
|
|
|
|
2014-12-21 14:42:44 +00:00
|
|
|
int GraphNode::get_slot_type_left(int p_idx) const {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!slot_info.has(p_idx)) {
|
2015-07-21 01:15:06 +00:00
|
|
|
return 0;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-07-21 01:15:06 +00:00
|
|
|
return slot_info[p_idx].type_left;
|
2014-12-20 15:32:14 +00:00
|
|
|
}
|
2014-12-21 14:42:44 +00:00
|
|
|
|
2021-05-11 07:17:47 +00:00
|
|
|
void GraphNode::set_slot_color_left(int p_idx, const Color &p_color_left) {
|
|
|
|
ERR_FAIL_COND_MSG(!slot_info.has(p_idx), vformat("Cannot set color_left for the slot '%d' because it hasn't been enabled.", p_idx));
|
|
|
|
|
2022-03-16 07:50:48 +00:00
|
|
|
if (slot_info[p_idx].color_left == p_color_left) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-11 07:17:47 +00:00
|
|
|
slot_info[p_idx].color_left = p_color_left;
|
2022-08-13 21:21:24 +00:00
|
|
|
queue_redraw();
|
2021-05-11 07:17:47 +00:00
|
|
|
connpos_dirty = true;
|
|
|
|
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("slot_updated"), p_idx);
|
2021-05-11 07:17:47 +00:00
|
|
|
}
|
|
|
|
|
2014-12-20 15:32:14 +00:00
|
|
|
Color GraphNode::get_slot_color_left(int p_idx) const {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!slot_info.has(p_idx)) {
|
2015-07-21 01:15:06 +00:00
|
|
|
return Color(1, 1, 1, 1);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-07-21 01:15:06 +00:00
|
|
|
return slot_info[p_idx].color_left;
|
2014-12-20 15:32:14 +00:00
|
|
|
}
|
|
|
|
|
2014-12-21 14:42:44 +00:00
|
|
|
bool GraphNode::is_slot_enabled_right(int p_idx) const {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!slot_info.has(p_idx)) {
|
2015-07-21 01:15:06 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-07-21 01:15:06 +00:00
|
|
|
return slot_info[p_idx].enable_right;
|
2014-12-20 15:32:14 +00:00
|
|
|
}
|
2014-12-21 14:42:44 +00:00
|
|
|
|
2021-05-11 07:17:47 +00:00
|
|
|
void GraphNode::set_slot_enabled_right(int p_idx, bool p_enable_right) {
|
|
|
|
ERR_FAIL_COND_MSG(p_idx < 0, vformat("Cannot set enable_right for the slot with p_idx (%d) lesser than zero.", p_idx));
|
|
|
|
|
2022-03-16 07:50:48 +00:00
|
|
|
if (slot_info[p_idx].enable_right == p_enable_right) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-11 07:17:47 +00:00
|
|
|
slot_info[p_idx].enable_right = p_enable_right;
|
2022-08-13 21:21:24 +00:00
|
|
|
queue_redraw();
|
2021-05-11 07:17:47 +00:00
|
|
|
connpos_dirty = true;
|
|
|
|
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("slot_updated"), p_idx);
|
2021-05-11 07:17:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GraphNode::set_slot_type_right(int p_idx, int p_type_right) {
|
|
|
|
ERR_FAIL_COND_MSG(!slot_info.has(p_idx), vformat("Cannot set type_right for the slot '%d' because it hasn't been enabled.", p_idx));
|
|
|
|
|
2022-03-16 07:50:48 +00:00
|
|
|
if (slot_info[p_idx].type_right == p_type_right) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-11 07:17:47 +00:00
|
|
|
slot_info[p_idx].type_right = p_type_right;
|
2022-08-13 21:21:24 +00:00
|
|
|
queue_redraw();
|
2021-05-11 07:17:47 +00:00
|
|
|
connpos_dirty = true;
|
|
|
|
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("slot_updated"), p_idx);
|
2021-05-11 07:17:47 +00:00
|
|
|
}
|
|
|
|
|
2014-12-21 14:42:44 +00:00
|
|
|
int GraphNode::get_slot_type_right(int p_idx) const {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!slot_info.has(p_idx)) {
|
2015-07-21 01:15:06 +00:00
|
|
|
return 0;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-07-21 01:15:06 +00:00
|
|
|
return slot_info[p_idx].type_right;
|
2014-12-20 15:32:14 +00:00
|
|
|
}
|
2014-12-21 14:42:44 +00:00
|
|
|
|
2021-05-11 07:17:47 +00:00
|
|
|
void GraphNode::set_slot_color_right(int p_idx, const Color &p_color_right) {
|
|
|
|
ERR_FAIL_COND_MSG(!slot_info.has(p_idx), vformat("Cannot set color_right for the slot '%d' because it hasn't been enabled.", p_idx));
|
|
|
|
|
2022-03-16 07:50:48 +00:00
|
|
|
if (slot_info[p_idx].color_right == p_color_right) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-11 07:17:47 +00:00
|
|
|
slot_info[p_idx].color_right = p_color_right;
|
2022-08-13 21:21:24 +00:00
|
|
|
queue_redraw();
|
2021-05-11 07:17:47 +00:00
|
|
|
connpos_dirty = true;
|
|
|
|
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("slot_updated"), p_idx);
|
2021-05-11 07:17:47 +00:00
|
|
|
}
|
|
|
|
|
2014-12-20 15:32:14 +00:00
|
|
|
Color GraphNode::get_slot_color_right(int p_idx) const {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!slot_info.has(p_idx)) {
|
2015-07-21 01:15:06 +00:00
|
|
|
return Color(1, 1, 1, 1);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-07-21 01:15:06 +00:00
|
|
|
return slot_info[p_idx].color_right;
|
2014-12-20 15:32:14 +00:00
|
|
|
}
|
|
|
|
|
2022-04-30 01:56:57 +00:00
|
|
|
bool GraphNode::is_slot_draw_stylebox(int p_idx) const {
|
|
|
|
if (!slot_info.has(p_idx)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return slot_info[p_idx].draw_stylebox;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphNode::set_slot_draw_stylebox(int p_idx, bool p_enable) {
|
|
|
|
ERR_FAIL_COND_MSG(p_idx < 0, vformat("Cannot set draw_stylebox for the slot with p_idx (%d) lesser than zero.", p_idx));
|
|
|
|
|
|
|
|
slot_info[p_idx].draw_stylebox = p_enable;
|
2022-08-13 21:21:24 +00:00
|
|
|
queue_redraw();
|
2022-04-30 01:56:57 +00:00
|
|
|
connpos_dirty = true;
|
|
|
|
|
|
|
|
emit_signal(SNAME("slot_updated"), p_idx);
|
|
|
|
}
|
|
|
|
|
2014-12-20 15:32:14 +00:00
|
|
|
Size2 GraphNode::get_minimum_size() const {
|
2021-07-17 21:22:52 +00:00
|
|
|
Ref<StyleBox> sb = get_theme_stylebox(SNAME("frame"));
|
2022-04-30 01:56:57 +00:00
|
|
|
Ref<StyleBox> sb_slot = get_theme_stylebox(SNAME("slot"));
|
|
|
|
|
|
|
|
int sep = get_theme_constant(SNAME("separation"));
|
|
|
|
int title_h_offset = get_theme_constant(SNAME("title_h_offset"));
|
|
|
|
|
2015-07-21 01:15:06 +00:00
|
|
|
bool first = true;
|
2014-12-20 15:32:14 +00:00
|
|
|
|
2015-07-21 01:15:06 +00:00
|
|
|
Size2 minsize;
|
2022-04-30 01:56:57 +00:00
|
|
|
minsize.x = title_buf->get_size().x + title_h_offset;
|
2015-07-21 01:15:06 +00:00
|
|
|
if (show_close) {
|
2022-04-30 01:56:57 +00:00
|
|
|
int close_h_offset = get_theme_constant(SNAME("close_h_offset"));
|
2021-07-17 21:22:52 +00:00
|
|
|
Ref<Texture2D> close = get_theme_icon(SNAME("close"));
|
2022-04-30 01:56:57 +00:00
|
|
|
//TODO: Remove this magic number after GraphNode rework.
|
|
|
|
minsize.x += 12 + close->get_width() + close_h_offset;
|
2015-07-21 01:15:06 +00:00
|
|
|
}
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2015-07-21 01:15:06 +00:00
|
|
|
for (int i = 0; i < get_child_count(); i++) {
|
2017-08-24 20:58:51 +00:00
|
|
|
Control *c = Object::cast_to<Control>(get_child(i));
|
2023-04-07 15:44:38 +00:00
|
|
|
if (!c || !c->is_visible()) {
|
2015-07-21 01:15:06 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2020-10-01 07:17:33 +00:00
|
|
|
if (c->is_set_as_top_level()) {
|
2015-07-21 01:15:06 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-12-20 15:32:14 +00:00
|
|
|
|
2015-07-21 01:15:06 +00:00
|
|
|
Size2i size = c->get_combined_minimum_size();
|
2022-04-30 01:56:57 +00:00
|
|
|
if (slot_info.has(i)) {
|
|
|
|
size += slot_info[i].draw_stylebox ? sb_slot->get_minimum_size() : Size2();
|
|
|
|
}
|
2014-12-20 15:32:14 +00:00
|
|
|
|
2015-07-21 01:15:06 +00:00
|
|
|
minsize.y += size.y;
|
|
|
|
minsize.x = MAX(minsize.x, size.x);
|
2014-12-20 15:32:14 +00:00
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (first) {
|
2015-07-21 01:15:06 +00:00
|
|
|
first = false;
|
2020-05-14 14:41:43 +00:00
|
|
|
} else {
|
2015-07-21 01:15:06 +00:00
|
|
|
minsize.y += sep;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-07-21 01:15:06 +00:00
|
|
|
}
|
2014-12-20 15:32:14 +00:00
|
|
|
|
2015-07-21 01:15:06 +00:00
|
|
|
return minsize + sb->get_minimum_size();
|
2014-12-20 15:32:14 +00:00
|
|
|
}
|
|
|
|
|
2015-01-03 19:52:37 +00:00
|
|
|
void GraphNode::set_title(const String &p_title) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (title == p_title) {
|
2019-03-10 10:22:15 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-07-21 01:15:06 +00:00
|
|
|
title = p_title;
|
2020-09-03 11:22:16 +00:00
|
|
|
_shape();
|
|
|
|
|
2022-08-13 21:21:24 +00:00
|
|
|
queue_redraw();
|
2021-12-06 13:02:34 +00:00
|
|
|
update_minimum_size();
|
2015-01-03 19:52:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
String GraphNode::get_title() const {
|
2015-07-21 01:15:06 +00:00
|
|
|
return title;
|
2015-01-03 19:52:37 +00:00
|
|
|
}
|
|
|
|
|
2020-09-03 11:22:16 +00: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();
|
2022-08-13 21:21:24 +00:00
|
|
|
queue_redraw();
|
2020-09-03 11:22:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Control::TextDirection GraphNode::get_text_direction() const {
|
|
|
|
return text_direction;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphNode::set_language(const String &p_language) {
|
|
|
|
if (language != p_language) {
|
|
|
|
language = p_language;
|
|
|
|
_shape();
|
2022-08-13 21:21:24 +00:00
|
|
|
queue_redraw();
|
2020-09-03 11:22:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String GraphNode::get_language() const {
|
|
|
|
return language;
|
|
|
|
}
|
|
|
|
|
2020-12-22 16:24:29 +00:00
|
|
|
void GraphNode::set_position_offset(const Vector2 &p_offset) {
|
2022-03-16 07:50:48 +00:00
|
|
|
if (position_offset == p_offset) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-12-22 16:24:29 +00:00
|
|
|
position_offset = p_offset;
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("position_offset_changed"));
|
2022-08-13 21:21:24 +00:00
|
|
|
queue_redraw();
|
2015-01-03 19:52:37 +00:00
|
|
|
}
|
|
|
|
|
2020-12-22 16:24:29 +00:00
|
|
|
Vector2 GraphNode::get_position_offset() const {
|
|
|
|
return position_offset;
|
2015-01-03 19:52:37 +00:00
|
|
|
}
|
|
|
|
|
2015-07-19 04:48:46 +00:00
|
|
|
void GraphNode::set_selected(bool p_selected) {
|
2022-08-24 14:57:17 +00:00
|
|
|
if (!is_selectable() || selected == p_selected) {
|
2022-03-16 07:50:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-21 01:15:06 +00:00
|
|
|
selected = p_selected;
|
2023-01-12 03:08:06 +00:00
|
|
|
emit_signal(p_selected ? SNAME("node_selected") : SNAME("node_deselected"));
|
2022-08-13 21:21:24 +00:00
|
|
|
queue_redraw();
|
2015-07-19 04:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GraphNode::is_selected() {
|
2015-07-21 01:15:06 +00:00
|
|
|
return selected;
|
2015-07-19 04:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GraphNode::set_drag(bool p_drag) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (p_drag) {
|
2020-12-22 16:24:29 +00:00
|
|
|
drag_from = get_position_offset();
|
2020-05-14 14:41:43 +00:00
|
|
|
} else {
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("dragged"), drag_from, get_position_offset()); //useful for undo/redo
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-07-19 04:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Vector2 GraphNode::get_drag_from() {
|
2015-07-21 01:15:06 +00:00
|
|
|
return drag_from;
|
2015-07-19 04:48:46 +00:00
|
|
|
}
|
2015-01-03 19:52:37 +00:00
|
|
|
|
|
|
|
void GraphNode::set_show_close_button(bool p_enable) {
|
2022-03-16 07:50:48 +00:00
|
|
|
if (show_close == p_enable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-21 01:15:06 +00:00
|
|
|
show_close = p_enable;
|
2022-08-13 21:21:24 +00:00
|
|
|
queue_redraw();
|
2015-01-03 19:52:37 +00:00
|
|
|
}
|
2020-05-14 12:29:06 +00:00
|
|
|
|
2015-01-03 19:52:37 +00:00
|
|
|
bool GraphNode::is_close_button_visible() const {
|
2015-07-21 01:15:06 +00:00
|
|
|
return show_close;
|
2015-01-03 19:52:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GraphNode::_connpos_update() {
|
2021-07-17 21:22:52 +00:00
|
|
|
int edgeofs = get_theme_constant(SNAME("port_offset"));
|
|
|
|
int sep = get_theme_constant(SNAME("separation"));
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2021-07-17 21:22:52 +00:00
|
|
|
Ref<StyleBox> sb = get_theme_stylebox(SNAME("frame"));
|
2022-09-09 13:29:51 +00:00
|
|
|
left_port_cache.clear();
|
|
|
|
right_port_cache.clear();
|
2015-07-21 01:15:06 +00:00
|
|
|
int vofs = 0;
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2015-07-21 01:15:06 +00:00
|
|
|
int idx = 0;
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2015-07-21 01:15:06 +00:00
|
|
|
for (int i = 0; i < get_child_count(); i++) {
|
2017-08-24 20:58:51 +00:00
|
|
|
Control *c = Object::cast_to<Control>(get_child(i));
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!c) {
|
2015-07-21 01:15:06 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2020-10-01 07:17:33 +00:00
|
|
|
if (c->is_set_as_top_level()) {
|
2015-07-21 01:15:06 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2021-06-28 16:52:13 +00:00
|
|
|
Size2i size = c->get_rect().size;
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2020-12-22 16:24:29 +00:00
|
|
|
int y = sb->get_margin(SIDE_TOP) + vofs;
|
2023-02-23 04:40:27 +00:00
|
|
|
int h = size.height;
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2015-07-21 01:15:06 +00:00
|
|
|
if (slot_info.has(idx)) {
|
|
|
|
if (slot_info[idx].enable_left) {
|
2022-09-09 13:29:51 +00:00
|
|
|
PortCache cc;
|
|
|
|
cc.position = Point2i(edgeofs, y + h / 2);
|
2023-02-23 04:40:27 +00:00
|
|
|
cc.height = h;
|
2022-09-09 13:29:51 +00:00
|
|
|
|
|
|
|
cc.slot_idx = idx;
|
2015-07-21 01:15:06 +00:00
|
|
|
cc.type = slot_info[idx].type_left;
|
|
|
|
cc.color = slot_info[idx].color_left;
|
2022-09-09 13:29:51 +00:00
|
|
|
|
|
|
|
left_port_cache.push_back(cc);
|
2015-07-21 01:15:06 +00:00
|
|
|
}
|
|
|
|
if (slot_info[idx].enable_right) {
|
2022-09-09 13:29:51 +00:00
|
|
|
PortCache cc;
|
|
|
|
cc.position = Point2i(get_size().width - edgeofs, y + h / 2);
|
2023-02-23 04:40:27 +00:00
|
|
|
cc.height = h;
|
2022-09-09 13:29:51 +00:00
|
|
|
|
|
|
|
cc.slot_idx = idx;
|
2015-07-21 01:15:06 +00:00
|
|
|
cc.type = slot_info[idx].type_right;
|
|
|
|
cc.color = slot_info[idx].color_right;
|
2022-09-09 13:29:51 +00:00
|
|
|
|
|
|
|
right_port_cache.push_back(cc);
|
2015-07-21 01:15:06 +00:00
|
|
|
}
|
|
|
|
}
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2020-03-21 21:09:48 +00:00
|
|
|
vofs += sep;
|
2023-02-23 04:40:27 +00:00
|
|
|
vofs += h;
|
2015-07-21 01:15:06 +00:00
|
|
|
idx++;
|
|
|
|
}
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2015-07-21 01:15:06 +00:00
|
|
|
connpos_dirty = false;
|
2015-01-03 19:52:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int GraphNode::get_connection_input_count() {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (connpos_dirty) {
|
2015-07-21 01:15:06 +00:00
|
|
|
_connpos_update();
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2022-09-09 13:29:51 +00:00
|
|
|
return left_port_cache.size();
|
2015-01-03 19:52:37 +00:00
|
|
|
}
|
2020-05-14 12:29:06 +00:00
|
|
|
|
2022-09-09 13:29:51 +00:00
|
|
|
int GraphNode::get_connection_input_height(int p_port) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (connpos_dirty) {
|
2015-07-21 01:15:06 +00:00
|
|
|
_connpos_update();
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2022-09-09 13:29:51 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_port, left_port_cache.size(), 0);
|
|
|
|
return left_port_cache[p_port].height;
|
2015-01-03 19:52:37 +00:00
|
|
|
}
|
|
|
|
|
2022-09-09 13:29:51 +00:00
|
|
|
Vector2 GraphNode::get_connection_input_position(int p_port) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (connpos_dirty) {
|
2015-07-21 01:15:06 +00:00
|
|
|
_connpos_update();
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2022-09-09 13:29:51 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_port, left_port_cache.size(), Vector2());
|
|
|
|
Vector2 pos = left_port_cache[p_port].position;
|
2016-01-18 23:32:37 +00:00
|
|
|
pos.x *= get_scale().x;
|
|
|
|
pos.y *= get_scale().y;
|
|
|
|
return pos;
|
2015-01-03 19:52:37 +00:00
|
|
|
}
|
|
|
|
|
2022-09-09 13:29:51 +00:00
|
|
|
int GraphNode::get_connection_input_type(int p_port) {
|
|
|
|
if (connpos_dirty) {
|
|
|
|
_connpos_update();
|
|
|
|
}
|
|
|
|
|
|
|
|
ERR_FAIL_INDEX_V(p_port, left_port_cache.size(), 0);
|
|
|
|
return left_port_cache[p_port].type;
|
|
|
|
}
|
|
|
|
|
|
|
|
Color GraphNode::get_connection_input_color(int p_port) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (connpos_dirty) {
|
2015-07-21 01:15:06 +00:00
|
|
|
_connpos_update();
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2022-09-09 13:29:51 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_port, left_port_cache.size(), Color());
|
|
|
|
return left_port_cache[p_port].color;
|
2015-01-03 19:52:37 +00:00
|
|
|
}
|
|
|
|
|
2022-09-09 13:29:51 +00:00
|
|
|
int GraphNode::get_connection_input_slot(int p_port) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (connpos_dirty) {
|
2015-07-21 01:15:06 +00:00
|
|
|
_connpos_update();
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2022-09-09 13:29:51 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_port, left_port_cache.size(), -1);
|
|
|
|
return left_port_cache[p_port].slot_idx;
|
2015-01-03 19:52:37 +00:00
|
|
|
}
|
|
|
|
|
2022-05-30 13:48:58 +00:00
|
|
|
int GraphNode::get_connection_output_count() {
|
|
|
|
if (connpos_dirty) {
|
|
|
|
_connpos_update();
|
|
|
|
}
|
|
|
|
|
2022-09-09 13:29:51 +00:00
|
|
|
return right_port_cache.size();
|
2022-05-30 13:48:58 +00:00
|
|
|
}
|
|
|
|
|
2022-09-09 13:29:51 +00:00
|
|
|
int GraphNode::get_connection_output_height(int p_port) {
|
2022-05-30 13:48:58 +00:00
|
|
|
if (connpos_dirty) {
|
|
|
|
_connpos_update();
|
|
|
|
}
|
|
|
|
|
2022-09-09 13:29:51 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_port, right_port_cache.size(), 0);
|
|
|
|
return right_port_cache[p_port].height;
|
2022-05-30 13:48:58 +00:00
|
|
|
}
|
|
|
|
|
2022-09-09 13:29:51 +00:00
|
|
|
Vector2 GraphNode::get_connection_output_position(int p_port) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (connpos_dirty) {
|
2015-07-21 01:15:06 +00:00
|
|
|
_connpos_update();
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2022-09-09 13:29:51 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_port, right_port_cache.size(), Vector2());
|
|
|
|
Vector2 pos = right_port_cache[p_port].position;
|
2016-01-18 23:32:37 +00:00
|
|
|
pos.x *= get_scale().x;
|
|
|
|
pos.y *= get_scale().y;
|
|
|
|
return pos;
|
2015-01-03 19:52:37 +00:00
|
|
|
}
|
|
|
|
|
2022-09-09 13:29:51 +00:00
|
|
|
int GraphNode::get_connection_output_type(int p_port) {
|
|
|
|
if (connpos_dirty) {
|
|
|
|
_connpos_update();
|
|
|
|
}
|
|
|
|
|
|
|
|
ERR_FAIL_INDEX_V(p_port, right_port_cache.size(), 0);
|
|
|
|
return right_port_cache[p_port].type;
|
|
|
|
}
|
|
|
|
|
|
|
|
Color GraphNode::get_connection_output_color(int p_port) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (connpos_dirty) {
|
2015-07-21 01:15:06 +00:00
|
|
|
_connpos_update();
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2022-09-09 13:29:51 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_port, right_port_cache.size(), Color());
|
|
|
|
return right_port_cache[p_port].color;
|
2015-01-03 19:52:37 +00:00
|
|
|
}
|
|
|
|
|
2022-09-09 13:29:51 +00:00
|
|
|
int GraphNode::get_connection_output_slot(int p_port) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (connpos_dirty) {
|
2015-07-21 01:15:06 +00:00
|
|
|
_connpos_update();
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2022-09-09 13:29:51 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_port, right_port_cache.size(), -1);
|
|
|
|
return right_port_cache[p_port].slot_idx;
|
2015-01-03 19:52:37 +00:00
|
|
|
}
|
|
|
|
|
2021-08-22 15:37:22 +00:00
|
|
|
void GraphNode::gui_input(const Ref<InputEvent> &p_ev) {
|
2021-04-05 06:52:21 +00:00
|
|
|
ERR_FAIL_COND(p_ev.is_null());
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
Ref<InputEventMouseButton> mb = p_ev;
|
|
|
|
if (mb.is_valid()) {
|
2020-04-01 23:20:12 +00:00
|
|
|
ERR_FAIL_COND_MSG(get_parent_control() == nullptr, "GraphNode must be the child of a GraphEdit node.");
|
2016-07-23 21:59:24 +00:00
|
|
|
|
2021-08-13 21:31:57 +00:00
|
|
|
if (mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT) {
|
2021-09-23 14:58:43 +00:00
|
|
|
Vector2 mpos = mb->get_position();
|
2015-07-26 00:16:07 +00:00
|
|
|
if (close_rect.size != Size2() && close_rect.has_point(mpos)) {
|
2019-07-11 05:58:43 +00:00
|
|
|
//send focus to parent
|
|
|
|
get_parent_control()->grab_focus();
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("close_request"));
|
2016-08-25 20:45:20 +00:00
|
|
|
accept_event();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-07-17 21:22:52 +00:00
|
|
|
Ref<Texture2D> resizer = get_theme_icon(SNAME("resizer"));
|
2016-08-25 20:45:20 +00:00
|
|
|
|
2017-09-03 18:10:43 +00:00
|
|
|
if (resizable && mpos.x > get_size().x - resizer->get_width() && mpos.y > get_size().y - resizer->get_height()) {
|
2016-08-25 20:45:20 +00:00
|
|
|
resizing = true;
|
|
|
|
resizing_from = mpos;
|
|
|
|
resizing_from_size = get_size();
|
|
|
|
accept_event();
|
2015-07-26 00:16:07 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-08-25 20:45:20 +00:00
|
|
|
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("raise_request"));
|
2015-07-21 01:15:06 +00:00
|
|
|
}
|
2016-08-25 20:45:20 +00:00
|
|
|
|
2021-08-13 21:31:57 +00:00
|
|
|
if (!mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT) {
|
2016-08-25 20:45:20 +00:00
|
|
|
resizing = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
Ref<InputEventMouseMotion> mm = p_ev;
|
|
|
|
if (resizing && mm.is_valid()) {
|
2017-06-03 08:54:24 +00:00
|
|
|
Vector2 mpos = mm->get_position();
|
2016-08-25 20:45:20 +00:00
|
|
|
|
|
|
|
Vector2 diff = mpos - resizing_from;
|
|
|
|
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("resize_request"), resizing_from_size + diff);
|
2015-07-21 01:15:06 +00:00
|
|
|
}
|
2015-01-03 19:52:37 +00:00
|
|
|
}
|
|
|
|
|
2016-08-06 22:00:54 +00:00
|
|
|
void GraphNode::set_overlay(Overlay p_overlay) {
|
2022-03-16 07:50:48 +00:00
|
|
|
if (overlay == p_overlay) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-06 22:00:54 +00:00
|
|
|
overlay = p_overlay;
|
2022-08-13 21:21:24 +00:00
|
|
|
queue_redraw();
|
2016-08-06 22:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GraphNode::Overlay GraphNode::get_overlay() const {
|
|
|
|
return overlay;
|
|
|
|
}
|
2014-12-20 15:32:14 +00:00
|
|
|
|
2016-08-25 20:45:20 +00:00
|
|
|
void GraphNode::set_comment(bool p_enable) {
|
2022-03-16 07:50:48 +00:00
|
|
|
if (comment == p_enable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-25 20:45:20 +00:00
|
|
|
comment = p_enable;
|
2022-08-13 21:21:24 +00:00
|
|
|
queue_redraw();
|
2016-08-25 20:45:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GraphNode::is_comment() const {
|
|
|
|
return comment;
|
|
|
|
}
|
|
|
|
|
2017-09-03 18:10:43 +00:00
|
|
|
void GraphNode::set_resizable(bool p_enable) {
|
2022-03-16 07:50:48 +00:00
|
|
|
if (resizable == p_enable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-03 18:10:43 +00:00
|
|
|
resizable = p_enable;
|
2022-08-13 21:21:24 +00:00
|
|
|
queue_redraw();
|
2016-08-25 20:45:20 +00:00
|
|
|
}
|
|
|
|
|
2017-09-03 18:10:43 +00:00
|
|
|
bool GraphNode::is_resizable() const {
|
|
|
|
return resizable;
|
2016-08-25 20:45:20 +00:00
|
|
|
}
|
|
|
|
|
2022-05-04 05:31:53 +00:00
|
|
|
void GraphNode::set_draggable(bool p_draggable) {
|
|
|
|
draggable = p_draggable;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GraphNode::is_draggable() {
|
|
|
|
return draggable;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphNode::set_selectable(bool p_selectable) {
|
2022-08-24 14:57:17 +00:00
|
|
|
if (!p_selectable) {
|
|
|
|
set_selected(false);
|
|
|
|
}
|
2022-05-04 05:31:53 +00:00
|
|
|
selectable = p_selectable;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GraphNode::is_selectable() {
|
|
|
|
return selectable;
|
|
|
|
}
|
|
|
|
|
2021-11-08 20:53:41 +00:00
|
|
|
Vector<int> GraphNode::get_allowed_size_flags_horizontal() const {
|
|
|
|
Vector<int> flags;
|
|
|
|
flags.append(SIZE_FILL);
|
|
|
|
flags.append(SIZE_SHRINK_BEGIN);
|
|
|
|
flags.append(SIZE_SHRINK_CENTER);
|
|
|
|
flags.append(SIZE_SHRINK_END);
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector<int> GraphNode::get_allowed_size_flags_vertical() const {
|
|
|
|
Vector<int> flags;
|
|
|
|
flags.append(SIZE_FILL);
|
|
|
|
flags.append(SIZE_EXPAND);
|
|
|
|
flags.append(SIZE_SHRINK_BEGIN);
|
|
|
|
flags.append(SIZE_SHRINK_CENTER);
|
|
|
|
flags.append(SIZE_SHRINK_END);
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2014-12-20 15:32:14 +00:00
|
|
|
void GraphNode::_bind_methods() {
|
2017-02-13 11:47:24 +00: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 11:22:16 +00: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_language", "language"), &GraphNode::set_language);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_language"), &GraphNode::get_language);
|
|
|
|
|
2022-09-09 13:29:51 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_slot", "slot_index", "enable_left_port", "type_left", "color_left", "enable_right_port", "type_right", "color_right", "custom_icon_left", "custom_icon_right", "draw_stylebox"), &GraphNode::set_slot, DEFVAL(Ref<Texture2D>()), DEFVAL(Ref<Texture2D>()), DEFVAL(true));
|
|
|
|
ClassDB::bind_method(D_METHOD("clear_slot", "slot_index"), &GraphNode::clear_slot);
|
2017-08-09 11:54:55 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("clear_all_slots"), &GraphNode::clear_all_slots);
|
2021-05-11 07:17:47 +00:00
|
|
|
|
2022-09-09 13:29:51 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_slot_enabled_left", "slot_index", "enable"), &GraphNode::set_slot_enabled_left);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_slot_enabled_left", "slot_index"), &GraphNode::is_slot_enabled_left);
|
2021-05-11 07:17:47 +00:00
|
|
|
|
2022-09-09 13:29:51 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_slot_type_left", "slot_index", "type"), &GraphNode::set_slot_type_left);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_slot_type_left", "slot_index"), &GraphNode::get_slot_type_left);
|
2021-05-11 07:17:47 +00:00
|
|
|
|
2022-09-09 13:29:51 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_slot_color_left", "slot_index", "color"), &GraphNode::set_slot_color_left);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_slot_color_left", "slot_index"), &GraphNode::get_slot_color_left);
|
2021-05-11 07:17:47 +00:00
|
|
|
|
2022-09-09 13:29:51 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_slot_enabled_right", "slot_index", "enable"), &GraphNode::set_slot_enabled_right);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_slot_enabled_right", "slot_index"), &GraphNode::is_slot_enabled_right);
|
2021-05-11 07:17:47 +00:00
|
|
|
|
2022-09-09 13:29:51 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_slot_type_right", "slot_index", "type"), &GraphNode::set_slot_type_right);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_slot_type_right", "slot_index"), &GraphNode::get_slot_type_right);
|
2021-05-11 07:17:47 +00:00
|
|
|
|
2022-09-09 13:29:51 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_slot_color_right", "slot_index", "color"), &GraphNode::set_slot_color_right);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_slot_color_right", "slot_index"), &GraphNode::get_slot_color_right);
|
2017-02-13 11:47:24 +00:00
|
|
|
|
2022-09-09 13:29:51 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("is_slot_draw_stylebox", "slot_index"), &GraphNode::is_slot_draw_stylebox);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_slot_draw_stylebox", "slot_index", "enable"), &GraphNode::set_slot_draw_stylebox);
|
2022-04-30 01:56:57 +00:00
|
|
|
|
2020-12-22 16:24:29 +00: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 11:47:24 +00:00
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_comment", "comment"), &GraphNode::set_comment);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_comment"), &GraphNode::is_comment);
|
|
|
|
|
2017-09-03 18:10:43 +00: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 11:47:24 +00:00
|
|
|
|
2022-05-04 05:31:53 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_draggable", "draggable"), &GraphNode::set_draggable);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_draggable"), &GraphNode::is_draggable);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_selectable", "selectable"), &GraphNode::set_selectable);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_selectable"), &GraphNode::is_selectable);
|
|
|
|
|
2017-02-13 11:47:24 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_selected", "selected"), &GraphNode::set_selected);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_selected"), &GraphNode::is_selected);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("get_connection_input_count"), &GraphNode::get_connection_input_count);
|
2022-09-09 13:29:51 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_connection_input_height", "port"), &GraphNode::get_connection_input_height);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_connection_input_position", "port"), &GraphNode::get_connection_input_position);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_connection_input_type", "port"), &GraphNode::get_connection_input_type);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_connection_input_color", "port"), &GraphNode::get_connection_input_color);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_connection_input_slot", "port"), &GraphNode::get_connection_input_slot);
|
2017-02-13 11:47:24 +00:00
|
|
|
|
2022-05-30 13:48:58 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_connection_output_count"), &GraphNode::get_connection_output_count);
|
2022-09-09 13:29:51 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_connection_output_height", "port"), &GraphNode::get_connection_output_height);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_connection_output_position", "port"), &GraphNode::get_connection_output_position);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_connection_output_type", "port"), &GraphNode::get_connection_output_type);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_connection_output_color", "port"), &GraphNode::get_connection_output_color);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_connection_output_slot", "port"), &GraphNode::get_connection_output_slot);
|
2017-02-13 11:47:24 +00: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);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_overlay", "overlay"), &GraphNode::set_overlay);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_overlay"), &GraphNode::get_overlay);
|
2016-08-06 22:00:54 +00:00
|
|
|
|
2017-02-12 00:11:37 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::STRING, "title"), "set_title", "get_title");
|
2022-05-20 05:24:41 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position_offset", PROPERTY_HINT_NONE, "suffix:px"), "set_position_offset", "get_position_offset");
|
2017-02-12 00:11:37 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_close"), "set_show_close_button", "is_close_button_visible");
|
2017-09-03 18:10:43 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "resizable"), "set_resizable", "is_resizable");
|
2022-05-04 05:31:53 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draggable"), "set_draggable", "is_draggable");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "selectable"), "set_selectable", "is_selectable");
|
2018-01-11 22:35:12 +00: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 19:52:37 +00:00
|
|
|
|
2022-05-09 09:47:10 +00:00
|
|
|
ADD_GROUP("BiDi", "");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "text_direction", PROPERTY_HINT_ENUM, "Auto,Left-to-Right,Right-to-Left,Inherited"), "set_text_direction", "get_text_direction");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::STRING, "language", PROPERTY_HINT_LOCALE_ID, ""), "set_language", "get_language");
|
2022-08-02 13:39:56 +00:00
|
|
|
ADD_GROUP("", "");
|
2022-05-09 09:47:10 +00:00
|
|
|
|
2020-12-22 16:24:29 +00:00
|
|
|
ADD_SIGNAL(MethodInfo("position_offset_changed"));
|
2023-01-12 03:08:06 +00:00
|
|
|
ADD_SIGNAL(MethodInfo("node_selected"));
|
|
|
|
ADD_SIGNAL(MethodInfo("node_deselected"));
|
2021-02-10 14:18:34 +00:00
|
|
|
ADD_SIGNAL(MethodInfo("slot_updated", PropertyInfo(Variant::INT, "idx")));
|
2015-07-21 01:15:06 +00:00
|
|
|
ADD_SIGNAL(MethodInfo("dragged", PropertyInfo(Variant::VECTOR2, "from"), PropertyInfo(Variant::VECTOR2, "to")));
|
|
|
|
ADD_SIGNAL(MethodInfo("raise_request"));
|
|
|
|
ADD_SIGNAL(MethodInfo("close_request"));
|
2016-08-25 20:45:20 +00:00
|
|
|
ADD_SIGNAL(MethodInfo("resize_request", PropertyInfo(Variant::VECTOR2, "new_minsize")));
|
2016-08-06 22:00:54 +00:00
|
|
|
|
2017-08-20 15:45:01 +00:00
|
|
|
BIND_ENUM_CONSTANT(OVERLAY_DISABLED);
|
|
|
|
BIND_ENUM_CONSTANT(OVERLAY_BREAKPOINT);
|
|
|
|
BIND_ENUM_CONSTANT(OVERLAY_POSITION);
|
2014-12-20 15:32:14 +00:00
|
|
|
}
|
|
|
|
|
2014-12-21 14:42:44 +00:00
|
|
|
GraphNode::GraphNode() {
|
2021-06-17 22:03:09 +00:00
|
|
|
title_buf.instantiate();
|
2017-08-08 13:57:33 +00:00
|
|
|
set_mouse_filter(MOUSE_FILTER_STOP);
|
2014-12-20 15:32:14 +00:00
|
|
|
}
|