mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2024-12-23 12:26:59 +01:00
Reimplemented the PaintVisualGrid differently.
This commit is contained in:
parent
5e03f0f82b
commit
5f683261ff
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,33 +24,52 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
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);
|
for (int x = 0; x < sx; x += size) {
|
||||||
float ceil_y = Math::ceil(rect_size.y / temp_size);
|
draw_line(Vector2(x, 0), Vector2(x, sy), color, 1);
|
||||||
|
|
||||||
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) {
|
for (int y = 0; y < sy; y += size) {
|
||||||
Point2 start_y = Vector2((i * temp_size) + wrap_offset.x, 0);
|
draw_line(Vector2(0, y), Vector2(sx, y), color, 1);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
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) {
|
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;
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user