-
Notifications
You must be signed in to change notification settings - Fork 497
/
GuiBetterButton.java
91 lines (75 loc) · 2.68 KB
/
GuiBetterButton.java
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package buildcraft.core.gui.buttons;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.resources.ResourceLocation;
import org.lwjgl.opengl.GL11;
import buildcraft.core.gui.tooltips.ToolTip;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
*
* @author CovertJaguar <railcraft.wikispaces.com>
*/
@SideOnly(Side.CLIENT)
public class GuiBetterButton extends GuiButton {
public static final ResourceLocation BUTTON_TEXTURES = new ResourceLocation("buildcraft","gfx/buildcraft/gui/buttons.png");
protected final IButtonTextureSet texture;
private ToolTip toolTip;
public GuiBetterButton(int id, int x, int y, String label) {
this(id, x, y, 200, StandardButtonTextureSets.LARGE_BUTTON, label);
}
public GuiBetterButton(int id, int x, int y, int width, String label) {
this(id, x, y, width, StandardButtonTextureSets.LARGE_BUTTON, label);
}
public GuiBetterButton(int id, int x, int y, int width, IButtonTextureSet texture, String label) {
super(id, x, y, width, texture.getHeight(), label);
this.texture = texture;
}
public int getWidth() {
return width;
}
public int getHeight() {
return texture.getHeight();
}
public int getTextColor(boolean mouseOver) {
if (!enabled) {
return 0xffa0a0a0;
} else if (mouseOver) {
return 0xffffa0;
} else {
return 0xe0e0e0;
}
}
public boolean isMouseOverButton(int mouseX, int mouseY) {
return mouseX >= xPosition && mouseY >= yPosition && mouseX < xPosition + width && mouseY < yPosition + getHeight();
}
protected void bindButtonTextures(Minecraft minecraft) {
minecraft.renderEngine.func_110577_a(BUTTON_TEXTURES);
}
@Override
public void drawButton(Minecraft minecraft, int mouseX, int mouseY) {
if (!drawButton) {
return;
}
FontRenderer fontrenderer = minecraft.fontRenderer;
bindButtonTextures(minecraft);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
int xOffset = texture.getX();
int yOffset = texture.getY();
int h = texture.getHeight();
int w = texture.getWidth();
boolean mouseOver = isMouseOverButton(mouseX, mouseY);
int hoverState = getHoverState(mouseOver);
drawTexturedModalRect(xPosition, yPosition, xOffset, yOffset + hoverState * h, width / 2, h);
drawTexturedModalRect(xPosition + width / 2, yPosition, xOffset + w - width / 2, yOffset + hoverState * h, width / 2, h);
mouseDragged(minecraft, mouseX, mouseY);
drawCenteredString(fontrenderer, displayString, xPosition + width / 2, yPosition + (h - 8) / 2, getTextColor(mouseOver));
}
public ToolTip getToolTip() {
return toolTip;
}
public void setToolTip(ToolTip tips) {
this.toolTip = tips;
}
}