forked from pack-png-mods/ModMenu
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathModMenuTexturedButtonWidget.java
More file actions
76 lines (66 loc) · 2.85 KB
/
ModMenuTexturedButtonWidget.java
File metadata and controls
76 lines (66 loc) · 2.85 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package io.github.prospector.modmenu.gui;
import net.minecraft.client.Minecraft;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.render.Tessellator;
import org.lwjgl.opengl.GL11;
public class ModMenuTexturedButtonWidget extends ButtonWidget {
private final String texture;
private final int u;
private final int v;
private final int uWidth;
private final int vHeight;
protected ModMenuTexturedButtonWidget(int buttonId, int x, int y, int width, int height, int u, int v, String texture) {
this(buttonId, x, y, width, height, u, v, texture, 256, 256);
}
protected ModMenuTexturedButtonWidget(int buttonId, int x, int y, int width, int height, int u, int v, String texture, int uWidth, int vHeight) {
this(buttonId, x, y, width, height, u, v, texture, uWidth, vHeight, "");
}
protected ModMenuTexturedButtonWidget(int buttonId, int x, int y, int width, int height, int u, int v, String texture, int uWidth, int vHeight, String message) {
super(buttonId, x, y, width, height, message);
this.uWidth = uWidth;
this.vHeight = vHeight;
this.u = u;
this.v = v;
this.texture = texture;
}
protected void setPos(int x, int y) {
this.x = x;
this.y = y;
}
protected boolean isHovered(int mouseX, int mouseY) {
return mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
}
@Override
public void render(Minecraft mc, int mouseX, int mouseY) {
if (this.visible) {
TextRenderer font = mc.textRenderer;
GL11.glBindTexture(GL11.GL_TEXTURE_2D, mc.textureManager.getTextureId(texture));
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
boolean hovered = isHovered(mouseX, mouseY);
int adjustedV = this.v;
if (!active) {
adjustedV += this.height * 2;
} else if (hovered) {
adjustedV += this.height;
}
float uScale = 1f / uWidth;
float vScale = 1f / vHeight;
Tessellator tess = Tessellator.INSTANCE;
tess.startQuads();
tess.vertex(x, y + height, this.zOffset, (float) u * uScale, (float)(adjustedV + height) * vScale);
tess.vertex(x + width, y + height, this.zOffset, ((float)(u + width) * uScale), (float)(adjustedV + height) * vScale);
tess.vertex(x + width, y, this.zOffset, (float)(u + width) * uScale, (float)adjustedV * vScale);
tess.vertex(x, y, this.zOffset, (float) u * uScale, (float) adjustedV * vScale);
tess.draw();
this.renderBackground(mc, mouseX, mouseY);
if (!this.active) {
this.drawCenteredTextWithShadow(font, this.text, this.x + this.width / 2, this.y + (this.height - 8) / 2, 0xffa0a0a0);
} else if (hovered) {
this.drawCenteredTextWithShadow(font, this.text, this.x + this.width / 2, this.y + (this.height - 8) / 2, 0xffffa0);
} else {
this.drawCenteredTextWithShadow(font, this.text, this.x + this.width / 2, this.y + (this.height - 8) / 2, 0xe0e0e0);
}
}
}
}