From d2ff927ab6cb27ee10701085b9165007b4b3457e Mon Sep 17 00:00:00 2001 From: yugecin Date: Tue, 27 Sep 2016 17:35:53 +0200 Subject: [PATCH] allow scrolling in the list by dragging mouse --- src/yugecin/opsudance/ui/ItemList.java | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/yugecin/opsudance/ui/ItemList.java b/src/yugecin/opsudance/ui/ItemList.java index 0031c606..6e74725e 100644 --- a/src/yugecin/opsudance/ui/ItemList.java +++ b/src/yugecin/opsudance/ui/ItemList.java @@ -18,6 +18,7 @@ package yugecin.opsudance.ui; +import itdelatrisu.opsu.Utils; import itdelatrisu.opsu.ui.Fonts; import itdelatrisu.opsu.ui.UI; import org.newdawn.slick.Color; @@ -84,7 +85,20 @@ public class ItemList { } } + private int startStart; + private int mouseStartX; + private int mouseStartY; + public void mousePressed(int button, int x, int y) { + mouseStartX = x; + mouseStartY = y; + startStart = start; + } + + public void mouseReleased(int button, int x, int y) { + if (Utils.distance(x, y, mouseStartX, mouseStartY) > 5) { + return; + } if (UI.getBackButton().contains(x, y)) { visible = false; } @@ -108,7 +122,12 @@ public class ItemList { } public void mouseDragged(int oldx, int oldy, int x, int y) { - + start = startStart - (y - mouseStartY) / (Fonts.MEDIUM.getLineHeight() + 5); + if (start < 0) { + start = 0; + } else if (start > items.length - 1) { + start = items.length - 1; + } } public void mouseWheelMoved(int delta) {