001    package net.minecraft.client.gui;
002    
003    import cpw.mods.fml.relauncher.Side;
004    import cpw.mods.fml.relauncher.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        protected boolean field_82253_i;
035    
036        public GuiButton(int par1, int par2, int par3, String par4Str)
037        {
038            this(par1, par2, par3, 200, 20, par4Str);
039        }
040    
041        public GuiButton(int par1, int par2, int par3, int par4, int par5, String par6Str)
042        {
043            this.width = 200;
044            this.height = 20;
045            this.enabled = true;
046            this.drawButton = true;
047            this.id = par1;
048            this.xPosition = par2;
049            this.yPosition = par3;
050            this.width = par4;
051            this.height = par5;
052            this.displayString = par6Str;
053        }
054    
055        /**
056         * Returns 0 if the button is disabled, 1 if the mouse is NOT hovering over this button and 2 if it IS hovering over
057         * this button.
058         */
059        protected int getHoverState(boolean par1)
060        {
061            byte var2 = 1;
062    
063            if (!this.enabled)
064            {
065                var2 = 0;
066            }
067            else if (par1)
068            {
069                var2 = 2;
070            }
071    
072            return var2;
073        }
074    
075        /**
076         * Draws this button to the screen.
077         */
078        public void drawButton(Minecraft par1Minecraft, int par2, int par3)
079        {
080            if (this.drawButton)
081            {
082                FontRenderer var4 = par1Minecraft.fontRenderer;
083                GL11.glBindTexture(GL11.GL_TEXTURE_2D, par1Minecraft.renderEngine.getTexture("/gui/gui.png"));
084                GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
085                this.field_82253_i = par2 >= this.xPosition && par3 >= this.yPosition && par2 < this.xPosition + this.width && par3 < this.yPosition + this.height;
086                int var5 = this.getHoverState(this.field_82253_i);
087                this.drawTexturedModalRect(this.xPosition, this.yPosition, 0, 46 + var5 * 20, this.width / 2, this.height);
088                this.drawTexturedModalRect(this.xPosition + this.width / 2, this.yPosition, 200 - this.width / 2, 46 + var5 * 20, this.width / 2, this.height);
089                this.mouseDragged(par1Minecraft, par2, par3);
090                int var6 = 14737632;
091    
092                if (!this.enabled)
093                {
094                    var6 = -6250336;
095                }
096                else if (this.field_82253_i)
097                {
098                    var6 = 16777120;
099                }
100    
101                this.drawCenteredString(var4, this.displayString, this.xPosition + this.width / 2, this.yPosition + (this.height - 8) / 2, var6);
102            }
103        }
104    
105        /**
106         * Fired when the mouse button is dragged. Equivalent of MouseListener.mouseDragged(MouseEvent e).
107         */
108        protected void mouseDragged(Minecraft par1Minecraft, int par2, int par3) {}
109    
110        /**
111         * Fired when the mouse button is released. Equivalent of MouseListener.mouseReleased(MouseEvent e).
112         */
113        public void mouseReleased(int par1, int par2) {}
114    
115        /**
116         * Returns true if the mouse has been pressed on this control. Equivalent of MouseListener.mousePressed(MouseEvent
117         * e).
118         */
119        public boolean mousePressed(Minecraft par1Minecraft, int par2, int par3)
120        {
121            return this.enabled && this.drawButton && par2 >= this.xPosition && par3 >= this.yPosition && par2 < this.xPosition + this.width && par3 < this.yPosition + this.height;
122        }
123    
124        public boolean func_82252_a()
125        {
126            return this.field_82253_i;
127        }
128    
129        public void func_82251_b(int par1, int par2) {}
130    }