summaryrefslogtreecommitdiff
path: root/Userland/Applications/PixelPaint/ImageEditor.cpp
diff options
context:
space:
mode:
authorMustafa Quraish <mustafaq9@gmail.com>2021-09-11 14:31:41 -0400
committerAndreas Kling <kling@serenityos.org>2021-09-12 00:17:04 +0200
commitf890f8529ae882795b7358fab5cdc524dc87da7e (patch)
tree307eb3cf99fde498c1d5212fdcd4941dc996d27b /Userland/Applications/PixelPaint/ImageEditor.cpp
parent1e1e5bb5f7a1c086078d1c289c511a59e3157db4 (diff)
downloadserenity-f890f8529ae882795b7358fab5cdc524dc87da7e.zip
PixelPaint: Make `Fit Image To View` account for rulers
Because of the way rulers are implemented in the ImageEditor currently, the `Fit Image To View` action doesn't work correctly with them enabled. This patch makes them adjust to the effective viewport area and account for the rulers. This is a bit of a hack, but the correct way to deal with this would be to put the rulers in a new widget so they don't interfere with the actual viewport rect (which is being used all over).
Diffstat (limited to 'Userland/Applications/PixelPaint/ImageEditor.cpp')
-rw-r--r--Userland/Applications/PixelPaint/ImageEditor.cpp20
1 files changed, 17 insertions, 3 deletions
diff --git a/Userland/Applications/PixelPaint/ImageEditor.cpp b/Userland/Applications/PixelPaint/ImageEditor.cpp
index 9c23d4f065..d34f7b3d51 100644
--- a/Userland/Applications/PixelPaint/ImageEditor.cpp
+++ b/Userland/Applications/PixelPaint/ImageEditor.cpp
@@ -562,13 +562,27 @@ void ImageEditor::scale_by(float scale_delta)
void ImageEditor::fit_image_to_view()
{
+ auto viewport_rect = rect();
+ m_pan_origin = Gfx::FloatPoint(0, 0);
+
+ if (m_show_rulers) {
+ viewport_rect = {
+ viewport_rect.x() + m_ruler_thickness,
+ viewport_rect.y() + m_ruler_thickness,
+ viewport_rect.width() - m_ruler_thickness,
+ viewport_rect.height() - m_ruler_thickness
+ };
+ }
+
const float border_ratio = 0.95f;
auto image_size = image().size();
- auto height_ratio = rect().height() / (float)image_size.height();
- auto width_ratio = rect().width() / (float)image_size.width();
+ auto height_ratio = viewport_rect.height() / (float)image_size.height();
+ auto width_ratio = viewport_rect.width() / (float)image_size.width();
m_scale = border_ratio * min(height_ratio, width_ratio);
- m_pan_origin = Gfx::FloatPoint(0, 0);
+ float offset = m_show_rulers ? -m_ruler_thickness / (m_scale * 2.0f) : 0.0f;
+ m_pan_origin = Gfx::FloatPoint(offset, offset);
+
relayout();
}