Ported LineAction.

This commit is contained in:
Relintai 2022-06-20 23:22:52 +02:00
parent 61a8942070
commit bafde8e9db
2 changed files with 51 additions and 35 deletions

View File

@ -31,46 +31,61 @@ SOFTWARE.
void LineAction::do_action(PaintCanvas *canvas, const Array &data) { void LineAction::do_action(PaintCanvas *canvas, const Array &data) {
PaintAction::do_action(canvas, data); PaintAction::do_action(canvas, data);
/* if (!mouse_start_pos_set) {
.do_action(canvas, data) mouse_start_pos = data[0];
mouse_start_pos_set = true;
if mouse_start_pos == null: }
mouse_start_pos = data[0]
preview_cells.resize(0);
action_data.preview.cells.clear() preview_colors.resize(0);
action_data.preview.colors.clear() canvas->clear_preview_layer();
canvas.clear_preview_layer()
PoolVector2iArray pixels = PaintUtilities::get_pixels_in_line(data[0], mouse_start_pos);
var pixels = GEUtils.get_pixels_in_line(data[0], mouse_start_pos)
for pixel in pixels: for (int i = 0; i < pixels.size(); ++i) {
if canvas.is_alpha_locked() and canvas.get_pixel_v(pixel) == Color.transparent: Vector2i pixel = pixels[i];
continue
Color col = canvas->get_pixel_v(pixel);
canvas.set_preview_pixel_v(pixel, data[2])
action_data.preview.cells.append(pixel) if (canvas->is_alpha_locked() && col.a < 0.00001) {
action_data.preview.colors.append(data[2]) continue;
*/ }
Color nc = data[2];
canvas->set_preview_pixel_v(pixel, nc);
preview_cells.append(pixel);
preview_colors.append(nc);
}
} }
void LineAction::commit_action(PaintCanvas *canvas) { void LineAction::commit_action(PaintCanvas *canvas) {
/* canvas->clear_preview_layer();
canvas.clear_preview_layer()
var cells = action_data.preview.cells for (int i = 0; i < preview_cells.size(); ++i) {
var colors = action_data.preview.colors Vector2i pc = preview_cells[i];
for idx in range(cells.size()):
if canvas.get_pixel_v(cells[idx]) == null: if (!canvas->validate_pixel_v(pc)) {
continue continue;
action_data.undo.cells.append(cells[idx]) }
action_data.undo.colors.append(canvas.get_pixel_v(cells[idx]))
Color pcol = preview_colors[i];
canvas.set_pixel_v(cells[idx], colors[idx])
undo_cells.append(pc);
action_data.redo.cells.append(cells[idx]) undo_colors.append(canvas->get_pixel_v(pc));
action_data.redo.colors.append(colors[idx])
mouse_start_pos = null canvas->set_pixel_v(pc, pcol);
*/
redo_cells.append(pc);
redo_colors.append(pcol);
}
mouse_start_pos_set = false;
} }
LineAction::LineAction() { LineAction::LineAction() {
mouse_start_pos_set = false;
} }
LineAction::~LineAction() { LineAction::~LineAction() {

View File

@ -39,6 +39,7 @@ public:
LineAction(); LineAction();
~LineAction(); ~LineAction();
bool mouse_start_pos_set;
Vector2 mouse_start_pos; Vector2 mouse_start_pos;
protected: protected: