]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/blob - src/main/java/com/irtimaled/bbor/client/gui/AbstractSlider.java
Downgrade to 1.12.2
[BoundingBoxOutlineReloaded.git] / src / main / java / com / irtimaled / bbor / client / gui / AbstractSlider.java
1 package com.irtimaled.bbor.client.gui;
2
3 import net.minecraft.client.Minecraft;
4 import net.minecraft.client.gui.GuiButton;
5 import net.minecraft.util.math.MathHelper;
6 import org.lwjgl.opengl.GL11;
7
8 abstract class AbstractSlider extends GuiButton implements IRenderableControl {
9     double progress;
10     private boolean dragging = false;
11
12     AbstractSlider(int id, int x, int y, int width) {
13         super(id, x, y, width, 20, "");
14     }
15
16     @Override
17     public void render(int mouseX, int mouseY) {
18         super.drawButton(Minecraft.getMinecraft(), mouseX, mouseY, 0f);
19     }
20
21     @Override
22     protected void mouseDragged(Minecraft minecraft, int mouseX, int mouseY) {
23         if (dragging) {
24             changeProgress(mouseX);
25         }
26         minecraft.getTextureManager().bindTexture(BUTTON_TEXTURES);
27         GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
28         this.drawTexturedModalRect(this.x + (int) (this.progress * (double) (this.width - 8)), this.y, 0, 66, 4, 20);
29         this.drawTexturedModalRect(this.x + (int) (this.progress * (double) (this.width - 8)) + 4, this.y, 196, 66, 4, 20);
30     }
31
32     boolean setProgress(double progress) {
33         progress = MathHelper.clamp(progress, 0d, 1d);
34         if (this.progress == progress) return false;
35
36         this.progress = progress;
37         return true;
38     }
39
40     private void changeProgress(double mouseX) {
41         double progress = (mouseX - (double) (this.x + 4)) / (double) (this.width - 8);
42         if (setProgress(progress)) {
43             onProgressChanged();
44         }
45         updateText();
46     }
47
48     @Override
49     protected int getHoverState(boolean hovered) {
50         return 0;
51     }
52
53
54     @Override
55     public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) {
56         if (super.mousePressed(mc, mouseX, mouseY)) {
57             changeProgress(mouseX);
58             dragging = true;
59             return true;
60         }
61         return false;
62     }
63
64     @Override
65     public void mouseReleased(int mouseX, int mouseY) {
66         dragging = false;
67     }
68
69     protected abstract void updateText();
70
71     protected abstract void onProgressChanged();
72 }