From c17b32e0586a497554a6f3811ef6170f6b772560 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Sat, 11 Mar 2023 23:49:47 +0000 Subject: [PATCH] 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. --- Userland/Applications/PixelPaint/Image.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Userland/Applications/PixelPaint/Image.cpp b/Userland/Applications/PixelPaint/Image.cpp index 2d476d685f..2de8f72d01 100644 --- a/Userland/Applications/PixelPaint/Image.cpp +++ b/Userland/Applications/PixelPaint/Image.cpp @@ -677,8 +677,11 @@ ErrorOr 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(); + auto scaled_top_left = layer_rect.top_left().scaled(scale_x, scale_y).to_rounded(); + auto scaled_bottom_right = layer_rect.bottom_right().translated(1).scaled(scale_x, scale_y).to_rounded(); + 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); }