diff --git a/jzy3d-core-awt/src/main/java/org/jzy3d/plot3d/rendering/view/AWTImageViewport.java b/jzy3d-core-awt/src/main/java/org/jzy3d/plot3d/rendering/view/AWTImageViewport.java index 6df11e9a..81abc76d 100644 --- a/jzy3d-core-awt/src/main/java/org/jzy3d/plot3d/rendering/view/AWTImageViewport.java +++ b/jzy3d-core-awt/src/main/java/org/jzy3d/plot3d/rendering/view/AWTImageViewport.java @@ -66,34 +66,36 @@ public class AWTImageViewport extends AbstractViewportManager implements IImageV int xPosition = 0; int yPosition = 0; + System.out.println("AWTImageViewport : im : " + imageWidth + " screen : " + screenWidth + " margin : " + margin.getWidth()); + + // If image is smaller than viewport, move it a bit to let it appear in the center if (imageWidth < screenWidth) { - if(margin.getLeft()!=margin.getRight()) { - xPosition = Math.round(screenWidth / 2f - (imageWidth / 2f + margin.getWidth())); - - } - else { xPosition = Math.round((float) screenWidth / 2 - (float) imageWidth / 2); + + // If margin are asymetric, shift by taking them into account + if(margin.getLeft()!=margin.getRight()) { + xPosition += (margin.getLeft() - margin.getRight()); } } - else + // If image is bigger than viewport, unzoom it a bit to let it fit the dimensions + else if(imageWidth > screenWidth){ xZoom = ((float) screenWidth) / ((float) imageWidth); - + } + + // If image is smaller than viewport, move it a bit to let it appear in the center if (imageHeight < screenHeight) { - //int shiftForMargin = 0; - - // TODO : clarify this - + yPosition = Math.round((float) screenHeight / 2 - ((float) imageHeight / 2)); + if(margin.getTop()!=margin.getBottom()) { - //shiftForMargin = Math.round(margin.getHeight()/2); - yPosition = Math.round(screenHeight / 2f - (imageHeight / 2f - margin.getHeight()/2f) /*margin.getTop())*/); + yPosition += (margin.getBottom()-margin.getTop()); } else { - yPosition = Math.round((float) screenHeight / 2 - ((float) imageHeight / 2)); } } - else + // If image is bigger than viewport, unzoom it a bit to let it fit the dimensions + else if(imageWidth > screenWidth) { yZoom = ((float) screenHeight) / ((float) imageHeight); - + } //System.out.println("AWTImageViewport posi.x:" + xPosition + " posi.y:" + xPosition); //System.out.println("AWTImageViewport zoom.x:" + xZoom + " zoom.y:" + yZoom); //System.out.println("AWTImageViewport size.x:" + imageWidth + " size.y:" + imageHeight); diff --git a/jzy3d-jGL/jzy3d-jGL-awt/src/main/java/examples/apps/hello.java b/jzy3d-jGL/jzy3d-jGL-awt/src/main/java/examples/apps/hello.java index a3107a57..4df41c18 100644 --- a/jzy3d-jGL/jzy3d-jGL-awt/src/main/java/examples/apps/hello.java +++ b/jzy3d-jGL/jzy3d-jGL-awt/src/main/java/examples/apps/hello.java @@ -47,6 +47,7 @@ public class hello extends GLCanvas { /* initialize viewing values */ myGL.glMatrixMode(GL.GL_PROJECTION); myGL.glLoadIdentity(); + myGL.glOrtho(0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f); } diff --git a/jzy3d-tester/src/main/java/org/jzy3d/debug/View2DLayout_Debug.java b/jzy3d-tester/src/main/java/org/jzy3d/debug/View2DLayout_Debug.java index 258d102f..3be2d497 100644 --- a/jzy3d-tester/src/main/java/org/jzy3d/debug/View2DLayout_Debug.java +++ b/jzy3d-tester/src/main/java/org/jzy3d/debug/View2DLayout_Debug.java @@ -151,7 +151,7 @@ public class View2DLayout_Debug extends AbstractAWTRenderer2d implements AWTRend x= viewport.getX(); int yminDim= yBar+lineHeight; - w =Math.round(colorbar.getMinimumDimension().width*pixelScale.getX()); + w = Math.round(colorbar.getMinimumDimension().width*pixelScale.getX()); h = Math.round(colorbar.getMinimumDimension().height+pixelScale.getY()); g2d.setStroke(new BasicStroke(2)); @@ -160,6 +160,7 @@ public class View2DLayout_Debug extends AbstractAWTRenderer2d implements AWTRend //maxTextWidth = g2d.drawString("Colorbar.MinDim", x, yminDim); + g2d.drawString(colorbar.getMinimumDimension().toString(), x, yminDim+g2d.getFont().getSize()+1); g2d.setStroke(new BasicStroke(1));