From 1254cd4b89b8d2a07e05f3dc0c4bdb9f7e4fee3a Mon Sep 17 00:00:00 2001 From: Leo dev Date: Sat, 26 Apr 2025 15:43:10 +0200 Subject: [PATCH] few theme stuff to button and rounded corners --- .../saturnclient/event/KeyInputHandler.java | 4 +- .../org/saturnclient/ui2/RenderScope.java | 65 +++++++++---------- .../org/saturnclient/ui2/elements/Button.java | 35 ++++------ 3 files changed, 46 insertions(+), 58 deletions(-) diff --git a/src/main/java/org/saturnclient/saturnclient/event/KeyInputHandler.java b/src/main/java/org/saturnclient/saturnclient/event/KeyInputHandler.java index 42b027c..8fe7aa0 100644 --- a/src/main/java/org/saturnclient/saturnclient/event/KeyInputHandler.java +++ b/src/main/java/org/saturnclient/saturnclient/event/KeyInputHandler.java @@ -7,7 +7,7 @@ import net.minecraft.client.option.KeyBinding; import net.minecraft.client.util.InputUtil; // import org.saturnclient.modules.mods.FreeLook; -import org.saturnclient.saturnclient.menus.ModMenu; +import org.saturnclient.ui2.screens.ShiftMenu; // import org.saturnclient.saturnclient.menus.SaturnMenu; import org.lwjgl.glfw.GLFW; @@ -46,7 +46,7 @@ public class KeyInputHandler { // Register the event handler for the main menu key ClientTickEvents.END_CLIENT_TICK.register(client -> { if (mainMenuKeyBinding.wasPressed()) { - client.setScreen(new ModMenu()); + client.setScreen(new ShiftMenu()); } // else if (freelookKeyBinding.wasPressed() && FreeLook.enabled.value && FreeLook.toggle.value) { // FreeLook.isFreeLooking = !FreeLook.isFreeLooking; diff --git a/src/main/java/org/saturnclient/ui2/RenderScope.java b/src/main/java/org/saturnclient/ui2/RenderScope.java index d24cb74..2160bf0 100644 --- a/src/main/java/org/saturnclient/ui2/RenderScope.java +++ b/src/main/java/org/saturnclient/ui2/RenderScope.java @@ -117,6 +117,7 @@ public class RenderScope { } public void drawRoundedRectangle(int x, int y, int width, int height, int radius, int color) { + radius = Math.min(radius, Math.min(width, height)); int cornerWidth = width / 2; int cornerHeight = height / 2; @@ -187,13 +188,13 @@ public class RenderScope { } public void drawRoundedBorder(int width, int height, int size, int radius, int color) { - radius = Math.min(radius, Math.min(width, height)) * 10; + radius = Math.min(radius, Math.min(width, height)) * 20; size *= 10; - width *= 20; - height *= 20; + width *= 40; + height *= 40; matrices.push(); - matrices.scale(0.05f, 0.05f, 1.0f); + matrices.scale(0.025f, 0.025f, 1.0f); drawRoundedBorderCornerTopLeft(size, radius, color); drawRect(radius, 0, width - (radius * 2), size, color); @@ -216,35 +217,33 @@ public class RenderScope { return SaturnClient.client.getWindow().getScaledWidth(); } - public int getScaledWindowHeight() { - return SaturnClient.client.getWindow().getScaledHeight(); - } + public int getScaledWindowHeight() { + return SaturnClient.client.getWindow().getScaledHeight(); + } + public void drawTexture(Function renderLayers, Identifier sprite, int x, int y, float u, float v, int width, int height, int textureWidth, int textureHeight, int color) { + this.drawTexture(renderLayers, sprite, x, y, u, v, width, height, width, height, textureWidth, textureHeight, color); + } - public void drawTexture(Function renderLayers, Identifier sprite, int x, int y, float u, float v, int width, int height, int textureWidth, int textureHeight, int color) { - this.drawTexture(renderLayers, sprite, x, y, u, v, width, height, width, height, textureWidth, textureHeight, color); - } - - public void drawTexture(Function renderLayers, Identifier sprite, int x, int y, float u, float v, int width, int height, int textureWidth, int textureHeight) { - this.drawTexture(renderLayers, sprite, x, y, u, v, width, height, width, height, textureWidth, textureHeight); - } - - public void drawTexture(Function renderLayers, Identifier sprite, int x, int y, float u, float v, int width, int height, int regionWith, int regionHeight, int textureWidth, int textureHeight) { - this.drawTexture(renderLayers, sprite, x, y, u, v, width, height, regionWith, regionHeight, textureWidth, textureHeight, -1); - } - - public void drawTexture(Function renderLayers, 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(renderLayers, 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(Function renderLayers, Identifier sprite, int x1, int x2, int y1, int y2, float u1, float u2, float v1, float v2, int color) { - RenderSystem.setShaderTexture(0, sprite); + public void drawTexture(Function renderLayers, Identifier sprite, int x, int y, float u, float v, int width, int height, int textureWidth, int textureHeight) { + this.drawTexture(renderLayers, sprite, x, y, u, v, width, height, width, height, textureWidth, textureHeight); + } - RenderLayer renderLayer = (RenderLayer)renderLayers.apply(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); - } + public void drawTexture(Function renderLayers, Identifier sprite, int x, int y, float u, float v, int width, int height, int regionWith, int regionHeight, int textureWidth, int textureHeight) { + this.drawTexture(renderLayers, sprite, x, y, u, v, width, height, regionWith, regionHeight, textureWidth, textureHeight, -1); + } + + public void drawTexture(Function renderLayers, 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(renderLayers, 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(Function renderLayers, Identifier sprite, int x1, int x2, int y1, int y2, float u1, float u2, float v1, float v2, int color) { + RenderSystem.setShaderTexture(0, sprite); + RenderLayer renderLayer = (RenderLayer)renderLayers.apply(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/elements/Button.java b/src/main/java/org/saturnclient/ui2/elements/Button.java index bbb2c25..200c65c 100644 --- a/src/main/java/org/saturnclient/ui2/elements/Button.java +++ b/src/main/java/org/saturnclient/ui2/elements/Button.java @@ -8,16 +8,19 @@ import org.saturnclient.ui2.RenderScope; import org.saturnclient.ui2.resources.Fonts; import net.minecraft.util.Identifier; -import net.minecraft.util.math.RotationAxis; public class Button extends Element { private static ThemeManager theme = new ThemeManager("Button", "hovering"); private static Property bgColor = theme.property("bg-color", new Property(0xFF000000)); private static Property fgColor = theme.property("fg-color", new Property(0xFFFFFFFF)); + private static Property borderColor = theme.property("border-color", new Property(0xFFFFFFFF)); + private static Property border = theme.property("border", new Property(1)); + private static Property cornerRadius = theme.property("corner-radius", new Property(10)); private static Property bold = theme.property("fg-bold", new Property(false)); static { theme.propertyStateDefault("hovering", "fg-color", 0xFFFF0000); + theme.propertyStateDefault("hovering", "border-color", 0xFFFF0000); } private String text; @@ -33,30 +36,16 @@ public class Button extends Element { @Override public void render(RenderScope renderScope, RenderContext ctx) { - int w = width; - int h = width; - int r = 30; - int s = 1; + if (ctx.isHovering()) { + theme.setState("hovering"); + } else { + theme.setState(null); + } + renderScope.drawRoundedRectangle(0, 0, width, height, cornerRadius.value, bgColor.value); - renderScope.drawRect(0, 0, w, h, bgColor.value); + renderScope.drawRoundedBorder(width, height, border.value, cornerRadius.value, borderColor.value); - renderScope.drawRoundedBorder(w, h, s, r, fgColor.value); - - // renderScope.drawRoundedSide(w - (r / 2 + s - 1), 0, w, h, s, r, fgColor.value); // right - - // renderScope.matrices.push(); - // renderScope.matrices.multiply(RotationAxis.NEGATIVE_Z.rotationDegrees(180)); - - // renderScope.matrices.pop(); - - // if (ctx.isHovering()) { - // theme.setState("hovering"); - // } else { - // theme.setState(null); - // } - // renderScope.drawRoundedRectangle(0, 0, width, height, 10, bgColor.value); - - // renderScope.drawText(text, width / 2 - Fonts.getWidth(text, font) / 2, height / 2 - Fonts.getHeight() / 2, bold.value, fgColor.value); + renderScope.drawText(text, width / 2 - Fonts.getWidth(text, font) / 2, height / 2 - Fonts.getHeight() / 2, bold.value, fgColor.value); } @Override