Bit more work on porting PaintActions.

This commit is contained in:
Relintai 2022-04-18 14:10:21 +02:00
parent 111daab50e
commit 71ac7bc4e3
5 changed files with 68 additions and 63 deletions

View File

@ -30,37 +30,39 @@ SOFTWARE.
void BucketAction::do_action(PaintCanvas *canvas, const Array &data) {
PaintAction::do_action(canvas, data);
/*
Color col = canvas->get_pixel_v(data[0]);
Color col2 = data[2];
Vector2i pos = data[0];
if (col == col2) {
return;
Color col = canvas->get_pixel_v(pos);
Color col2 = data[2];
if (col == col2) {
return;
}
PoolVector2iArray pixels = canvas->select_same_color(pos.x, pos.y);
for (int i = 0; i < pixels.size(); ++i) {
Vector2i pixel = pixels[i];
if (undo_cells.contains(pixel)) {
continue;
}
PoolVector2iArray pixels = canvas->select_same_color(data[0].x, data[0].y);
Color col = canvas->get_pixel_v(pixel);
for (int i = 0; i < pixels.size(); ++i) {
Vector2i pixel = pixels[i];
if (pv2ia_contains(undo_cells, pixel)) {
continue;
}
if canvas.is_alpha_locked() and canvas.get_pixel_v(pixel) == Color.transparent:
continue;
action_data.undo.colors.append(canvas.get_pixel_v(pixel));
action_data.undo.cells.append(pixel);
canvas.set_pixel_v(pixel, data[2]);
action_data.redo.cells.append(pixel);
action_data.redo.colors.append(data[2]);
if (canvas->is_alpha_locked() && col.a < 0.00001) {
continue;
}
*/
undo_cells.append(pixel);
undo_colors.append(col);
canvas->set_pixel_v(pixel, col2);
redo_cells.append(pixel);
redo_colors.append(col2);
}
}
BucketAction::BucketAction() {

View File

@ -34,31 +34,29 @@ bool CutAction::can_commit() {
void CutAction::do_action(PaintCanvas *canvas, const Array &data) {
PaintAction::do_action(canvas, data);
/*
.do_action(canvas, data)
/*
if mouse_start_pos == null:
mouse_start_pos = data[0]
mouse_end_pos = data[0]
mouse_start_pos = data[0];
action_data.preview.cells.clear()
action_data.preview.colors.clear()
canvas.clear_preview_layer()
mouse_end_pos = data[0];
var p = mouse_start_pos
var s = mouse_end_pos - mouse_start_pos
action_data.preview.cells.clear();
action_data.preview.colors.clear();
canvas.clear_preview_layer();
var pixels = GEUtils.get_pixels_in_line(p, p + Vector2(s.x, 0))
pixels += GEUtils.get_pixels_in_line(p, p + Vector2(0, s.y))
pixels += GEUtils.get_pixels_in_line(p + s, p + s + Vector2(0, -s.y))
pixels += GEUtils.get_pixels_in_line(p + s, p + s + Vector2(-s.x, 0))
var p = mouse_start_pos;
var s = mouse_end_pos - mouse_start_pos;
var pixels = GEUtils.get_pixels_in_line(p, p + Vector2(s.x, 0));
pixels += GEUtils.get_pixels_in_line(p, p + Vector2(0, s.y));
pixels += GEUtils.get_pixels_in_line(p + s, p + s + Vector2(0, -s.y));
pixels += GEUtils.get_pixels_in_line(p + s, p + s + Vector2(-s.x, 0));
for pixel in pixels:
canvas.set_preview_pixel_v(pixel, selection_color)
action_data.preview.cells.append(pixel)
action_data.preview.colors.append(selection_color)
*/
canvas.set_preview_pixel_v(pixel, selection_color);
action_data.preview.cells.append(pixel);
action_data.preview.colors.append(selection_color);
*/
}
void CutAction::commit_action(PaintCanvas *canvas) {
/*

View File

@ -31,7 +31,6 @@ void PaintAction::do_action(PaintCanvas *canvas, const Array &data) {
layer = canvas->get_active_layer();
}
void PaintAction::commit_action(PaintCanvas *canvas) {
ERR_PRINT("NO IMPL commit_action");
}
void PaintAction::undo_action(PaintCanvas *canvas) {

View File

@ -31,25 +31,31 @@ SOFTWARE.
void PencilAction::do_action(PaintCanvas *canvas, const Array &data) {
PaintAction::do_action(canvas, data);
/*
.do_action(canvas, data)
var pixels = GEUtils.get_pixels_in_line(data[0], data[1])
for pixel in pixels:
for p in get_points(canvas, pixel):
_set_pixel(canvas, p, data[2])
*/
Color c = data[2];
PoolVector2iArray pixels = PaintUtilities::get_pixels_in_line(data[0], data[1]);
for (int i = 0; i < pixels.size(); ++i) {
Vector2i pixel = pixels[i];
PoolVector2iArray points = get_points(canvas, pixel);
for (int j = 0; j < points.size(); ++j) {
Vector2i p = points[i];
_set_pixel(canvas, p, c);
}
}
}
void PencilAction::_set_pixel(PaintCanvas *canvas, Vector2i pixel, Color color) {
/*
action_data.undo.colors.append(canvas.get_pixel_v(pixel))
action_data.undo.cells.append(pixel)
canvas.set_pixel_v(pixel, color)
action_data.redo.cells.append(pixel)
action_data.redo.colors.append(color)
*/
undo_colors.append(canvas->get_pixel_v(pixel));
undo_cells.append(pixel);
canvas->set_pixel_v(pixel, color);
redo_cells.append(pixel);
redo_colors.append(color);
}
PencilAction::PencilAction() {

View File

@ -622,8 +622,8 @@ void PaintWindow::commit_action() {
_cut_pos = ca->mouse_start_pos;
_cut_size = ca->mouse_end_pos - ca->mouse_start_pos;
PoolVector2iArray dcell = ca->action_data_redo["cells"];
PoolColorArray dcol = ca->action_data_redo["colors"];
PoolVector2iArray dcell = ca->redo_cells;
PoolColorArray dcol = ca->redo_colors;
//_selection_cells = dcell.duplicate();
//_selection_colors = dcol.duplicate();