Skip to content
Permalink
Browse files
8263389: IGV: Zooming changes the point that is currently centered
Reviewed-by: rrich, neliasso
  • Loading branch information
jtfuller111 authored and TobiHartmann committed Jul 5, 2021
1 parent 371d996 commit 164eff8c8a8f96efc5bfb659d8b02de420b8416b
Showing 1 changed file with 11 additions and 8 deletions.
@@ -151,28 +151,31 @@ private static boolean intersects(Set<? extends Object> s1, Set<? extends Object
@Override
public void zoomOut() {
double zoom = getZoomFactor();
Point viewPosition = getScrollPane().getViewport().getViewPosition();
double newZoom = zoom / DiagramScene.ZOOM_INCREMENT;
if (newZoom > DiagramScene.ZOOM_MIN_FACTOR) {
setZoomFactor(newZoom);
validate();
getScrollPane().getViewport().setViewPosition(new Point((int) (viewPosition.x / DiagramScene.ZOOM_INCREMENT), (int) (viewPosition.y / DiagramScene.ZOOM_INCREMENT)));
zoom(newZoom);
}
}

@Override
public void zoomIn() {

double zoom = getZoomFactor();
Point viewPosition = getScrollPane().getViewport().getViewPosition();
double newZoom = zoom * DiagramScene.ZOOM_INCREMENT;
if (newZoom < DiagramScene.ZOOM_MAX_FACTOR) {
setZoomFactor(newZoom);
validate();
getScrollPane().getViewport().setViewPosition(new Point((int) (viewPosition.x * DiagramScene.ZOOM_INCREMENT), (int) (viewPosition.y * DiagramScene.ZOOM_INCREMENT)));
zoom(newZoom);
}
}

private void zoom(double newZoom) {
double currentZoom = getZoomFactor();
Point viewPosition = getScrollPane().getViewport().getViewPosition();
Rectangle viewRect = getScrollPane().getViewport().getViewRect();
setZoomFactor(newZoom);
validate();
getScrollPane().getViewport().validate();
getScrollPane().getViewport().setViewPosition(new Point((int) ((viewPosition.x + viewRect.width / 2) * newZoom / currentZoom - viewRect.width / 2), (int) ((viewPosition.y + viewRect.height / 2) * newZoom / currentZoom - viewRect.height / 2)));
}

@Override
public void centerFigures(List<Figure> list) {

1 comment on commit 164eff8

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 164eff8 Jul 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.