]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/blob - src/main/java/com/irtimaled/bbor/client/gui/AbstractSlider.java
059ce943e642c636bad7d35804bca769f320ceaa
[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
11     AbstractSlider(int id, int x, int y, int width) {
12         super(id, x, y, width, 20, "");
13     }
14
15     @Override
16     public void render(int mouseX, int mouseY) {
17         super.render(mouseX, mouseY, 0f);
18     }
19
20     @Override
21     protected void renderBg(Minecraft minecraft, int mouseX, int mouseY) {
22         minecraft.getTextureManager().bindTexture(BUTTON_TEXTURES);
23         GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
24         this.drawTexturedModalRect(this.x + (int) (this.progress * (double) (this.width - 8)), this.y, 0, 66, 4, 20);
25         this.drawTexturedModalRect(this.x + (int) (this.progress * (double) (this.width - 8)) + 4, this.y, 196, 66, 4, 20);
26     }
27
28     boolean setProgress(double progress) {
29         progress = MathHelper.clamp(progress, 0d, 1d);
30         if (this.progress == progress) return false;
31
32         this.progress = progress;
33         return true;
34     }
35
36     private void changeProgress(double mouseX) {
37         double progress = (mouseX - (double) (this.x + 4)) / (double) (this.width - 8);
38         if (setProgress(progress)) {
39             onProgressChanged();
40         }
41         updateText();
42     }
43
44     @Override
45     protected int getHoverState(boolean hovered) {
46         return 0;
47     }
48
49     @Override
50     protected void onDrag(double mouseX, double mouseY, double deltaX, double deltaY) {
51         changeProgress(mouseX);
52         super.onDrag(mouseX, mouseY, deltaX, deltaY);
53     }
54
55     @Override
56     public void onClick(double mouseX, double mouseY) {
57         changeProgress(mouseX);
58         super.onClick(mouseX, mouseY);
59     }
60
61     protected abstract void updateText();
62
63     protected abstract void onProgressChanged();
64 }