2022-04-15 02:20:27 +02:00
|
|
|
/*
|
|
|
|
Copyright (c) 2019 Flairieve
|
|
|
|
Copyright (c) 2020-2022 cobrapitz
|
2022-12-31 19:34:43 +01:00
|
|
|
Copyright (c) 2022-2023 Péter Magyar
|
2022-04-15 02:20:27 +02:00
|
|
|
|
|
|
|
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"
|
|
|
|
|
2022-11-19 02:31:39 +01:00
|
|
|
int PaintVisualGrid::get_grid_size() {
|
|
|
|
return _grid_size;
|
|
|
|
}
|
2022-06-20 00:59:32 +02:00
|
|
|
void PaintVisualGrid::set_grid_size(const int gs) {
|
2022-11-19 02:31:39 +01:00
|
|
|
_grid_size = gs;
|
2022-06-20 00:59:32 +02:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2022-11-19 02:31:39 +01:00
|
|
|
Color PaintVisualGrid::get_grid_color() {
|
|
|
|
return _grid_color;
|
|
|
|
}
|
|
|
|
void PaintVisualGrid::set_grid_color(const Color &val) {
|
|
|
|
_grid_color = val;
|
|
|
|
update();
|
|
|
|
}
|
2022-06-20 00:59:32 +02:00
|
|
|
|
2022-04-15 02:20:27 +02:00
|
|
|
void PaintVisualGrid::_notification(int p_what) {
|
2022-11-19 02:31:39 +01:00
|
|
|
switch (p_what) {
|
2022-11-19 13:21:05 +01:00
|
|
|
case NOTIFICATION_ENTER_TREE:
|
2022-11-19 19:26:19 +01:00
|
|
|
case PaintNode::NOTIFICATION_PARENT_PAINT_NODE_RESIZED: {
|
2022-11-20 21:42:04 +01:00
|
|
|
PaintNode *pn = get_parent_paint_node();
|
2022-11-19 13:16:54 +01:00
|
|
|
|
|
|
|
if (pn) {
|
|
|
|
set_size(pn->get_size());
|
|
|
|
}
|
|
|
|
} break;
|
2022-11-19 02:31:39 +01:00
|
|
|
case NOTIFICATION_DRAW: {
|
|
|
|
ERR_FAIL_COND(_grid_size <= 0);
|
2022-04-15 02:20:27 +02:00
|
|
|
|
2022-11-19 02:31:39 +01:00
|
|
|
Size2 rect_size = get_size();
|
|
|
|
int sx = rect_size.x;
|
|
|
|
int sy = rect_size.y;
|
2022-04-17 18:14:06 +02:00
|
|
|
|
2022-11-19 02:31:39 +01:00
|
|
|
for (int x = 0; x < sx; x += _grid_size) {
|
|
|
|
draw_line(Vector2(x, 0), Vector2(x, sy), _grid_color, 1);
|
2022-04-17 18:14:06 +02:00
|
|
|
}
|
|
|
|
|
2022-11-19 02:31:39 +01:00
|
|
|
for (int y = 0; y < sy; y += _grid_size) {
|
|
|
|
draw_line(Vector2(0, y), Vector2(sx, y), _grid_color, 1);
|
|
|
|
}
|
2022-04-17 18:14:06 +02:00
|
|
|
} break;
|
|
|
|
}
|
2022-04-15 02:20:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
PaintVisualGrid::PaintVisualGrid() {
|
2022-11-19 02:31:39 +01:00
|
|
|
_grid_color = Color(1, 1, 1, 0.42);
|
|
|
|
_grid_size = 2;
|
2022-04-15 02:20:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
PaintVisualGrid::~PaintVisualGrid() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void PaintVisualGrid::_bind_methods() {
|
2022-11-19 02:31:39 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_grid_size"), &PaintVisualGrid::get_grid_size);
|
2022-11-14 17:11:38 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_grid_size", "size"), &PaintVisualGrid::set_grid_size);
|
2022-11-19 02:31:39 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "grid_size"), "set_grid_size", "get_grid_size");
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("get_grid_color"), &PaintVisualGrid::get_grid_color);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_grid_color", "color"), &PaintVisualGrid::set_grid_color);
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "grid_color"), "set_grid_color", "get_grid_color");
|
2022-04-15 02:20:27 +02:00
|
|
|
}
|