Fixed EmulGL colorbar layout

This commit is contained in:
Martin Pernollet 2022-06-16 17:56:42 +02:00
parent 1d8a46284e
commit 68aed9cbe1
5 changed files with 34 additions and 32 deletions

View File

@ -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

View File

@ -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");
}

View File

@ -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);

View File

@ -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<ILegend> 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;
}
}*/
}

View File

@ -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);
}