Reimplemented the PaintVisualGrid differently.

This commit is contained in:
Relintai 2022-06-20 00:59:32 +02:00
parent 5e03f0f82b
commit 5f683261ff
3 changed files with 40 additions and 20 deletions

View File

@ -101,7 +101,7 @@ void PaintCanvas::set_grid_size(const int size) {
if (grid) { if (grid) {
int s = size * _pixel_size; int s = size * _pixel_size;
grid->set_size(Size2(s, s)); grid->set_grid_size(s);
} }
} }

View File

@ -24,11 +24,29 @@ SOFTWARE.
#include "paint_visual_grid.h" #include "paint_visual_grid.h"
void PaintVisualGrid::set_grid_size(const int gs) {
size = gs;
update();
}
void PaintVisualGrid::_draw() { void PaintVisualGrid::_draw() {
if (size == 0) { if (size == 0) {
size = 1; size = 1;
} }
Size2 rect_size = get_size();
int sx = rect_size.x;
int sy = rect_size.y;
for (int x = 0; x < sx; x += size) {
draw_line(Vector2(x, 0), Vector2(x, sy), 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; float temp_size = size + zoom;
Vector2 wrap_offset = Vector2(Math::wrapf(offset.x, 0, temp_size), Math::wrapf(offset.y, 0, temp_size)); Vector2 wrap_offset = Vector2(Math::wrapf(offset.x, 0, temp_size), Math::wrapf(offset.y, 0, temp_size));
@ -51,6 +69,7 @@ void PaintVisualGrid::_draw() {
//var end_y = Vector2((i * temp_size) + (wrap_offset.x), int(rect_size.y) + size - int(rect_size.y) % size); //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); draw_line(start_y, end_y, color, 1);
} }
*/
} }
void PaintVisualGrid::_notification(int p_what) { void PaintVisualGrid::_notification(int p_what) {
@ -81,7 +100,7 @@ void PaintVisualGrid::_notification(int p_what) {
} }
PaintVisualGrid::PaintVisualGrid() { PaintVisualGrid::PaintVisualGrid() {
color = Color(1, 1, 1); color = Color(1, 1, 1, 1);
size = 16; size = 16;
zoom = 0; zoom = 0;
} }

View File

@ -31,6 +31,8 @@ class PaintVisualGrid : public Control {
GDCLASS(PaintVisualGrid, Control); GDCLASS(PaintVisualGrid, Control);
public: public:
void set_grid_size(const int gs);
void _draw(); void _draw();
PaintVisualGrid(); PaintVisualGrid();
@ -44,7 +46,6 @@ public:
protected: protected:
void _notification(int p_what); void _notification(int p_what);
static void _bind_methods(); static void _bind_methods();
}; };
#endif #endif