few theme stuff to button and rounded corners
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
@@ -219,7 +220,6 @@ public class RenderScope {
|
||||
public int getScaledWindowHeight() {
|
||||
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);
|
||||
}
|
||||
@@ -238,7 +238,6 @@ public class RenderScope {
|
||||
|
||||
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) {
|
||||
RenderSystem.setShaderTexture(0, sprite);
|
||||
|
||||
RenderLayer renderLayer = (RenderLayer)renderLayers.apply(sprite);
|
||||
Matrix4f matrix4f = this.matrices.peek().getPositionMatrix();
|
||||
VertexConsumer vertexConsumer = this.vertexConsumers.getBuffer(renderLayer);
|
||||
|
||||
@@ -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<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> 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));
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user