diff options
author | FrHun <28605587+frhun@users.noreply.github.com> | 2022-12-06 00:12:02 +0100 |
---|---|---|
committer | Sam Atkins <atkinssj@gmail.com> | 2022-12-23 12:16:46 +0000 |
commit | 79f5c49afeff6db89e66c325acf96b36551664a3 (patch) | |
tree | d7d072f8be3b5b5d12c92d42152ef59843f3274b /Userland/Applications | |
parent | 6187cfec49225d091b7c8d0e4a30d7e324dc7dab (diff) | |
download | serenity-79f5c49afeff6db89e66c325acf96b36551664a3.zip |
Magnifier: Eliminate flickering when downsizing
Previously the content flickered when downsizing the window, because the
previously grabbed frame was still active, but was now too large for the
window.
This crops the source rect to a size where it now perfectly fits the
content area.
Diffstat (limited to 'Userland/Applications')
-rw-r--r-- | Userland/Applications/Magnifier/MagnifierWidget.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/Userland/Applications/Magnifier/MagnifierWidget.cpp b/Userland/Applications/Magnifier/MagnifierWidget.cpp index ffe0da2505..e5b77ea225 100644 --- a/Userland/Applications/Magnifier/MagnifierWidget.cpp +++ b/Userland/Applications/Magnifier/MagnifierWidget.cpp @@ -79,7 +79,7 @@ void MagnifierWidget::sync() return; auto size = frame_inner_rect().size(); - Gfx::IntSize grab_size { size.width() / m_scale_factor, size.height() / m_scale_factor }; + Gfx::IntSize grab_size { (size.width() + m_scale_factor - 1) / m_scale_factor, (size.height() + m_scale_factor - 1) / m_scale_factor }; VERIFY(grab_size.width() != 0 && grab_size.height() != 0); if (m_locked_location.has_value()) { @@ -101,8 +101,20 @@ void MagnifierWidget::paint_event(GUI::PaintEvent& event) GUI::Painter painter(*this); + if (m_pause_capture) + painter.fill_rect(frame_inner_rect(), Gfx::Color::Black); + + // We have to clip the source rect for cases when the currently captured image is larger than the inner_rect + int horizontal_clip = (frame_inner_rect().width() + m_scale_factor - 1) / m_scale_factor; + int vertical_clip = (frame_inner_rect().height() + m_scale_factor - 1) / m_scale_factor; + if (m_grabbed_bitmap) - painter.draw_scaled_bitmap(frame_inner_rect(), *m_grabbed_bitmap, m_grabbed_bitmap->rect(), 1.0, Gfx::Painter::ScalingMode::NearestFractional); + painter.draw_scaled_bitmap( + frame_inner_rect().intersected(Gfx::IntRect { { 0, 0 }, m_grabbed_bitmap->rect().size() } * m_scale_factor), + *m_grabbed_bitmap, + m_grabbed_bitmap->rect().intersected({ 0, 0, horizontal_clip, vertical_clip }), + 1.0, + Gfx::Painter::ScalingMode::NearestFractional); if (m_show_grid) { |