package net.minecraft.client.gui; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.Minecraft; import net.minecraft.client.audio.PositionedSoundRecord; import net.minecraft.client.audio.SoundHandler; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL11; @SideOnly(Side.CLIENT) public class GuiButton extends Gui { protected static final ResourceLocation buttonTextures = new ResourceLocation("textures/gui/widgets.png"); /** Button width in pixels */ public int width; /** Button height in pixels */ public int height; /** The x position of this control. */ public int xPosition; /** The y position of this control. */ public int yPosition; /** The string displayed on this control. */ public String displayString; public int id; /** True if this control is enabled, false to disable. */ public boolean enabled; /** Hides the button completely if false. */ public boolean visible; protected boolean hovered; private static final String __OBFID = "CL_00000668"; public int packedFGColour; public GuiButton(int buttonId, int x, int y, String buttonText) { this(buttonId, x, y, 200, 20, buttonText); } public GuiButton(int stateName, int id, int p_i1021_3_, int p_i1021_4_, int p_i1021_5_, String p_i1021_6_) { this.width = 200; this.height = 20; this.enabled = true; this.visible = true; this.id = stateName; this.xPosition = id; this.yPosition = p_i1021_3_; this.width = p_i1021_4_; this.height = p_i1021_5_; this.displayString = p_i1021_6_; } /** * Returns 0 if the button is disabled, 1 if the mouse is NOT hovering over this button and 2 if it IS hovering over * this button. */ public int getHoverState(boolean mouseOver) { byte b0 = 1; if (!this.enabled) { b0 = 0; } else if (mouseOver) { b0 = 2; } return b0; } /** * Draws this button to the screen. */ public void drawButton(Minecraft mc, int mouseX, int mouseY) { if (this.visible) { FontRenderer fontrenderer = mc.fontRendererObj; mc.getTextureManager().bindTexture(buttonTextures); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.hovered = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height; int k = this.getHoverState(this.hovered); GL11.glEnable(GL11.GL_BLEND); OpenGlHelper.glBlendFunc(770, 771, 1, 0); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); this.drawTexturedModalRect(this.xPosition, this.yPosition, 0, 46 + k * 20, this.width / 2, this.height); this.drawTexturedModalRect(this.xPosition + this.width / 2, this.yPosition, 200 - this.width / 2, 46 + k * 20, this.width / 2, this.height); this.mouseDragged(mc, mouseX, mouseY); int l = 14737632; if (packedFGColour != 0) { l = packedFGColour; } else if (!this.enabled) { l = 10526880; } else if (this.hovered) { l = 16777120; } this.drawCenteredString(fontrenderer, this.displayString, this.xPosition + this.width / 2, this.yPosition + (this.height - 8) / 2, l); } } /** * Fired when the mouse button is dragged. Equivalent of MouseListener.mouseDragged(MouseEvent e). */ protected void mouseDragged(Minecraft mc, int mouseX, int mouseY) {} /** * Fired when the mouse button is released. Equivalent of MouseListener.mouseReleased(MouseEvent e). */ public void mouseReleased(int mouseX, int mouseY) {} /** * Returns true if the mouse has been pressed on this control. Equivalent of MouseListener.mousePressed(MouseEvent * e). */ public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) { return this.enabled && this.visible && mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height; } /** * Whether the mouse cursor is currently over the button. */ public boolean isMouseOver() { return this.hovered; } public void drawButtonForegroundLayer(int mouseX, int mouseY) {} public void playPressSound(SoundHandler soundHandlerIn) { soundHandlerIn.playSound(PositionedSoundRecord.createPositionedSoundRecord(new ResourceLocation("gui.button.press"), 1.0F)); } public int getButtonWidth() { return this.width; } public int getButtonHeight() { return this.height; } }