Frost translucent panels with glass
Panels whose background isn't solid draw the blurred game behind them, cut to the same rounded rectangle texture as the background, where the version supports glass. Panel screens then leave the rest of the game unblurred. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -34,6 +34,14 @@ public interface RenderScope {
|
||||
if (color == 0)
|
||||
return;
|
||||
|
||||
drawTexture(getRoundedRectangle(width, height, radius), x, y, 0, 0, width, height, color);
|
||||
}
|
||||
|
||||
/**
|
||||
* The white rounded rectangle that {@link #drawRoundedRectangle} tints, as a
|
||||
* cached texture.
|
||||
*/
|
||||
default IdentifierRef getRoundedRectangle(int width, int height, int radius) {
|
||||
radius = Math.min(radius, width / 2);
|
||||
radius = Math.min(radius, height / 2);
|
||||
|
||||
@@ -42,7 +50,24 @@ public interface RenderScope {
|
||||
width, height,
|
||||
radius, radius);
|
||||
|
||||
drawSvgShape(rect, "rounded_" + width + "_" + height + "_" + radius, x, y, width, height, color);
|
||||
return getSvgShape(rect, "rounded_" + width + "_" + height + "_" + radius, width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Frosts a rounded rectangle for a translucent background to be drawn over:
|
||||
* the game behind the screen, blurred, cut to exactly the shape
|
||||
* {@link #drawRoundedRectangle} draws. Draws nothing on versions without
|
||||
* glass.
|
||||
*/
|
||||
default void drawGlass(int x, int y, int width, int height, int radius) {
|
||||
drawGlass(getRoundedRectangle(width, height, radius), x, y, width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the blurred game behind the screen where {@code mask}, stretched
|
||||
* over the area, is opaque.
|
||||
*/
|
||||
default void drawGlass(IdentifierRef mask, int x, int y, int width, int height) {
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,15 +114,22 @@ public interface RenderScope {
|
||||
* {@code color}.
|
||||
*/
|
||||
private void drawSvgShape(String shape, String cacheKey, int x, int y, int width, int height, int color) {
|
||||
drawTexture(getSvgShape(shape, cacheKey, width, height), x, y, 0, 0, width, height, color);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code shape} (SVG elements in a {@code width} x {@code height} canvas,
|
||||
* drawn in white) rendered to a cached texture.
|
||||
*/
|
||||
private IdentifierRef getSvgShape(String shape, String cacheKey, int width, int height) {
|
||||
String svg = String.format(
|
||||
"<svg xmlns='http://www.w3.org/2000/svg' width='%d' height='%d'>%s</svg>",
|
||||
width, height, shape);
|
||||
|
||||
InputStream svgStream = new ByteArrayInputStream(svg.getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
drawTexture(SvgTexture.getSvg(svgStream,
|
||||
IdentifierRef.ofSaturn("textures/gui/tmp_rect/" + cacheKey),
|
||||
width * 4, height * 4), x, y, 0, 0, width, height, color);
|
||||
return SvgTexture.getSvg(svgStream, IdentifierRef.ofSaturn("textures/gui/tmp_rect/" + cacheKey),
|
||||
width * 4, height * 4);
|
||||
}
|
||||
|
||||
void drawBorder(int x, int y, int width, int height, int color);
|
||||
|
||||
Reference in New Issue
Block a user