From ee3d4ca63caa1dcc3f87e6ad85730e335638ffe7 Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 7 May 2015 17:23:44 -0300 Subject: [PATCH] Improve zoom movement using a "subpixel" factor This factor indicates exactly where the mouse is inside the zoomed pixel, and uses it to locate the new zoom with the same factor (if it's possible). --- src/app/ui/editor/editor.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/app/ui/editor/editor.cpp b/src/app/ui/editor/editor.cpp index f2eb40fc4..e9d5cea40 100644 --- a/src/app/ui/editor/editor.cpp +++ b/src/app/ui/editor/editor.cpp @@ -1451,6 +1451,8 @@ void Editor::setZoomAndCenterInMouse(Zoom zoom, gfx::Point screenPos; gfx::Point spritePos; + gfx::PointT subpixelPos(0.5, 0.5); + switch (zoomBehavior) { case ZoomBehavior::CENTER: screenPos = gfx::Point(vp.x + vp.w/2, @@ -1462,9 +1464,19 @@ void Editor::setZoomAndCenterInMouse(Zoom zoom, } spritePos = screenToEditor(screenPos); + if (zoomBehavior == ZoomBehavior::MOUSE && + m_zoom.scale() > 1.0) { + gfx::Point screenPos2 = editorToScreen(spritePos); + subpixelPos.x = (0.5 + screenPos.x - screenPos2.x) / m_zoom.scale(); + subpixelPos.y = (0.5 + screenPos.y - screenPos2.y) / m_zoom.scale(); + + ASSERT(subpixelPos.x >= 0.0 && subpixelPos.x <= 1.0); + ASSERT(subpixelPos.y >= 0.0 && subpixelPos.y <= 1.0); + } + gfx::Point scrollPos( - m_offset_x - (screenPos.x-vp.x) + zoom.apply(spritePos.x+zoom.remove(1)/2) + zoom.apply(1)/2, - m_offset_y - (screenPos.y-vp.y) + zoom.apply(spritePos.y+zoom.remove(1)/2) + zoom.apply(1)/2); + m_offset_x - (screenPos.x-vp.x) + zoom.apply(spritePos.x+zoom.remove(1)/2) + int(zoom.apply(subpixelPos.x)), + m_offset_y - (screenPos.y-vp.y) + zoom.apply(spritePos.y+zoom.remove(1)/2) + int(zoom.apply(subpixelPos.y))); if ((m_zoom != zoom) || (screenPos != view->getViewScroll())) { bool blit_valid_rgn = (m_zoom == zoom);