-
-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathTextScaledButtonWidget.java
More file actions
61 lines (50 loc) · 2.53 KB
/
Copy pathTextScaledButtonWidget.java
File metadata and controls
61 lines (50 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package dev.isxander.yacl3.gui;
import net.minecraft.client.Minecraft;
//? if >=1.21.11 {
import org.jspecify.annotations.NonNull;
//?}
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);
}
//? if >=1.21.11 {
@Override
protected void renderContents(@NonNull GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
this.renderDefaultSprite(guiGraphics);
if (Math.abs(textScale - 1.0f) < 0.01f) {
this.renderDefaultLabel(guiGraphics.textRendererForWidget(this, GuiGraphics.HoveredTextEffects.NONE));
return;
}
Font font = Minecraft.getInstance().font;
Component message = getMessage();
float scaledX = getX() + getWidth() / 2.0f - (font.width(message) * textScale) / 2.0f;
float scaledY = getY() + getHeight() / 2.0f - (font.lineHeight * textScale) / 2.0f;
guiGraphics.pose().pushMatrix();
guiGraphics.pose().translate(scaledX, scaledY);
guiGraphics.pose().scale(textScale, textScale);
int color = this.active ? 0xFFFFFFFF : 0xFFA0A0A0;
guiGraphics.drawString(font, message, 0, 0, color | Mth.ceil(this.alpha * 255.0F) << 24, true);
guiGraphics.pose().popMatrix();
}
//?} else {
/*@Override
public void renderString(GuiGraphics graphics, Font textRenderer, int color) {
Font font = Minecraft.getInstance().font;
GuiUtils.pushPose(graphics);
GuiUtils.translate2D(graphics, ((this.getX() + this.width / 2f) - font.width(getMessage()) * textScale / 2), (float)this.getY() + (this.height - 8 * textScale) / 2f / textScale);
GuiUtils.scale2D(graphics, textScale, textScale);
graphics.drawString(font, getMessage(), 0, 0, color | Mth.ceil(this.alpha * 255.0F) << 24, true);
GuiUtils.popPose(graphics);
}
*///?}
}