diff options
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/gui/elements/Slider.java')
-rw-r--r-- | src/main/java/cc/polyfrost/oneconfig/gui/elements/Slider.java | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/Slider.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/Slider.java index 360d78e..f03ecfc 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/Slider.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/Slider.java @@ -10,6 +10,8 @@ public class Slider extends BasicElement { protected float value; protected float currentDragPoint; protected float dragPointerSize = 8f; + private boolean dragging = false; + private boolean mouseWasDown = false; public Slider(int length, float min, float max, float startValue) { super(length, 8, false); @@ -30,15 +32,16 @@ public class Slider extends BasicElement { public void update(int x, int y) { super.update(x, y); - if (InputUtils.isAreaHovered((int) ((x + width * value)), y - 12, 32, 32)) { - boolean drag = Mouse.isButtonDown(0); - if (drag) { - value = ((float) InputUtils.mouseX() - x) / width; - } - } else if (InputUtils.isAreaHovered(x - 20, y - 4, width + 40, height + 8)) { - if (Mouse.isButtonDown(0)) { - value = ((float) InputUtils.mouseX() - x) / width; - } + boolean isMouseDown = Mouse.isButtonDown(0); + boolean hovered = InputUtils.isAreaHovered(x - 6, y - 3, width + 12, height + 6); + if (hovered && isMouseDown && !mouseWasDown) dragging = true; + mouseWasDown = isMouseDown; + if (dragging) { + value = ((float) InputUtils.mouseX() - x) / width; + } + if (dragging && InputUtils.isClicked()) { + dragging = false; + value = ((float) InputUtils.mouseX() - x) / width; } if (value < 0) value = 0; @@ -55,4 +58,8 @@ public class Slider extends BasicElement { public void setValue(float value) { this.value = (value - min) / (max - min); } + + public boolean isDragging() { + return dragging; + } } |