1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:57:44 +00:00

PixelPaint: Make Resize Image scale each layer to the correct size

The "Resize Image" action will now scale layer such that
the corners of each layer maintain their position relative to the edge
of the canvas.

Previously, each layer was scaled to the same size of the canvas.
This commit is contained in:
Tim Ledbetter 2023-03-11 23:49:47 +00:00 committed by Andreas Kling
parent 92a0a7e3fa
commit c17b32e058

View file

@ -677,8 +677,11 @@ ErrorOr<void> Image::resize(Gfx::IntSize new_size, Gfx::Painter::ScalingMode sca
if (layer->is_selected())
selected_layer_index = i;
Gfx::IntPoint new_location(scale_x * new_layer->location().x(), scale_y * new_layer->location().y());
TRY(new_layer->resize(new_size, new_location, scaling_mode, Layer::NotifyClients::No));
auto layer_rect = layer->relative_rect().to_type<float>();
auto scaled_top_left = layer_rect.top_left().scaled(scale_x, scale_y).to_rounded<int>();
auto scaled_bottom_right = layer_rect.bottom_right().translated(1).scaled(scale_x, scale_y).to_rounded<int>();
auto scaled_layer_rect = Gfx::IntRect::from_two_points(scaled_top_left, scaled_bottom_right);
TRY(new_layer->resize(scaled_layer_rect, scaling_mode, Layer::NotifyClients::No));
resized_layers.unchecked_append(new_layer);
}