001 package net.minecraft.src;
002
003 import cpw.mods.fml.common.Side;
004 import cpw.mods.fml.common.asm.SideOnly;
005 import net.minecraft.client.Minecraft;
006 import org.lwjgl.opengl.GL11;
007
008 @SideOnly(Side.CLIENT)
009 public class GuiButton extends Gui
010 {
011 /** Button width in pixels */
012 protected int width;
013
014 /** Button height in pixels */
015 protected int height;
016
017 /** The x position of this control. */
018 public int xPosition;
019
020 /** The y position of this control. */
021 public int yPosition;
022
023 /** The string displayed on this control. */
024 public String displayString;
025
026 /** ID for this control. */
027 public int id;
028
029 /** True if this control is enabled, false to disable. */
030 public boolean enabled;
031
032 /** Hides the button completely if false. */
033 public boolean drawButton;
034
035 public GuiButton(int par1, int par2, int par3, String par4Str)
036 {
037 this(par1, par2, par3, 200, 20, par4Str);
038 }
039
040 public GuiButton(int par1, int par2, int par3, int par4, int par5, String par6Str)
041 {
042 this.width = 200;
043 this.height = 20;
044 this.enabled = true;
045 this.drawButton = true;
046 this.id = par1;
047 this.xPosition = par2;
048 this.yPosition = par3;
049 this.width = par4;
050 this.height = par5;
051 this.displayString = par6Str;
052 }
053
054 /**
055 * Returns 0 if the button is disabled, 1 if the mouse is NOT hovering over this button and 2 if it IS hovering over
056 * this button.
057 */
058 protected int getHoverState(boolean par1)
059 {
060 byte var2 = 1;
061
062 if (!this.enabled)
063 {
064 var2 = 0;
065 }
066 else if (par1)
067 {
068 var2 = 2;
069 }
070
071 return var2;
072 }
073
074 /**
075 * Draws this button to the screen.
076 */
077 public void drawButton(Minecraft par1Minecraft, int par2, int par3)
078 {
079 if (this.drawButton)
080 {
081 FontRenderer var4 = par1Minecraft.fontRenderer;
082 GL11.glBindTexture(GL11.GL_TEXTURE_2D, par1Minecraft.renderEngine.getTexture("/gui/gui.png"));
083 GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
084 boolean var5 = par2 >= this.xPosition && par3 >= this.yPosition && par2 < this.xPosition + this.width && par3 < this.yPosition + this.height;
085 int var6 = this.getHoverState(var5);
086 this.drawTexturedModalRect(this.xPosition, this.yPosition, 0, 46 + var6 * 20, this.width / 2, this.height);
087 this.drawTexturedModalRect(this.xPosition + this.width / 2, this.yPosition, 200 - this.width / 2, 46 + var6 * 20, this.width / 2, this.height);
088 this.mouseDragged(par1Minecraft, par2, par3);
089 int var7 = 14737632;
090
091 if (!this.enabled)
092 {
093 var7 = -6250336;
094 }
095 else if (var5)
096 {
097 var7 = 16777120;
098 }
099
100 this.drawCenteredString(var4, this.displayString, this.xPosition + this.width / 2, this.yPosition + (this.height - 8) / 2, var7);
101 }
102 }
103
104 /**
105 * Fired when the mouse button is dragged. Equivalent of MouseListener.mouseDragged(MouseEvent e).
106 */
107 protected void mouseDragged(Minecraft par1Minecraft, int par2, int par3) {}
108
109 /**
110 * Fired when the mouse button is released. Equivalent of MouseListener.mouseReleased(MouseEvent e).
111 */
112 public void mouseReleased(int par1, int par2) {}
113
114 /**
115 * Returns true if the mouse has been pressed on this control. Equivalent of MouseListener.mousePressed(MouseEvent
116 * e).
117 */
118 public boolean mousePressed(Minecraft par1Minecraft, int par2, int par3)
119 {
120 return this.enabled && this.drawButton && par2 >= this.xPosition && par3 >= this.yPosition && par2 < this.xPosition + this.width && par3 < this.yPosition + this.height;
121 }
122 }