diff --git a/modules/paint/actions/paint_action.cpp b/modules/paint/actions/paint_action.cpp index d6f977555..ec91b19d6 100644 --- a/modules/paint/actions/paint_action.cpp +++ b/modules/paint/actions/paint_action.cpp @@ -4,21 +4,21 @@ 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 +of this software && 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 +copies of the Software, && 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 above copyright notice && this permission notice shall be included in all +copies || 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 +FITNESS FOR A PARTICULAR PURPOSE && NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS || COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES || OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT || OTHERWISE, ARISING FROM, +OUT OF || IN CONNECTION WITH THE SOFTWARE || THE USE || OTHER DEALINGS IN THE SOFTWARE. */ @@ -92,44 +92,73 @@ PoolVector2iArray PaintAction::get_xy_sym_points(const int canvas_width, const i return points; } + PoolVector2iArray PaintAction::get_points(PaintCanvas *canvas, const Vector2i &pixel) { - /* PoolVector2iArray points; - if canvas.symmetry_x and canvas.symmetry_y: - var sym_points = get_xy_sym_points(canvas.canvas_width, canvas.canvas_height, pixel) - for point in sym_points: - if point in action_data.undo.cells or canvas.get_pixel_v(point) == null: - continue - if canvas.is_alpha_locked() and canvas.get_pixel_v(pixel) == Color.transparent: - continue - points.append(point) - elif canvas.symmetry_y: - var sym_points = get_y_sym_points(canvas.canvas_height, pixel) - for point in sym_points: - if point in action_data.undo.cells or canvas.get_pixel_v(point) == null: - continue - if canvas.is_alpha_locked() and canvas.get_pixel_v(pixel) == Color.transparent: - continue - points.append(point) - elif canvas.symmetry_x: - var sym_points = get_x_sym_points(canvas.canvas_width, pixel) - for point in sym_points: - if point in action_data.undo.cells or canvas.get_pixel_v(point) == null: - continue - if canvas.is_alpha_locked() and canvas.get_pixel_v(pixel) == Color.transparent: - continue - points.append(point) - else: - if pixel in action_data.undo.cells or canvas.get_pixel_v(pixel) == null: - return [] - if canvas.is_alpha_locked() and canvas.get_pixel_v(pixel) == Color.transparent: - return [] - points.append(pixel) + + if (canvas->symmetry_x && canvas->symmetry_y) { + PoolVector2iArray sym_points = get_xy_sym_points(canvas->get_canvas_width(), canvas->get_canvas_height(), pixel); + + for (int i = 0; i < sym_points.size(); ++i) { + Vector2i point = sym_points[i]; + + if (undo_cells.contains(point) || !canvas->validate_pixel_v(point)) { + continue; + } + + if (canvas->is_alpha_locked() && canvas->get_pixel_v(pixel) == Color(0, 0, 0, 0)) { + continue; + } + + points.append(point); + } + } else if (canvas->symmetry_y) { + PoolVector2iArray sym_points = get_y_sym_points(canvas->get_canvas_height(), pixel); + + for (int i = 0; i < sym_points.size(); ++i) { + Vector2i point = sym_points[i]; + + if (undo_cells.contains(point) || !canvas->validate_pixel_v(point)) { + continue; + } + + if (canvas->is_alpha_locked() && canvas->get_pixel_v(pixel) == Color(0, 0, 0, 0)) { + continue; + } + + points.append(point); + } + } else if (canvas->symmetry_x) { + PoolVector2iArray sym_points = get_x_sym_points(canvas->get_canvas_width(), pixel); + + for (int i = 0; i < sym_points.size(); ++i) { + Vector2i point = sym_points[i]; + + if (undo_cells.contains(point) || !canvas->validate_pixel_v(point)) { + continue; + } + + if (canvas->is_alpha_locked() && canvas->get_pixel_v(pixel) == Color(0, 0, 0, 0)) { + continue; + } + + points.append(point); + } + } else { + if (undo_cells.contains(pixel) || !canvas->validate_pixel_v(pixel)) { + //empty + return points; + } + + if (canvas->is_alpha_locked() && canvas->get_pixel_v(pixel) == Color(0, 0, 0, 0)) { + //empty + return points; + } + + points.append(pixel); + } return points; - */ - - return PoolVector2iArray(); } void PaintAction::draw_points(PaintCanvas *canvas, const PoolVector2iArray &point_arr, const PoolColorArray &color_arr) { diff --git a/modules/paint/paint_canvas.cpp b/modules/paint/paint_canvas.cpp index b6bc768be..6a18fbbad 100644 --- a/modules/paint/paint_canvas.cpp +++ b/modules/paint/paint_canvas.cpp @@ -432,6 +432,15 @@ Color PaintCanvas::get_preview_pixel(const int x, const int y) { return preview_layer->get_pixel(x, y); } + +bool PaintCanvas::validate_pixel_v(const Vector2i &pos) const { + if (active_layer.is_valid()) { + return active_layer->validate_pixel_v(pos); + } + + return false; +} + void PaintCanvas::toggle_grid() { grid->set_visible(!grid->is_visible()); } diff --git a/modules/paint/paint_canvas.h b/modules/paint/paint_canvas.h index 738f67b44..46c4578a5 100644 --- a/modules/paint/paint_canvas.h +++ b/modules/paint/paint_canvas.h @@ -99,6 +99,8 @@ public: Color get_preview_pixel_v(const Vector2i &pos); Color get_preview_pixel(const int x, const int y); + bool validate_pixel_v(const Vector2i &pos) const; + void toggle_grid(); void show_grid(); void hide_grid(); diff --git a/modules/paint/paint_canvas_layer.cpp b/modules/paint/paint_canvas_layer.cpp index 803f94047..62d598774 100644 --- a/modules/paint/paint_canvas_layer.cpp +++ b/modules/paint/paint_canvas_layer.cpp @@ -100,6 +100,13 @@ Color PaintCanvasLayer::get_pixel(const int x, const int y) { return pixel; } +bool PaintCanvasLayer::validate_pixel_v(const Vector2i &pos) const { + if (pos.x < 0 || pos.y < 0 || pos.x >= image->get_width() || pos.y >= image->get_height()) { + return false; + } + + return true; +} void PaintCanvasLayer::clear() { //Color.transparent image->fill(Color(1.00, 1.00, 1.00, 0.00)); diff --git a/modules/paint/paint_canvas_layer.h b/modules/paint/paint_canvas_layer.h index b69b23184..91c5afdf7 100644 --- a/modules/paint/paint_canvas_layer.h +++ b/modules/paint/paint_canvas_layer.h @@ -56,6 +56,7 @@ public: void resize(const int width, const int height); void set_pixel(const int x, const int y, const Color &color); Color get_pixel(const int x, const int y); + bool validate_pixel_v(const Vector2i &pos) const; void clear(); void update_texture();