From: Niki Roo Date: Tue, 5 May 2020 20:21:38 +0000 (+0200) Subject: fix image viewer zoom X-Git-Tag: fanfix-swing-1.2.0~1 X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=2ba30697574d1811f2c4a867e48b055ae8ebc9f2;p=fanfix-swing.git fix image viewer zoom --- diff --git a/src/be/nikiroo/fanfix_swing/gui/viewer/ViewerImages.java b/src/be/nikiroo/fanfix_swing/gui/viewer/ViewerImages.java index 0be44f49..4cc9da3f 100644 --- a/src/be/nikiroo/fanfix_swing/gui/viewer/ViewerImages.java +++ b/src/be/nikiroo/fanfix_swing/gui/viewer/ViewerImages.java @@ -133,8 +133,8 @@ public class ViewerImages extends JFrame { * the {@link Story} to display */ public ViewerImages(Story story) { - setTitle(Main.trans(StringIdGui.TITLE_STORY, - story.getMeta().getLuid(), story.getMeta().getTitle())); + setTitle(Main.trans(StringIdGui.TITLE_STORY, story.getMeta().getLuid(), + story.getMeta().getTitle())); setSize(800, 600); @@ -410,10 +410,10 @@ public class ViewerImages extends JFrame { && previousImageSize != null) { Rectangle view = scroll.getViewport().getViewRect(); - double ratioW = view.getCenterX() - / previousImageSize.width; - double ratioH = view.getCenterY() - / previousImageSize.height; + double centerX = view.getCenterX(); + double centerY = view.getCenterY(); + double ratioW = centerX / previousImageSize.width; + double ratioH = centerY / previousImageSize.height; if (turn) { double tmp = ratioW; @@ -421,18 +421,19 @@ public class ViewerImages extends JFrame { ratioH = tmp; } - double centerX = ratioW * currentImageSize.width; - double centerY = ratioH * currentImageSize.height; + centerX = currentImageSize.width * ratioW; + centerY = currentImageSize.height * ratioH; + if (zoomCenterOffset != null) { + double dzoom = currentZoom - previousZoom; + centerX += zoomCenterOffset.x * dzoom * ratioW; + centerY += zoomCenterOffset.y * dzoom * ratioH; + } + int x = (int) Math .round(centerX - (view.width / 2.0)); int y = (int) Math .round(centerY - (view.height / 2.0)); - if (zoomCenterOffset != null) { - x += zoomCenterOffset.x; - y += zoomCenterOffset.y; - } - scrollTo = new Rectangle(x, y, // view.width, view.height); }