allow scrolling in the list by dragging mouse

This commit is contained in:
yugecin 2016-09-27 17:35:53 +02:00
parent 825a8a44fe
commit d2ff927ab6

View File

@ -18,6 +18,7 @@
package yugecin.opsudance.ui; package yugecin.opsudance.ui;
import itdelatrisu.opsu.Utils;
import itdelatrisu.opsu.ui.Fonts; import itdelatrisu.opsu.ui.Fonts;
import itdelatrisu.opsu.ui.UI; import itdelatrisu.opsu.ui.UI;
import org.newdawn.slick.Color; 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) { 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)) { if (UI.getBackButton().contains(x, y)) {
visible = false; visible = false;
} }
@ -108,7 +122,12 @@ public class ItemList {
} }
public void mouseDragged(int oldx, int oldy, int x, int y) { 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) { public void mouseWheelMoved(int delta) {