Ported RectAction.

This commit is contained in:
Relintai 2022-06-21 10:08:41 +02:00
parent ad3a5aa196
commit 1e979d3061
2 changed files with 51 additions and 38 deletions

View File

@ -31,56 +31,68 @@ SOFTWARE.
void RectAction::do_action(PaintCanvas *canvas, const Array &data) { void RectAction::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];
//print("init:", mouse_start_pos)
mouse_start_pos_set = true;
}
if mouse_start_pos == null: undo_cells.clear();
mouse_start_pos = data[0] undo_colors.clear();
#print("init:", mouse_start_pos) preview_cells.clear();
preview_colors.clear();
canvas->clear_preview_layer();
action_data.undo.cells.clear() Vector2i p = mouse_start_pos;
action_data.undo.colors.clear() Vector2i current_mouse_pos = data[0];
action_data.preview.cells.clear() Vector2i s = current_mouse_pos - mouse_start_pos;
action_data.preview.colors.clear()
canvas.clear_preview_layer()
var p = mouse_start_pos PoolVector2iArray pixels = PaintUtilities::get_pixels_in_line(p, p + Vector2i(s.x, 0));
var s = data[0] - mouse_start_pos pixels.append_array(PaintUtilities::get_pixels_in_line(p, p + Vector2(0, s.y)));
var pixels = GEUtils.get_pixels_in_line(p, p + Vector2(s.x, 0)) pixels.append_array(PaintUtilities::get_pixels_in_line(p + s, p + s + Vector2(0, -s.y)));
pixels += GEUtils.get_pixels_in_line(p, p + Vector2(0, s.y)) pixels.append_array(PaintUtilities::get_pixels_in_line(p + s, p + s + Vector2(-s.x, 0)));
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: for (int i = 0; i < pixels.size(); ++i) {
if canvas.get_pixel_v(pixel) == null: Vector2i pixel = pixels[i];
continue
if canvas.is_alpha_locked() and canvas.get_pixel_v(pixel) == Color.transparent: if (!canvas->validate_pixel_v(pixel)) {
continue continue;
}
canvas.set_preview_pixel_v(pixel, data[2]) Color col = canvas->get_pixel_v(pixel);
action_data.undo.cells.append(pixel)
action_data.undo.colors.append(canvas.get_pixel_v(pixel)) if (canvas->is_alpha_locked() && col.a < 0.00001) {
action_data.preview.cells.append(pixel) continue;
action_data.preview.colors.append(data[2]) }
*/
Color tc = data[2];
canvas->set_preview_pixel_v(pixel, tc);
undo_cells.append(pixel);
undo_colors.append(col);
preview_cells.append(pixel);
preview_colors.append(tc);
}
} }
void RectAction::commit_action(PaintCanvas *canvas) { void RectAction::commit_action(PaintCanvas *canvas) {
/* canvas->clear_preview_layer();
canvas.clear_preview_layer()
var cells = action_data.preview.cells
var colors = action_data.preview.colors
for idx in range(cells.size()):
canvas.set_pixel_v(cells[idx], colors[idx])
action_data.redo.cells.append(cells[idx]) for (int idx = 0; idx < preview_cells.size(); ++idx) {
action_data.redo.colors.append(colors[idx]) Vector2i pcell = preview_cells[idx];
mouse_start_pos = null Color pcolor = preview_colors[idx];
*/
canvas->set_pixel_v(pcell, pcolor);
redo_cells.append(pcell);
redo_colors.append(pcolor);
}
mouse_start_pos_set = false;
} }
RectAction::RectAction() { RectAction::RectAction() {
mouse_start_pos_set = false;
} }
RectAction::~RectAction() { RectAction::~RectAction() {

View File

@ -39,7 +39,8 @@ public:
RectAction(); RectAction();
~RectAction(); ~RectAction();
Vector2 mouse_start_pos; Vector2i mouse_start_pos;
bool mouse_start_pos_set;
protected: protected:
static void _bind_methods(); static void _bind_methods();