diff --git a/jzy3d-core/src/main/java/org/jzy3d/plot3d/rendering/view/AbstractViewportManager.java b/jzy3d-core/src/main/java/org/jzy3d/plot3d/rendering/view/AbstractViewportManager.java index 3f3af5d4..fc53c757 100644 --- a/jzy3d-core/src/main/java/org/jzy3d/plot3d/rendering/view/AbstractViewportManager.java +++ b/jzy3d-core/src/main/java/org/jzy3d/plot3d/rendering/view/AbstractViewportManager.java @@ -90,7 +90,15 @@ public abstract class AbstractViewportManager { this.screenLeft = viewport.getX(); this.screenBottom = viewport.getY(); } + + public ViewportConfiguration getViewPort() { + ViewportConfiguration vp = + new ViewportConfiguration(screenWidth, screenHeight, screenXOffset, screenYOffset); + vp.setMode(mode); + return vp; + } + /** Return the viewport as it was invoked at last rendering. */ public ViewportConfiguration getLastViewPort() { return lastViewPort; } @@ -148,7 +156,7 @@ public abstract class AbstractViewportManager { } - private void applyViewportRectangle(IPainter painter) { + protected void applyViewportRectangle(IPainter painter) { screenXOffset = screenLeft; screenYOffset = 0; @@ -160,7 +168,7 @@ public abstract class AbstractViewportManager { lastViewPort.setMode(mode); } - private void applyViewportSquared(IPainter painter) { + protected void applyViewportSquared(IPainter painter) { screenSquaredDim = Math.min(screenWidth, screenHeight); screenXOffset = screenLeft + screenWidth / 2 - screenSquaredDim / 2; screenYOffset = screenBottom + screenHeight / 2 - screenSquaredDim / 2; @@ -170,9 +178,7 @@ public abstract class AbstractViewportManager { lastViewPort = new ViewportConfiguration(screenSquaredDim, screenSquaredDim, screenXOffset, screenYOffset); lastViewPort.setMode(mode); - } - - + } /** * Returns the (x,y) offset that was applied to make this {@link AbstractViewportManager} stand in diff --git a/jzy3d-core/src/main/java/org/jzy3d/plot3d/rendering/view/View.java b/jzy3d-core/src/main/java/org/jzy3d/plot3d/rendering/view/View.java index ca905046..db271920 100644 --- a/jzy3d-core/src/main/java/org/jzy3d/plot3d/rendering/view/View.java +++ b/jzy3d-core/src/main/java/org/jzy3d/plot3d/rendering/view/View.java @@ -255,7 +255,7 @@ public class View { // EmulGL need this to layout colorbar properly // Native need this to /sometime/ get the good resolution - //chart.render(10); + chart.render(10); //System.out.println("View :update pix scale"); } diff --git a/jzy3d-core/src/main/java/org/jzy3d/plot3d/rendering/view/layout/ViewAndColorbarsLayout.java b/jzy3d-core/src/main/java/org/jzy3d/plot3d/rendering/view/layout/ViewAndColorbarsLayout.java index 29d5deb4..b3790ddf 100644 --- a/jzy3d-core/src/main/java/org/jzy3d/plot3d/rendering/view/layout/ViewAndColorbarsLayout.java +++ b/jzy3d-core/src/main/java/org/jzy3d/plot3d/rendering/view/layout/ViewAndColorbarsLayout.java @@ -80,7 +80,7 @@ public class ViewAndColorbarsLayout implements IViewportLayout { for (ILegend data : list) { minWidth += updateAndGetMinDimensions(painter, data); - System.out.println("ViewAndColorbarsLayout : legend.minDim : " + data.getMinimumDimension() + " minWidth:" +minWidth ); + //System.out.println("ViewAndColorbarsLayout : legend.minDim : " + data.getMinimumDimension() + " minWidth:" +minWidth ); } screenSeparator = computeSeparator(canvas, minWidth); diff --git a/jzy3d-emul-gl-awt/src/main/java/org/jzy3d/plot3d/rendering/view/layout/EmulGLViewAndColorbarsLayout.java b/jzy3d-emul-gl-awt/src/main/java/org/jzy3d/plot3d/rendering/view/layout/EmulGLViewAndColorbarsLayout.java index fb35eda0..dfe7dd4a 100644 --- a/jzy3d-emul-gl-awt/src/main/java/org/jzy3d/plot3d/rendering/view/layout/EmulGLViewAndColorbarsLayout.java +++ b/jzy3d-emul-gl-awt/src/main/java/org/jzy3d/plot3d/rendering/view/layout/EmulGLViewAndColorbarsLayout.java @@ -17,7 +17,6 @@ import org.jzy3d.plot3d.rendering.view.ViewportMode; import jgl.GL; public class EmulGLViewAndColorbarsLayout extends ViewAndColorbarsLayout { - boolean fixHiDPI = true; @Override public void update(Chart chart) { @@ -53,55 +52,55 @@ public class EmulGLViewAndColorbarsLayout extends ViewAndColorbarsLayout { @Override protected void renderLegends(IPainter painter, float left, float right, List legends, ICanvas canvas) { - - int width = canvas.getRendererWidth(); - int height = canvas.getRendererHeight(); - - View view = chart.getView(); - Coord2d pixelScale = view.getPixelScale(); + Coord2d scale = chart.getView().getPixelScale(); - if (fixHiDPI) { - width = (int) (sceneViewport.getWidth() * pixelScale.x); - height = (int) (sceneViewport.getHeight() * pixelScale.y); - } + int width = Math.round(sceneViewport.getWidth() * scale.x); + int height = Math.round(sceneViewport.getHeight() * scale.y); //System.out.println("EmulGLViewAndColorbar : legendWidth " + legendsWidth); + Font font = painter.getView().getAxis().getLayout().getFont(); + // --------------------------------------- float slice = (right - left) / legends.size(); int k = 0; for (ILegend legend : legends) { - legend.setViewportMode(ViewportMode.STRETCH_TO_FILL); float from = left + slice * (k++); float to = from + slice; - Font font = painter.getView().getAxis().getLayout().getFont(); - legend.setFont(font); + //System.out.println("EmulGLViewLayout left " + from + " to " + to); // FALLBACK ON DIRECT AWT IMAGE RENDERING THROUGH jGL if (legend instanceof AWTColorbarLegend) { AWTColorbarLegend awtLegend = (AWTColorbarLegend) legend; awtLegend.setViewPort(width, height, from, to); + awtLegend.setViewportMode(ViewportMode.STRETCH_TO_FILL); + awtLegend.setFont(font); + awtLegend.updateImage(); + + //System.out.println("EmulGLViewLayout " + awtLegend.getViewPort()); BufferedImage legendImage = (BufferedImage) awtLegend.getImage(); - int legendWidth = legendImage.getWidth(); + int legendHeight = legendImage.getHeight(); // --------------------------------------- // Processing image offset with pixel scale Margin margin = awtLegend.getMargin(); - int xOffset = width - legendWidth * (k); - xOffset += Math.round (pixelScale.x * margin.getLeft()); - xOffset -= Math.round (pixelScale.x * margin.getRight()); + // inspired from AWTImageViewport.computeLayout + int xOffset = Math.round(width - (legendWidth + (margin.getWidth() * scale.x))); + xOffset += (margin.getLeft() * scale.x); + + int yOffset = + Math.round((height - (legendHeight + (margin.getHeight() * scale.y))) / 2f); + yOffset += (margin.getBottom() * scale.y); - int yOffset = 0; - yOffset += Math.round (pixelScale.y * margin.getTop()); // --------------------------------------- // Send image rendering directly to jGL @@ -122,10 +121,10 @@ public class EmulGLViewAndColorbarsLayout extends ViewAndColorbarsLayout { } } - public boolean isFixHiDPI() { + /*public boolean isFixHiDPI() { return fixHiDPI; } public void setFixHiDPI(boolean fixHiDPI) { this.fixHiDPI = fixHiDPI; - } + }*/ } diff --git a/jzy3d-emul-gl-awt/src/test/java/org/jzy3d/plot3d/rendering/view/layout/TestEmulGLViewAndColorbarsLayout.java b/jzy3d-emul-gl-awt/src/test/java/org/jzy3d/plot3d/rendering/view/layout/TestEmulGLViewAndColorbarsLayout.java index bfd62f32..d319404a 100644 --- a/jzy3d-emul-gl-awt/src/test/java/org/jzy3d/plot3d/rendering/view/layout/TestEmulGLViewAndColorbarsLayout.java +++ b/jzy3d-emul-gl-awt/src/test/java/org/jzy3d/plot3d/rendering/view/layout/TestEmulGLViewAndColorbarsLayout.java @@ -7,9 +7,6 @@ public class TestEmulGLViewAndColorbarsLayout extends TestViewAndColorbarsLayout public void whenColorbars_ThenScreenSeparatorIsProcessed() { EmulGLViewAndColorbarsLayout layout = new EmulGLViewAndColorbarsLayout(); - // TODO :REMOVE ME!! - //layout.fixHiDPI = false; - whenColorbars_ThenScreenSeparatorIsProcessed(layout, true); }