/
GuiIconButtonSmall.java
52 lines (45 loc) · 1.92 KB
/
GuiIconButtonSmall.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
package mezz.jei.gui.elements;
import mezz.jei.api.gui.IDrawable;
import mezz.jei.config.Constants;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.client.config.GuiUtils;
/**
* A small gui button that has an {@link IDrawable} instead of a string label.
*/
public class GuiIconButtonSmall extends GuiButton {
private static final ResourceLocation BUTTON_RESOURCE = new ResourceLocation(Constants.RESOURCE_DOMAIN, Constants.TEXTURE_RECIPE_BACKGROUND_PATH);
private final IDrawable icon;
public GuiIconButtonSmall(int buttonId, int x, int y, int widthIn, int heightIn, IDrawable icon) {
super(buttonId, x, y, widthIn, heightIn, "");
this.icon = icon;
}
@Override
public void drawButton(Minecraft mc, int mouseX, int mouseY) {
if (this.visible) {
this.hovered = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height;
int k = this.getHoverState(this.hovered);
GuiUtils.drawContinuousTexturedBox(BUTTON_RESOURCE, this.xPosition, this.yPosition, 0, 182 + k * 20, this.width, this.height, 95, 20, 2, 2, 2, 2, this.zLevel);
this.mouseDragged(mc, mouseX, mouseY);
int color = 14737632;
if (!this.enabled) {
color = 10526880;
} else if (this.hovered) {
color = 16777120;
}
if ((color & -67108864) == 0) {
color |= -16777216;
}
float red = (float) (color >> 16 & 255) / 255.0F;
float blue = (float) (color >> 8 & 255) / 255.0F;
float green = (float) (color & 255) / 255.0F;
float alpha = (float) (color >> 24 & 255) / 255.0F;
GlStateManager.color(red, blue, green, alpha);
int xOffset = xPosition + (height - this.icon.getWidth()) / 2;
int yOffset = yPosition + (width - this.icon.getHeight()) / 2;
this.icon.draw(mc, xOffset, yOffset);
}
}
}