feat(renderer): add z-index support for fine-grained layer ordering in rendering
This commit is contained in:
@@ -43,6 +43,8 @@ public class G2DRenderer implements Renderer {
|
|||||||
private static final Logger LOGGER = LoggerFactory.getLogger(G2DRenderer.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(G2DRenderer.class);
|
||||||
|
|
||||||
private static final long SLEEP_PRECISION = TimeUnit.MILLISECONDS.toNanos(2);
|
private static final long SLEEP_PRECISION = TimeUnit.MILLISECONDS.toNanos(2);
|
||||||
|
|
||||||
|
private static final short ZINDEX_STEPS = RenderingBoLayer.UI_TOP - RenderingBoLayer.UI_BGR + 1;
|
||||||
|
|
||||||
private final RingBuffer<Integer> fpsHistory = new RingBuffer<>(90);
|
private final RingBuffer<Integer> fpsHistory = new RingBuffer<>(90);
|
||||||
|
|
||||||
@@ -175,7 +177,7 @@ public class G2DRenderer implements Renderer {
|
|||||||
this.drawStatistics();
|
this.drawStatistics();
|
||||||
this.rendererData.getRendererWorkingSet().commit(this.rendererModuleId, true);
|
this.rendererData.getRendererWorkingSet().commit(this.rendererModuleId, true);
|
||||||
this.rendererData.getRendererWorkingSet().getLiveSet(this.renderingBOs, this.rendererData.getModuleService()::isDisplayed);
|
this.rendererData.getRendererWorkingSet().getLiveSet(this.renderingBOs, this.rendererData.getModuleService()::isDisplayed);
|
||||||
this.renderingBOs.sort((bo0, bo1) -> Short.compare(bo0.getLayer(), bo1.getLayer()));
|
this.renderingBOs.sort((bo0, bo1) -> Integer.compare(this.getEffectiveLayer(bo0), this.getEffectiveLayer(bo1)));
|
||||||
|
|
||||||
Graphics2D screenGraphics = null;
|
Graphics2D screenGraphics = null;
|
||||||
try {
|
try {
|
||||||
@@ -204,7 +206,7 @@ public class G2DRenderer implements Renderer {
|
|||||||
for (final RenderingBo bo : usedRenderingBoTypes.values()) {
|
for (final RenderingBo bo : usedRenderingBoTypes.values()) {
|
||||||
bo.staticCleanupAfterFrame();
|
bo.staticCleanupAfterFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.rendererData.getRenderingBoPool().releasePending();
|
this.rendererData.getRenderingBoPool().releasePending();
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -329,6 +331,14 @@ public class G2DRenderer implements Renderer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getEffectiveLayer(final RenderingBo bo) {
|
||||||
|
final var layer = bo.getLayer();
|
||||||
|
if (layer >= RenderingBoLayer.UI_BGR && layer <= RenderingBoLayer.UI_TOP) {
|
||||||
|
return layer + (bo.getZIndex() * ZINDEX_STEPS);
|
||||||
|
}
|
||||||
|
return layer;
|
||||||
|
}
|
||||||
|
|
||||||
public G2DMainFrame getMainFrame() {
|
public G2DMainFrame getMainFrame() {
|
||||||
return this.mainFrame;
|
return this.mainFrame;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ public abstract class AbstractRenderingBo implements RenderingBo {
|
|||||||
|
|
||||||
private final short defaultLayer;
|
private final short defaultLayer;
|
||||||
|
|
||||||
|
protected short zIndex;
|
||||||
|
|
||||||
public AbstractRenderingBo(final short layer) {
|
public AbstractRenderingBo(final short layer) {
|
||||||
this.layer = layer;
|
this.layer = layer;
|
||||||
this.defaultLayer = layer;
|
this.defaultLayer = layer;
|
||||||
@@ -224,6 +226,7 @@ public abstract class AbstractRenderingBo implements RenderingBo {
|
|||||||
this.width = 0;
|
this.width = 0;
|
||||||
this.height = 0;
|
this.height = 0;
|
||||||
this.layer = this.defaultLayer;
|
this.layer = this.defaultLayer;
|
||||||
|
this.zIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -238,6 +241,7 @@ public abstract class AbstractRenderingBo implements RenderingBo {
|
|||||||
this.width = abstractRenderingBo.width;
|
this.width = abstractRenderingBo.width;
|
||||||
this.height = abstractRenderingBo.height;
|
this.height = abstractRenderingBo.height;
|
||||||
this.layer = abstractRenderingBo.layer;
|
this.layer = abstractRenderingBo.layer;
|
||||||
|
this.zIndex = abstractRenderingBo.zIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,6 +302,17 @@ public abstract class AbstractRenderingBo implements RenderingBo {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public short getZIndex() {
|
||||||
|
return this.zIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RenderingBo setZIndex(final short zIndex) {
|
||||||
|
this.zIndex = zIndex;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public int getWidth() {
|
public int getWidth() {
|
||||||
return this.width;
|
return this.width;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,16 @@ public interface RenderingBo extends AutoCloseable {
|
|||||||
|
|
||||||
short getLayer();
|
short getLayer();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the z-index for fine-grained ordering within UI layers (UI_BGR to UI_TOP).
|
||||||
|
*/
|
||||||
|
short getZIndex();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the z-index for fine-grained ordering within UI layers (UI_BGR to UI_TOP).
|
||||||
|
*/
|
||||||
|
RenderingBo setZIndex(short zIndex);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Positions this bo with an absolute position on the viewport. x0 y0 coordinates are at the top left. Call RendererControl#getEffectiveViewportDimension to get the absolute dimension of the viewport.
|
* Positions this bo with an absolute position on the viewport. x0 y0 coordinates are at the top left. Call RendererControl#getEffectiveViewportDimension to get the absolute dimension of the viewport.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -426,6 +426,16 @@ public class RendererWorkingSetImplTest {
|
|||||||
public short getLayer() {
|
public short getLayer() {
|
||||||
return RenderingBoLayer.UI0;
|
return RenderingBoLayer.UI0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public short getZIndex() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RenderingBo setZIndex(short zIndex) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RenderingBo withPositionAbsoluteAnchorTopLeft(final int x, final int y) {
|
public RenderingBo withPositionAbsoluteAnchorTopLeft(final int x, final int y) {
|
||||||
|
|||||||
@@ -343,6 +343,16 @@ public class RenderingBoPoolImplTest {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public short getZIndex() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RenderingBo setZIndex(short zIndex) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RenderingBo withPositionAbsoluteAnchorTopLeft(final int x, final int y) {
|
public RenderingBo withPositionAbsoluteAnchorTopLeft(final int x, final int y) {
|
||||||
return this;
|
return this;
|
||||||
@@ -492,6 +502,16 @@ public class RenderingBoPoolImplTest {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public short getZIndex() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RenderingBo setZIndex(short zIndex) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RenderingBo withPositionAbsoluteAnchorTopLeft(final int x, final int y) {
|
public RenderingBo withPositionAbsoluteAnchorTopLeft(final int x, final int y) {
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
Reference in New Issue
Block a user