From 82269bf2bbb9beb15112381ee01c1a92eb675b9b Mon Sep 17 00:00:00 2001 From: yugecin Date: Sun, 11 Dec 2016 02:29:48 +0100 Subject: [PATCH] fix scrollbar and max scroll position --- src/yugecin/opsudance/ui/OptionsOverlay.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/yugecin/opsudance/ui/OptionsOverlay.java b/src/yugecin/opsudance/ui/OptionsOverlay.java index 35fe7c3a..cf4c0d21 100644 --- a/src/yugecin/opsudance/ui/OptionsOverlay.java +++ b/src/yugecin/opsudance/ui/OptionsOverlay.java @@ -94,7 +94,7 @@ public class OptionsOverlay { tabY += GameImage.MENU_TAB.getImage().getHeight() / 2f; } } - this.maxScrollOffset = maxScrollOffset; + this.maxScrollOffset = maxScrollOffset - optionStartY - optionHeight; // calculate other positions optionStartY = (int) (tabY + tabImage.getHeight() / 2 + 2); // +2 for the separator line @@ -154,7 +154,7 @@ public class OptionsOverlay { } // scrollbar g.setColor(Color.white); - g.fillRoundRect(optionStartX + optionWidth + 15, optionStartY + ((float) scrollOffset / maxScrollOffset) * (height - optionStartY), 10, 45, 2); + g.fillRoundRect(optionStartX + optionWidth + 15, optionStartY + ((float) scrollOffset / (maxScrollOffset)) * (height - optionStartY - 45), 10, 45, 2); g.clearClip(); } @@ -270,7 +270,7 @@ public class OptionsOverlay { } public void mouseDragged(int oldx, int oldy, int newx, int newy) { - scrollOffset += oldy - newy; + scrollOffset = Utils.clamp(scrollOffset + oldy - newy, 0, maxScrollOffset); } public void mouseWheelMoved(int delta) {