From 5f683261ffde32488ee7b2c6b2d6eb63029bc8dc Mon Sep 17 00:00:00 2001 From: Relintai Date: Mon, 20 Jun 2022 00:59:32 +0200 Subject: [PATCH] Reimplemented the PaintVisualGrid differently. --- modules/paint/paint_canvas.cpp | 2 +- modules/paint/paint_visual_grid.cpp | 55 +++++++++++++++++++---------- modules/paint/paint_visual_grid.h | 3 +- 3 files changed, 40 insertions(+), 20 deletions(-) diff --git a/modules/paint/paint_canvas.cpp b/modules/paint/paint_canvas.cpp index 6a18fbbad..e10b33234 100644 --- a/modules/paint/paint_canvas.cpp +++ b/modules/paint/paint_canvas.cpp @@ -101,7 +101,7 @@ void PaintCanvas::set_grid_size(const int size) { if (grid) { int s = size * _pixel_size; - grid->set_size(Size2(s, s)); + grid->set_grid_size(s); } } diff --git a/modules/paint/paint_visual_grid.cpp b/modules/paint/paint_visual_grid.cpp index 1f68c55fa..fefef4ca5 100644 --- a/modules/paint/paint_visual_grid.cpp +++ b/modules/paint/paint_visual_grid.cpp @@ -24,33 +24,52 @@ SOFTWARE. #include "paint_visual_grid.h" +void PaintVisualGrid::set_grid_size(const int gs) { + size = gs; + update(); +} + void PaintVisualGrid::_draw() { if (size == 0) { size = 1; } - float temp_size = size + zoom; - - Vector2 wrap_offset = Vector2(Math::wrapf(offset.x, 0, temp_size), Math::wrapf(offset.y, 0, temp_size)); - Size2 rect_size = get_size(); + int sx = rect_size.x; + int sy = rect_size.y; - float ceil_x = Math::ceil(rect_size.x / temp_size); - float ceil_y = Math::ceil(rect_size.y / temp_size); - - for (int i = 0; i < ceil_y; ++i) { - Point2 start_x = Vector2(0, (i * temp_size) + wrap_offset.y); - Point2 end_x = Vector2(rect_size.x, (i * temp_size) + wrap_offset.y); - //var end_x = Vector2(int(rect_size.x) + size - int(rect_size.x) % size, (i * temp_size) + wrap_offset.y); - draw_line(start_x, end_x, color, 1); + for (int x = 0; x < sx; x += size) { + draw_line(Vector2(x, 0), Vector2(x, sy), color, 1); } - for (int i = 0; i < ceil_x; ++i) { - Point2 start_y = Vector2((i * temp_size) + wrap_offset.x, 0); - Point2 end_y = Vector2((i * temp_size) + (wrap_offset.x), rect_size.y); - //var end_y = Vector2((i * temp_size) + (wrap_offset.x), int(rect_size.y) + size - int(rect_size.y) % size); - draw_line(start_y, end_y, color, 1); + for (int y = 0; y < sy; y += size) { + draw_line(Vector2(0, y), Vector2(sx, y), color, 1); } + + /* + float temp_size = size + zoom; + + Vector2 wrap_offset = Vector2(Math::wrapf(offset.x, 0, temp_size), Math::wrapf(offset.y, 0, temp_size)); + + Size2 rect_size = get_size(); + + float ceil_x = Math::ceil(rect_size.x / temp_size); + float ceil_y = Math::ceil(rect_size.y / temp_size); + + for (int i = 0; i < ceil_y; ++i) { + Point2 start_x = Vector2(0, (i * temp_size) + wrap_offset.y); + Point2 end_x = Vector2(rect_size.x, (i * temp_size) + wrap_offset.y); + //var end_x = Vector2(int(rect_size.x) + size - int(rect_size.x) % size, (i * temp_size) + wrap_offset.y); + draw_line(start_x, end_x, color, 1); + } + + for (int i = 0; i < ceil_x; ++i) { + Point2 start_y = Vector2((i * temp_size) + wrap_offset.x, 0); + Point2 end_y = Vector2((i * temp_size) + (wrap_offset.x), rect_size.y); + //var end_y = Vector2((i * temp_size) + (wrap_offset.x), int(rect_size.y) + size - int(rect_size.y) % size); + draw_line(start_y, end_y, color, 1); + } + */ } void PaintVisualGrid::_notification(int p_what) { @@ -81,7 +100,7 @@ void PaintVisualGrid::_notification(int p_what) { } PaintVisualGrid::PaintVisualGrid() { - color = Color(1, 1, 1); + color = Color(1, 1, 1, 1); size = 16; zoom = 0; } diff --git a/modules/paint/paint_visual_grid.h b/modules/paint/paint_visual_grid.h index 5ea8ba260..0f43c2bf8 100644 --- a/modules/paint/paint_visual_grid.h +++ b/modules/paint/paint_visual_grid.h @@ -31,6 +31,8 @@ class PaintVisualGrid : public Control { GDCLASS(PaintVisualGrid, Control); public: + void set_grid_size(const int gs); + void _draw(); PaintVisualGrid(); @@ -44,7 +46,6 @@ public: protected: void _notification(int p_what); static void _bind_methods(); - }; #endif