mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
QuickShow: When zooming with the mouse wheel, keep image centered at cursor.
This commit is contained in:
parent
e7ce4514ec
commit
038f99eeff
Notes:
sideshowbarker
2024-07-19 13:26:01 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/038f99eeff8
2 changed files with 8 additions and 1 deletions
|
@ -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);
|
||||
|
|
|
@ -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());
|
||||
|
||||
|
|
Loading…
Reference in a new issue