diff --git a/doc/classes/GraphEdit.xml b/doc/classes/GraphEdit.xml
index 410efd6389b7..23aadbce7251 100644
--- a/doc/classes/GraphEdit.xml
+++ b/doc/classes/GraphEdit.xml
@@ -237,6 +237,9 @@
The thickness of the lines between the nodes.
+
+ The pattern used for drawing the grid.
+
If [code]true[/code], the minimap is visible.
@@ -405,16 +408,22 @@
[kbd]Mouse Wheel[/kbd] will move the view, [kbd]Ctrl + Mouse Wheel[/kbd] will zoom.
+
+ Draw the grid using solid lines.
+
+
+ Draw the grid using dots.
+
Color of the connection's activity (see [method set_connection_activity]).
- Color of major grid lines.
+ Color of major grid lines/dots.
- Color of minor grid lines.
+ Color of minor grid lines/dots.
The fill color of the selection rectangle.
diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp
index 8dddbf78cf8b..f53e2ce50487 100644
--- a/scene/gui/graph_edit.cpp
+++ b/scene/gui/graph_edit.cpp
@@ -542,40 +542,9 @@ void GraphEdit::_notification(int p_what) {
// Draw background grid.
if (show_grid) {
- Vector2 offset = get_scroll_offset() / zoom;
- Size2 size = get_size() / zoom;
-
- Point2i from_pos = (offset / float(snapping_distance)).floor();
- Point2i len = (size / float(snapping_distance)).floor() + Vector2(1, 1);
-
- 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 = theme_cache.grid_major;
- } else {
- color = theme_cache.grid_minor;
- }
-
- float base_offset = i * snapping_distance * zoom - offset.x * zoom;
- draw_line(Vector2(base_offset, 0), Vector2(base_offset, get_size().height), color);
- }
-
- for (int i = from_pos.y; i < from_pos.y + len.y; i++) {
- Color color;
-
- if (ABS(i) % GRID_MINOR_STEPS_PER_MAJOR_LINE == 0) {
- color = theme_cache.grid_major;
- } else {
- color = theme_cache.grid_minor;
- }
-
- float base_offset = i * snapping_distance * zoom - offset.y * zoom;
- draw_line(Vector2(0, base_offset), Vector2(get_size().width, base_offset), color);
- }
+ _draw_grid();
}
} break;
-
case NOTIFICATION_RESIZED: {
_update_scroll();
top_layer->queue_redraw();
@@ -1128,6 +1097,67 @@ void GraphEdit::_minimap_draw() {
minimap->draw_texture(resizer, Point2(), resizer_color);
}
+void GraphEdit::_draw_grid() {
+ Vector2 offset = get_scroll_offset() / zoom;
+ Size2 size = get_size() / zoom;
+
+ Point2i from_pos = (offset / float(snapping_distance)).floor();
+ Point2i len = (size / float(snapping_distance)).floor() + Vector2(1, 1);
+
+ switch (grid_pattern) {
+ case GRID_PATTERN_LINES: {
+ 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 = theme_cache.grid_major;
+ } else {
+ color = theme_cache.grid_minor;
+ }
+
+ float base_offset = i * snapping_distance * zoom - offset.x * zoom;
+ draw_line(Vector2(base_offset, 0), Vector2(base_offset, get_size().height), color);
+ }
+
+ for (int i = from_pos.y; i < from_pos.y + len.y; i++) {
+ Color color;
+
+ if (ABS(i) % GRID_MINOR_STEPS_PER_MAJOR_LINE == 0) {
+ color = theme_cache.grid_major;
+ } else {
+ color = theme_cache.grid_minor;
+ }
+
+ float base_offset = i * snapping_distance * zoom - offset.y * zoom;
+ draw_line(Vector2(0, base_offset), Vector2(get_size().width, base_offset), color);
+ }
+ } break;
+ case GRID_PATTERN_DOTS: {
+ Color transparent_grid_minor = theme_cache.grid_minor;
+ transparent_grid_minor.a *= CLAMP(2 * (zoom - 0.4), 0, 1);
+
+ for (int i = from_pos.x; i < from_pos.x + len.x; i++) {
+ for (int j = from_pos.y; j < from_pos.y + len.y; j++) {
+ Color color = transparent_grid_minor;
+
+ if (ABS(i) % GRID_MINOR_STEPS_PER_MAJOR_LINE == 0 && ABS(j) % GRID_MINOR_STEPS_PER_MAJOR_LINE == 0) {
+ color = theme_cache.grid_major;
+ }
+
+ if (color.a == 0) {
+ continue;
+ }
+
+ float base_offset_x = i * snapping_distance * zoom - offset.x * zoom;
+ float base_offset_y = j * snapping_distance * zoom - offset.y * zoom;
+
+ draw_rect(Rect2(base_offset_x - 1, base_offset_y - 1, 3, 3), color);
+ }
+ }
+ } break;
+ }
+}
+
void GraphEdit::set_selected(Node *p_child) {
for (int i = get_child_count() - 1; i >= 0; i--) {
GraphNode *graph_node = Object::cast_to(get_child(i));
@@ -1647,6 +1677,19 @@ bool GraphEdit::is_showing_grid() const {
return show_grid;
}
+void GraphEdit::set_grid_pattern(GridPattern p_pattern) {
+ if (grid_pattern == p_pattern) {
+ return;
+ }
+
+ grid_pattern = p_pattern;
+ queue_redraw();
+}
+
+GraphEdit::GridPattern GraphEdit::get_grid_pattern() const {
+ return grid_pattern;
+}
+
void GraphEdit::_snapping_toggled() {
snapping_enabled = toggle_snapping_button->is_pressed();
}
@@ -1859,6 +1902,9 @@ void GraphEdit::_bind_methods() {
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);
+ ClassDB::bind_method(D_METHOD("set_grid_pattern", "pattern"), &GraphEdit::set_grid_pattern);
+ ClassDB::bind_method(D_METHOD("get_grid_pattern"), &GraphEdit::get_grid_pattern);
+
ClassDB::bind_method(D_METHOD("set_snapping_enabled", "enable"), &GraphEdit::set_snapping_enabled);
ClassDB::bind_method(D_METHOD("is_snapping_enabled"), &GraphEdit::is_snapping_enabled);
@@ -1917,6 +1963,7 @@ void GraphEdit::_bind_methods() {
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::INT, "grid_pattern", PROPERTY_HINT_ENUM, "Lines,Dots"), "set_grid_pattern", "get_grid_pattern");
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");
@@ -1970,6 +2017,9 @@ void GraphEdit::_bind_methods() {
BIND_ENUM_CONSTANT(SCROLL_ZOOMS);
BIND_ENUM_CONSTANT(SCROLL_PANS);
+ BIND_ENUM_CONSTANT(GRID_PATTERN_LINES);
+ BIND_ENUM_CONSTANT(GRID_PATTERN_DOTS);
+
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);
diff --git a/scene/gui/graph_edit.h b/scene/gui/graph_edit.h
index a7be9ac0b36f..31cb495bf8da 100644
--- a/scene/gui/graph_edit.h
+++ b/scene/gui/graph_edit.h
@@ -126,6 +126,11 @@ class GraphEdit : public Control {
SCROLL_PANS,
};
+ enum GridPattern {
+ GRID_PATTERN_LINES,
+ GRID_PATTERN_DOTS
+ };
+
private:
struct ConnectionType {
union {
@@ -176,6 +181,7 @@ class GraphEdit : public Control {
bool snapping_enabled = true;
int snapping_distance = 20;
bool show_grid = true;
+ GridPattern grid_pattern = GRID_PATTERN_LINES;
bool connecting = false;
String connecting_from;
@@ -289,6 +295,8 @@ class GraphEdit : public Control {
void _connections_layer_draw();
void _minimap_draw();
+ void _draw_grid();
+
TypedArray _get_connection_list() const;
friend class GraphEditFilter;
@@ -412,6 +420,9 @@ class GraphEdit : public Control {
void set_show_grid(bool p_enable);
bool is_showing_grid() const;
+ void set_grid_pattern(GridPattern p_pattern);
+ GridPattern get_grid_pattern() const;
+
void set_connection_lines_curvature(float p_curvature);
float get_connection_lines_curvature() const;
@@ -431,5 +442,6 @@ class GraphEdit : public Control {
};
VARIANT_ENUM_CAST(GraphEdit::PanningScheme);
+VARIANT_ENUM_CAST(GraphEdit::GridPattern);
#endif // GRAPH_EDIT_H