public static void drawRoundedGradientOutline(PoseStack poseStack, float x, float y, float width, float height, float radius, int startColor, int endColor) {
Matrix4f matrix = poseStack.last().pose();
float alpha = (startColor >> 24 & 255) / 255.0F;
float red = (startColor >> 16 & 255) / 255.0F;
float green = (startColor >> 8 & 255) / 255.0F;
float blue = (startColor & 255) / 255.0F;
float alpha2 = (endColor >> 24 & 255) / 255.0F;
float red2 = (endColor >> 16 & 255) / 255.0F;
float green2 = (endColor >> 8 & 255) / 255.0F;
float blue2 = (endColor & 255) / 255.0F;
BufferBuilder bufferBuilder = Tesselator.getInstance().getBuilder();
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
RenderSystem.setShader(GameRenderer::getPositionColorShader);
bufferBuilder.begin(VertexFormat.Mode.TRIANGLE_STRIP, DefaultVertexFormat.POSITION_COLOR);
drawGradientLine(bufferBuilder, matrix, x + radius, y, x + width - radius, y,
red, green, blue, alpha, red2, green2, blue2, alpha2);
drawGradientLine(bufferBuilder, matrix, x + width, y + radius, x + width, y + height - radius,
red2, green2, blue2, alpha2, red, green, blue, alpha);
drawGradientLine(bufferBuilder, matrix, x + width - radius, y + height, x + radius, y + height,
red, green, blue, alpha, red2, green2, blue2, alpha2);
drawGradientLine(bufferBuilder, matrix, x, y + height - radius, x, y + radius,
red2, green2, blue2, alpha2, red, green, blue, alpha);
drawRoundedCorner(bufferBuilder, matrix, x + radius, y + radius, radius, 180, 270,
red, green, blue, alpha);
drawRoundedCorner(bufferBuilder, matrix, x + width - radius, y + radius, radius, 270, 360,
red2, green2, blue2, alpha2);
drawRoundedCorner(bufferBuilder, matrix, x + width - radius, y + height - radius, radius, 0, 90,
red, green, blue, alpha);
drawRoundedCorner(bufferBuilder, matrix, x + radius, y + height - radius, radius, 90, 180,
red2, green2, blue2, alpha2);
BufferUploader.drawWithShader(bufferBuilder.end());
RenderSystem.disableBlend();
}
private static void drawGradientLine(BufferBuilder buffer, Matrix4f matrix, float x1, float y1, float x2, float y2,
float r1, float g1, float b1, float a1,
float r2, float g2, float b2, float a2) {
buffer.vertex(matrix, x1, y1, 0).color(r1, g1, b1, a1).endVertex();
buffer.vertex(matrix, x2, y2, 0).color(r2, g2, b2, a2).endVertex();
}
private static void drawRoundedCorner(BufferBuilder buffer, Matrix4f matrix, float x, float y, float radius,
float startAngle, float endAngle,
float r, float g, float b, float a) {
float segments = radius * 4;
float angleStep = (endAngle - startAngle) / segments;
for (float angle = startAngle; angle <= endAngle; angle += angleStep) {
float rad = (float) Math.toRadians(angle);
float xPos = x + (float) Math.cos(rad) * radius;
float yPos = y + (float) Math.sin(rad) * radius;
buffer.vertex(matrix, xPos, yPos, 0).color(r, g, b, a).endVertex();
}
}