summaryrefslogtreecommitdiffstats
path: root/scene/gui/graph_edit.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui/graph_edit.cpp')
-rw-r--r--scene/gui/graph_edit.cpp692
1 files changed, 405 insertions, 287 deletions
diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp
index cb9fba44e5..69023d2056 100644
--- a/scene/gui/graph_edit.cpp
+++ b/scene/gui/graph_edit.cpp
@@ -29,6 +29,7 @@
/**************************************************************************/
#include "graph_edit.h"
+#include "graph_edit.compat.inc"
#include "core/input/input.h"
#include "core/math/math_funcs.h"
@@ -36,8 +37,13 @@
#include "scene/gui/box_container.h"
#include "scene/gui/button.h"
#include "scene/gui/graph_edit_arranger.h"
+#include "scene/gui/label.h"
+#include "scene/gui/panel_container.h"
+#include "scene/gui/scroll_bar.h"
+#include "scene/gui/spin_box.h"
#include "scene/gui/view_panner.h"
#include "scene/resources/style_box_flat.h"
+#include "scene/theme/theme_db.h"
constexpr int MINIMAP_OFFSET = 12;
constexpr int MINIMAP_PADDING = 5;
@@ -56,23 +62,8 @@ GraphEditFilter::GraphEditFilter(GraphEdit *p_edit) {
ge = p_edit;
}
-GraphEditMinimap::GraphEditMinimap(GraphEdit *p_edit) {
- ge = p_edit;
-
- graph_proportions = Vector2(1, 1);
- graph_padding = Vector2(0, 0);
- camera_position = Vector2(100, 50);
- camera_size = Vector2(200, 200);
- minimap_padding = Vector2(MINIMAP_PADDING, MINIMAP_PADDING);
- minimap_offset = minimap_padding + _convert_from_graph_position(graph_padding);
-
- is_pressing = false;
- is_resizing = false;
-}
-
Control::CursorShape GraphEditMinimap::get_cursor_shape(const Point2 &p_pos) const {
- Ref<Texture2D> resizer = get_theme_icon(SNAME("resizer"));
- if (is_resizing || (p_pos.x < resizer->get_width() && p_pos.y < resizer->get_height())) {
+ if (is_resizing || (p_pos.x < theme_cache.resizer->get_width() && p_pos.y < theme_cache.resizer->get_height())) {
return CURSOR_FDIAGSIZE;
}
@@ -172,8 +163,7 @@ void GraphEditMinimap::gui_input(const Ref<InputEvent> &p_ev) {
if (mb->is_pressed()) {
is_pressing = true;
- Ref<Texture2D> resizer = get_theme_icon(SNAME("resizer"));
- Rect2 resizer_hitbox = Rect2(Point2(), resizer->get_size());
+ Rect2 resizer_hitbox = Rect2(Point2(), theme_cache.resizer->get_size());
if (resizer_hitbox.has_point(mb->get_position())) {
is_resizing = true;
} else {
@@ -207,6 +197,21 @@ void GraphEditMinimap::_adjust_graph_scroll(const Vector2 &p_offset) {
ge->set_scroll_offset(p_offset + graph_offset - camera_size / 2);
}
+void GraphEditMinimap::_bind_methods() {
+ BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, GraphEditMinimap, panel);
+ BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, GraphEditMinimap, node_style, "node");
+ BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, GraphEditMinimap, camera_style, "camera");
+ BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, GraphEditMinimap, resizer);
+ BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, GraphEditMinimap, resizer_color);
+}
+
+GraphEditMinimap::GraphEditMinimap(GraphEdit *p_edit) {
+ ge = p_edit;
+
+ minimap_padding = Vector2(MINIMAP_PADDING, MINIMAP_PADDING);
+ minimap_offset = minimap_padding + _convert_from_graph_position(graph_padding);
+}
+
Control::CursorShape GraphEdit::get_cursor_shape(const Point2 &p_pos) const {
if (moving_selection) {
return CURSOR_MOVE;
@@ -295,16 +300,16 @@ void GraphEdit::_update_scroll_offset() {
set_block_minimum_size_adjust(true);
for (int i = 0; i < get_child_count(); i++) {
- GraphNode *graph_node = Object::cast_to<GraphNode>(get_child(i));
- if (!graph_node) {
+ GraphElement *graph_element = Object::cast_to<GraphElement>(get_child(i));
+ if (!graph_element) {
continue;
}
- Point2 pos = graph_node->get_position_offset() * zoom;
+ Point2 pos = graph_element->get_position_offset() * zoom;
pos -= Point2(h_scrollbar->get_value(), v_scrollbar->get_value());
- graph_node->set_position(pos);
- if (graph_node->get_scale() != Vector2(zoom, zoom)) {
- graph_node->set_scale(Vector2(zoom, zoom));
+ graph_element->set_position(pos);
+ if (graph_element->get_scale() != Vector2(zoom, zoom)) {
+ graph_element->set_scale(Vector2(zoom, zoom));
}
}
@@ -328,14 +333,14 @@ void GraphEdit::_update_scroll() {
Rect2 screen_rect;
for (int i = 0; i < get_child_count(); i++) {
- GraphNode *graph_node = Object::cast_to<GraphNode>(get_child(i));
- if (!graph_node) {
+ GraphElement *graph_element = Object::cast_to<GraphElement>(get_child(i));
+ if (!graph_element) {
continue;
}
Rect2 node_rect;
- node_rect.position = graph_node->get_position_offset() * zoom;
- node_rect.size = graph_node->get_size() * zoom;
+ node_rect.position = graph_element->get_position_offset() * zoom;
+ node_rect.size = graph_element->get_size() * zoom;
screen_rect = screen_rect.merge(node_rect);
}
@@ -378,46 +383,48 @@ void GraphEdit::_update_scroll() {
updating = false;
}
-void GraphEdit::_graph_node_moved_to_front(Node *p_gn) {
- GraphNode *graph_node = Object::cast_to<GraphNode>(p_gn);
- ERR_FAIL_NULL(graph_node);
+void GraphEdit::_graph_element_moved_to_front(Node *p_node) {
+ GraphElement *graph_element = Object::cast_to<GraphElement>(p_node);
+ ERR_FAIL_NULL(graph_element);
- graph_node->move_to_front();
+ graph_element->move_to_front();
}
-void GraphEdit::_graph_node_selected(Node *p_gn) {
- GraphNode *graph_node = Object::cast_to<GraphNode>(p_gn);
- ERR_FAIL_NULL(graph_node);
+void GraphEdit::_graph_element_selected(Node *p_node) {
+ GraphElement *graph_element = Object::cast_to<GraphElement>(p_node);
+ ERR_FAIL_NULL(graph_element);
- emit_signal(SNAME("node_selected"), graph_node);
+ emit_signal(SNAME("node_selected"), graph_element);
}
-void GraphEdit::_graph_node_deselected(Node *p_gn) {
- GraphNode *graph_node = Object::cast_to<GraphNode>(p_gn);
- ERR_FAIL_NULL(graph_node);
+void GraphEdit::_graph_element_deselected(Node *p_node) {
+ GraphElement *graph_element = Object::cast_to<GraphElement>(p_node);
+ ERR_FAIL_NULL(graph_element);
- emit_signal(SNAME("node_deselected"), graph_node);
+ emit_signal(SNAME("node_deselected"), graph_element);
}
-void GraphEdit::_graph_node_resized(Vector2 p_new_minsize, Node *p_gn) {
- GraphNode *graph_node = Object::cast_to<GraphNode>(p_gn);
- ERR_FAIL_NULL(graph_node);
+void GraphEdit::_graph_element_resized(Vector2 p_new_minsize, Node *p_node) {
+ GraphElement *graph_element = Object::cast_to<GraphElement>(p_node);
+ ERR_FAIL_NULL(graph_element);
- graph_node->set_custom_minimum_size(p_new_minsize);
+ graph_element->set_size(p_new_minsize);
}
-void GraphEdit::_graph_node_moved(Node *p_gn) {
- GraphNode *graph_node = Object::cast_to<GraphNode>(p_gn);
- ERR_FAIL_NULL(graph_node);
+void GraphEdit::_graph_element_moved(Node *p_node) {
+ GraphElement *graph_element = Object::cast_to<GraphElement>(p_node);
+ ERR_FAIL_NULL(graph_element);
+
top_layer->queue_redraw();
minimap->queue_redraw();
queue_redraw();
connections_layer->queue_redraw();
}
-void GraphEdit::_graph_node_slot_updated(int p_index, Node *p_gn) {
- GraphNode *graph_node = Object::cast_to<GraphNode>(p_gn);
+void GraphEdit::_graph_node_slot_updated(int p_index, Node *p_node) {
+ GraphNode *graph_node = Object::cast_to<GraphNode>(p_node);
ERR_FAIL_NULL(graph_node);
+
top_layer->queue_redraw();
minimap->queue_redraw();
queue_redraw();
@@ -430,19 +437,25 @@ void GraphEdit::add_child_notify(Node *p_child) {
// Keep the top layer always on top!
callable_mp((CanvasItem *)top_layer, &CanvasItem::move_to_front).call_deferred();
- GraphNode *graph_node = Object::cast_to<GraphNode>(p_child);
- if (graph_node) {
- graph_node->set_scale(Vector2(zoom, zoom));
- graph_node->connect("position_offset_changed", callable_mp(this, &GraphEdit::_graph_node_moved).bind(graph_node));
- graph_node->connect("node_selected", callable_mp(this, &GraphEdit::_graph_node_selected).bind(graph_node));
- graph_node->connect("node_deselected", callable_mp(this, &GraphEdit::_graph_node_deselected).bind(graph_node));
- graph_node->connect("slot_updated", callable_mp(this, &GraphEdit::_graph_node_slot_updated).bind(graph_node));
- graph_node->connect("raise_request", callable_mp(this, &GraphEdit::_graph_node_moved_to_front).bind(graph_node));
- graph_node->connect("resize_request", callable_mp(this, &GraphEdit::_graph_node_resized).bind(graph_node));
- graph_node->connect("item_rect_changed", callable_mp((CanvasItem *)connections_layer, &CanvasItem::queue_redraw));
- graph_node->connect("item_rect_changed", callable_mp((CanvasItem *)minimap, &GraphEditMinimap::queue_redraw));
- _graph_node_moved(graph_node);
- graph_node->set_mouse_filter(MOUSE_FILTER_PASS);
+ GraphElement *graph_element = Object::cast_to<GraphElement>(p_child);
+ if (graph_element) {
+ graph_element->connect("position_offset_changed", callable_mp(this, &GraphEdit::_graph_element_moved).bind(graph_element));
+ graph_element->connect("node_selected", callable_mp(this, &GraphEdit::_graph_element_selected).bind(graph_element));
+ graph_element->connect("node_deselected", callable_mp(this, &GraphEdit::_graph_element_deselected).bind(graph_element));
+
+ GraphNode *graph_node = Object::cast_to<GraphNode>(graph_element);
+ if (graph_node) {
+ graph_element->connect("slot_updated", callable_mp(this, &GraphEdit::_graph_node_slot_updated).bind(graph_element));
+ }
+
+ graph_element->connect("raise_request", callable_mp(this, &GraphEdit::_graph_element_moved_to_front).bind(graph_element));
+ graph_element->connect("resize_request", callable_mp(this, &GraphEdit::_graph_element_resized).bind(graph_element));
+ graph_element->connect("item_rect_changed", callable_mp((CanvasItem *)connections_layer, &CanvasItem::queue_redraw));
+ graph_element->connect("item_rect_changed", callable_mp((CanvasItem *)minimap, &GraphEditMinimap::queue_redraw));
+
+ graph_element->set_scale(Vector2(zoom, zoom));
+ _graph_element_moved(graph_element);
+ graph_element->set_mouse_filter(MOUSE_FILTER_PASS);
}
}
@@ -461,40 +474,51 @@ void GraphEdit::remove_child_notify(Node *p_child) {
callable_mp((CanvasItem *)top_layer, &CanvasItem::move_to_front).call_deferred();
}
- GraphNode *graph_node = Object::cast_to<GraphNode>(p_child);
- if (graph_node) {
- graph_node->disconnect("position_offset_changed", callable_mp(this, &GraphEdit::_graph_node_moved));
- graph_node->disconnect("node_selected", callable_mp(this, &GraphEdit::_graph_node_selected));
- graph_node->disconnect("node_deselected", callable_mp(this, &GraphEdit::_graph_node_deselected));
- graph_node->disconnect("slot_updated", callable_mp(this, &GraphEdit::_graph_node_slot_updated));
- graph_node->disconnect("raise_request", callable_mp(this, &GraphEdit::_graph_node_moved_to_front));
+ GraphElement *graph_element = Object::cast_to<GraphElement>(p_child);
+ if (graph_element) {
+ graph_element->disconnect("position_offset_changed", callable_mp(this, &GraphEdit::_graph_element_moved));
+ graph_element->disconnect("node_selected", callable_mp(this, &GraphEdit::_graph_element_selected));
+ graph_element->disconnect("node_deselected", callable_mp(this, &GraphEdit::_graph_element_deselected));
+
+ GraphNode *graph_node = Object::cast_to<GraphNode>(graph_element);
+ if (graph_node) {
+ graph_element->disconnect("slot_updated", callable_mp(this, &GraphEdit::_graph_node_slot_updated));
+ }
+
+ graph_element->disconnect("raise_request", callable_mp(this, &GraphEdit::_graph_element_moved_to_front));
+ graph_element->disconnect("resize_request", callable_mp(this, &GraphEdit::_graph_element_resized));
// In case of the whole GraphEdit being destroyed these references can already be freed.
if (connections_layer != nullptr && connections_layer->is_inside_tree()) {
- graph_node->disconnect("item_rect_changed", callable_mp((CanvasItem *)connections_layer, &CanvasItem::queue_redraw));
+ graph_element->disconnect("item_rect_changed", callable_mp((CanvasItem *)connections_layer, &CanvasItem::queue_redraw));
}
if (minimap != nullptr && minimap->is_inside_tree()) {
- graph_node->disconnect("item_rect_changed", callable_mp((CanvasItem *)minimap, &GraphEditMinimap::queue_redraw));
+ graph_element->disconnect("item_rect_changed", callable_mp((CanvasItem *)minimap, &GraphEditMinimap::queue_redraw));
}
}
}
+void GraphEdit::_update_theme_item_cache() {
+ Control::_update_theme_item_cache();
+
+ theme_cache.base_scale = get_theme_default_base_scale();
+}
+
void GraphEdit::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_THEME_CHANGED: {
- port_hotzone_inner_extent = get_theme_constant("port_hotzone_inner_extent");
- port_hotzone_outer_extent = get_theme_constant("port_hotzone_outer_extent");
+ zoom_minus_button->set_icon(theme_cache.zoom_out);
+ zoom_reset_button->set_icon(theme_cache.zoom_reset);
+ zoom_plus_button->set_icon(theme_cache.zoom_in);
- zoom_minus_button->set_icon(get_theme_icon(SNAME("zoom_out")));
- zoom_reset_button->set_icon(get_theme_icon(SNAME("zoom_reset")));
- zoom_plus_button->set_icon(get_theme_icon(SNAME("zoom_in")));
+ toggle_snapping_button->set_icon(theme_cache.snapping_toggle);
+ toggle_grid_button->set_icon(theme_cache.grid_toggle);
+ minimap_button->set_icon(theme_cache.minimap_toggle);
+ arrange_button->set_icon(theme_cache.layout);
- toggle_snapping_button->set_icon(get_theme_icon(SNAME("snapping_toggle")));
- show_grid_button->set_icon(get_theme_icon(SNAME("grid_toggle")));
- minimap_button->set_icon(get_theme_icon(SNAME("minimap_toggle")));
- layout_button->set_icon(get_theme_icon(SNAME("layout")));
+ zoom_label->set_custom_minimum_size(Size2(48, 0) * theme_cache.base_scale);
- zoom_label->set_custom_minimum_size(Size2(48, 0) * get_theme_default_base_scale());
+ menu_panel->add_theme_style_override("panel", theme_cache.menu_panel);
} break;
case NOTIFICATION_READY: {
@@ -514,7 +538,7 @@ void GraphEdit::_notification(int p_what) {
case NOTIFICATION_DRAW: {
// Draw background fill.
- draw_style_box(get_theme_stylebox(SNAME("panel")), Rect2(Point2(), get_size()));
+ draw_style_box(theme_cache.panel, Rect2(Point2(), get_size()));
// Draw background grid.
if (show_grid) {
@@ -524,16 +548,13 @@ void GraphEdit::_notification(int p_what) {
Point2i from_pos = (offset / float(snapping_distance)).floor();
Point2i len = (size / float(snapping_distance)).floor() + Vector2(1, 1);
- Color grid_minor = get_theme_color(SNAME("grid_minor"));
- Color grid_major = get_theme_color(SNAME("grid_major"));
-
for (int i = from_pos.x; i < from_pos.x + len.x; i++) {
Color color;
if (ABS(i) % GRID_MINOR_STEPS_PER_MAJOR_LINE == 0) {
- color = grid_major;
+ color = theme_cache.grid_major;
} else {
- color = grid_minor;
+ color = theme_cache.grid_minor;
}
float base_offset = i * snapping_distance * zoom - offset.x * zoom;
@@ -544,9 +565,9 @@ void GraphEdit::_notification(int p_what) {
Color color;
if (ABS(i) % GRID_MINOR_STEPS_PER_MAJOR_LINE == 0) {
- color = grid_major;
+ color = theme_cache.grid_major;
} else {
- color = grid_minor;
+ color = theme_cache.grid_minor;
}
float base_offset = i * snapping_distance * zoom - offset.y * zoom;
@@ -564,20 +585,20 @@ void GraphEdit::_notification(int p_what) {
}
bool GraphEdit::_filter_input(const Point2 &p_point) {
- Ref<Texture2D> port_icon = get_theme_icon(SNAME("port"), SNAME("GraphNode"));
-
for (int i = get_child_count() - 1; i >= 0; i--) {
GraphNode *graph_node = Object::cast_to<GraphNode>(get_child(i));
if (!graph_node || !graph_node->is_visible_in_tree()) {
continue;
}
- for (int j = 0; j < graph_node->get_connection_input_count(); j++) {
+ Ref<Texture2D> port_icon = graph_node->theme_cache.port;
+
+ for (int j = 0; j < graph_node->get_input_port_count(); j++) {
Vector2i port_size = Vector2i(port_icon->get_width(), port_icon->get_height());
// Determine slot height.
- int slot_index = graph_node->get_connection_input_slot(j);
- Control *child = Object::cast_to<Control>(graph_node->get_child(slot_index));
+ int slot_index = graph_node->get_input_port_slot(j);
+ Control *child = Object::cast_to<Control>(graph_node->get_child(slot_index, false));
port_size.height = MAX(port_size.height, child ? child->get_size().y : 0);
@@ -586,12 +607,12 @@ bool GraphEdit::_filter_input(const Point2 &p_point) {
}
}
- for (int j = 0; j < graph_node->get_connection_output_count(); j++) {
+ for (int j = 0; j < graph_node->get_output_port_count(); j++) {
Vector2i port_size = Vector2i(port_icon->get_width(), port_icon->get_height());
// Determine slot height.
- int slot_index = graph_node->get_connection_output_slot(j);
- Control *child = Object::cast_to<Control>(graph_node->get_child(slot_index));
+ int slot_index = graph_node->get_output_port_slot(j);
+ Control *child = Object::cast_to<Control>(graph_node->get_child(slot_index, false));
port_size.height = MAX(port_size.height, child ? child->get_size().y : 0);
if (is_in_output_hotzone(graph_node, j, p_point / zoom, port_size)) {
@@ -606,8 +627,6 @@ bool GraphEdit::_filter_input(const Point2 &p_point) {
void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
Ref<InputEventMouseButton> mb = p_ev;
if (mb.is_valid() && mb->get_button_index() == MouseButton::LEFT && mb->is_pressed()) {
- Ref<Texture2D> port_icon = get_theme_icon(SNAME("port"), SNAME("GraphNode"));
-
connecting_valid = false;
click_pos = mb->get_position() / zoom;
for (int i = get_child_count() - 1; i >= 0; i--) {
@@ -616,17 +635,19 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
continue;
}
- for (int j = 0; j < graph_node->get_connection_output_count(); j++) {
- Vector2 pos = graph_node->get_connection_output_position(j) * zoom + graph_node->get_position();
+ Ref<Texture2D> port_icon = graph_node->theme_cache.port;
+
+ for (int j = 0; j < graph_node->get_output_port_count(); j++) {
+ Vector2 pos = graph_node->get_output_port_position(j) * zoom + graph_node->get_position();
Vector2i port_size = Vector2i(port_icon->get_width(), port_icon->get_height());
// Determine slot height.
- int slot_index = graph_node->get_connection_output_slot(j);
- Control *child = Object::cast_to<Control>(graph_node->get_child(slot_index));
+ int slot_index = graph_node->get_output_port_slot(j);
+ Control *child = Object::cast_to<Control>(graph_node->get_child(slot_index, false));
port_size.height = MAX(port_size.height, child ? child->get_size().y : 0);
if (is_in_output_hotzone(graph_node, j, click_pos, port_size)) {
- if (valid_left_disconnect_types.has(graph_node->get_connection_output_type(j))) {
+ if (valid_left_disconnect_types.has(graph_node->get_output_port_type(j))) {
// Check disconnect.
for (const Connection &E : connections) {
if (E.from_node == graph_node->get_name() && E.from_port == j) {
@@ -635,8 +656,8 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
connecting_from = E.to_node;
connecting_index = E.to_port;
connecting_out = false;
- connecting_type = Object::cast_to<GraphNode>(to)->get_connection_input_type(E.to_port);
- connecting_color = Object::cast_to<GraphNode>(to)->get_connection_input_color(E.to_port);
+ connecting_type = Object::cast_to<GraphNode>(to)->get_input_port_type(E.to_port);
+ connecting_color = Object::cast_to<GraphNode>(to)->get_input_port_color(E.to_port);
connecting_target = false;
connecting_to = pos;
@@ -659,8 +680,8 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
connecting_from = graph_node->get_name();
connecting_index = j;
connecting_out = true;
- connecting_type = graph_node->get_connection_output_type(j);
- connecting_color = graph_node->get_connection_output_color(j);
+ connecting_type = graph_node->get_output_port_type(j);
+ connecting_color = graph_node->get_output_port_color(j);
connecting_target = false;
connecting_to = pos;
if (connecting_type >= 0) {
@@ -672,18 +693,18 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
}
}
- for (int j = 0; j < graph_node->get_connection_input_count(); j++) {
- Vector2 pos = graph_node->get_connection_input_position(j) + graph_node->get_position();
+ for (int j = 0; j < graph_node->get_input_port_count(); j++) {
+ Vector2 pos = graph_node->get_input_port_position(j) * zoom + graph_node->get_position();
Vector2i port_size = Vector2i(port_icon->get_width(), port_icon->get_height());
// Determine slot height.
- int slot_index = graph_node->get_connection_input_slot(j);
- Control *child = Object::cast_to<Control>(graph_node->get_child(slot_index));
+ int slot_index = graph_node->get_input_port_slot(j);
+ Control *child = Object::cast_to<Control>(graph_node->get_child(slot_index, false));
port_size.height = MAX(port_size.height, child ? child->get_size().y : 0);
if (is_in_input_hotzone(graph_node, j, click_pos, port_size)) {
- if (right_disconnects || valid_right_disconnect_types.has(graph_node->get_connection_input_type(j))) {
+ if (right_disconnects || valid_right_disconnect_types.has(graph_node->get_input_port_type(j))) {
// Check disconnect.
for (const Connection &E : connections) {
if (E.to_node == graph_node->get_name() && E.to_port == j) {
@@ -692,8 +713,8 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
connecting_from = E.from_node;
connecting_index = E.from_port;
connecting_out = true;
- connecting_type = Object::cast_to<GraphNode>(fr)->get_connection_output_type(E.from_port);
- connecting_color = Object::cast_to<GraphNode>(fr)->get_connection_output_color(E.from_port);
+ connecting_type = Object::cast_to<GraphNode>(fr)->get_output_port_type(E.from_port);
+ connecting_color = Object::cast_to<GraphNode>(fr)->get_output_port_color(E.from_port);
connecting_target = false;
connecting_to = pos;
just_disconnected = true;
@@ -715,8 +736,8 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
connecting_from = graph_node->get_name();
connecting_index = j;
connecting_out = false;
- connecting_type = graph_node->get_connection_input_type(j);
- connecting_color = graph_node->get_connection_input_color(j);
+ connecting_type = graph_node->get_input_port_type(j);
+ connecting_color = graph_node->get_input_port_color(j);
connecting_target = false;
connecting_to = pos;
if (connecting_type >= 0) {
@@ -742,25 +763,26 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
if (connecting_valid) {
Vector2 mpos = mm->get_position() / zoom;
for (int i = get_child_count() - 1; i >= 0; i--) {
- Ref<Texture2D> port_icon = get_theme_icon(SNAME("port"), SNAME("GraphNode"));
GraphNode *graph_node = Object::cast_to<GraphNode>(get_child(i));
if (!graph_node || !graph_node->is_visible_in_tree()) {
continue;
}
+ Ref<Texture2D> port_icon = graph_node->theme_cache.port;
+
if (!connecting_out) {
- for (int j = 0; j < graph_node->get_connection_output_count(); j++) {
- Vector2 pos = graph_node->get_connection_output_position(j) + graph_node->get_position();
+ for (int j = 0; j < graph_node->get_output_port_count(); j++) {
+ Vector2 pos = graph_node->get_output_port_position(j) * zoom + graph_node->get_position();
Vector2i port_size = Vector2i(port_icon->get_width(), port_icon->get_height());
// Determine slot height.
- int slot_index = graph_node->get_connection_output_slot(j);
- Control *child = Object::cast_to<Control>(graph_node->get_child(slot_index));
+ int slot_index = graph_node->get_output_port_slot(j);
+ Control *child = Object::cast_to<Control>(graph_node->get_child(slot_index, false));
port_size.height = MAX(port_size.height, child ? child->get_size().y : 0);
- int type = graph_node->get_connection_output_type(j);
+ int type = graph_node->get_output_port_type(j);
if ((type == connecting_type ||
- valid_connection_types.has(ConnectionType(connecting_type, type))) &&
+ valid_connection_types.has(ConnectionType(type, connecting_type))) &&
is_in_output_hotzone(graph_node, j, mpos, port_size)) {
if (!is_node_hover_valid(graph_node->get_name(), j, connecting_from, connecting_index)) {
continue;
@@ -773,16 +795,16 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
}
}
} else {
- for (int j = 0; j < graph_node->get_connection_input_count(); j++) {
- Vector2 pos = graph_node->get_connection_input_position(j) + graph_node->get_position();
+ for (int j = 0; j < graph_node->get_input_port_count(); j++) {
+ Vector2 pos = graph_node->get_input_port_position(j) * zoom + graph_node->get_position();
Vector2i port_size = Vector2i(port_icon->get_width(), port_icon->get_height());
// Determine slot height.
- int slot_index = graph_node->get_connection_input_slot(j);
- Control *child = Object::cast_to<Control>(graph_node->get_child(slot_index));
+ int slot_index = graph_node->get_input_port_slot(j);
+ Control *child = Object::cast_to<Control>(graph_node->get_child(slot_index, false));
port_size.height = MAX(port_size.height, child ? child->get_size().y : 0);
- int type = graph_node->get_connection_input_type(j);
+ int type = graph_node->get_input_port_type(j);
if ((type == connecting_type || valid_connection_types.has(ConnectionType(connecting_type, type))) &&
is_in_input_hotzone(graph_node, j, mpos, port_size)) {
if (!is_node_hover_valid(connecting_from, connecting_index, graph_node->get_name(), j)) {
@@ -851,19 +873,19 @@ bool GraphEdit::_check_clickable_control(Control *p_control, const Vector2 &mpos
}
}
-bool GraphEdit::is_in_input_hotzone(GraphNode *p_graph_node, int p_port, const Vector2 &p_mouse_pos, const Vector2i &p_port_size) {
+bool GraphEdit::is_in_input_hotzone(GraphNode *p_graph_node, int p_port_idx, const Vector2 &p_mouse_pos, const Vector2i &p_port_size) {
bool success;
- if (GDVIRTUAL_CALL(_is_in_input_hotzone, p_graph_node, p_port, p_mouse_pos, success)) {
+ if (GDVIRTUAL_CALL(_is_in_input_hotzone, p_graph_node, p_port_idx, p_mouse_pos, success)) {
return success;
} else {
- Vector2 pos = p_graph_node->get_connection_input_position(p_port) + p_graph_node->get_position();
+ Vector2 pos = p_graph_node->get_input_port_position(p_port_idx) * zoom + p_graph_node->get_position();
return is_in_port_hotzone(pos / zoom, p_mouse_pos, p_port_size, true);
}
}
-bool GraphEdit::is_in_output_hotzone(GraphNode *p_graph_node, int p_port, const Vector2 &p_mouse_pos, const Vector2i &p_port_size) {
+bool GraphEdit::is_in_output_hotzone(GraphNode *p_graph_node, int p_port_idx, const Vector2 &p_mouse_pos, const Vector2i &p_port_size) {
if (p_graph_node->is_resizable()) {
- Ref<Texture2D> resizer = p_graph_node->get_theme_icon(SNAME("resizer"));
+ Ref<Texture2D> resizer = p_graph_node->theme_cache.resizer;
Rect2 resizer_rect = Rect2(p_graph_node->get_position() / zoom + p_graph_node->get_size() - resizer->get_size(), resizer->get_size());
if (resizer_rect.has_point(p_mouse_pos)) {
return false;
@@ -871,19 +893,19 @@ bool GraphEdit::is_in_output_hotzone(GraphNode *p_graph_node, int p_port, const
}
bool success;
- if (GDVIRTUAL_CALL(_is_in_output_hotzone, p_graph_node, p_port, p_mouse_pos, success)) {
+ if (GDVIRTUAL_CALL(_is_in_output_hotzone, p_graph_node, p_port_idx, p_mouse_pos, success)) {
return success;
} else {
- Vector2 pos = p_graph_node->get_connection_output_position(p_port) + p_graph_node->get_position();
+ Vector2 pos = p_graph_node->get_output_port_position(p_port_idx) * zoom + p_graph_node->get_position();
return is_in_port_hotzone(pos / zoom, p_mouse_pos, p_port_size, false);
}
}
bool GraphEdit::is_in_port_hotzone(const Vector2 &p_pos, const Vector2 &p_mouse_pos, const Vector2i &p_port_size, bool p_left) {
Rect2 hotzone = Rect2(
- p_pos.x - (p_left ? port_hotzone_outer_extent : port_hotzone_inner_extent),
+ p_pos.x - (p_left ? theme_cache.port_hotzone_outer_extent : theme_cache.port_hotzone_inner_extent),
p_pos.y - p_port_size.height / 2.0,
- port_hotzone_inner_extent + port_hotzone_outer_extent,
+ theme_cache.port_hotzone_inner_extent + theme_cache.port_hotzone_outer_extent,
p_port_size.height);
if (!hotzone.has_point(p_mouse_pos)) {
@@ -951,12 +973,10 @@ void GraphEdit::_draw_connection_line(CanvasItem *p_where, const Vector2 &p_from
}
// Thickness below 0.5 doesn't look good on the graph or its minimap.
- p_where->draw_polyline_colors(scaled_points, colors, MAX(0.5, Math::floor(p_width * get_theme_default_base_scale())), lines_antialiased);
+ p_where->draw_polyline_colors(scaled_points, colors, MAX(0.5, Math::floor(p_width * theme_cache.base_scale)), lines_antialiased);
}
void GraphEdit::_connections_layer_draw() {
- Color activity_color = get_theme_color(SNAME("activity"));
-
// Draw connections.
List<List<Connection>::Element *> to_erase;
for (List<Connection>::Element *E = connections.front(); E; E = E->next()) {
@@ -978,14 +998,14 @@ void GraphEdit::_connections_layer_draw() {
continue;
}
- Vector2 frompos = gnode_from->get_connection_output_position(c.from_port) + gnode_from->get_position_offset() * zoom;
- Color color = gnode_from->get_connection_output_color(c.from_port);
- Vector2 topos = gnode_to->get_connection_input_position(c.to_port) + gnode_to->get_position_offset() * zoom;
- Color tocolor = gnode_to->get_connection_input_color(c.to_port);
+ Vector2 frompos = gnode_from->get_output_port_position(c.from_port) * zoom + gnode_from->get_position_offset() * zoom;
+ Color color = gnode_from->get_output_port_color(c.from_port);
+ Vector2 topos = gnode_to->get_input_port_position(c.to_port) * zoom + gnode_to->get_position_offset() * zoom;
+ Color tocolor = gnode_to->get_input_port_color(c.to_port);
if (c.activity > 0) {
- color = color.lerp(activity_color, c.activity);
- tocolor = tocolor.lerp(activity_color, c.activity);
+ color = color.lerp(theme_cache.activity_color, c.activity);
+ tocolor = tocolor.lerp(theme_cache.activity_color, c.activity);
}
_draw_connection_line(connections_layer, frompos, topos, color, tocolor, lines_thickness, zoom);
}
@@ -1005,9 +1025,9 @@ void GraphEdit::_top_layer_draw() {
ERR_FAIL_NULL(graph_node_from);
Vector2 pos;
if (connecting_out) {
- pos = graph_node_from->get_connection_output_position(connecting_index);
+ pos = graph_node_from->get_output_port_position(connecting_index) * zoom;
} else {
- pos = graph_node_from->get_connection_input_position(connecting_index);
+ pos = graph_node_from->get_input_port_position(connecting_index) * zoom;
}
pos += graph_node_from->get_position();
@@ -1028,8 +1048,8 @@ void GraphEdit::_top_layer_draw() {
}
if (box_selecting) {
- top_layer->draw_rect(box_selecting_rect, get_theme_color(SNAME("selection_fill")));
- top_layer->draw_rect(box_selecting_rect, get_theme_color(SNAME("selection_stroke")), false);
+ top_layer->draw_rect(box_selecting_rect, theme_cache.selection_fill);
+ top_layer->draw_rect(box_selecting_rect, theme_cache.selection_stroke, false);
}
}
@@ -1042,7 +1062,7 @@ void GraphEdit::_minimap_draw() {
// Draw the minimap background.
Rect2 minimap_rect = Rect2(Point2(), minimap->get_size());
- minimap->draw_style_box(minimap->get_theme_stylebox(SNAME("panel")), minimap_rect);
+ minimap->draw_style_box(minimap->theme_cache.panel, minimap_rect);
Vector2 graph_offset = minimap->_get_graph_offset();
Vector2 minimap_offset = minimap->minimap_offset;
@@ -1058,10 +1078,10 @@ void GraphEdit::_minimap_draw() {
Vector2 node_size = minimap->_convert_from_graph_position(graph_node->get_size() * zoom);
Rect2 node_rect = Rect2(node_position, node_size);
- Ref<StyleBoxFlat> sb_minimap = minimap->get_theme_stylebox(SNAME("node"))->duplicate();
+ Ref<StyleBoxFlat> sb_minimap = minimap->theme_cache.node_style->duplicate();
// Override default values with colors provided by the GraphNode's stylebox, if possible.
- Ref<StyleBoxFlat> sb_frame = graph_node->get_theme_stylebox(graph_node->is_selected() ? "selected_frame" : "frame");
+ Ref<StyleBoxFlat> sb_frame = graph_node->is_selected() ? graph_node->theme_cache.panel_selected : graph_node->theme_cache.panel;
if (sb_frame.is_valid()) {
Color node_color = sb_frame->get_bg_color();
sb_minimap->set_bg_color(node_color);
@@ -1071,7 +1091,6 @@ void GraphEdit::_minimap_draw() {
}
// Draw node connections.
- Color activity_color = get_theme_color(SNAME("activity"));
for (const Connection &E : connections) {
Node *from = get_node(NodePath(E.from_node));
GraphNode *graph_node_from = Object::cast_to<GraphNode>(from);
@@ -1085,27 +1104,27 @@ void GraphEdit::_minimap_draw() {
continue;
}
- Vector2 from_port_position = graph_node_from->get_position_offset() + graph_node_from->get_connection_output_position(E.from_port);
+ Vector2 from_port_position = graph_node_from->get_position_offset() * zoom + graph_node_from->get_output_port_position(E.from_port) * zoom;
Vector2 from_position = minimap->_convert_from_graph_position(from_port_position - graph_offset) + minimap_offset;
- Color from_color = graph_node_from->get_connection_output_color(E.from_port);
- Vector2 to_port_position = graph_node_to->get_position_offset() + graph_node_to->get_connection_input_position(E.to_port);
+ Color from_color = graph_node_from->get_output_port_color(E.from_port);
+ Vector2 to_port_position = graph_node_to->get_position_offset() * zoom + graph_node_to->get_input_port_position(E.to_port) * zoom;
Vector2 to_position = minimap->_convert_from_graph_position(to_port_position - graph_offset) + minimap_offset;
- Color to_color = graph_node_to->get_connection_input_color(E.to_port);
+ Color to_color = graph_node_to->get_input_port_color(E.to_port);
if (E.activity > 0) {
- from_color = from_color.lerp(activity_color, E.activity);
- to_color = to_color.lerp(activity_color, E.activity);
+ from_color = from_color.lerp(theme_cache.activity_color, E.activity);
+ to_color = to_color.lerp(theme_cache.activity_color, E.activity);
}
_draw_connection_line(minimap, from_position, to_position, from_color, to_color, 0.5, minimap->_convert_from_graph_position(Vector2(zoom, zoom)).length());
}
// Draw the "camera" viewport.
Rect2 camera_rect = minimap->get_camera_rect();
- minimap->draw_style_box(minimap->get_theme_stylebox(SNAME("camera")), camera_rect);
+ minimap->draw_style_box(minimap->theme_cache.camera_style, camera_rect);
// Draw the resizer control.
- Ref<Texture2D> resizer = minimap->get_theme_icon(SNAME("resizer"));
- Color resizer_color = minimap->get_theme_color(SNAME("resizer_color"));
+ Ref<Texture2D> resizer = minimap->theme_cache.resizer;
+ Color resizer_color = minimap->theme_cache.resizer_color;
minimap->draw_texture(resizer, Point2(), resizer_color);
}
@@ -1137,17 +1156,17 @@ void GraphEdit::gui_input(const Ref<InputEvent> &p_ev) {
just_selected = true;
drag_accum += mm->get_relative();
for (int i = get_child_count() - 1; i >= 0; i--) {
- GraphNode *graph_node = Object::cast_to<GraphNode>(get_child(i));
- if (graph_node && graph_node->is_selected() && graph_node->is_draggable()) {
- Vector2 pos = (graph_node->get_drag_from() * zoom + drag_accum) / zoom;
+ GraphElement *graph_element = Object::cast_to<GraphElement>(get_child(i));
+ if (graph_element && graph_element->is_selected() && graph_element->is_draggable()) {
+ Vector2 pos = (graph_element->get_drag_from() * zoom + drag_accum) / zoom;
// Snapping can be toggled temporarily by holding down Ctrl.
// This is done here as to not toggle the grid when holding down Ctrl.
- if (snapping_enabled ^ Input::get_singleton()->is_key_pressed(Key::CTRL)) {
+ if (snapping_enabled ^ Input::get_singleton()->is_key_pressed(Key::CMD_OR_CTRL)) {
pos = pos.snapped(Vector2(snapping_distance, snapping_distance));
}
- graph_node->set_position_offset(pos);
+ graph_element->set_position_offset(pos);
}
}
}
@@ -1158,18 +1177,18 @@ void GraphEdit::gui_input(const Ref<InputEvent> &p_ev) {
box_selecting_rect = Rect2(box_selecting_from.min(box_selecting_to), (box_selecting_from - box_selecting_to).abs());
for (int i = get_child_count() - 1; i >= 0; i--) {
- GraphNode *graph_node = Object::cast_to<GraphNode>(get_child(i));
- if (!graph_node) {
+ GraphElement *graph_element = Object::cast_to<GraphElement>(get_child(i));
+ if (!graph_element) {
continue;
}
- Rect2 r = graph_node->get_rect();
+ Rect2 r = graph_element->get_rect();
bool in_box = r.intersects(box_selecting_rect);
if (in_box) {
- graph_node->set_selected(box_selection_mode_additive);
+ graph_element->set_selected(box_selection_mode_additive);
} else {
- graph_node->set_selected(prev_selected.find(graph_node) != nullptr);
+ graph_element->set_selected(prev_selected.find(graph_element) != nullptr);
}
}
@@ -1183,12 +1202,12 @@ void GraphEdit::gui_input(const Ref<InputEvent> &p_ev) {
if (box_selecting) {
box_selecting = false;
for (int i = get_child_count() - 1; i >= 0; i--) {
- GraphNode *graph_node = Object::cast_to<GraphNode>(get_child(i));
- if (!graph_node) {
+ GraphElement *graph_element = Object::cast_to<GraphElement>(get_child(i));
+ if (!graph_element) {
continue;
}
- graph_node->set_selected(prev_selected.find(graph_node) != nullptr);
+ graph_element->set_selected(prev_selected.find(graph_element) != nullptr);
}
top_layer->queue_redraw();
minimap->queue_redraw();
@@ -1202,15 +1221,15 @@ void GraphEdit::gui_input(const Ref<InputEvent> &p_ev) {
}
if (mb->get_button_index() == MouseButton::LEFT && !mb->is_pressed() && dragging) {
- if (!just_selected && drag_accum == Vector2() && Input::get_singleton()->is_key_pressed(Key::CTRL)) {
+ if (!just_selected && drag_accum == Vector2() && Input::get_singleton()->is_key_pressed(Key::CMD_OR_CTRL)) {
// Deselect current node.
for (int i = get_child_count() - 1; i >= 0; i--) {
- GraphNode *graph_node = Object::cast_to<GraphNode>(get_child(i));
+ GraphElement *graph_element = Object::cast_to<GraphElement>(get_child(i));
- if (graph_node) {
- Rect2 r = graph_node->get_rect();
+ if (graph_element) {
+ Rect2 r = graph_element->get_rect();
if (r.has_point(mb->get_position())) {
- graph_node->set_selected(false);
+ graph_element->set_selected(false);
}
}
}
@@ -1218,9 +1237,9 @@ void GraphEdit::gui_input(const Ref<InputEvent> &p_ev) {
if (drag_accum != Vector2()) {
for (int i = get_child_count() - 1; i >= 0; i--) {
- GraphNode *graph_node = Object::cast_to<GraphNode>(get_child(i));
- if (graph_node && graph_node->is_selected()) {
- graph_node->set_drag(false);
+ GraphElement *graph_element = Object::cast_to<GraphElement>(get_child(i));
+ if (graph_element && graph_element->is_selected()) {
+ graph_element->set_drag(false);
}
}
}
@@ -1240,27 +1259,27 @@ void GraphEdit::gui_input(const Ref<InputEvent> &p_ev) {
// Node selection logic.
if (mb->get_button_index() == MouseButton::LEFT && mb->is_pressed()) {
- GraphNode *graph_node = nullptr;
+ GraphElement *graph_element = nullptr;
// Find node which was clicked on.
for (int i = get_child_count() - 1; i >= 0; i--) {
- GraphNode *selected_gcontrol = Object::cast_to<GraphNode>(get_child(i));
+ GraphElement *selected_element = Object::cast_to<GraphElement>(get_child(i));
- if (!selected_gcontrol) {
+ if (!selected_element) {
continue;
}
- if (selected_gcontrol->is_resizing()) {
+ if (selected_element->is_resizing()) {
continue;
}
- if (selected_gcontrol->has_point((mb->get_position() - selected_gcontrol->get_position()) / zoom)) {
- graph_node = selected_gcontrol;
+ if (selected_element->has_point((mb->get_position() - selected_element->get_position()) / zoom)) {
+ graph_element = selected_element;
break;
}
}
- if (graph_node) {
+ if (graph_element) {
if (_filter_input(mb->get_position())) {
return;
}
@@ -1268,26 +1287,26 @@ void GraphEdit::gui_input(const Ref<InputEvent> &p_ev) {
// Left-clicked on a node, select it.
dragging = true;
drag_accum = Vector2();
- just_selected = !graph_node->is_selected();
- if (!graph_node->is_selected() && !Input::get_singleton()->is_key_pressed(Key::CTRL)) {
+ just_selected = !graph_element->is_selected();
+ if (!graph_element->is_selected() && !Input::get_singleton()->is_key_pressed(Key::CMD_OR_CTRL)) {
for (int i = 0; i < get_child_count(); i++) {
- GraphNode *o_gn = Object::cast_to<GraphNode>(get_child(i));
- if (!o_gn) {
+ GraphElement *child_element = Object::cast_to<GraphElement>(get_child(i));
+ if (!child_element) {
continue;
}
- o_gn->set_selected(o_gn == graph_node);
+ child_element->set_selected(child_element == graph_element);
}
}
- graph_node->set_selected(true);
+ graph_element->set_selected(true);
for (int i = 0; i < get_child_count(); i++) {
- GraphNode *o_gn = Object::cast_to<GraphNode>(get_child(i));
- if (!o_gn) {
+ GraphElement *child_element = Object::cast_to<GraphElement>(get_child(i));
+ if (!child_element) {
continue;
}
- if (o_gn->is_selected()) {
- o_gn->set_drag(true);
+ if (child_element->is_selected()) {
+ child_element->set_drag(true);
}
}
@@ -1302,38 +1321,38 @@ void GraphEdit::gui_input(const Ref<InputEvent> &p_ev) {
// Left-clicked on empty space, start box select.
box_selecting = true;
box_selecting_from = mb->get_position();
- if (mb->is_ctrl_pressed()) {
+ if (mb->is_command_or_control_pressed()) {
box_selection_mode_additive = true;
prev_selected.clear();
for (int i = get_child_count() - 1; i >= 0; i--) {
- GraphNode *gn2 = Object::cast_to<GraphNode>(get_child(i));
- if (!gn2 || !gn2->is_selected()) {
+ GraphElement *child_element = Object::cast_to<GraphElement>(get_child(i));
+ if (!child_element || !child_element->is_selected()) {
continue;
}
- prev_selected.push_back(gn2);
+ prev_selected.push_back(child_element);
}
} else if (mb->is_shift_pressed()) {
box_selection_mode_additive = false;
prev_selected.clear();
for (int i = get_child_count() - 1; i >= 0; i--) {
- GraphNode *gn2 = Object::cast_to<GraphNode>(get_child(i));
- if (!gn2 || !gn2->is_selected()) {
+ GraphElement *child_element = Object::cast_to<GraphElement>(get_child(i));
+ if (!child_element || !child_element->is_selected()) {
continue;
}
- prev_selected.push_back(gn2);
+ prev_selected.push_back(child_element);
}
} else {
box_selection_mode_additive = true;
prev_selected.clear();
for (int i = get_child_count() - 1; i >= 0; i--) {
- GraphNode *gn2 = Object::cast_to<GraphNode>(get_child(i));
- if (!gn2) {
+ GraphElement *child_element = Object::cast_to<GraphElement>(get_child(i));
+ if (!child_element) {
continue;
}
- gn2->set_selected(false);
+ child_element->set_selected(false);
}
}
}
@@ -1390,7 +1409,7 @@ void GraphEdit::_zoom_callback(float p_zoom_factor, Vector2 p_origin, Ref<InputE
void GraphEdit::set_connection_activity(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port, float p_activity) {
for (Connection &E : connections) {
if (E.from_node == p_from && E.from_port == p_from_port && E.to_node == p_to && E.to_port == p_to_port) {
- if (Math::is_equal_approx(E.activity, p_activity)) {
+ if (!Math::is_equal_approx(E.activity, p_activity)) {
// Update only if changed.
top_layer->queue_redraw();
minimap->queue_redraw();
@@ -1516,18 +1535,6 @@ float GraphEdit::get_zoom_max() const {
return zoom_max;
}
-void GraphEdit::set_show_zoom_label(bool p_enable) {
- if (zoom_label->is_visible() == p_enable) {
- return;
- }
-
- zoom_label->set_visible(p_enable);
-}
-
-bool GraphEdit::is_showing_zoom_label() const {
- return zoom_label->is_visible();
-}
-
void GraphEdit::set_right_disconnects(bool p_enable) {
right_disconnects = p_enable;
}
@@ -1632,7 +1639,7 @@ void GraphEdit::set_show_grid(bool p_show) {
}
show_grid = p_show;
- show_grid_button->set_pressed(p_show);
+ toggle_grid_button->set_pressed(p_show);
queue_redraw();
}
@@ -1650,7 +1657,7 @@ void GraphEdit::_snapping_distance_changed(double) {
}
void GraphEdit::_show_grid_toggled() {
- show_grid = show_grid_button->is_pressed();
+ show_grid = toggle_grid_button->is_pressed();
queue_redraw();
}
@@ -1696,17 +1703,64 @@ bool GraphEdit::is_minimap_enabled() const {
return minimap_button->is_pressed();
}
-void GraphEdit::set_arrange_nodes_button_hidden(bool p_enable) {
- arrange_nodes_button_hidden = p_enable;
- if (arrange_nodes_button_hidden) {
- layout_button->hide();
- } else {
- layout_button->show();
- }
+void GraphEdit::set_show_menu(bool p_hidden) {
+ show_menu = p_hidden;
+ menu_panel->set_visible(show_menu);
+}
+
+bool GraphEdit::is_showing_menu() const {
+ return show_menu;
+}
+
+void GraphEdit::set_show_zoom_label(bool p_hidden) {
+ show_zoom_label = p_hidden;
+ zoom_label->set_visible(show_zoom_label);
+}
+
+bool GraphEdit::is_showing_zoom_label() const {
+ return show_zoom_label;
+}
+
+void GraphEdit::set_show_zoom_buttons(bool p_hidden) {
+ show_zoom_buttons = p_hidden;
+
+ zoom_minus_button->set_visible(show_zoom_buttons);
+ zoom_reset_button->set_visible(show_zoom_buttons);
+ zoom_plus_button->set_visible(show_zoom_buttons);
+}
+
+bool GraphEdit::is_showing_zoom_buttons() const {
+ return show_zoom_buttons;
+}
+
+void GraphEdit::set_show_grid_buttons(bool p_hidden) {
+ show_grid_buttons = p_hidden;
+
+ toggle_grid_button->set_visible(show_grid_buttons);
+ toggle_snapping_button->set_visible(show_grid_buttons);
+ snapping_distance_spinbox->set_visible(show_grid_buttons);
}
-bool GraphEdit::is_arrange_nodes_button_hidden() const {
- return arrange_nodes_button_hidden;
+bool GraphEdit::is_showing_grid_buttons() const {
+ return show_grid_buttons;
+}
+
+void GraphEdit::set_show_minimap_button(bool p_hidden) {
+ show_minimap_button = p_hidden;
+ minimap_button->set_visible(show_minimap_button);
+}
+
+bool GraphEdit::is_showing_minimap_button() const {
+ return show_minimap_button;
+}
+
+void GraphEdit::set_show_arrange_button(bool p_hidden) {
+ show_arrange_button = p_hidden;
+ arrange_button->set_visible(show_arrange_button);
+}
+
+bool GraphEdit::is_showing_arrange_button() const {
+ return show_arrange_button;
}
void GraphEdit::_minimap_toggled() {
@@ -1802,9 +1856,6 @@ void GraphEdit::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_zoom_step", "zoom_step"), &GraphEdit::set_zoom_step);
ClassDB::bind_method(D_METHOD("get_zoom_step"), &GraphEdit::get_zoom_step);
- ClassDB::bind_method(D_METHOD("set_show_zoom_label", "enable"), &GraphEdit::set_show_zoom_label);
- ClassDB::bind_method(D_METHOD("is_showing_zoom_label"), &GraphEdit::is_showing_zoom_label);
-
ClassDB::bind_method(D_METHOD("set_show_grid", "enable"), &GraphEdit::set_show_grid);
ClassDB::bind_method(D_METHOD("is_showing_grid"), &GraphEdit::is_showing_grid);
@@ -1831,8 +1882,23 @@ void GraphEdit::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_minimap_enabled", "enable"), &GraphEdit::set_minimap_enabled);
ClassDB::bind_method(D_METHOD("is_minimap_enabled"), &GraphEdit::is_minimap_enabled);
- ClassDB::bind_method(D_METHOD("set_arrange_nodes_button_hidden", "enable"), &GraphEdit::set_arrange_nodes_button_hidden);
- ClassDB::bind_method(D_METHOD("is_arrange_nodes_button_hidden"), &GraphEdit::is_arrange_nodes_button_hidden);
+ ClassDB::bind_method(D_METHOD("set_show_menu", "hidden"), &GraphEdit::set_show_menu);
+ ClassDB::bind_method(D_METHOD("is_showing_menu"), &GraphEdit::is_showing_menu);
+
+ ClassDB::bind_method(D_METHOD("set_show_zoom_label", "enable"), &GraphEdit::set_show_zoom_label);
+ ClassDB::bind_method(D_METHOD("is_showing_zoom_label"), &GraphEdit::is_showing_zoom_label);
+
+ ClassDB::bind_method(D_METHOD("set_show_grid_buttons", "hidden"), &GraphEdit::set_show_grid_buttons);
+ ClassDB::bind_method(D_METHOD("is_showing_grid_buttons"), &GraphEdit::is_showing_grid_buttons);
+
+ ClassDB::bind_method(D_METHOD("set_show_zoom_buttons", "hidden"), &GraphEdit::set_show_zoom_buttons);
+ ClassDB::bind_method(D_METHOD("is_showing_zoom_buttons"), &GraphEdit::is_showing_zoom_buttons);
+
+ ClassDB::bind_method(D_METHOD("set_show_minimap_button", "hidden"), &GraphEdit::set_show_minimap_button);
+ ClassDB::bind_method(D_METHOD("is_showing_minimap_button"), &GraphEdit::is_showing_minimap_button);
+
+ ClassDB::bind_method(D_METHOD("set_show_arrange_button", "hidden"), &GraphEdit::set_show_arrange_button);
+ ClassDB::bind_method(D_METHOD("is_showing_arrange_button"), &GraphEdit::is_showing_arrange_button);
ClassDB::bind_method(D_METHOD("set_right_disconnects", "enable"), &GraphEdit::set_right_disconnects);
ClassDB::bind_method(D_METHOD("is_right_disconnects_enabled"), &GraphEdit::is_right_disconnects_enabled);
@@ -1849,12 +1915,12 @@ void GraphEdit::_bind_methods() {
GDVIRTUAL_BIND(_get_connection_line, "from_position", "to_position")
GDVIRTUAL_BIND(_is_node_hover_valid, "from_node", "from_port", "to_node", "to_port");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "right_disconnects"), "set_right_disconnects", "is_right_disconnects_enabled");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scroll_offset", PROPERTY_HINT_NONE, "suffix:px"), "set_scroll_offset", "get_scroll_offset");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_grid"), "set_show_grid", "is_showing_grid");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "snapping_enabled"), "set_snapping_enabled", "is_snapping_enabled");
ADD_PROPERTY(PropertyInfo(Variant::INT, "snapping_distance", PROPERTY_HINT_NONE, "suffix:px"), "set_snapping_distance", "get_snapping_distance");
ADD_PROPERTY(PropertyInfo(Variant::INT, "panning_scheme", PROPERTY_HINT_ENUM, "Scroll Zooms,Scroll Pans"), "set_panning_scheme", "get_panning_scheme");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "right_disconnects"), "set_right_disconnects", "is_right_disconnects_enabled");
ADD_GROUP("Connection Lines", "connection_lines");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "connection_lines_curvature"), "set_connection_lines_curvature", "get_connection_lines_curvature");
@@ -1866,35 +1932,65 @@ void GraphEdit::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "zoom_min"), "set_zoom_min", "get_zoom_min");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "zoom_max"), "set_zoom_max", "get_zoom_max");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "zoom_step"), "set_zoom_step", "get_zoom_step");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_zoom_label"), "set_show_zoom_label", "is_showing_zoom_label");
ADD_GROUP("Minimap", "minimap_");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "minimap_enabled"), "set_minimap_enabled", "is_minimap_enabled");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "minimap_size", PROPERTY_HINT_NONE, "suffix:px"), "set_minimap_size", "get_minimap_size");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "minimap_opacity"), "set_minimap_opacity", "get_minimap_opacity");
- ADD_GROUP("UI", "");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "arrange_nodes_button_hidden"), "set_arrange_nodes_button_hidden", "is_arrange_nodes_button_hidden");
+ ADD_GROUP("Toolbar Menu", "");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_menu"), "set_show_menu", "is_showing_menu");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_zoom_label"), "set_show_zoom_label", "is_showing_zoom_label");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_zoom_buttons"), "set_show_zoom_buttons", "is_showing_zoom_buttons");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_grid_buttons"), "set_show_grid_buttons", "is_showing_grid_buttons");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_minimap_button"), "set_show_minimap_button", "is_showing_minimap_button");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_arrange_button"), "set_show_arrange_button", "is_showing_arrange_button");
ADD_SIGNAL(MethodInfo("connection_request", PropertyInfo(Variant::STRING_NAME, "from_node"), PropertyInfo(Variant::INT, "from_port"), PropertyInfo(Variant::STRING_NAME, "to_node"), PropertyInfo(Variant::INT, "to_port")));
ADD_SIGNAL(MethodInfo("disconnection_request", PropertyInfo(Variant::STRING_NAME, "from_node"), PropertyInfo(Variant::INT, "from_port"), PropertyInfo(Variant::STRING_NAME, "to_node"), PropertyInfo(Variant::INT, "to_port")));
- ADD_SIGNAL(MethodInfo("popup_request", PropertyInfo(Variant::VECTOR2, "position")));
- ADD_SIGNAL(MethodInfo("duplicate_nodes_request"));
+ ADD_SIGNAL(MethodInfo("connection_to_empty", PropertyInfo(Variant::STRING_NAME, "from_node"), PropertyInfo(Variant::INT, "from_port"), PropertyInfo(Variant::VECTOR2, "release_position")));
+ ADD_SIGNAL(MethodInfo("connection_from_empty", PropertyInfo(Variant::STRING_NAME, "to_node"), PropertyInfo(Variant::INT, "to_port"), PropertyInfo(Variant::VECTOR2, "release_position")));
+ ADD_SIGNAL(MethodInfo("connection_drag_started", PropertyInfo(Variant::STRING_NAME, "from_node"), PropertyInfo(Variant::INT, "from_port"), PropertyInfo(Variant::BOOL, "is_output")));
+ ADD_SIGNAL(MethodInfo("connection_drag_ended"));
+
ADD_SIGNAL(MethodInfo("copy_nodes_request"));
ADD_SIGNAL(MethodInfo("paste_nodes_request"));
+ ADD_SIGNAL(MethodInfo("duplicate_nodes_request"));
+ ADD_SIGNAL(MethodInfo("delete_nodes_request", PropertyInfo(Variant::ARRAY, "nodes", PROPERTY_HINT_ARRAY_TYPE, "StringName")));
+
ADD_SIGNAL(MethodInfo("node_selected", PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "Node")));
ADD_SIGNAL(MethodInfo("node_deselected", PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "Node")));
- ADD_SIGNAL(MethodInfo("connection_to_empty", PropertyInfo(Variant::STRING_NAME, "from_node"), PropertyInfo(Variant::INT, "from_port"), PropertyInfo(Variant::VECTOR2, "release_position")));
- ADD_SIGNAL(MethodInfo("connection_from_empty", PropertyInfo(Variant::STRING_NAME, "to_node"), PropertyInfo(Variant::INT, "to_port"), PropertyInfo(Variant::VECTOR2, "release_position")));
- ADD_SIGNAL(MethodInfo("delete_nodes_request", PropertyInfo(Variant::ARRAY, "nodes", PROPERTY_HINT_ARRAY_TYPE, "StringName")));
+
+ ADD_SIGNAL(MethodInfo("popup_request", PropertyInfo(Variant::VECTOR2, "position")));
+
ADD_SIGNAL(MethodInfo("begin_node_move"));
ADD_SIGNAL(MethodInfo("end_node_move"));
ADD_SIGNAL(MethodInfo("scroll_offset_changed", PropertyInfo(Variant::VECTOR2, "offset")));
- ADD_SIGNAL(MethodInfo("connection_drag_started", PropertyInfo(Variant::STRING_NAME, "from_node"), PropertyInfo(Variant::INT, "from_port"), PropertyInfo(Variant::BOOL, "is_output")));
- ADD_SIGNAL(MethodInfo("connection_drag_ended"));
BIND_ENUM_CONSTANT(SCROLL_ZOOMS);
BIND_ENUM_CONSTANT(SCROLL_PANS);
+
+ BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, GraphEdit, panel);
+ BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, GraphEdit, grid_major);
+ BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, GraphEdit, grid_minor);
+
+ BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_COLOR, GraphEdit, activity_color, "activity");
+ BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, GraphEdit, selection_fill);
+ BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, GraphEdit, selection_stroke);
+
+ BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, GraphEdit, menu_panel);
+
+ BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, GraphEdit, zoom_in);
+ BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, GraphEdit, zoom_out);
+ BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, GraphEdit, zoom_reset);
+
+ BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, GraphEdit, snapping_toggle);
+ BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, GraphEdit, grid_toggle);
+ BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, GraphEdit, minimap_toggle);
+ BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, GraphEdit, layout);
+
+ BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, GraphEdit, port_hotzone_inner_extent);
+ BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, GraphEdit, port_hotzone_outer_extent);
}
GraphEdit::GraphEdit() {
@@ -1919,7 +2015,7 @@ GraphEdit::GraphEdit() {
top_layer->connect("focus_exited", callable_mp(panner.ptr(), &ViewPanner::release_pan_key));
connections_layer = memnew(Control);
- add_child(connections_layer, false);
+ add_child(connections_layer, false, INTERNAL_MODE_FRONT);
connections_layer->connect("draw", callable_mp(this, &GraphEdit::_connections_layer_draw));
connections_layer->set_name("_connection_layer");
connections_layer->set_disable_visibility_clip(true); // Necessary, so it can draw freely and be offset.
@@ -1943,84 +2039,106 @@ GraphEdit::GraphEdit() {
h_scrollbar->connect("value_changed", callable_mp(this, &GraphEdit::_scroll_moved));
v_scrollbar->connect("value_changed", callable_mp(this, &GraphEdit::_scroll_moved));
+ // Toolbar menu.
+
+ menu_panel = memnew(PanelContainer);
+ menu_panel->set_visible(show_menu);
+ top_layer->add_child(menu_panel);
+ menu_panel->set_position(Vector2(10, 10));
+
menu_hbox = memnew(HBoxContainer);
- top_layer->add_child(menu_hbox);
- menu_hbox->set_position(Vector2(10, 10));
+ menu_panel->add_child(menu_hbox);
+
+ // Zoom label and controls.
zoom_label = memnew(Label);
- menu_hbox->add_child(zoom_label);
- zoom_label->set_visible(false);
+ zoom_label->set_visible(show_zoom_label);
zoom_label->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
zoom_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
zoom_label->set_custom_minimum_size(Size2(48, 0));
+ menu_hbox->add_child(zoom_label);
_update_zoom_label();
zoom_minus_button = memnew(Button);
- zoom_minus_button->set_flat(true);
- menu_hbox->add_child(zoom_minus_button);
+ zoom_minus_button->set_theme_type_variation("FlatButton");
+ zoom_minus_button->set_visible(show_zoom_buttons);
zoom_minus_button->set_tooltip_text(RTR("Zoom Out"));
- zoom_minus_button->connect("pressed", callable_mp(this, &GraphEdit::_zoom_minus));
zoom_minus_button->set_focus_mode(FOCUS_NONE);
+ menu_hbox->add_child(zoom_minus_button);
+ zoom_minus_button->connect("pressed", callable_mp(this, &GraphEdit::_zoom_minus));
zoom_reset_button = memnew(Button);
- zoom_reset_button->set_flat(true);
- menu_hbox->add_child(zoom_reset_button);
+ zoom_reset_button->set_theme_type_variation("FlatButton");
+ zoom_reset_button->set_visible(show_zoom_buttons);
zoom_reset_button->set_tooltip_text(RTR("Zoom Reset"));
- zoom_reset_button->connect("pressed", callable_mp(this, &GraphEdit::_zoom_reset));
zoom_reset_button->set_focus_mode(FOCUS_NONE);
+ menu_hbox->add_child(zoom_reset_button);
+ zoom_reset_button->connect("pressed", callable_mp(this, &GraphEdit::_zoom_reset));
zoom_plus_button = memnew(Button);
- zoom_plus_button->set_flat(true);
- menu_hbox->add_child(zoom_plus_button);
+ zoom_plus_button->set_theme_type_variation("FlatButton");
+ zoom_plus_button->set_visible(show_zoom_buttons);
zoom_plus_button->set_tooltip_text(RTR("Zoom In"));
- zoom_plus_button->connect("pressed", callable_mp(this, &GraphEdit::_zoom_plus));
zoom_plus_button->set_focus_mode(FOCUS_NONE);
+ menu_hbox->add_child(zoom_plus_button);
+ zoom_plus_button->connect("pressed", callable_mp(this, &GraphEdit::_zoom_plus));
- show_grid_button = memnew(Button);
- show_grid_button->set_flat(true);
- show_grid_button->set_toggle_mode(true);
- show_grid_button->set_tooltip_text(RTR("Toggle the visual grid."));
- show_grid_button->connect("pressed", callable_mp(this, &GraphEdit::_show_grid_toggled));
- show_grid_button->set_pressed(true);
- show_grid_button->set_focus_mode(FOCUS_NONE);
- menu_hbox->add_child(show_grid_button);
+ // Grid controls.
+
+ toggle_grid_button = memnew(Button);
+ toggle_grid_button->set_theme_type_variation("FlatButton");
+ toggle_grid_button->set_visible(show_grid_buttons);
+ toggle_grid_button->set_toggle_mode(true);
+ toggle_grid_button->set_pressed(true);
+ toggle_grid_button->set_tooltip_text(RTR("Toggle the visual grid."));
+ toggle_grid_button->set_focus_mode(FOCUS_NONE);
+ menu_hbox->add_child(toggle_grid_button);
+ toggle_grid_button->connect("pressed", callable_mp(this, &GraphEdit::_show_grid_toggled));
toggle_snapping_button = memnew(Button);
- toggle_snapping_button->set_flat(true);
+ toggle_snapping_button->set_theme_type_variation("FlatButton");
+ toggle_snapping_button->set_visible(show_grid_buttons);
toggle_snapping_button->set_toggle_mode(true);
toggle_snapping_button->set_tooltip_text(RTR("Toggle snapping to the grid."));
- toggle_snapping_button->connect("pressed", callable_mp(this, &GraphEdit::_snapping_toggled));
toggle_snapping_button->set_pressed(snapping_enabled);
toggle_snapping_button->set_focus_mode(FOCUS_NONE);
menu_hbox->add_child(toggle_snapping_button);
+ toggle_snapping_button->connect("pressed", callable_mp(this, &GraphEdit::_snapping_toggled));
snapping_distance_spinbox = memnew(SpinBox);
+ snapping_distance_spinbox->set_visible(show_grid_buttons);
snapping_distance_spinbox->set_min(GRID_MIN_SNAPPING_DISTANCE);
snapping_distance_spinbox->set_max(GRID_MAX_SNAPPING_DISTANCE);
snapping_distance_spinbox->set_step(1);
snapping_distance_spinbox->set_value(snapping_distance);
snapping_distance_spinbox->set_tooltip_text(RTR("Change the snapping distance."));
- snapping_distance_spinbox->connect("value_changed", callable_mp(this, &GraphEdit::_snapping_distance_changed));
menu_hbox->add_child(snapping_distance_spinbox);
+ snapping_distance_spinbox->connect("value_changed", callable_mp(this, &GraphEdit::_snapping_distance_changed));
+
+ // Extra controls.
minimap_button = memnew(Button);
- minimap_button->set_flat(true);
+ minimap_button->set_theme_type_variation("FlatButton");
+ minimap_button->set_visible(show_minimap_button);
minimap_button->set_toggle_mode(true);
minimap_button->set_tooltip_text(RTR("Toggle the graph minimap."));
- minimap_button->connect("pressed", callable_mp(this, &GraphEdit::_minimap_toggled));
minimap_button->set_pressed(show_grid);
minimap_button->set_focus_mode(FOCUS_NONE);
menu_hbox->add_child(minimap_button);
+ minimap_button->connect("pressed", callable_mp(this, &GraphEdit::_minimap_toggled));
+
+ arrange_button = memnew(Button);
+ arrange_button->set_theme_type_variation("FlatButton");
+ arrange_button->set_visible(show_arrange_button);
+ arrange_button->connect("pressed", callable_mp(this, &GraphEdit::arrange_nodes));
+ arrange_button->set_focus_mode(FOCUS_NONE);
+ menu_hbox->add_child(arrange_button);
+ arrange_button->set_tooltip_text(RTR("Automatically arrange selected nodes."));
- layout_button = memnew(Button);
- layout_button->set_flat(true);
- menu_hbox->add_child(layout_button);
- layout_button->set_tooltip_text(RTR("Automatically arrange selected nodes."));
- layout_button->connect("pressed", callable_mp(this, &GraphEdit::arrange_nodes));
- layout_button->set_focus_mode(FOCUS_NONE);
+ // Minimap.
- Vector2 minimap_size = Vector2(240, 160);
- float minimap_opacity = 0.65;
+ const Vector2 minimap_size = Vector2(240, 160);
+ const float minimap_opacity = 0.65;
minimap = memnew(GraphEditMinimap(this));
top_layer->add_child(minimap);