diff options
Diffstat (limited to 'scene/gui/graph_node.cpp')
-rw-r--r-- | scene/gui/graph_node.cpp | 197 |
1 files changed, 93 insertions, 104 deletions
diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp index c28a60ff87..b6a96238dc 100644 --- a/scene/gui/graph_node.cpp +++ b/scene/gui/graph_node.cpp @@ -33,31 +33,33 @@ #include "core/method_bind_ext.gen.inc" bool GraphNode::_set(const StringName &p_name, const Variant &p_value) { - - if (!p_name.operator String().begins_with("slot/")) + if (!p_name.operator String().begins_with("slot/")) { return false; + } int idx = p_name.operator String().get_slice("/", 1).to_int(); String what = p_name.operator String().get_slice("/", 2); Slot si; - if (slot_info.has(idx)) + if (slot_info.has(idx)) { si = slot_info[idx]; + } - if (what == "left_enabled") + if (what == "left_enabled") { si.enable_left = p_value; - else if (what == "left_type") + } else if (what == "left_type") { si.type_left = p_value; - else if (what == "left_color") + } else if (what == "left_color") { si.color_left = p_value; - else if (what == "right_enabled") + } else if (what == "right_enabled") { si.enable_right = p_value; - else if (what == "right_type") + } else if (what == "right_type") { si.type_right = p_value; - else if (what == "right_color") + } else if (what == "right_color") { si.color_right = p_value; - else + } else { return false; + } set_slot(idx, si.enable_left, si.type_left, si.color_left, si.enable_right, si.type_right, si.color_right); update(); @@ -65,7 +67,6 @@ bool GraphNode::_set(const StringName &p_name, const Variant &p_value) { } bool GraphNode::_get(const StringName &p_name, Variant &r_ret) const { - if (!p_name.operator String().begins_with("slot/")) { return false; } @@ -74,33 +75,36 @@ bool GraphNode::_get(const StringName &p_name, Variant &r_ret) const { String what = p_name.operator String().get_slice("/", 2); Slot si; - if (slot_info.has(idx)) + if (slot_info.has(idx)) { si = slot_info[idx]; + } - if (what == "left_enabled") + if (what == "left_enabled") { r_ret = si.enable_left; - else if (what == "left_type") + } else if (what == "left_type") { r_ret = si.type_left; - else if (what == "left_color") + } else if (what == "left_color") { r_ret = si.color_left; - else if (what == "right_enabled") + } else if (what == "right_enabled") { r_ret = si.enable_right; - else if (what == "right_type") + } else if (what == "right_type") { r_ret = si.type_right; - else if (what == "right_color") + } else if (what == "right_color") { r_ret = si.color_right; - else + } else { return false; + } return true; } -void GraphNode::_get_property_list(List<PropertyInfo> *p_list) 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_toplevel()) + if (!c || c->is_set_as_toplevel()) { continue; + } String base = "slot/" + itos(idx) + "/"; @@ -116,7 +120,6 @@ void GraphNode::_get_property_list(List<PropertyInfo> *p_list) const { } void GraphNode::_resort() { - int sep = get_theme_constant("separation"); Ref<StyleBox> sb = get_theme_stylebox("frame"); bool first = true; @@ -125,20 +128,23 @@ void GraphNode::_resort() { for (int i = 0; i < get_child_count(); i++) { Control *c = Object::cast_to<Control>(get_child(i)); - if (!c) + if (!c) { continue; - if (c->is_set_as_toplevel()) + } + if (c->is_set_as_toplevel()) { continue; + } Size2i size = c->get_combined_minimum_size(); minsize.y += size.y; minsize.x = MAX(minsize.x, size.x); - if (first) + if (first) { first = false; - else + } else { minsize.y += sep; + } } int vofs = 0; @@ -147,10 +153,12 @@ void GraphNode::_resort() { cache_y.clear(); for (int i = 0; i < get_child_count(); i++) { Control *c = Object::cast_to<Control>(get_child(i)); - if (!c) + if (!c) { continue; - if (c->is_set_as_toplevel()) + } + if (c->is_set_as_toplevel()) { continue; + } Size2i size = c->get_combined_minimum_size(); @@ -167,7 +175,6 @@ void GraphNode::_resort() { } bool GraphNode::has_point(const Point2 &p_point) const { - if (comment) { Ref<StyleBox> comment = get_theme_stylebox("comment"); Ref<Texture2D> resizer = get_theme_icon("resizer"); @@ -188,17 +195,14 @@ bool GraphNode::has_point(const Point2 &p_point) const { } void GraphNode::_notification(int p_what) { - switch (p_what) { case NOTIFICATION_DRAW: { - Ref<StyleBox> sb; if (comment) { sb = get_theme_stylebox(selected ? "commentfocus" : "comment"); } else { - sb = get_theme_stylebox(selected ? "selectedframe" : "frame"); } @@ -223,10 +227,8 @@ void GraphNode::_notification(int p_what) { switch (overlay) { case OVERLAY_DISABLED: { - } break; case OVERLAY_BREAKPOINT: { - draw_style_box(get_theme_stylebox("breakpoint"), Rect2(Point2(), get_size())); } break; case OVERLAY_POSITION: { @@ -237,8 +239,9 @@ void GraphNode::_notification(int p_what) { int w = get_size().width - sb->get_minimum_size().x; - if (show_close) + if (show_close) { w -= close->get_width(); + } draw_string(title_font, Point2(sb->get_margin(MARGIN_LEFT) + title_h_offset, -title_font->get_height() + title_font->get_ascent() + title_offset), title, title_color, w); if (show_close) { @@ -251,11 +254,12 @@ void GraphNode::_notification(int p_what) { } for (Map<int, Slot>::Element *E = slot_info.front(); E; E = E->next()) { - - if (E->key() < 0 || E->key() >= cache_y.size()) + if (E->key() < 0 || E->key() >= cache_y.size()) { continue; - if (!slot_info.has(E->key())) + } + if (!slot_info.has(E->key())) { continue; + } const Slot &s = slot_info[E->key()]; //left if (s.enable_left) { @@ -280,19 +284,16 @@ void GraphNode::_notification(int p_what) { } break; case NOTIFICATION_SORT_CHILDREN: { - _resort(); } break; case NOTIFICATION_THEME_CHANGED: { - minimum_size_changed(); } break; } } 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) { - ERR_FAIL_COND(p_idx < 0); 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)) { @@ -315,61 +316,60 @@ void GraphNode::set_slot(int p_idx, bool p_enable_left, int p_type_left, const C } void GraphNode::clear_slot(int p_idx) { - slot_info.erase(p_idx); update(); connpos_dirty = true; } -void GraphNode::clear_all_slots() { +void GraphNode::clear_all_slots() { slot_info.clear(); update(); connpos_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_idx) const { + if (!slot_info.has(p_idx)) { return false; + } return slot_info[p_idx].enable_left; } int GraphNode::get_slot_type_left(int p_idx) const { - - if (!slot_info.has(p_idx)) + if (!slot_info.has(p_idx)) { return 0; + } return slot_info[p_idx].type_left; } Color GraphNode::get_slot_color_left(int p_idx) const { - - if (!slot_info.has(p_idx)) + if (!slot_info.has(p_idx)) { return Color(1, 1, 1, 1); + } return slot_info[p_idx].color_left; } bool GraphNode::is_slot_enabled_right(int p_idx) const { - - if (!slot_info.has(p_idx)) + if (!slot_info.has(p_idx)) { return false; + } return slot_info[p_idx].enable_right; } int GraphNode::get_slot_type_right(int p_idx) const { - - if (!slot_info.has(p_idx)) + if (!slot_info.has(p_idx)) { return 0; + } return slot_info[p_idx].type_right; } Color GraphNode::get_slot_color_right(int p_idx) const { - - if (!slot_info.has(p_idx)) + if (!slot_info.has(p_idx)) { return Color(1, 1, 1, 1); + } return slot_info[p_idx].color_right; } Size2 GraphNode::get_minimum_size() const { - Ref<Font> title_font = get_theme_font("title_font"); int sep = get_theme_constant("separation"); @@ -384,31 +384,33 @@ Size2 GraphNode::get_minimum_size() const { } for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to<Control>(get_child(i)); - if (!c) + if (!c) { continue; - if (c->is_set_as_toplevel()) + } + if (c->is_set_as_toplevel()) { continue; + } Size2i size = c->get_combined_minimum_size(); minsize.y += size.y; minsize.x = MAX(minsize.x, size.x); - if (first) + if (first) { first = false; - else + } else { minsize.y += sep; + } } return minsize + sb->get_minimum_size(); } void GraphNode::set_title(const String &p_title) { - - if (title == p_title) + if (title == p_title) { return; + } title = p_title; update(); _change_notify("title"); @@ -416,19 +418,16 @@ void GraphNode::set_title(const String &p_title) { } String GraphNode::get_title() const { - return title; } void GraphNode::set_offset(const Vector2 &p_offset) { - offset = p_offset; emit_signal("offset_changed"); update(); } Vector2 GraphNode::get_offset() const { - return offset; } @@ -442,10 +441,11 @@ bool GraphNode::is_selected() { } void GraphNode::set_drag(bool p_drag) { - if (p_drag) + if (p_drag) { drag_from = get_offset(); - else + } else { emit_signal("dragged", drag_from, get_offset()); //useful for undo/redo + } } Vector2 GraphNode::get_drag_from() { @@ -453,17 +453,15 @@ Vector2 GraphNode::get_drag_from() { } void GraphNode::set_show_close_button(bool p_enable) { - show_close = p_enable; update(); } -bool GraphNode::is_close_button_visible() const { +bool GraphNode::is_close_button_visible() const { return show_close; } void GraphNode::_connpos_update() { - int edgeofs = get_theme_constant("port_offset"); int sep = get_theme_constant("separation"); @@ -476,10 +474,12 @@ void GraphNode::_connpos_update() { for (int i = 0; i < get_child_count(); i++) { Control *c = Object::cast_to<Control>(get_child(i)); - if (!c) + if (!c) { continue; - if (c->is_set_as_toplevel()) + } + if (c->is_set_as_toplevel()) { continue; + } Size2i size = c->get_combined_minimum_size(); @@ -487,7 +487,6 @@ void GraphNode::_connpos_update() { int h = size.y; if (slot_info.has(idx)) { - if (slot_info[idx].enable_left) { ConnCache cc; cc.pos = Point2i(edgeofs, y + h / 2); @@ -504,8 +503,9 @@ void GraphNode::_connpos_update() { } } - if (vofs > 0) + if (vofs > 0) { vofs += sep; + } vofs += size.y; idx++; } @@ -514,24 +514,25 @@ void GraphNode::_connpos_update() { } int GraphNode::get_connection_input_count() { - - if (connpos_dirty) + if (connpos_dirty) { _connpos_update(); + } return conn_input_cache.size(); } -int GraphNode::get_connection_output_count() { - if (connpos_dirty) +int GraphNode::get_connection_output_count() { + if (connpos_dirty) { _connpos_update(); + } return conn_output_cache.size(); } Vector2 GraphNode::get_connection_input_position(int p_idx) { - - if (connpos_dirty) + if (connpos_dirty) { _connpos_update(); + } ERR_FAIL_INDEX_V(p_idx, conn_input_cache.size(), Vector2()); Vector2 pos = conn_input_cache[p_idx].pos; @@ -541,27 +542,27 @@ Vector2 GraphNode::get_connection_input_position(int p_idx) { } int GraphNode::get_connection_input_type(int p_idx) { - - if (connpos_dirty) + if (connpos_dirty) { _connpos_update(); + } ERR_FAIL_INDEX_V(p_idx, conn_input_cache.size(), 0); return conn_input_cache[p_idx].type; } Color GraphNode::get_connection_input_color(int p_idx) { - - if (connpos_dirty) + if (connpos_dirty) { _connpos_update(); + } ERR_FAIL_INDEX_V(p_idx, conn_input_cache.size(), Color()); return conn_input_cache[p_idx].color; } Vector2 GraphNode::get_connection_output_position(int p_idx) { - - if (connpos_dirty) + if (connpos_dirty) { _connpos_update(); + } ERR_FAIL_INDEX_V(p_idx, conn_output_cache.size(), Vector2()); Vector2 pos = conn_output_cache[p_idx].pos; @@ -571,32 +572,29 @@ Vector2 GraphNode::get_connection_output_position(int p_idx) { } int GraphNode::get_connection_output_type(int p_idx) { - - if (connpos_dirty) + if (connpos_dirty) { _connpos_update(); + } ERR_FAIL_INDEX_V(p_idx, conn_output_cache.size(), 0); return conn_output_cache[p_idx].type; } Color GraphNode::get_connection_output_color(int p_idx) { - - if (connpos_dirty) + if (connpos_dirty) { _connpos_update(); + } ERR_FAIL_INDEX_V(p_idx, conn_output_cache.size(), Color()); return conn_output_cache[p_idx].color; } void GraphNode::_gui_input(const Ref<InputEvent> &p_ev) { - Ref<InputEventMouseButton> mb = p_ev; if (mb.is_valid()) { - - ERR_FAIL_COND_MSG(get_parent_control() == NULL, "GraphNode must be the child of a GraphEdit node."); + 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() == BUTTON_LEFT) { - Vector2 mpos = Vector2(mb->get_position().x, mb->get_position().y); if (close_rect.size != Size2() && close_rect.has_point(mpos)) { //send focus to parent @@ -609,7 +607,6 @@ void GraphNode::_gui_input(const Ref<InputEvent> &p_ev) { Ref<Texture2D> resizer = get_theme_icon("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(); @@ -636,40 +633,33 @@ void GraphNode::_gui_input(const Ref<InputEvent> &p_ev) { } void GraphNode::set_overlay(Overlay p_overlay) { - overlay = p_overlay; update(); } GraphNode::Overlay GraphNode::get_overlay() const { - return overlay; } void GraphNode::set_comment(bool p_enable) { - comment = p_enable; update(); } bool GraphNode::is_comment() const { - return comment; } void GraphNode::set_resizable(bool p_enable) { - resizable = p_enable; update(); } bool GraphNode::is_resizable() const { - return resizable; } 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("_gui_input"), &GraphNode::_gui_input); @@ -732,7 +722,6 @@ void GraphNode::_bind_methods() { } GraphNode::GraphNode() { - overlay = OVERLAY_DISABLED; show_close = false; connpos_dirty = true; |