From 5c15af05905a27bc58e2316b1ec62f3cff9a1a47 Mon Sep 17 00:00:00 2001 From: Leo dev Date: Sat, 19 Apr 2025 10:40:56 -0500 Subject: [PATCH] added renderScope --- .../java/org/saturnclient/ui2/Element.java | 5 + .../org/saturnclient/ui2/RenderScope.java | 103 ++++++++++++++++++ .../org/saturnclient/ui2/SaturnScreen.java | 12 ++ 3 files changed, 120 insertions(+) create mode 100644 src/main/java/org/saturnclient/ui2/Element.java create mode 100644 src/main/java/org/saturnclient/ui2/RenderScope.java create mode 100644 src/main/java/org/saturnclient/ui2/SaturnScreen.java diff --git a/src/main/java/org/saturnclient/ui2/Element.java b/src/main/java/org/saturnclient/ui2/Element.java new file mode 100644 index 0000000..421eb98 --- /dev/null +++ b/src/main/java/org/saturnclient/ui2/Element.java @@ -0,0 +1,5 @@ +package org.saturnclient.ui2; + +public class Element { + +} diff --git a/src/main/java/org/saturnclient/ui2/RenderScope.java b/src/main/java/org/saturnclient/ui2/RenderScope.java new file mode 100644 index 0000000..ec4df90 --- /dev/null +++ b/src/main/java/org/saturnclient/ui2/RenderScope.java @@ -0,0 +1,103 @@ +package org.saturnclient.ui2; + +import org.joml.Matrix4f; + +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; + +public class RenderScope { + private MatrixStack matrices; + private VertexConsumerProvider.Immediate vertexConsumers; + private RenderLayer renderLayer; + + public RenderScope(MatrixStack matrices, VertexConsumerProvider.Immediate vertexConsumers) { + this.matrices = matrices; + this.vertexConsumers = vertexConsumers; + } + + public void drawRect(int x, int y, int width, int height, int color) { + Matrix4f matrix4f = this.matrices.peek().getPositionMatrix(); + + int x1 = x; + int x2 = x+width; + int y1 = y; + int y2 = y+height; + + int i; + if (x1 < x2) { + i = x1; + x1 = x2; + x2 = i; + } + + if (y1 < y2) { + i = y1; + y1 = y2; + y2 = i; + } + + VertexConsumer vertexConsumer = this.vertexConsumers.getBuffer(renderLayer); + vertexConsumer.vertex(matrix4f, (float)x1, (float)y1, 0).color(color); + vertexConsumer.vertex(matrix4f, (float)x1, (float)y2, 0).color(color); + vertexConsumer.vertex(matrix4f, (float)x2, (float)y2, 0).color(color); + vertexConsumer.vertex(matrix4f, (float)x2, (float)y1, 0).color(color); + } + + + public void drawTexture(int x, int y, int width, int height, int color) { + Matrix4f matrix4f = this.matrices.peek().getPositionMatrix(); + + int x1 = x; + int x2 = x+width; + int y1 = y; + int y2 = y+height; + + int i; + if (x1 < x2) { + i = x1; + x1 = x2; + x2 = i; + } + + if (y1 < y2) { + i = y1; + y1 = y2; + y2 = i; + } + + VertexConsumer vertexConsumer = this.vertexConsumers.getBuffer(renderLayer); + vertexConsumer.vertex(matrix4f, (float)x1, (float)y1, 0).color(color); + vertexConsumer.vertex(matrix4f, (float)x1, (float)y2, 0).color(color); + vertexConsumer.vertex(matrix4f, (float)x2, (float)y2, 0).color(color); + vertexConsumer.vertex(matrix4f, (float)x2, (float)y1, 0).color(color); + } + + public void drawTexture(Identifier sprite, int x, int y, float u, float v, int width, int height, int textureWidth, int textureHeight, int color) { + this.drawTexture(sprite, x, y, u, v, width, height, width, height, textureWidth, textureHeight, color); + } + + public void drawTexture(Identifier sprite, int x, int y, float u, float v, int width, int height, int textureWidth, int textureHeight) { + this.drawTexture(sprite, x, y, u, v, width, height, width, height, textureWidth, textureHeight); + } + + public void drawTexture(Identifier sprite, int x, int y, float u, float v, int width, int height, int regionWith, int regionHeight, int textureWidth, int textureHeight) { + this.drawTexture(sprite, x, y, u, v, width, height, regionWith, regionHeight, textureWidth, textureHeight, -1); + } + + public void drawTexture(Identifier sprite, int x, int y, float u, float v, int width, int height, int regionWidth, int regionHeight, int textureWidth, int textureHeight, int color) { + this.drawTexturedQuad(sprite, x, x + width, y, y + height, (u + 0.0F) / (float)textureWidth, (u + (float)regionWidth) / (float)textureWidth, (v + 0.0F) / (float)textureHeight, (v + (float)regionHeight) / (float)textureHeight, color); + } + + private void drawTexturedQuad(Identifier sprite, int x1, int x2, int y1, int y2, float u1, float u2, float v1, float v2, int color) { + RenderLayer renderLayer = RenderLayer.getGuiTextured(sprite); + Matrix4f matrix4f = this.matrices.peek().getPositionMatrix(); + VertexConsumer vertexConsumer = this.vertexConsumers.getBuffer(renderLayer); + vertexConsumer.vertex(matrix4f, (float)x1, (float)y1, 0.0F).texture(u1, v1).color(color); + vertexConsumer.vertex(matrix4f, (float)x1, (float)y2, 0.0F).texture(u1, v2).color(color); + vertexConsumer.vertex(matrix4f, (float)x2, (float)y2, 0.0F).texture(u2, v2).color(color); + vertexConsumer.vertex(matrix4f, (float)x2, (float)y1, 0.0F).texture(u2, v1).color(color); + } +} diff --git a/src/main/java/org/saturnclient/ui2/SaturnScreen.java b/src/main/java/org/saturnclient/ui2/SaturnScreen.java new file mode 100644 index 0000000..982ed8c --- /dev/null +++ b/src/main/java/org/saturnclient/ui2/SaturnScreen.java @@ -0,0 +1,12 @@ +package org.saturnclient.ui2; + +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.text.Text; + +public class SaturnScreen extends Screen { + SaturnScreen(String title) { + super(Text.literal(title)); + } + + +}