2022-04-15 02:20:27 +02:00
|
|
|
/*
|
|
|
|
Copyright (c) 2019 Flairieve
|
|
|
|
Copyright (c) 2020-2022 cobrapitz
|
|
|
|
Copyright (c) 2022 Péter Magyar
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
|
|
copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "paint_visual_grid.h"
|
|
|
|
|
|
|
|
void PaintVisualGrid::_draw() {
|
2022-04-17 18:14:06 +02:00
|
|
|
if (size == 0) {
|
|
|
|
size = 1;
|
|
|
|
}
|
2022-04-15 02:20:27 +02:00
|
|
|
|
2022-04-17 18:14:06 +02:00
|
|
|
float temp_size = size + zoom;
|
2022-04-15 02:20:27 +02:00
|
|
|
|
2022-04-17 18:14:06 +02:00
|
|
|
Vector2 wrap_offset = Vector2(Math::wrapf(offset.x, 0, temp_size), Math::wrapf(offset.y, 0, temp_size));
|
2022-04-15 02:20:27 +02:00
|
|
|
|
2022-04-17 18:14:06 +02:00
|
|
|
Size2 rect_size = get_size();
|
2022-04-15 02:20:27 +02:00
|
|
|
|
2022-04-17 18:14:06 +02:00
|
|
|
float ceil_x = Math::ceil(rect_size.x / temp_size);
|
|
|
|
float ceil_y = Math::ceil(rect_size.y / temp_size);
|
2022-04-15 02:20:27 +02:00
|
|
|
|
2022-04-17 18:14:06 +02:00
|
|
|
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);
|
|
|
|
}
|
2022-04-15 02:20:27 +02:00
|
|
|
|
2022-04-17 18:14:06 +02:00
|
|
|
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);
|
|
|
|
}
|
2022-04-15 02:20:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PaintVisualGrid::_notification(int p_what) {
|
|
|
|
/*
|
|
|
|
func _enter_tree():
|
|
|
|
set_process(true)
|
|
|
|
|
|
|
|
func _process(delta):
|
|
|
|
if not is_visible_in_tree():
|
|
|
|
return
|
|
|
|
update()
|
|
|
|
*/
|
2022-04-17 18:14:06 +02:00
|
|
|
|
|
|
|
switch (p_what) {
|
|
|
|
/*
|
|
|
|
case NOTIFICATION_PROCESS: {
|
|
|
|
if (!is_visible_in_tree()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
update();
|
|
|
|
} break;
|
|
|
|
*/
|
|
|
|
case NOTIFICATION_DRAW: {
|
|
|
|
_draw();
|
|
|
|
} break;
|
|
|
|
}
|
2022-04-15 02:20:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
PaintVisualGrid::PaintVisualGrid() {
|
2022-04-17 18:14:06 +02:00
|
|
|
color = Color(1, 1, 1);
|
|
|
|
size = 16;
|
|
|
|
zoom = 0;
|
2022-04-15 02:20:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
PaintVisualGrid::~PaintVisualGrid() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void PaintVisualGrid::_bind_methods() {
|
|
|
|
}
|