few theme stuff to button and rounded corners

This commit is contained in:
2025-04-26 15:43:10 +02:00
parent ff02427aa3
commit 1254cd4b89
3 changed files with 46 additions and 58 deletions
@@ -7,7 +7,7 @@ import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil; import net.minecraft.client.util.InputUtil;
// import org.saturnclient.modules.mods.FreeLook; // 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.saturnclient.saturnclient.menus.SaturnMenu;
import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.GLFW;
@@ -46,7 +46,7 @@ public class KeyInputHandler {
// Register the event handler for the main menu key // Register the event handler for the main menu key
ClientTickEvents.END_CLIENT_TICK.register(client -> { ClientTickEvents.END_CLIENT_TICK.register(client -> {
if (mainMenuKeyBinding.wasPressed()) { if (mainMenuKeyBinding.wasPressed()) {
client.setScreen(new ModMenu()); client.setScreen(new ShiftMenu());
} }
// else if (freelookKeyBinding.wasPressed() && FreeLook.enabled.value && FreeLook.toggle.value) { // else if (freelookKeyBinding.wasPressed() && FreeLook.enabled.value && FreeLook.toggle.value) {
// FreeLook.isFreeLooking = !FreeLook.isFreeLooking; // FreeLook.isFreeLooking = !FreeLook.isFreeLooking;
@@ -117,6 +117,7 @@ public class RenderScope {
} }
public void drawRoundedRectangle(int x, int y, int width, int height, int radius, int color) { 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 cornerWidth = width / 2;
int cornerHeight = height / 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) { 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; size *= 10;
width *= 20; width *= 40;
height *= 20; height *= 40;
matrices.push(); matrices.push();
matrices.scale(0.05f, 0.05f, 1.0f); matrices.scale(0.025f, 0.025f, 1.0f);
drawRoundedBorderCornerTopLeft(size, radius, color); drawRoundedBorderCornerTopLeft(size, radius, color);
drawRect(radius, 0, width - (radius * 2), size, color); drawRect(radius, 0, width - (radius * 2), size, color);
@@ -216,35 +217,33 @@ public class RenderScope {
return SaturnClient.client.getWindow().getScaledWidth(); return SaturnClient.client.getWindow().getScaledWidth();
} }
public int getScaledWindowHeight() { public int getScaledWindowHeight() {
return SaturnClient.client.getWindow().getScaledHeight(); return SaturnClient.client.getWindow().getScaledHeight();
} }
public void drawTexture(Function<Identifier, RenderLayer> 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<Identifier, RenderLayer> renderLayers, Identifier sprite, int x, int y, float u, float v, int width, int height, int textureWidth, int textureHeight, int color) { public void drawTexture(Function<Identifier, RenderLayer> 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, color); this.drawTexture(renderLayers, sprite, x, y, u, v, width, height, width, height, textureWidth, textureHeight);
} }
public void drawTexture(Function<Identifier, RenderLayer> renderLayers, Identifier sprite, int x, int y, float u, float v, int width, int height, int textureWidth, int textureHeight) { public void drawTexture(Function<Identifier, RenderLayer> 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, width, height, textureWidth, textureHeight); this.drawTexture(renderLayers, sprite, x, y, u, v, width, height, regionWith, regionHeight, textureWidth, textureHeight, -1);
} }
public void drawTexture(Function<Identifier, RenderLayer> renderLayers, Identifier sprite, int x, int y, float u, float v, int width, int height, int regionWith, int regionHeight, int textureWidth, int textureHeight) { public void drawTexture(Function<Identifier, RenderLayer> 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.drawTexture(renderLayers, sprite, x, y, u, v, width, height, regionWith, regionHeight, textureWidth, textureHeight, -1); 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);
} }
public void drawTexture(Function<Identifier, RenderLayer> 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) { private void drawTexturedQuad(Function<Identifier, RenderLayer> renderLayers, Identifier sprite, int x1, int x2, int y1, int y2, float u1, float u2, float v1, float v2, 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); RenderSystem.setShaderTexture(0, sprite);
} RenderLayer renderLayer = (RenderLayer)renderLayers.apply(sprite);
Matrix4f matrix4f = this.matrices.peek().getPositionMatrix();
private void drawTexturedQuad(Function<Identifier, RenderLayer> renderLayers, Identifier sprite, int x1, int x2, int y1, int y2, float u1, float u2, float v1, float v2, int color) { VertexConsumer vertexConsumer = this.vertexConsumers.getBuffer(renderLayer);
RenderSystem.setShaderTexture(0, sprite); 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);
RenderLayer renderLayer = (RenderLayer)renderLayers.apply(sprite); vertexConsumer.vertex(matrix4f, (float)x2, (float)y2, 0.0F).texture(u2, v2).color(color);
Matrix4f matrix4f = this.matrices.peek().getPositionMatrix(); vertexConsumer.vertex(matrix4f, (float)x2, (float)y1, 0.0F).texture(u2, v1).color(color);
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);
}
} }
@@ -8,16 +8,19 @@ import org.saturnclient.ui2.RenderScope;
import org.saturnclient.ui2.resources.Fonts; import org.saturnclient.ui2.resources.Fonts;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.math.RotationAxis;
public class Button extends Element { public class Button extends Element {
private static ThemeManager theme = new ThemeManager("Button", "hovering"); private static ThemeManager theme = new ThemeManager("Button", "hovering");
private static Property<Integer> bgColor = theme.property("bg-color", new Property<Integer>(0xFF000000)); private static Property<Integer> bgColor = theme.property("bg-color", new Property<Integer>(0xFF000000));
private static Property<Integer> fgColor = theme.property("fg-color", new Property<Integer>(0xFFFFFFFF)); private static Property<Integer> fgColor = theme.property("fg-color", new Property<Integer>(0xFFFFFFFF));
private static Property<Integer> borderColor = theme.property("border-color", new Property<Integer>(0xFFFFFFFF));
private static Property<Integer> border = theme.property("border", new Property<Integer>(1));
private static Property<Integer> cornerRadius = theme.property("corner-radius", new Property<Integer>(10));
private static Property<Boolean> bold = theme.property("fg-bold", new Property<Boolean>(false)); private static Property<Boolean> bold = theme.property("fg-bold", new Property<Boolean>(false));
static { static {
theme.propertyStateDefault("hovering", "fg-color", 0xFFFF0000); theme.propertyStateDefault("hovering", "fg-color", 0xFFFF0000);
theme.propertyStateDefault("hovering", "border-color", 0xFFFF0000);
} }
private String text; private String text;
@@ -33,30 +36,16 @@ public class Button extends Element {
@Override @Override
public void render(RenderScope renderScope, RenderContext ctx) { public void render(RenderScope renderScope, RenderContext ctx) {
int w = width; if (ctx.isHovering()) {
int h = width; theme.setState("hovering");
int r = 30; } else {
int s = 1; 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.drawText(text, width / 2 - Fonts.getWidth(text, font) / 2, height / 2 - Fonts.getHeight() / 2, bold.value, 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);
} }
@Override @Override