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

PixelPaint: Add Fit Image To View action

This is a feature I missed from Photoshop: it sets the scale and
position so that the image fits (it's longest dimension) into
the editor view. There's a 5% border left around the image to
provide context. This is just arbitrary seemed like the right
amount after some trial and error.
This commit is contained in:
Mustafa Quraish 2021-09-07 14:14:18 -04:00 committed by Andreas Kling
parent 111ef19114
commit d9832f8d0b
3 changed files with 18 additions and 0 deletions

View file

@ -425,6 +425,18 @@ void ImageEditor::scale_by(float scale_delta)
}
}
void ImageEditor::fit_image_to_view()
{
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();
m_scale = border_ratio * min(height_ratio, width_ratio);
m_pan_origin = Gfx::FloatPoint(0, 0);
relayout();
}
void ImageEditor::reset_scale_and_position()
{
if (m_scale != 1.0f)