Skip to content

Commit 84102af

Browse files
committed
GraphEdit: Improve dotted pattern grid performance
1 parent 83d54ab commit 84102af

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

scene/gui/graph_edit.cpp

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,24 +1646,34 @@ void GraphEdit::_draw_grid() {
16461646
Color transparent_grid_minor = theme_cache.grid_minor;
16471647
transparent_grid_minor.a *= CLAMP(1.0 * (zoom - 0.4), 0, 1);
16481648

1649-
for (int i = from_pos.x; i < from_pos.x + len.x; i++) {
1650-
for (int j = from_pos.y; j < from_pos.y + len.y; j++) {
1651-
Color color = transparent_grid_minor;
1649+
// Minor dots.
1650+
if (transparent_grid_minor.a != 0) {
1651+
for (int i = from_pos.x; i < from_pos.x + len.x; i++) {
1652+
for (int j = from_pos.y; j < from_pos.y + len.y; j++) {
1653+
if (ABS(i) % GRID_MINOR_STEPS_PER_MAJOR_DOT == 0 && ABS(j) % GRID_MINOR_STEPS_PER_MAJOR_DOT == 0) {
1654+
continue;
1655+
}
16521656

1653-
if (ABS(i) % GRID_MINOR_STEPS_PER_MAJOR_DOT == 0 && ABS(j) % GRID_MINOR_STEPS_PER_MAJOR_DOT == 0) {
1654-
color = theme_cache.grid_major;
1655-
}
1657+
float base_offset_x = i * snapping_distance * zoom - offset.x * zoom;
1658+
float base_offset_y = j * snapping_distance * zoom - offset.y * zoom;
16561659

1657-
if (color.a == 0) {
1658-
continue;
1660+
draw_rect(Rect2(base_offset_x - 1, base_offset_y - 1, 3, 3), transparent_grid_minor);
16591661
}
1662+
}
1663+
}
16601664

1661-
float base_offset_x = i * snapping_distance * zoom - offset.x * zoom;
1662-
float base_offset_y = j * snapping_distance * zoom - offset.y * zoom;
1665+
// Major dots.
1666+
if (theme_cache.grid_major.a != 0) {
1667+
for (int i = from_pos.x - from_pos.x % GRID_MINOR_STEPS_PER_MAJOR_DOT; i < from_pos.x + len.x; i += GRID_MINOR_STEPS_PER_MAJOR_DOT) {
1668+
for (int j = from_pos.y - from_pos.y % GRID_MINOR_STEPS_PER_MAJOR_DOT; j < from_pos.y + len.y; j += GRID_MINOR_STEPS_PER_MAJOR_DOT) {
1669+
float base_offset_x = i * snapping_distance * zoom - offset.x * zoom;
1670+
float base_offset_y = j * snapping_distance * zoom - offset.y * zoom;
16631671

1664-
draw_rect(Rect2(base_offset_x - 1, base_offset_y - 1, 3, 3), color);
1672+
draw_rect(Rect2(base_offset_x - 1, base_offset_y - 1, 3, 3), theme_cache.grid_major);
1673+
}
16651674
}
16661675
}
1676+
16671677
} break;
16681678
}
16691679
}

0 commit comments

Comments
 (0)