From 038f99eeff8326112a23003e170966640b0feba2 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 30 Jun 2019 15:01:35 +0200 Subject: [PATCH] QuickShow: When zooming with the mouse wheel, keep image centered at cursor. --- Applications/QuickShow/QSWidget.cpp | 7 +++++++ Applications/QuickShow/main.cpp | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Applications/QuickShow/QSWidget.cpp b/Applications/QuickShow/QSWidget.cpp index 1aa667d03b1..a7cda20ef89 100644 --- a/Applications/QuickShow/QSWidget.cpp +++ b/Applications/QuickShow/QSWidget.cpp @@ -72,12 +72,19 @@ void QSWidget::mousemove_event(GMouseEvent& event) void QSWidget::mousewheel_event(GMouseEvent& event) { auto old_scale = m_scale; + auto old_scale_factor = (float)m_scale / 100.0f; + auto zoom_point = event.position().translated(-m_bitmap_rect.location()); + zoom_point.set_x((float)zoom_point.x() / old_scale_factor); + zoom_point.set_y((float)zoom_point.y() / old_scale_factor); m_scale += -event.wheel_delta() * 10; if (m_scale < 10) m_scale = 10; if (m_scale > 1000) m_scale = 1000; relayout(); + auto new_scale_factor = (float)m_scale / 100.0f; + auto scale_factor_change = new_scale_factor - old_scale_factor; + m_bitmap_rect.move_by(-Point((float)zoom_point.x() * scale_factor_change, (float)zoom_point.y() * scale_factor_change)); if (old_scale != m_scale) { if (on_scale_change) on_scale_change(m_scale); diff --git a/Applications/QuickShow/main.cpp b/Applications/QuickShow/main.cpp index 97f992646a6..adb34b84690 100644 --- a/Applications/QuickShow/main.cpp +++ b/Applications/QuickShow/main.cpp @@ -56,7 +56,7 @@ int main(int argc, char** argv) window->set_title(String::format("QuickShow: %s %s %d%%", path, bitmap->size().to_string().characters(), scale)); }; - window->set_double_buffering_enabled(false); + window->set_double_buffering_enabled(true); update_window_title(100); window->set_rect(200, 200, bitmap->width(), bitmap->height());