summaryrefslogtreecommitdiff
path: root/Userland/Applications/PixelPaint
diff options
context:
space:
mode:
authorAndreas Krohn <hamburger1984@gmail.com>2022-08-26 00:03:22 +0200
committerSam Atkins <atkinssj@gmail.com>2022-08-28 11:22:42 +0100
commit8aca5ab3b3770ade693bef38186725eb4d4b1936 (patch)
treeb67deaf65209824089851ae3354a40db56b00435 /Userland/Applications/PixelPaint
parent6e006be9e6b6c5c6c1653be7c88f91a56dc03d3b (diff)
downloadserenity-8aca5ab3b3770ade693bef38186725eb4d4b1936.zip
PixelPaint: Cropping to content with moved layers was broken
When cropping to content with a layer not positioned at 0,0 the moved layers content disappeared and the layers position was not updated according to the crop offset. There's probably an easier/more efficient way, but for my testcase this improves the behavior.
Diffstat (limited to 'Userland/Applications/PixelPaint')
-rw-r--r--Userland/Applications/PixelPaint/Image.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/Userland/Applications/PixelPaint/Image.cpp b/Userland/Applications/PixelPaint/Image.cpp
index ed1d2dce5b..b0d4139bb0 100644
--- a/Userland/Applications/PixelPaint/Image.cpp
+++ b/Userland/Applications/PixelPaint/Image.cpp
@@ -528,7 +528,14 @@ void Image::rotate(Gfx::RotationDirection direction)
void Image::crop(Gfx::IntRect const& cropped_rect)
{
for (auto& layer : m_layers) {
- layer.crop(cropped_rect);
+ auto layer_location = layer.location();
+ auto layer_local_crop_rect = layer.relative_rect().intersected(cropped_rect).translated(-layer_location.x(), -layer_location.y());
+ layer.crop(layer_local_crop_rect);
+
+ auto new_layer_x = max(0, layer_location.x() - cropped_rect.x());
+ auto new_layer_y = max(0, layer_location.y() - cropped_rect.y());
+
+ layer.set_location({ new_layer_x, new_layer_y });
}
m_size = { cropped_rect.width(), cropped_rect.height() };