diff --git a/src/main/java/org/saturnclient/ui2/RenderScope.java b/src/main/java/org/saturnclient/ui2/RenderScope.java index 87b8d41..69f3013 100644 --- a/src/main/java/org/saturnclient/ui2/RenderScope.java +++ b/src/main/java/org/saturnclient/ui2/RenderScope.java @@ -5,12 +5,12 @@ import org.joml.Matrix4f; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.font.TextRenderer.TextLayerType; -import net.minecraft.client.gui.DrawContext; import net.minecraft.client.render.RenderLayer; import net.minecraft.client.render.VertexConsumer; import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.util.Identifier; +import net.minecraft.util.math.RotationAxis; public class RenderScope { public MatrixStack matrices; @@ -115,4 +115,89 @@ public class RenderScope { textRenderer.draw(text, (float) x, (float) y, color, false, this.matrices.peek().getPositionMatrix(), this.vertexConsumers, TextLayerType.NORMAL, 0, 15728880); } + + public void drawRoundedCorner(int width, int height, int radius, int color) { + int w = width * 10; // Width of the box + int h = height * 10; // Height of the box + + for (int y = 0; y < h; y++) { + int startX; + + if (y < radius) { + double dy = y - radius; + double dx = radius - Math.sqrt(radius * radius - dy * dy); + startX = (int) Math.ceil(dx); + } else { + startX = 0; + } + + this.drawRect(startX, y, w - startX, 1, color); + } + } + + public void drawRoundedRectangle(int x, int y, int width, int height, int radius, int color) { + int cornerWidth = width / 2; + int cornerHeight = height / 2; + + this.matrices.push(); + + this.matrices.translate(x, y, 0); + + this.matrices.push(); + + this.matrices.scale(0.1f, 0.1f, 1.0f); + + this.drawRoundedCorner(cornerWidth, cornerHeight, radius, color); + + this.matrices.pop(); + + + this.matrices.push(); + + this.matrices.translate(cornerWidth, cornerHeight * 2, 0); + + this.matrices.multiply(RotationAxis.NEGATIVE_Z.rotationDegrees(90)); + + this.matrices.translate(0, -cornerWidth, 0); + + this.matrices.scale(0.1f, 0.1f, 1.0f); + + this.drawRoundedCorner(cornerWidth, cornerHeight, radius, color); + + this.matrices.pop(); + + + + this.matrices.push(); + + this.matrices.translate(cornerWidth * 2, cornerHeight, 0); + + this.matrices.multiply(RotationAxis.NEGATIVE_Z.rotationDegrees(180)); + + this.matrices.translate(0, -cornerWidth, 0); + + this.matrices.scale(0.1f, 0.1f, 1.0f); + + this.drawRoundedCorner(cornerWidth, cornerHeight, radius, color); + + this.matrices.pop(); + + + + this.matrices.push(); + + this.matrices.translate(cornerWidth, 0, 0); + + this.matrices.multiply(RotationAxis.NEGATIVE_Z.rotationDegrees(270)); + + this.matrices.translate(0, -cornerWidth, 0); + + this.matrices.scale(0.1f, 0.1f, 1.0f); + + this.drawRoundedCorner(cornerWidth, cornerHeight, radius, color); + + this.matrices.pop(); + + this.matrices.pop(); + } } diff --git a/src/main/java/org/saturnclient/ui2/elements/Text.java b/src/main/java/org/saturnclient/ui2/elements/Text.java index 1331135..72f3149 100644 --- a/src/main/java/org/saturnclient/ui2/elements/Text.java +++ b/src/main/java/org/saturnclient/ui2/elements/Text.java @@ -6,8 +6,6 @@ import org.saturnclient.ui2.RenderScope; public class Text extends Element { private String text; - private boolean logged = false; - public Text(String text) { this.text = text; this.color = 0xFFFFFFFF; @@ -15,33 +13,6 @@ public class Text extends Element { @Override public void render(RenderScope renderScope) { - // renderScope.drawText(this.text, this.x, this.y, this.color); - - int rectWidth = 300; - int rectHeight = 300; - - renderScope.matrices.push(); - - renderScope.matrices.scale(0.1f, 0.1f, 1.0f); - - int r = 90; // Radius of the corner - int h = (rectHeight / 2) * 10; // Height of the box - int w = (rectWidth / 2) * 10; // Width of the box - - for (int y = 0; y < h; y++) { - int startX; - - if (y < r) { - double dy = y - r; - double dx = r - Math.sqrt(r * r - dy * dy); - startX = (int) Math.ceil(dx); - } else { - startX = 0; - } - - renderScope.drawRect(startX, y, w - startX, 1, this.color); - } - - renderScope.matrices.pop(); + renderScope.drawText(this.text, this.x, this.y, this.color); } }