Merge pull request #96910 from zaevi/improve_GraphEdit_dot_grid

GraphEdit: Improve dotted pattern grid performance
This commit is contained in:
Rémi Verschelde 2024-09-13 11:22:05 +02:00
commit 84f1fe781c
No known key found for this signature in database
GPG key ID: C3336907360768E1

View file

@ -1646,24 +1646,34 @@ void GraphEdit::_draw_grid() {
Color transparent_grid_minor = theme_cache.grid_minor;
transparent_grid_minor.a *= CLAMP(1.0 * (zoom - 0.4), 0, 1);
// Minor dots.
if (transparent_grid_minor.a != 0) {
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_DOT == 0 && ABS(j) % GRID_MINOR_STEPS_PER_MAJOR_DOT == 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);
draw_rect(Rect2(base_offset_x - 1, base_offset_y - 1, 3, 3), transparent_grid_minor);
}
}
}
// Major dots.
if (theme_cache.grid_major.a != 0) {
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) {
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) {
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), theme_cache.grid_major);
}
}
}
} break;
}
}