feat(renderer): enhance rendering with clipping area support in G2DDrawEffect
This commit is contained in:
@@ -3,6 +3,7 @@ package de.extio.game_engine.renderer.g2d.bo.rendering;
|
|||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Frame;
|
import java.awt.Frame;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Shape;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -58,6 +59,74 @@ public class G2DDrawEffect extends G2DAbstractRenderingBo implements DrawEffectR
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Shape oldClip = null;
|
||||||
|
Area2 intersection = null;
|
||||||
|
if (visibleAreaX != 0 || visibleAreaY != 0 || visibleAreaWidth != 0 || visibleAreaHeight != 0) {
|
||||||
|
int minX = x0;
|
||||||
|
int minY = y0;
|
||||||
|
int maxX = x0;
|
||||||
|
int maxY = y0;
|
||||||
|
if (coordinates != null && !coordinates.isEmpty()) {
|
||||||
|
for (final CoordI2 c : coordinates) {
|
||||||
|
final int px = x0 + c.getX();
|
||||||
|
final int py = y0 + c.getY();
|
||||||
|
minX = Math.min(minX, px);
|
||||||
|
minY = Math.min(minY, py);
|
||||||
|
maxX = Math.max(maxX, px);
|
||||||
|
maxY = Math.max(maxY, py);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this.width > 0) {
|
||||||
|
maxX = Math.max(maxX, x0 + this.width);
|
||||||
|
}
|
||||||
|
if (this.height > 0) {
|
||||||
|
maxY = Math.max(maxY, y0 + this.height);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (this.effect) {
|
||||||
|
case CIRCLE:
|
||||||
|
case CIRCLE_FILLED: {
|
||||||
|
final int diameter = Math.max(3, (int) Math.round(this.customInt0 * scaleFactor));
|
||||||
|
maxX = Math.max(maxX, x0 + diameter);
|
||||||
|
maxY = Math.max(maxY, y0 + diameter);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case CIRCLE_CENTERED:
|
||||||
|
case CIRCLE_CENTERED_FILLED: {
|
||||||
|
final int radius = Math.max(3, (int) Math.round(this.customInt0 * scaleFactor));
|
||||||
|
minX = Math.min(minX, x0 - radius);
|
||||||
|
minY = Math.min(minY, y0 - radius);
|
||||||
|
maxX = Math.max(maxX, x0 + radius);
|
||||||
|
maxY = Math.max(maxY, y0 + radius);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case TEXT: {
|
||||||
|
if (this.customString0 != null && !this.customString0.isEmpty()) {
|
||||||
|
final var td = G2DDrawFont.getTextDimensions(this.customString0, graphics, (int) (this.customInt0), scaleFactor);
|
||||||
|
maxX = Math.max(maxX, x0 + td.getX());
|
||||||
|
maxY = Math.max(maxY, y0 + td.getY());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
final int blockX = minX;
|
||||||
|
final int blockY = minY;
|
||||||
|
final int blockW = Math.max(1, maxX - minX);
|
||||||
|
final int blockH = Math.max(1, maxY - minY);
|
||||||
|
final var controlArea = new Area2(ImmutableCoordI2.create(blockX, blockY), ImmutableCoordI2.create(blockW, blockH));
|
||||||
|
final var visibleArea = new Area2(ImmutableCoordI2.create((int) (this.visibleAreaX * scaleFactor), (int) (this.visibleAreaY * scaleFactor)), ImmutableCoordI2.create((int) (this.visibleAreaWidth * scaleFactor), (int) (this.visibleAreaHeight * scaleFactor)));
|
||||||
|
intersection = SpatialUtils2.intersectAreas(controlArea, visibleArea);
|
||||||
|
if (intersection == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
oldClip = graphics.getClip();
|
||||||
|
graphics.setClip(intersection.getPosition().getX(), intersection.getPosition().getY(), intersection.getDimension().getX(), intersection.getDimension().getY());
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
switch (this.effect) {
|
switch (this.effect) {
|
||||||
case LINE: {
|
case LINE: {
|
||||||
if (coordinates == null || coordinates.isEmpty()) {
|
if (coordinates == null || coordinates.isEmpty()) {
|
||||||
@@ -220,11 +289,12 @@ public class G2DDrawEffect extends G2DAbstractRenderingBo implements DrawEffectR
|
|||||||
final var theme = themeManager.getCurrentTheme();
|
final var theme = themeManager.getCurrentTheme();
|
||||||
final PatternRenderer patternRenderer = themeManager.getPatternRenderer(theme.getPatternRendererName());
|
final PatternRenderer patternRenderer = themeManager.getPatternRenderer(theme.getPatternRendererName());
|
||||||
final var strength = this.customInt0 <= 0 ? 2 : this.customInt0;
|
final var strength = this.customInt0 <= 0 ? 2 : this.customInt0;
|
||||||
final var effectColor = this.color == null ? theme.getBorderOuter().toColor() : this.color.toAwtColor();
|
final var effectColor = this.color == null ? theme.getBorderInner().toColor() : this.color.toAwtColor();
|
||||||
if (patternRenderer != null) {
|
if (patternRenderer != null) {
|
||||||
if (this.effect == DrawEffectRenderingBoEffects.DECORATIVE_BORDER) {
|
if (this.effect == DrawEffectRenderingBoEffects.DECORATIVE_BORDER) {
|
||||||
patternRenderer.drawDecorativeBorder(graphics, area.getPosition().getX(), area.getPosition().getY(), area.getDimension().getX(), area.getDimension().getY(), strength, effectColor);
|
patternRenderer.drawDecorativeBorder(graphics, area.getPosition().getX(), area.getPosition().getY(), area.getDimension().getX(), area.getDimension().getY(), strength, effectColor);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
patternRenderer.drawDecorativeBorderFilled(graphics, area.getPosition().getX(), area.getPosition().getY(), area.getDimension().getX(), area.getDimension().getY(), strength, effectColor, theme.getWindowBackground().toColor());
|
patternRenderer.drawDecorativeBorderFilled(graphics, area.getPosition().getX(), area.getPosition().getY(), area.getDimension().getX(), area.getDimension().getY(), strength, effectColor, theme.getWindowBackground().toColor());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -245,6 +315,10 @@ public class G2DDrawEffect extends G2DAbstractRenderingBo implements DrawEffectR
|
|||||||
throw new UnsupportedOperationException("Effect not implemented: " + this.effect.toString());
|
throw new UnsupportedOperationException("Effect not implemented: " + this.effect.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
finally {
|
||||||
|
graphics.setClip(oldClip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean cull(final Area2 area) {
|
private boolean cull(final Area2 area) {
|
||||||
final Frame mainFrame = ((G2DRenderer) this.rendererData.getRenderer()).getMainFrame();
|
final Frame mainFrame = ((G2DRenderer) this.rendererData.getRenderer()).getMainFrame();
|
||||||
@@ -270,7 +344,8 @@ public class G2DDrawEffect extends G2DAbstractRenderingBo implements DrawEffectR
|
|||||||
this.effect = o.effect;
|
this.effect = o.effect;
|
||||||
if (o.relativeCoordinates != null) {
|
if (o.relativeCoordinates != null) {
|
||||||
this.relativeCoordinates = List.copyOf(o.relativeCoordinates);
|
this.relativeCoordinates = List.copyOf(o.relativeCoordinates);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
this.relativeCoordinates = null;
|
this.relativeCoordinates = null;
|
||||||
}
|
}
|
||||||
this.customInt0 = o.customInt0;
|
this.customInt0 = o.customInt0;
|
||||||
|
|||||||
Reference in New Issue
Block a user