001package net.minecraft.client.gui;
002
003import cpw.mods.fml.relauncher.Side;
004import cpw.mods.fml.relauncher.SideOnly;
005import net.minecraft.client.Minecraft;
006import net.minecraft.client.settings.EnumOptions;
007import org.lwjgl.opengl.GL11;
008
009@SideOnly(Side.CLIENT)
010public class GuiSlider extends GuiButton
011{
012    /** The value of this slider control. */
013    public float sliderValue = 1.0F;
014
015    /** Is this slider control being dragged. */
016    public boolean dragging = false;
017
018    /** Additional ID for this slider control. */
019    private EnumOptions idFloat = null;
020
021    public GuiSlider(int par1, int par2, int par3, EnumOptions par4EnumOptions, String par5Str, float par6)
022    {
023        super(par1, par2, par3, 150, 20, par5Str);
024        this.idFloat = par4EnumOptions;
025        this.sliderValue = par6;
026    }
027
028    /**
029     * Returns 0 if the button is disabled, 1 if the mouse is NOT hovering over this button and 2 if it IS hovering over
030     * this button.
031     */
032    protected int getHoverState(boolean par1)
033    {
034        return 0;
035    }
036
037    /**
038     * Fired when the mouse button is dragged. Equivalent of MouseListener.mouseDragged(MouseEvent e).
039     */
040    protected void mouseDragged(Minecraft par1Minecraft, int par2, int par3)
041    {
042        if (this.drawButton)
043        {
044            if (this.dragging)
045            {
046                this.sliderValue = (float)(par2 - (this.xPosition + 4)) / (float)(this.width - 8);
047
048                if (this.sliderValue < 0.0F)
049                {
050                    this.sliderValue = 0.0F;
051                }
052
053                if (this.sliderValue > 1.0F)
054                {
055                    this.sliderValue = 1.0F;
056                }
057
058                par1Minecraft.gameSettings.setOptionFloatValue(this.idFloat, this.sliderValue);
059                this.displayString = par1Minecraft.gameSettings.getKeyBinding(this.idFloat);
060            }
061
062            GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
063            this.drawTexturedModalRect(this.xPosition + (int)(this.sliderValue * (float)(this.width - 8)), this.yPosition, 0, 66, 4, 20);
064            this.drawTexturedModalRect(this.xPosition + (int)(this.sliderValue * (float)(this.width - 8)) + 4, this.yPosition, 196, 66, 4, 20);
065        }
066    }
067
068    /**
069     * Returns true if the mouse has been pressed on this control. Equivalent of MouseListener.mousePressed(MouseEvent
070     * e).
071     */
072    public boolean mousePressed(Minecraft par1Minecraft, int par2, int par3)
073    {
074        if (super.mousePressed(par1Minecraft, par2, par3))
075        {
076            this.sliderValue = (float)(par2 - (this.xPosition + 4)) / (float)(this.width - 8);
077
078            if (this.sliderValue < 0.0F)
079            {
080                this.sliderValue = 0.0F;
081            }
082
083            if (this.sliderValue > 1.0F)
084            {
085                this.sliderValue = 1.0F;
086            }
087
088            par1Minecraft.gameSettings.setOptionFloatValue(this.idFloat, this.sliderValue);
089            this.displayString = par1Minecraft.gameSettings.getKeyBinding(this.idFloat);
090            this.dragging = true;
091            return true;
092        }
093        else
094        {
095            return false;
096        }
097    }
098
099    /**
100     * Fired when the mouse button is released. Equivalent of MouseListener.mouseReleased(MouseEvent e).
101     */
102    public void mouseReleased(int par1, int par2)
103    {
104        this.dragging = false;
105    }
106}