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