mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 17:40:27 +00:00
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).
This commit is contained in:
parent
1e1e5bb5f7
commit
f890f8529a
Notes:
sideshowbarker
2024-07-18 04:14:01 +09:00
Author: https://github.com/mustafaquraish Commit: https://github.com/SerenityOS/serenity/commit/f890f8529ae Pull-request: https://github.com/SerenityOS/serenity/pull/9974 Issue: https://github.com/SerenityOS/serenity/issues/9971 Reviewed-by: https://github.com/Granddave ✅ Reviewed-by: https://github.com/TobyAsE
1 changed files with 17 additions and 3 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue