mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 23:27:35 +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
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()
|
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;
|
const float border_ratio = 0.95f;
|
||||||
auto image_size = image().size();
|
auto image_size = image().size();
|
||||||
auto height_ratio = rect().height() / (float)image_size.height();
|
auto height_ratio = viewport_rect.height() / (float)image_size.height();
|
||||||
auto width_ratio = rect().width() / (float)image_size.width();
|
auto width_ratio = viewport_rect.width() / (float)image_size.width();
|
||||||
m_scale = border_ratio * min(height_ratio, width_ratio);
|
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();
|
relayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue