1 package com.irtimaled.bbor.client.gui;
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;
8 abstract class AbstractSlider extends GuiButton implements IRenderableControl {
10 private boolean dragging = false;
12 AbstractSlider(int id, int x, int y, int width) {
13 super(id, x, y, width, 20, "");
17 public void render(int mouseX, int mouseY) {
18 super.drawButton(Minecraft.getMinecraft(), mouseX, mouseY, 0f);
22 protected void mouseDragged(Minecraft minecraft, int mouseX, int mouseY) {
24 changeProgress(mouseX);
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);
32 boolean setProgress(double progress) {
33 progress = MathHelper.clamp(progress, 0d, 1d);
34 if (this.progress == progress) return false;
36 this.progress = progress;
40 private void changeProgress(double mouseX) {
41 double progress = (mouseX - (double) (this.x + 4)) / (double) (this.width - 8);
42 if (setProgress(progress)) {
49 protected int getHoverState(boolean hovered) {
55 public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) {
56 if (super.mousePressed(mc, mouseX, mouseY)) {
57 changeProgress(mouseX);
65 public void mouseReleased(int mouseX, int mouseY) {
69 protected abstract void updateText();
71 protected abstract void onProgressChanged();