2022-04-15 19:40:12 +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_action.h"
|
|
|
|
|
|
|
|
void PaintAction::do_action(PaintCanvas *canvas, Array data) {
|
|
|
|
/*
|
2022-04-10 21:14:56 +02:00
|
|
|
if not "cells" in action_data.redo:
|
|
|
|
action_data.redo["cells"] = []
|
|
|
|
action_data.redo["colors"] = []
|
2022-04-15 19:40:12 +02:00
|
|
|
|
2022-04-10 21:14:56 +02:00
|
|
|
if not "cells" in action_data.undo:
|
|
|
|
action_data.undo["cells"] = []
|
|
|
|
action_data.undo["colors"] = []
|
2022-04-15 19:40:12 +02:00
|
|
|
|
2022-04-10 21:14:56 +02:00
|
|
|
if not "cells" in action_data.preview:
|
|
|
|
action_data.preview["cells"] = []
|
|
|
|
action_data.preview["colors"] = []
|
2022-04-15 19:40:12 +02:00
|
|
|
|
2022-04-10 21:14:56 +02:00
|
|
|
if not "layer" in action_data:
|
|
|
|
action_data["layer"] = canvas.active_layer
|
2022-04-15 19:40:12 +02:00
|
|
|
*/
|
|
|
|
}
|
|
|
|
void PaintAction::commit_action(PaintCanvas *canvas) {
|
|
|
|
/*
|
2022-04-10 21:14:56 +02:00
|
|
|
print("NO IMPL commit_action ")
|
|
|
|
return []
|
2022-04-15 19:40:12 +02:00
|
|
|
*/
|
|
|
|
}
|
2022-04-10 21:14:56 +02:00
|
|
|
|
2022-04-15 19:40:12 +02:00
|
|
|
void PaintAction::undo_action(PaintCanvas *canvas) {
|
|
|
|
/*
|
2022-04-10 21:14:56 +02:00
|
|
|
print("NO IMPL undo_action ")
|
2022-04-15 19:40:12 +02:00
|
|
|
*/
|
|
|
|
}
|
|
|
|
void PaintAction::redo_action(PaintCanvas *canvas) {
|
|
|
|
/*
|
2022-04-10 21:14:56 +02:00
|
|
|
print("NO IMPL redo_action ")
|
2022-04-15 19:40:12 +02:00
|
|
|
*/
|
|
|
|
}
|
|
|
|
bool PaintAction::can_commit() {
|
|
|
|
/*
|
2022-04-10 21:14:56 +02:00
|
|
|
return not action_data.redo.empty()
|
2022-04-15 19:40:12 +02:00
|
|
|
*/
|
|
|
|
}
|
2022-04-10 21:14:56 +02:00
|
|
|
|
2022-04-15 19:40:12 +02:00
|
|
|
Array PaintAction::get_x_sym_points(int canvas_width, Vector2i pixel) {
|
|
|
|
/*
|
2022-04-10 21:14:56 +02:00
|
|
|
var p = int(canvas_width - pixel.x)
|
|
|
|
var all_points = [pixel, Vector2(p-1, pixel.y)]
|
2022-04-15 19:40:12 +02:00
|
|
|
|
2022-04-10 21:14:56 +02:00
|
|
|
var points :Array = []
|
|
|
|
for point in all_points:
|
|
|
|
if point in points:
|
|
|
|
continue
|
|
|
|
points.append(point)
|
|
|
|
return points
|
2022-04-15 19:40:12 +02:00
|
|
|
*/
|
|
|
|
}
|
|
|
|
Array PaintAction::get_y_sym_points(int canvas_height, Vector2i pixel) {
|
|
|
|
/*
|
2022-04-10 21:14:56 +02:00
|
|
|
var p = int(canvas_height - pixel.y)
|
|
|
|
var all_points = [pixel, Vector2(pixel.x, p-1)]
|
2022-04-15 19:40:12 +02:00
|
|
|
|
2022-04-10 21:14:56 +02:00
|
|
|
var points :Array = []
|
|
|
|
for point in all_points:
|
|
|
|
if point in points:
|
|
|
|
continue
|
|
|
|
points.append(point)
|
|
|
|
return points
|
2022-04-15 19:40:12 +02:00
|
|
|
*/
|
|
|
|
}
|
|
|
|
Array PaintAction::get_xy_sym_points(int canvas_width, int canvas_height, Vector2i pixel) {
|
|
|
|
/*
|
2022-04-10 21:14:56 +02:00
|
|
|
var all_points = []
|
|
|
|
var xpoints = get_x_sym_points(canvas_width, pixel)
|
2022-04-15 19:40:12 +02:00
|
|
|
|
2022-04-10 21:14:56 +02:00
|
|
|
all_points += get_y_sym_points(canvas_height, xpoints[0])
|
|
|
|
all_points += get_y_sym_points(canvas_height, xpoints[1])
|
2022-04-15 19:40:12 +02:00
|
|
|
|
2022-04-10 21:14:56 +02:00
|
|
|
var points :Array = []
|
|
|
|
for point in all_points:
|
|
|
|
if point in points:
|
|
|
|
continue
|
|
|
|
points.append(point)
|
|
|
|
|
2022-04-15 19:40:12 +02:00
|
|
|
return points
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
Array PaintAction::get_points(PaintCanvas *canvas, Vector2i pixel) {
|
|
|
|
/*
|
2022-04-10 21:14:56 +02:00
|
|
|
var 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)
|
2022-04-15 19:40:12 +02:00
|
|
|
|
2022-04-10 21:14:56 +02:00
|
|
|
return points
|
2022-04-15 19:40:12 +02:00
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
PaintAction::PaintAction() {
|
|
|
|
/*
|
|
|
|
|
|
|
|
action_data["redo"] = {}
|
|
|
|
action_data["undo"] = {}
|
|
|
|
action_data["preview"] = {}
|
|
|
|
|
|
|
|
*/
|
|
|
|
}
|
2022-04-10 21:14:56 +02:00
|
|
|
|
2022-04-15 19:40:12 +02:00
|
|
|
PaintAction::~PaintAction() {
|
|
|
|
}
|
2022-04-10 21:14:56 +02:00
|
|
|
|
2022-04-15 19:40:12 +02:00
|
|
|
void PaintAction::_bind_methods() {
|
|
|
|
}
|