From a46eb96ca7bd84aad27599a08827009a59b09200 Mon Sep 17 00:00:00 2001 From: cobrapitz <12397702+cobrapitz@users.noreply.github.com> Date: Tue, 3 Nov 2020 19:24:15 +0100 Subject: [PATCH] added pastecut tool --- addons/graphics_editor/actions/PasteCut.gd | 56 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 addons/graphics_editor/actions/PasteCut.gd diff --git a/addons/graphics_editor/actions/PasteCut.gd b/addons/graphics_editor/actions/PasteCut.gd new file mode 100644 index 0000000..fceafa1 --- /dev/null +++ b/addons/graphics_editor/actions/PasteCut.gd @@ -0,0 +1,56 @@ +extends GEAction +class_name GEPasteCut + + +#data[2] = selection_pos +#data[3] = selection_color +#data[4] = cut pos +#data[5] = cut size +func do_action(canvas, data: Array): + .do_action(canvas, data) + + for pixel_pos in GEUtils.get_pixels_in_line(data[0], data[1]): + for idx in range(data[2].size()): + var pixel = data[2][idx] + var color = data[3][idx] + pixel -= data[4] + data[5] / 2 + pixel += pixel_pos + + if canvas.get_pixel_v(pixel) == null: + continue + + var found = action_data.redo.cells.find(pixel) + if found == -1: + action_data.redo.cells.append(pixel) + action_data.redo.colors.append(color) + else: + action_data.redo.colors[found] = color + + found = action_data.undo.cells.find(pixel) + if found == -1: + action_data.undo.colors.append(canvas.get_pixel_v(pixel)) + action_data.undo.cells.append(pixel) + + canvas.set_pixel_v(pixel, color) + + +func commit_action(canvas): + canvas.clear_preview_layer() + return [] + + +func undo_action(canvas): + var cells = action_data.undo.cells + var colors = action_data.undo.colors + for idx in range(cells.size()): + canvas._set_pixel_v(action_data.layer, cells[idx], colors[idx]) + + +func redo_action(canvas): + var cells = action_data.redo.cells + var colors = action_data.redo.colors + for idx in range(cells.size()): + canvas._set_pixel_v(action_data.layer, cells[idx], colors[idx]) + + +