diff options
author | isxander <xander@isxander.dev> | 2024-04-11 18:43:06 +0100 |
---|---|---|
committer | isxander <xander@isxander.dev> | 2024-04-11 18:43:06 +0100 |
commit | 04fe933f4c24817100f3101f088accf55a621f8a (patch) | |
tree | feff94ca3ab4484160e69a24f4ee38522381950e /src/main/java/dev/isxander/yacl3/gui/TextScaledButtonWidget.java | |
parent | 831b894fdb7fe3e173d81387c8f6a2402b8ccfa9 (diff) | |
download | YetAnotherConfigLib-04fe933f4c24817100f3101f088accf55a621f8a.tar.gz YetAnotherConfigLib-04fe933f4c24817100f3101f088accf55a621f8a.tar.bz2 YetAnotherConfigLib-04fe933f4c24817100f3101f088accf55a621f8a.zip |
Extremely fragile and broken multiversion build with stonecutter
Diffstat (limited to 'src/main/java/dev/isxander/yacl3/gui/TextScaledButtonWidget.java')
-rw-r--r-- | src/main/java/dev/isxander/yacl3/gui/TextScaledButtonWidget.java | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/main/java/dev/isxander/yacl3/gui/TextScaledButtonWidget.java b/src/main/java/dev/isxander/yacl3/gui/TextScaledButtonWidget.java new file mode 100644 index 0000000..6ad0d1c --- /dev/null +++ b/src/main/java/dev/isxander/yacl3/gui/TextScaledButtonWidget.java @@ -0,0 +1,34 @@ +package dev.isxander.yacl3.gui; + +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.Component; +import net.minecraft.util.Mth; + +public class TextScaledButtonWidget extends TooltipButtonWidget { + public float textScale; + + public TextScaledButtonWidget(Screen screen, int x, int y, int width, int height, float textScale, Component message, Component tooltip, OnPress onPress) { + super(screen, x, y, width, height, message, tooltip, onPress); + this.textScale = textScale; + } + + public TextScaledButtonWidget(Screen screen, int x, int y, int width, int height, float textScale, Component message, OnPress onPress) { + this(screen, x, y, width, height, textScale, message, null, onPress); + } + + @Override + public void renderString(GuiGraphics graphics, Font textRenderer, int color) { + Font font = Minecraft.getInstance().font; + PoseStack pose = graphics.pose(); + + pose.pushPose(); + pose.translate(((this.getX() + this.width / 2f) - font.width(getMessage()) * textScale / 2), (float)this.getY() + (this.height - 8 * textScale) / 2f / textScale, 0); + pose.scale(textScale, textScale, 1); + graphics.drawString(font, getMessage(), 0, 0, color | Mth.ceil(this.alpha * 255.0F) << 24, true); + pose.popPose(); + } +} |