diff options
Diffstat (limited to 'scene/gui/graph_node.cpp')
-rw-r--r-- | scene/gui/graph_node.cpp | 1119 |
1 files changed, 411 insertions, 708 deletions
diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp index 2223beafda..385b564b7c 100644 --- a/scene/gui/graph_node.cpp +++ b/scene/gui/graph_node.cpp @@ -31,8 +31,8 @@ #include "graph_node.h" #include "core/string/translation.h" - -#include "graph_edit.h" +#include "scene/gui/box_container.h" +#include "scene/gui/label.h" bool GraphNode::_set(const StringName &p_name, const Variant &p_value) { String str = p_name; @@ -42,72 +42,83 @@ bool GraphNode::_set(const StringName &p_name, const Variant &p_value) { } int idx = str.get_slice("/", 1).to_int(); - String what = str.get_slice("/", 2); - - Slot si; - if (slot_info.has(idx)) { - si = slot_info[idx]; - } - - if (what == "left_enabled") { - si.enable_left = p_value; - } else if (what == "left_type") { - si.type_left = p_value; - } else if (what == "left_icon") { - si.custom_slot_left = p_value; - } else if (what == "left_color") { - si.color_left = p_value; - } else if (what == "right_enabled") { - si.enable_right = p_value; - } else if (what == "right_type") { - si.type_right = p_value; - } else if (what == "right_color") { - si.color_right = p_value; - } else if (what == "right_icon") { - si.custom_slot_right = p_value; - } else if (what == "draw_stylebox") { - si.draw_stylebox = p_value; + String slot_property_name = str.get_slice("/", 2); + + Slot slot; + if (slot_table.has(idx)) { + slot = slot_table[idx]; + } + + if (slot_property_name == "left_enabled") { + slot.enable_left = p_value; + } else if (slot_property_name == "left_type") { + slot.type_left = p_value; + } else if (slot_property_name == "left_icon") { + slot.custom_port_icon_left = p_value; + } else if (slot_property_name == "left_color") { + slot.color_left = p_value; + } else if (slot_property_name == "right_enabled") { + slot.enable_right = p_value; + } else if (slot_property_name == "right_type") { + slot.type_right = p_value; + } else if (slot_property_name == "right_color") { + slot.color_right = p_value; + } else if (slot_property_name == "right_icon") { + slot.custom_port_icon_right = p_value; + } else if (slot_property_name == "draw_stylebox") { + slot.draw_stylebox = p_value; } else { return false; } - 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); + set_slot(idx, + slot.enable_left, + slot.type_left, + slot.color_left, + slot.enable_right, + slot.type_right, + slot.color_right, + slot.custom_port_icon_left, + slot.custom_port_icon_right, + slot.draw_stylebox); + queue_redraw(); return true; } bool GraphNode::_get(const StringName &p_name, Variant &r_ret) const { String str = p_name; + if (!str.begins_with("slot/")) { return false; } int idx = str.get_slice("/", 1).to_int(); - String what = str.get_slice("/", 2); - - Slot si; - if (slot_info.has(idx)) { - si = slot_info[idx]; - } - - if (what == "left_enabled") { - r_ret = si.enable_left; - } else if (what == "left_type") { - r_ret = si.type_left; - } else if (what == "left_color") { - r_ret = si.color_left; - } else if (what == "left_icon") { - r_ret = si.custom_slot_left; - } else if (what == "right_enabled") { - r_ret = si.enable_right; - } else if (what == "right_type") { - r_ret = si.type_right; - } else if (what == "right_color") { - r_ret = si.color_right; - } else if (what == "right_icon") { - r_ret = si.custom_slot_right; - } else if (what == "draw_stylebox") { - r_ret = si.draw_stylebox; + StringName slot_property_name = str.get_slice("/", 2); + + Slot slot; + if (slot_table.has(idx)) { + slot = slot_table[idx]; + } + + if (slot_property_name == "left_enabled") { + r_ret = slot.enable_left; + } else if (slot_property_name == "left_type") { + r_ret = slot.type_left; + } else if (slot_property_name == "left_color") { + r_ret = slot.color_left; + } else if (slot_property_name == "left_icon") { + r_ret = slot.custom_port_icon_left; + } else if (slot_property_name == "right_enabled") { + r_ret = slot.enable_right; + } else if (slot_property_name == "right_type") { + r_ret = slot.type_right; + } else if (slot_property_name == "right_color") { + r_ret = slot.color_right; + } else if (slot_property_name == "right_icon") { + r_ret = slot.custom_port_icon_right; + } else if (slot_property_name == "draw_stylebox") { + r_ret = slot.draw_stylebox; } else { return false; } @@ -117,9 +128,9 @@ bool GraphNode::_get(const StringName &p_name, Variant &r_ret) const { void GraphNode::_get_property_list(List<PropertyInfo> *p_list) const { int idx = 0; - for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to<Control>(get_child(i)); - if (!c || c->is_set_as_top_level()) { + for (int i = 0; i < get_child_count(false); i++) { + Control *child = Object::cast_to<Control>(get_child(i, false)); + if (!child || child->is_set_as_top_level()) { continue; } @@ -139,43 +150,51 @@ void GraphNode::_get_property_list(List<PropertyInfo> *p_list) const { } void GraphNode::_resort() { - /** First pass, determine minimum size AND amount of stretchable elements */ + Size2 new_size = get_size(); + Ref<StyleBox> sb_panel = get_theme_stylebox(SNAME("panel")); + Ref<StyleBox> sb_titlebar = get_theme_stylebox(SNAME("titlebar")); - Size2i new_size = get_size(); - Ref<StyleBox> sb = get_theme_stylebox(SNAME("frame")); - Ref<StyleBox> sb_slot = get_theme_stylebox(SNAME("slot")); + // Resort titlebar first. + Size2 titlebar_size = Size2(new_size.width, titlebar_hbox->get_size().height); + titlebar_size -= sb_titlebar->get_minimum_size(); + Rect2 titlebar_rect = Rect2(sb_titlebar->get_offset(), titlebar_size); + fit_child_in_rect(titlebar_hbox, titlebar_rect); - int sep = get_theme_constant(SNAME("separation")); + // After resort, the children of the titlebar container may have changed their height (e.g. Label autowrap). + Size2i titlebar_min_size = titlebar_hbox->get_combined_minimum_size(); + + // First pass, determine minimum size AND amount of stretchable elements. + Ref<StyleBox> sb_slot = get_theme_stylebox(SNAME("slot")); + int separation = get_theme_constant(SNAME("separation")); - bool first = true; int children_count = 0; int stretch_min = 0; - int stretch_avail = 0; + int available_stretch_space = 0; float stretch_ratio_total = 0; HashMap<Control *, _MinSizeCache> min_size_cache; - 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()) { + for (int i = 0; i < get_child_count(false); i++) { + Control *child = Object::cast_to<Control>(get_child(i, false)); + + if (!child || !child->is_visible_in_tree() || child->is_set_as_top_level()) { continue; } - Size2i size = c->get_combined_minimum_size() + (slot_info[i].draw_stylebox ? sb_slot->get_minimum_size() : Size2()); - _MinSizeCache msc; + Size2i size = child->get_combined_minimum_size() + (slot_table[i].draw_stylebox ? sb_slot->get_minimum_size() : Size2()); stretch_min += size.height; + + _MinSizeCache msc; msc.min_size = size.height; - msc.will_stretch = c->get_v_size_flags().has_flag(SIZE_EXPAND); + msc.will_stretch = child->get_v_size_flags().has_flag(SIZE_EXPAND); + msc.final_size = msc.min_size; + min_size_cache[child] = msc; if (msc.will_stretch) { - stretch_avail += msc.min_size; - stretch_ratio_total += c->get_stretch_ratio(); + available_stretch_space += msc.min_size; + stretch_ratio_total += child->get_stretch_ratio(); } - msc.final_size = msc.min_size; - min_size_cache[c] = msc; + children_count++; } @@ -183,43 +202,38 @@ void GraphNode::_resort() { return; } - int stretch_max = new_size.height - (children_count - 1) * sep; + int stretch_max = new_size.height - (children_count - 1) * separation; 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. - /** Second, pass successively to discard elements that can't be stretched, this will run while stretchable - elements exist */ + // Avoid negative stretch space. + stretch_diff = MAX(stretch_diff, 0); - 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 + available_stretch_space += stretch_diff - sb_panel->get_margin(SIDE_BOTTOM) - sb_panel->get_margin(SIDE_TOP); - 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()) { + // Second pass, discard elements that can't be stretched, this will run while stretchable elements exist. + + while (stretch_ratio_total > 0) { + // First of all, don't even be here if no stretchable objects exist. + bool refit_successful = true; + + for (int i = 0; i < get_child_count(false); i++) { + Control *child = Object::cast_to<Control>(get_child(i, false)); + if (!child || !child->is_visible_in_tree() || child->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 + ERR_FAIL_COND(!min_size_cache.has(child)); + _MinSizeCache &msc = min_size_cache[child]; - int final_pixel_size = stretch_avail * c->get_stretch_ratio() / stretch_ratio_total; + if (msc.will_stretch) { + int final_pixel_size = available_stretch_space * child->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 + // If the available stretching area is too small for a Control, + // then remove it from stretching area. msc.will_stretch = false; - stretch_ratio_total -= c->get_stretch_ratio(); + stretch_ratio_total -= child->get_stretch_ratio(); refit_successful = false; - stretch_avail -= msc.min_size; + available_stretch_space -= msc.min_size; msc.final_size = msc.min_size; break; } else { @@ -228,786 +242,514 @@ void GraphNode::_resort() { } } - if (refit_successful) { //uf refit went well, break + if (refit_successful) { break; } } - /** Final pass, draw and stretch elements **/ + // Final pass, draw and stretch elements. - int ofs = sb->get_margin(SIDE_TOP); - - first = true; - int idx = 0; - cache_y.clear(); - int w = new_size.width - sb->get_minimum_size().x; + int ofs_y = sb_panel->get_margin(SIDE_TOP) + titlebar_min_size.height + sb_titlebar->get_minimum_size().height; - 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()) { + slot_y_cache.clear(); + int width = new_size.width - sb_panel->get_minimum_size().width; + int valid_children_idx = 0; + for (int i = 0; i < get_child_count(false); i++) { + Control *child = Object::cast_to<Control>(get_child(i, false)); + if (!child || !child->is_visible_in_tree() || child->is_set_as_top_level()) { continue; } - if (c->is_set_as_top_level()) { - continue; + + _MinSizeCache &msc = min_size_cache[child]; + + if (valid_children_idx > 0) { + ofs_y += separation; } - _MinSizeCache &msc = min_size_cache[c]; + int from_y_pos = ofs_y; + int to_y_pos = ofs_y + msc.final_size; - if (first) { - first = false; - } else { - ofs += sep; + // Adjust so the last valid child always fits perfect, compensating for numerical imprecision. + if (msc.will_stretch && valid_children_idx == children_count - 1) { + to_y_pos = new_size.height - sb_panel->get_margin(SIDE_BOTTOM); } - int from = ofs; - int to = ofs + msc.final_size; + int height = to_y_pos - from_y_pos; + float margin = sb_panel->get_margin(SIDE_LEFT) + (slot_table[i].draw_stylebox ? sb_slot->get_margin(SIDE_LEFT) : 0); + float final_width = width - (slot_table[i].draw_stylebox ? sb_slot->get_minimum_size().x : 0); + Rect2 rect(margin, from_y_pos, final_width, height); + fit_child_in_rect(child, rect); - if (msc.will_stretch && idx == children_count - 1) { - //adjust so the last one always fits perfect - //compensating for numerical imprecision + slot_y_cache.push_back(from_y_pos - sb_panel->get_margin(SIDE_TOP) + height * 0.5); - to = new_size.height - sb->get_margin(SIDE_BOTTOM); - } + ofs_y = to_y_pos; + valid_children_idx++; + } - int size = to - from; + queue_redraw(); + port_pos_dirty = true; +} - 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); +void GraphNode::draw_port(int p_slot_index, Point2i p_pos, bool p_left, const Color &p_color) { + if (GDVIRTUAL_CALL(_draw_port, p_slot_index, p_pos, p_left, p_color)) { + return; + } - fit_child_in_rect(c, rect); - cache_y.push_back(from - sb->get_margin(SIDE_TOP) + size * 0.5); + Slot slot = slot_table[p_slot_index]; + Ref<Texture2D> port_icon = p_left ? slot.custom_port_icon_left : slot.custom_port_icon_right; - ofs = to; - idx++; + Point2 icon_offset; + if (!port_icon.is_valid()) { + port_icon = get_theme_icon(SNAME("port")); } - queue_redraw(); - connpos_dirty = true; + icon_offset = -port_icon->get_size() * 0.5; + port_icon->draw(get_canvas_item(), p_pos + icon_offset, p_color); } void GraphNode::_notification(int p_what) { switch (p_what) { case NOTIFICATION_DRAW: { - Ref<StyleBox> sb; - - sb = get_theme_stylebox(selected ? SNAME("selected_frame") : SNAME("frame")); + // Used for layout calculations. + Ref<StyleBox> sb_panel = get_theme_stylebox(SNAME("panel")); + Ref<StyleBox> sb_titlebar = get_theme_stylebox(SNAME("titlebar")); + // Used for drawing. + Ref<StyleBox> sb_to_draw_panel = get_theme_stylebox(selected ? SNAME("panel_selected") : SNAME("panel")); + Ref<StyleBox> sb_to_draw_titlebar = get_theme_stylebox(selected ? SNAME("titlebar_selected") : SNAME("titlebar")); Ref<StyleBox> sb_slot = get_theme_stylebox(SNAME("slot")); - 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")); + int port_h_offset = get_theme_constant(SNAME("port_h_offset")); + + Ref<Texture2D> resizer_icon = get_theme_icon(SNAME("resizer")); + 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")); - Point2i icofs = -port->get_size() * 0.5; - int edgeofs = get_theme_constant(SNAME("port_offset")); - icofs.y += sb->get_margin(SIDE_TOP); - - draw_style_box(sb, Rect2(Point2(), get_size())); - - switch (overlay) { - case OVERLAY_DISABLED: { - } break; - case OVERLAY_BREAKPOINT: { - draw_style_box(get_theme_stylebox(SNAME("breakpoint")), Rect2(Point2(), get_size())); - } break; - case OVERLAY_POSITION: { - draw_style_box(get_theme_stylebox(SNAME("position")), Rect2(Point2(), get_size())); - - } break; - } - int w = get_size().width - sb->get_minimum_size().x; + Rect2 titlebar_rect(Point2(), titlebar_hbox->get_size() + sb_titlebar->get_minimum_size()); + Size2 body_size = get_size(); + titlebar_rect.size.width = body_size.width; + body_size.height -= titlebar_rect.size.height; + Rect2 body_rect(0, titlebar_rect.size.height, body_size.width, body_size.height); - title_buf->draw(get_canvas_item(), Point2(sb->get_margin(SIDE_LEFT) + title_h_offset, -title_buf->get_size().y + title_offset), title_color); - if (show_close) { - Vector2 cpos = Point2(w + sb->get_margin(SIDE_LEFT) + close_h_offset - close->get_width(), -close->get_height() + close_offset); - draw_texture(close, cpos, close_color); - close_rect.position = cpos; - close_rect.size = close->get_size(); - } else { - close_rect = Rect2(); - } + // Draw body (slots area) stylebox. + draw_style_box(sb_to_draw_panel, body_rect); + + // Draw title bar stylebox above. + draw_style_box(sb_to_draw_titlebar, titlebar_rect); + + int width = get_size().width - sb_panel->get_minimum_size().x; if (get_child_count() > 0) { - for (const KeyValue<int, Slot> &E : slot_info) { - if (E.key < 0 || E.key >= cache_y.size()) { + int slot_index = 0; + for (const KeyValue<int, Slot> &E : slot_table) { + if (E.key < 0 || E.key >= slot_y_cache.size()) { continue; } - if (!slot_info.has(E.key)) { + if (!slot_table.has(E.key)) { continue; } - const Slot &s = slot_info[E.key]; + const Slot &slot = slot_table[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); + if (slot.enable_left) { + draw_port(slot_index, Point2i(port_h_offset, slot_y_cache[E.key] + sb_panel->get_margin(SIDE_TOP)), true, slot.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); + if (slot.enable_right) { + draw_port(slot_index, Point2i(get_size().x - port_h_offset, slot_y_cache[E.key] + sb_panel->get_margin(SIDE_TOP)), false, slot.color_right); } // 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()) { + if (slot.draw_stylebox) { + Control *child = Object::cast_to<Control>(get_child(E.key, false)); + if (!child || !child->is_visible_in_tree()) { 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); + Rect2 child_rect = child->get_rect(); + child_rect.position.x = sb_panel->get_margin(SIDE_LEFT); + child_rect.size.width = width; + draw_style_box(sb_slot, child_rect); } + + slot_index++; } } if (resizable) { - draw_texture(resizer, get_size() - resizer->get_size(), resizer_color); + draw_texture(resizer_icon, get_size() - resizer_icon->get_size(), resizer_color); } } break; - - case NOTIFICATION_SORT_CHILDREN: { - _resort(); - } break; - - case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: - case NOTIFICATION_TRANSLATION_CHANGED: - case NOTIFICATION_THEME_CHANGED: { - _shape(); - - update_minimum_size(); - queue_redraw(); - } break; } } -void GraphNode::_shape() { - Ref<Font> font = get_theme_font(SNAME("title_font")); - int font_size = get_theme_font_size(SNAME("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, language); -} - -#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_offset()) * graph->get_zoom(); - set_position_offset(offset); - } - set_position(p_position); -} -#endif - -void GraphNode::_validate_property(PropertyInfo &p_property) const { - GraphEdit *graph = Object::cast_to<GraphEdit>(get_parent()); - if (graph) { - if (p_property.name == "position") { - p_property.usage |= PROPERTY_USAGE_READ_ONLY; - } - } -} - -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) { - ERR_FAIL_COND_MSG(p_idx < 0, vformat("Cannot set slot with p_idx (%d) lesser than zero.", p_idx)); +void GraphNode::set_slot(int p_slot_index, 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) { + ERR_FAIL_COND_MSG(p_slot_index < 0, vformat("Cannot set slot with index (%d) lesser than zero.", p_slot_index)); 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()) { - slot_info.erase(p_idx); + slot_table.erase(p_slot_index); return; } - 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; - s.custom_slot_left = p_custom_left; - s.custom_slot_right = p_custom_right; - s.draw_stylebox = p_draw_stylebox; - slot_info[p_idx] = s; + Slot slot; + slot.enable_left = p_enable_left; + slot.type_left = p_type_left; + slot.color_left = p_color_left; + slot.enable_right = p_enable_right; + slot.type_right = p_type_right; + slot.color_right = p_color_right; + slot.custom_port_icon_left = p_custom_left; + slot.custom_port_icon_right = p_custom_right; + slot.draw_stylebox = p_draw_stylebox; + slot_table[p_slot_index] = slot; queue_redraw(); - connpos_dirty = true; + port_pos_dirty = true; - emit_signal(SNAME("slot_updated"), p_idx); + emit_signal(SNAME("slot_updated"), p_slot_index); } -void GraphNode::clear_slot(int p_idx) { - slot_info.erase(p_idx); +void GraphNode::clear_slot(int p_slot_index) { + slot_table.erase(p_slot_index); queue_redraw(); - connpos_dirty = true; + port_pos_dirty = true; } void GraphNode::clear_all_slots() { - slot_info.clear(); + slot_table.clear(); queue_redraw(); - connpos_dirty = true; + port_pos_dirty = true; } -bool GraphNode::is_slot_enabled_left(int p_idx) const { - if (!slot_info.has(p_idx)) { +bool GraphNode::is_slot_enabled_left(int p_slot_index) const { + if (!slot_table.has(p_slot_index)) { return false; } - return slot_info[p_idx].enable_left; + return slot_table[p_slot_index].enable_left; } -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)); +void GraphNode::set_slot_enabled_left(int p_slot_index, bool p_enable) { + ERR_FAIL_COND_MSG(p_slot_index < 0, vformat("Cannot set enable_left for the slot with index (%d) lesser than zero.", p_slot_index)); - if (slot_info[p_idx].enable_left == p_enable_left) { + if (slot_table[p_slot_index].enable_left == p_enable) { return; } - slot_info[p_idx].enable_left = p_enable_left; + slot_table[p_slot_index].enable_left = p_enable; queue_redraw(); - connpos_dirty = true; + port_pos_dirty = true; - emit_signal(SNAME("slot_updated"), p_idx); + emit_signal(SNAME("slot_updated"), p_slot_index); } -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)); +void GraphNode::set_slot_type_left(int p_slot_index, int p_type) { + ERR_FAIL_COND_MSG(!slot_table.has(p_slot_index), vformat("Cannot set type_left for the slot with index '%d' because it hasn't been enabled.", p_slot_index)); - if (slot_info[p_idx].type_left == p_type_left) { + if (slot_table[p_slot_index].type_left == p_type) { return; } - slot_info[p_idx].type_left = p_type_left; + slot_table[p_slot_index].type_left = p_type; queue_redraw(); - connpos_dirty = true; + port_pos_dirty = true; - emit_signal(SNAME("slot_updated"), p_idx); + emit_signal(SNAME("slot_updated"), p_slot_index); } -int GraphNode::get_slot_type_left(int p_idx) const { - if (!slot_info.has(p_idx)) { +int GraphNode::get_slot_type_left(int p_slot_index) const { + if (!slot_table.has(p_slot_index)) { return 0; } - return slot_info[p_idx].type_left; + return slot_table[p_slot_index].type_left; } -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)); +void GraphNode::set_slot_color_left(int p_slot_index, const Color &p_color) { + ERR_FAIL_COND_MSG(!slot_table.has(p_slot_index), vformat("Cannot set color_left for the slot with index '%d' because it hasn't been enabled.", p_slot_index)); - if (slot_info[p_idx].color_left == p_color_left) { + if (slot_table[p_slot_index].color_left == p_color) { return; } - slot_info[p_idx].color_left = p_color_left; + slot_table[p_slot_index].color_left = p_color; queue_redraw(); - connpos_dirty = true; + port_pos_dirty = true; - emit_signal(SNAME("slot_updated"), p_idx); + emit_signal(SNAME("slot_updated"), p_slot_index); } -Color GraphNode::get_slot_color_left(int p_idx) const { - if (!slot_info.has(p_idx)) { +Color GraphNode::get_slot_color_left(int p_slot_index) const { + if (!slot_table.has(p_slot_index)) { return Color(1, 1, 1, 1); } - return slot_info[p_idx].color_left; + return slot_table[p_slot_index].color_left; } -bool GraphNode::is_slot_enabled_right(int p_idx) const { - if (!slot_info.has(p_idx)) { +bool GraphNode::is_slot_enabled_right(int p_slot_index) const { + if (!slot_table.has(p_slot_index)) { return false; } - return slot_info[p_idx].enable_right; + return slot_table[p_slot_index].enable_right; } -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)); +void GraphNode::set_slot_enabled_right(int p_slot_index, bool p_enable) { + ERR_FAIL_COND_MSG(p_slot_index < 0, vformat("Cannot set enable_right for the slot with index (%d) lesser than zero.", p_slot_index)); - if (slot_info[p_idx].enable_right == p_enable_right) { + if (slot_table[p_slot_index].enable_right == p_enable) { return; } - slot_info[p_idx].enable_right = p_enable_right; + slot_table[p_slot_index].enable_right = p_enable; queue_redraw(); - connpos_dirty = true; + port_pos_dirty = true; - emit_signal(SNAME("slot_updated"), p_idx); + emit_signal(SNAME("slot_updated"), p_slot_index); } -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)); +void GraphNode::set_slot_type_right(int p_slot_index, int p_type) { + ERR_FAIL_COND_MSG(!slot_table.has(p_slot_index), vformat("Cannot set type_right for the slot with index '%d' because it hasn't been enabled.", p_slot_index)); - if (slot_info[p_idx].type_right == p_type_right) { + if (slot_table[p_slot_index].type_right == p_type) { return; } - slot_info[p_idx].type_right = p_type_right; + slot_table[p_slot_index].type_right = p_type; queue_redraw(); - connpos_dirty = true; + port_pos_dirty = true; - emit_signal(SNAME("slot_updated"), p_idx); + emit_signal(SNAME("slot_updated"), p_slot_index); } -int GraphNode::get_slot_type_right(int p_idx) const { - if (!slot_info.has(p_idx)) { +int GraphNode::get_slot_type_right(int p_slot_index) const { + if (!slot_table.has(p_slot_index)) { return 0; } - return slot_info[p_idx].type_right; + return slot_table[p_slot_index].type_right; } -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)); +void GraphNode::set_slot_color_right(int p_slot_index, const Color &p_color) { + ERR_FAIL_COND_MSG(!slot_table.has(p_slot_index), vformat("Cannot set color_right for the slot with index '%d' because it hasn't been enabled.", p_slot_index)); - if (slot_info[p_idx].color_right == p_color_right) { + if (slot_table[p_slot_index].color_right == p_color) { return; } - slot_info[p_idx].color_right = p_color_right; + slot_table[p_slot_index].color_right = p_color; queue_redraw(); - connpos_dirty = true; + port_pos_dirty = true; - emit_signal(SNAME("slot_updated"), p_idx); + emit_signal(SNAME("slot_updated"), p_slot_index); } -Color GraphNode::get_slot_color_right(int p_idx) const { - if (!slot_info.has(p_idx)) { +Color GraphNode::get_slot_color_right(int p_slot_index) const { + if (!slot_table.has(p_slot_index)) { return Color(1, 1, 1, 1); } - return slot_info[p_idx].color_right; + return slot_table[p_slot_index].color_right; } -bool GraphNode::is_slot_draw_stylebox(int p_idx) const { - if (!slot_info.has(p_idx)) { +bool GraphNode::is_slot_draw_stylebox(int p_slot_index) const { + if (!slot_table.has(p_slot_index)) { return false; } - return slot_info[p_idx].draw_stylebox; + return slot_table[p_slot_index].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)); +void GraphNode::set_slot_draw_stylebox(int p_slot_index, bool p_enable) { + ERR_FAIL_COND_MSG(p_slot_index < 0, vformat("Cannot set draw_stylebox for the slot with p_index (%d) lesser than zero.", p_slot_index)); - slot_info[p_idx].draw_stylebox = p_enable; + slot_table[p_slot_index].draw_stylebox = p_enable; queue_redraw(); - connpos_dirty = true; + port_pos_dirty = true; - emit_signal(SNAME("slot_updated"), p_idx); + emit_signal(SNAME("slot_updated"), p_slot_index); } Size2 GraphNode::get_minimum_size() const { - Ref<StyleBox> sb = get_theme_stylebox(SNAME("frame")); + Ref<StyleBox> sb_panel = get_theme_stylebox(SNAME("panel")); + Ref<StyleBox> sb_titlebar = get_theme_stylebox(SNAME("titlebar")); 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")); - - bool first = true; + int separation = get_theme_constant(SNAME("separation")); + Size2 minsize = titlebar_hbox->get_minimum_size() + sb_titlebar->get_minimum_size(); - Size2 minsize; - minsize.x = title_buf->get_size().x + title_h_offset; - if (show_close) { - int close_h_offset = get_theme_constant(SNAME("close_h_offset")); - Ref<Texture2D> close = get_theme_icon(SNAME("close")); - //TODO: Remove this magic number after GraphNode rework. - minsize.x += 12 + close->get_width() + close_h_offset; - } - - for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to<Control>(get_child(i)); - if (!c || !c->is_visible()) { - continue; - } - if (c->is_set_as_top_level()) { + for (int i = 0; i < get_child_count(false); i++) { + Control *child = Object::cast_to<Control>(get_child(i, false)); + if (!child || !child->is_visible() || child->is_set_as_top_level()) { continue; } - Size2i size = c->get_combined_minimum_size(); - if (slot_info.has(i)) { - size += slot_info[i].draw_stylebox ? sb_slot->get_minimum_size() : Size2(); + Size2i size = child->get_combined_minimum_size(); + size.width += sb_panel->get_minimum_size().width; + if (slot_table.has(i)) { + size += slot_table[i].draw_stylebox ? sb_slot->get_minimum_size() : Size2(); } - minsize.y += size.y; - minsize.x = MAX(minsize.x, size.x); + minsize.height += size.height; + minsize.width = MAX(minsize.width, size.width); - if (first) { - first = false; - } else { - minsize.y += sep; + if (i > 0) { + minsize.height += separation; } } - return minsize + sb->get_minimum_size(); -} - -void GraphNode::set_title(const String &p_title) { - if (title == p_title) { - return; - } - title = p_title; - _shape(); - - queue_redraw(); - update_minimum_size(); -} - -String GraphNode::get_title() const { - return title; -} - -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(); - queue_redraw(); - } -} + minsize.height += sb_panel->get_minimum_size().height; -Control::TextDirection GraphNode::get_text_direction() const { - return text_direction; + return minsize; } -void GraphNode::set_language(const String &p_language) { - if (language != p_language) { - language = p_language; - _shape(); - queue_redraw(); - } -} +void GraphNode::_port_pos_update() { + int edgeofs = get_theme_constant(SNAME("port_h_offset")); + int separation = get_theme_constant(SNAME("separation")); -String GraphNode::get_language() const { - return language; -} + Ref<StyleBox> sb_panel = get_theme_stylebox(SNAME("panel")); + Ref<StyleBox> sb_titlebar = get_theme_stylebox(SNAME("titlebar")); -void GraphNode::set_position_offset(const Vector2 &p_offset) { - if (position_offset == p_offset) { - return; - } - - position_offset = p_offset; - emit_signal(SNAME("position_offset_changed")); - queue_redraw(); -} - -Vector2 GraphNode::get_position_offset() const { - return position_offset; -} - -void GraphNode::set_selected(bool p_selected) { - if (!is_selectable() || selected == p_selected) { - return; - } - - selected = p_selected; - emit_signal(p_selected ? SNAME("node_selected") : SNAME("node_deselected")); - queue_redraw(); -} - -bool GraphNode::is_selected() { - return selected; -} - -void GraphNode::set_drag(bool p_drag) { - if (p_drag) { - drag_from = get_position_offset(); - } else { - emit_signal(SNAME("dragged"), drag_from, get_position_offset()); //useful for undo/redo - } -} - -Vector2 GraphNode::get_drag_from() { - return drag_from; -} - -void GraphNode::set_show_close_button(bool p_enable) { - if (show_close == p_enable) { - return; - } - - show_close = p_enable; - queue_redraw(); -} - -bool GraphNode::is_close_button_visible() const { - return show_close; -} - -void GraphNode::_connpos_update() { - int edgeofs = get_theme_constant(SNAME("port_offset")); - int sep = get_theme_constant(SNAME("separation")); - - Ref<StyleBox> sb = get_theme_stylebox(SNAME("frame")); left_port_cache.clear(); right_port_cache.clear(); - int vofs = 0; - - int idx = 0; + int vertical_ofs = titlebar_hbox->get_size().height + sb_titlebar->get_minimum_size().height + sb_panel->get_margin(SIDE_TOP); - for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to<Control>(get_child(i)); - if (!c) { + for (int i = 0; i < get_child_count(false); i++) { + Control *child = Object::cast_to<Control>(get_child(i, false)); + if (!child || child->is_set_as_top_level()) { continue; } - if (c->is_set_as_top_level()) { - continue; - } - - Size2i size = c->get_rect().size; - int y = sb->get_margin(SIDE_TOP) + vofs; - int h = size.height; + Size2i size = child->get_rect().size; - if (slot_info.has(idx)) { - if (slot_info[idx].enable_left) { - PortCache cc; - cc.position = Point2i(edgeofs, y + h / 2); - cc.height = h; - - cc.slot_idx = idx; - cc.type = slot_info[idx].type_left; - cc.color = slot_info[idx].color_left; - - left_port_cache.push_back(cc); + if (slot_table.has(i)) { + if (slot_table[i].enable_left) { + PortCache port_cache; + port_cache.pos = Point2i(edgeofs, vertical_ofs + size.height / 2); + port_cache.type = slot_table[i].type_left; + port_cache.color = slot_table[i].color_left; + port_cache.slot_index = child->get_index(); // Index with internal nodes included. + left_port_cache.push_back(port_cache); } - if (slot_info[idx].enable_right) { - PortCache cc; - cc.position = Point2i(get_size().width - edgeofs, y + h / 2); - cc.height = h; - - cc.slot_idx = idx; - cc.type = slot_info[idx].type_right; - cc.color = slot_info[idx].color_right; - - right_port_cache.push_back(cc); + if (slot_table[i].enable_right) { + PortCache port_cache; + port_cache.pos = Point2i(get_size().width - edgeofs, vertical_ofs + size.height / 2); + port_cache.type = slot_table[i].type_right; + port_cache.color = slot_table[i].color_right; + port_cache.slot_index = child->get_index(); // Index with internal nodes included. + right_port_cache.push_back(port_cache); } } - vofs += sep; - vofs += h; - idx++; + vertical_ofs += separation; + vertical_ofs += size.height; } - connpos_dirty = false; + port_pos_dirty = false; } -int GraphNode::get_connection_input_count() { - if (connpos_dirty) { - _connpos_update(); +int GraphNode::get_input_port_count() { + if (port_pos_dirty) { + _port_pos_update(); } return left_port_cache.size(); } -int GraphNode::get_connection_input_height(int p_port) { - if (connpos_dirty) { - _connpos_update(); +int GraphNode::get_output_port_count() { + if (port_pos_dirty) { + _port_pos_update(); } - ERR_FAIL_INDEX_V(p_port, left_port_cache.size(), 0); - return left_port_cache[p_port].height; + return right_port_cache.size(); } -Vector2 GraphNode::get_connection_input_position(int p_port) { - if (connpos_dirty) { - _connpos_update(); +Vector2 GraphNode::get_input_port_position(int p_port_idx) { + if (port_pos_dirty) { + _port_pos_update(); } - ERR_FAIL_INDEX_V(p_port, left_port_cache.size(), Vector2()); - Vector2 pos = left_port_cache[p_port].position; - pos.x *= get_scale().x; - pos.y *= get_scale().y; + ERR_FAIL_INDEX_V(p_port_idx, left_port_cache.size(), Vector2()); + Vector2 pos = left_port_cache[p_port_idx].pos; return pos; } -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) { - if (connpos_dirty) { - _connpos_update(); - } - - ERR_FAIL_INDEX_V(p_port, left_port_cache.size(), Color()); - return left_port_cache[p_port].color; -} - -int GraphNode::get_connection_input_slot(int p_port) { - if (connpos_dirty) { - _connpos_update(); +int GraphNode::get_input_port_type(int p_port_idx) { + if (port_pos_dirty) { + _port_pos_update(); } - ERR_FAIL_INDEX_V(p_port, left_port_cache.size(), -1); - return left_port_cache[p_port].slot_idx; + ERR_FAIL_INDEX_V(p_port_idx, left_port_cache.size(), 0); + return left_port_cache[p_port_idx].type; } -int GraphNode::get_connection_output_count() { - if (connpos_dirty) { - _connpos_update(); +Color GraphNode::get_input_port_color(int p_port_idx) { + if (port_pos_dirty) { + _port_pos_update(); } - return right_port_cache.size(); + ERR_FAIL_INDEX_V(p_port_idx, left_port_cache.size(), Color()); + return left_port_cache[p_port_idx].color; } -int GraphNode::get_connection_output_height(int p_port) { - if (connpos_dirty) { - _connpos_update(); +int GraphNode::get_input_port_slot(int p_port_idx) { + if (port_pos_dirty) { + _port_pos_update(); } - ERR_FAIL_INDEX_V(p_port, right_port_cache.size(), 0); - return right_port_cache[p_port].height; + ERR_FAIL_INDEX_V(p_port_idx, left_port_cache.size(), -1); + return left_port_cache[p_port_idx].slot_index; } -Vector2 GraphNode::get_connection_output_position(int p_port) { - if (connpos_dirty) { - _connpos_update(); +Vector2 GraphNode::get_output_port_position(int p_port_idx) { + if (port_pos_dirty) { + _port_pos_update(); } - ERR_FAIL_INDEX_V(p_port, right_port_cache.size(), Vector2()); - Vector2 pos = right_port_cache[p_port].position; - pos.x *= get_scale().x; - pos.y *= get_scale().y; + ERR_FAIL_INDEX_V(p_port_idx, right_port_cache.size(), Vector2()); + Vector2 pos = right_port_cache[p_port_idx].pos; return pos; } -int GraphNode::get_connection_output_type(int p_port) { - if (connpos_dirty) { - _connpos_update(); +int GraphNode::get_output_port_type(int p_port_idx) { + if (port_pos_dirty) { + _port_pos_update(); } - ERR_FAIL_INDEX_V(p_port, right_port_cache.size(), 0); - return right_port_cache[p_port].type; + ERR_FAIL_INDEX_V(p_port_idx, right_port_cache.size(), 0); + return right_port_cache[p_port_idx].type; } -Color GraphNode::get_connection_output_color(int p_port) { - if (connpos_dirty) { - _connpos_update(); +Color GraphNode::get_output_port_color(int p_port_idx) { + if (port_pos_dirty) { + _port_pos_update(); } - ERR_FAIL_INDEX_V(p_port, right_port_cache.size(), Color()); - return right_port_cache[p_port].color; + ERR_FAIL_INDEX_V(p_port_idx, right_port_cache.size(), Color()); + return right_port_cache[p_port_idx].color; } -int GraphNode::get_connection_output_slot(int p_port) { - if (connpos_dirty) { - _connpos_update(); +int GraphNode::get_output_port_slot(int p_port_idx) { + if (port_pos_dirty) { + _port_pos_update(); } - ERR_FAIL_INDEX_V(p_port, right_port_cache.size(), -1); - return right_port_cache[p_port].slot_idx; + ERR_FAIL_INDEX_V(p_port_idx, right_port_cache.size(), -1); + return right_port_cache[p_port_idx].slot_index; } -void GraphNode::gui_input(const Ref<InputEvent> &p_ev) { - ERR_FAIL_COND(p_ev.is_null()); - - Ref<InputEventMouseButton> mb = p_ev; - if (mb.is_valid()) { - ERR_FAIL_COND_MSG(get_parent_control() == nullptr, "GraphNode must be the child of a GraphEdit node."); - - if (mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT) { - Vector2 mpos = mb->get_position(); - if (close_rect.size != Size2() && close_rect.has_point(mpos)) { - //send focus to parent - get_parent_control()->grab_focus(); - emit_signal(SNAME("close_request")); - accept_event(); - return; - } - - Ref<Texture2D> resizer = get_theme_icon(SNAME("resizer")); - - if (resizable && mpos.x > get_size().x - resizer->get_width() && mpos.y > get_size().y - resizer->get_height()) { - resizing = true; - resizing_from = mpos; - resizing_from_size = get_size(); - accept_event(); - return; - } - - emit_signal(SNAME("raise_request")); - } - - if (!mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT) { - resizing = false; - } - } - - Ref<InputEventMouseMotion> mm = p_ev; - if (resizing && mm.is_valid()) { - Vector2 mpos = mm->get_position(); - Vector2 diff = mpos - resizing_from; - - emit_signal(SNAME("resize_request"), resizing_from_size + diff); - } -} - -void GraphNode::set_overlay(Overlay p_overlay) { - if (overlay == p_overlay) { +void GraphNode::set_title(const String &p_title) { + if (title == p_title) { return; } - - overlay = p_overlay; - queue_redraw(); -} - -GraphNode::Overlay GraphNode::get_overlay() const { - return overlay; -} - -void GraphNode::set_resizable(bool p_enable) { - if (resizable == p_enable) { - return; + title = p_title; + if (title_label) { + title_label->set_text(title); } - - resizable = p_enable; - queue_redraw(); -} - -bool GraphNode::is_resizable() const { - return resizable; -} - -void GraphNode::set_draggable(bool p_draggable) { - draggable = p_draggable; -} - -bool GraphNode::is_draggable() { - return draggable; + update_minimum_size(); } -void GraphNode::set_selectable(bool p_selectable) { - if (!p_selectable) { - set_selected(false); - } - selectable = p_selectable; +String GraphNode::get_title() const { + return title; } -bool GraphNode::is_selectable() { - return selectable; +HBoxContainer *GraphNode::get_titlebar_hbox() { + return titlebar_hbox; } Control::CursorShape GraphNode::get_cursor_shape(const Point2 &p_pos) const { @@ -1044,17 +786,15 @@ Vector<int> GraphNode::get_allowed_size_flags_vertical() const { void GraphNode::_bind_methods() { ClassDB::bind_method(D_METHOD("set_title", "title"), &GraphNode::set_title); ClassDB::bind_method(D_METHOD("get_title"), &GraphNode::get_title); - 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); + + ClassDB::bind_method(D_METHOD("get_titlebar_hbox"), &GraphNode::get_titlebar_hbox); 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); ClassDB::bind_method(D_METHOD("clear_all_slots"), &GraphNode::clear_all_slots); - 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); + ClassDB::bind_method(D_METHOD("set_slot_enabled_left", "slot_index", "enable"), &GraphNode::set_slot_enabled_left); 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); @@ -1062,8 +802,8 @@ void GraphNode::_bind_methods() { 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); - 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); + ClassDB::bind_method(D_METHOD("set_slot_enabled_right", "slot_index", "enable"), &GraphNode::set_slot_enabled_right); 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); @@ -1074,70 +814,33 @@ void GraphNode::_bind_methods() { 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); - 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); - - ClassDB::bind_method(D_METHOD("set_resizable", "resizable"), &GraphNode::set_resizable); - ClassDB::bind_method(D_METHOD("is_resizable"), &GraphNode::is_resizable); - - 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("get_input_port_count"), &GraphNode::get_input_port_count); + ClassDB::bind_method(D_METHOD("get_input_port_position", "port_idx"), &GraphNode::get_input_port_position); + ClassDB::bind_method(D_METHOD("get_input_port_type", "port_idx"), &GraphNode::get_input_port_type); + ClassDB::bind_method(D_METHOD("get_input_port_color", "port_idx"), &GraphNode::get_input_port_color); + ClassDB::bind_method(D_METHOD("get_input_port_slot", "port_idx"), &GraphNode::get_input_port_slot); - ClassDB::bind_method(D_METHOD("set_selectable", "selectable"), &GraphNode::set_selectable); - ClassDB::bind_method(D_METHOD("is_selectable"), &GraphNode::is_selectable); + ClassDB::bind_method(D_METHOD("get_output_port_count"), &GraphNode::get_output_port_count); + ClassDB::bind_method(D_METHOD("get_output_port_position", "port_idx"), &GraphNode::get_output_port_position); + ClassDB::bind_method(D_METHOD("get_output_port_type", "port_idx"), &GraphNode::get_output_port_type); + ClassDB::bind_method(D_METHOD("get_output_port_color", "port_idx"), &GraphNode::get_output_port_color); + ClassDB::bind_method(D_METHOD("get_output_port_slot", "port_idx"), &GraphNode::get_output_port_slot); - 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); - 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); - - ClassDB::bind_method(D_METHOD("get_connection_output_count"), &GraphNode::get_connection_output_count); - 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); - - 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); + GDVIRTUAL_BIND(_draw_port, "slot_index", "position", "left", "color") ADD_PROPERTY(PropertyInfo(Variant::STRING, "title"), "set_title", "get_title"); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position_offset", PROPERTY_HINT_NONE, "suffix:px"), "set_position_offset", "get_position_offset"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_close"), "set_show_close_button", "is_close_button_visible"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "resizable"), "set_resizable", "is_resizable"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draggable"), "set_draggable", "is_draggable"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "selectable"), "set_selectable", "is_selectable"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "selected"), "set_selected", "is_selected"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "overlay", PROPERTY_HINT_ENUM, "Disabled,Breakpoint,Position"), "set_overlay", "get_overlay"); - - 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"); - ADD_GROUP("", ""); - - ADD_SIGNAL(MethodInfo("position_offset_changed")); - ADD_SIGNAL(MethodInfo("node_selected")); - ADD_SIGNAL(MethodInfo("node_deselected")); - ADD_SIGNAL(MethodInfo("slot_updated", PropertyInfo(Variant::INT, "idx"))); - ADD_SIGNAL(MethodInfo("dragged", PropertyInfo(Variant::VECTOR2, "from"), PropertyInfo(Variant::VECTOR2, "to"))); - ADD_SIGNAL(MethodInfo("raise_request")); - ADD_SIGNAL(MethodInfo("close_request")); - ADD_SIGNAL(MethodInfo("resize_request", PropertyInfo(Variant::VECTOR2, "new_minsize"))); - - BIND_ENUM_CONSTANT(OVERLAY_DISABLED); - BIND_ENUM_CONSTANT(OVERLAY_BREAKPOINT); - BIND_ENUM_CONSTANT(OVERLAY_POSITION); + ADD_SIGNAL(MethodInfo("slot_updated", PropertyInfo(Variant::INT, "slot_index"))); } GraphNode::GraphNode() { - title_buf.instantiate(); + titlebar_hbox = memnew(HBoxContainer); + titlebar_hbox->set_h_size_flags(SIZE_EXPAND_FILL); + add_child(titlebar_hbox, false, INTERNAL_MODE_FRONT); + + title_label = memnew(Label); + title_label->set_theme_type_variation("GraphNodeTitleLabel"); + title_label->set_h_size_flags(SIZE_EXPAND_FILL); + titlebar_hbox->add_child(title_label); + set_mouse_filter(MOUSE_FILTER_STOP); } |