GuiSlider .java

net.minecraft.client.gui.GuiSlider (class): members: sliderPosition, func_175217_d, func_175218_a, func_175219_a, func_175220_c, FormatHelper, isMouseDown.

net.minecraft.client.guiclass146 linesclientextends GuiButton4.5 KB

API Surface (8)

float func_175220_c()
void func_175218_a(float p_175218_1_, boolean p_175218_2_)
float func_175217_d()
int getHoverState(boolean mouseOver)
void mouseDragged(Minecraft mc, int mouseX, int mouseY)
void func_175219_a(float p_175219_1_)
boolean mousePressed(Minecraft mc, int mouseX, int mouseY)
void mouseReleased(int mouseX, int mouseY)

Fields & Constants (7)

sliderPosition
isMouseDown
name
min
max
responder
formatHelper

Code Graph: Dependencies (5)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

GuiSlider.java146 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.client.gui;
2
3
import net.minecraft.client.Minecraft;
4
import net.minecraft.client.renderer.GlStateManager;
5
import net.minecraft.client.resources.I18n;
6
7
public class GuiSlider extends GuiButton
8
{
9
    private float sliderPosition = 1.0F;
10
    public boolean isMouseDown;
11
    private String name;
12
    private final float min;
13
    private final float max;
14
    private final GuiPageButtonList.GuiResponder responder;
15
    private GuiSlider.FormatHelper formatHelper;
16
17
    public GuiSlider(GuiPageButtonList.GuiResponder guiResponder, int idIn, int x, int y, String name, float min, float max, float defaultValue, GuiSlider.FormatHelper formatter)
18
    {
19
        super(idIn, x, y, 150, 20, "");
20
        this.name = name;
21
        this.min = min;
22
        this.max = max;
23
        this.sliderPosition = (defaultValue - min) / (max - min);
24
        this.formatHelper = formatter;
25
        this.responder = guiResponder;
26
        this.displayString = this.getDisplayString();
27
    }
28
29
    public float func_175220_c()
30
    {
31
        return this.min + (this.max - this.min) * this.sliderPosition;
32
    }
33
34
    public void func_175218_a(float p_175218_1_, boolean p_175218_2_)
35
    {
36
        this.sliderPosition = (p_175218_1_ - this.min) / (this.max - this.min);
37
        this.displayString = this.getDisplayString();
38
39
        if (p_175218_2_)
40
        {
41
            this.responder.onTick(this.id, this.func_175220_c());
42
        }
43
    }
44
45
    public float func_175217_d()
46
    {
47
        return this.sliderPosition;
48
    }
49
50
    private String getDisplayString()
51
    {
52
        return this.formatHelper == null ? I18n.format(this.name, new Object[0]) + ": " + this.func_175220_c() : this.formatHelper.getText(this.id, I18n.format(this.name, new Object[0]), this.func_175220_c());
53
    }
54
55
    /**
56
     * Returns 0 if the button is disabled, 1 if the mouse is NOT hovering over this button and 2 if it IS hovering over
57
     * this button.
58
     */
59
    protected int getHoverState(boolean mouseOver)
60
    {
61
        return 0;
62
    }
63
64
    /**
65
     * Fired when the mouse button is dragged. Equivalent of MouseListener.mouseDragged(MouseEvent e).
66
     */
67
    protected void mouseDragged(Minecraft mc, int mouseX, int mouseY)
68
    {
69
        if (this.visible)
70
        {
71
            if (this.isMouseDown)
72
            {
73
                this.sliderPosition = (float)(mouseX - (this.xPosition + 4)) / (float)(this.width - 8);
74
75
                if (this.sliderPosition < 0.0F)
76
                {
77
                    this.sliderPosition = 0.0F;
78
                }
79
80
                if (this.sliderPosition > 1.0F)
81
                {
82
                    this.sliderPosition = 1.0F;
83
                }
84
85
                this.displayString = this.getDisplayString();
86
                this.responder.onTick(this.id, this.func_175220_c());
87
            }
88
89
            GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
90
            this.drawTexturedModalRect(this.xPosition + (int)(this.sliderPosition * (float)(this.width - 8)), this.yPosition, 0, 66, 4, 20);
91
            this.drawTexturedModalRect(this.xPosition + (int)(this.sliderPosition * (float)(this.width - 8)) + 4, this.yPosition, 196, 66, 4, 20);
92
        }
93
    }
94
95
    public void func_175219_a(float p_175219_1_)
96
    {
97
        this.sliderPosition = p_175219_1_;
98
        this.displayString = this.getDisplayString();
99
        this.responder.onTick(this.id, this.func_175220_c());
100
    }
101
102
    /**
103
     * Returns true if the mouse has been pressed on this control. Equivalent of MouseListener.mousePressed(MouseEvent
104
     * e).
105
     */
106
    public boolean mousePressed(Minecraft mc, int mouseX, int mouseY)
107
    {
108
        if (super.mousePressed(mc, mouseX, mouseY))
109
        {
110
            this.sliderPosition = (float)(mouseX - (this.xPosition + 4)) / (float)(this.width - 8);
111
112
            if (this.sliderPosition < 0.0F)
113
            {
114
                this.sliderPosition = 0.0F;
115
            }
116
117
            if (this.sliderPosition > 1.0F)
118
            {
119
                this.sliderPosition = 1.0F;
120
            }
121
122
            this.displayString = this.getDisplayString();
123
            this.responder.onTick(this.id, this.func_175220_c());
124
            this.isMouseDown = true;
125
            return true;
126
        }
127
        else
128
        {
129
            return false;
130
        }
131
    }
132
133
    /**
134
     * Fired when the mouse button is released. Equivalent of MouseListener.mouseReleased(MouseEvent e).
135
     */
136
    public void mouseReleased(int mouseX, int mouseY)
137
    {
138
        this.isMouseDown = false;
139
    }
140
141
    public interface FormatHelper
142
    {
143
        String getText(int id, String name, float value);
144
    }
145
}
146

Deobfuscated MCP 1.8.9 source of GuiSlider from Marcelektro/MavenMCP-1.8.9 (net/minecraft/client/gui/GuiSlider.java), stored verbatim.