mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-18 11:29:30 +00:00
Improve scroll widget thumb icon behavior when dragging
This commit is contained in:
1 parent
a000b153b8
commit
720cb6f971
3 files changed
+23
-16
No files matched your search
@@ -116,16 +116,19 @@ public final class IconEIO {
|
||||
public static final IconEIO X_BUT_HOVER = new IconEIO(200, 48, 8, 8);
|
||||
public static final IconEIO X_BUT_HOVER_PRESSED = new IconEIO(200, 56, 8, 8);
|
||||
|
||||
public static final IconEIO UP_ARROW_OFF = new IconEIO(201, 64, 11, 8);
|
||||
public static final IconEIO UP_ARROW_ON = new IconEIO(212, 64, 11, 8);
|
||||
public static final IconEIO UP_ARROW_OFF = new IconEIO(212, 64, 11, 8);
|
||||
public static final IconEIO UP_ARROW_ON = new IconEIO(223, 64, 11, 8);
|
||||
public static final IconEIO UP_ARROW_HOVER_OFF = new IconEIO(234, 64, 11, 8);
|
||||
public static final IconEIO UP_ARROW_HOVER_ON = new IconEIO(245, 64, 11, 8);
|
||||
public static final IconEIO DOWN_ARROW_OFF = new IconEIO(201, 72, 11, 8);
|
||||
public static final IconEIO DOWN_ARROW_ON = new IconEIO(212, 72, 11, 8);
|
||||
public static final IconEIO DOWN_ARROW_OFF = new IconEIO(212, 72, 11, 8);
|
||||
public static final IconEIO DOWN_ARROW_ON = new IconEIO(223, 72, 11, 8);
|
||||
public static final IconEIO DOWN_ARROW_HOVER_OFF = new IconEIO(234, 72, 11, 8);
|
||||
public static final IconEIO DOWN_ARROW_HOVER_ON = new IconEIO(245, 72, 11, 8);
|
||||
public static final IconEIO VSCROLL_THUMB = new IconEIO(223, 64, 11, 8);
|
||||
public static final IconEIO VSCROLL_THUMB_HOVER = new IconEIO(223, 72, 11, 8);
|
||||
|
||||
public static final IconEIO VSCROLL_THUMB_OFF = new IconEIO(234, 80, 11, 8);
|
||||
public static final IconEIO VSCROLL_THUMB_HOVER_OFF = new IconEIO(234, 88, 11, 8);
|
||||
public static final IconEIO VSCROLL_THUMB_ON = new IconEIO(245, 80, 11, 8);
|
||||
public static final IconEIO VSCROLL_THUMB_HOVER_ON = new IconEIO(245, 88, 11, 8);
|
||||
|
||||
public static final IconEIO SOUND = new IconEIO(176, 208);
|
||||
|
||||
|
||||
@@ -42,13 +42,13 @@ public class VScrollbarEIO {
|
||||
xPosition = xOrigin + gui.getGuiLeft();
|
||||
yPosition = yOrigin + gui.getGuiTop();
|
||||
wholeArea = new Rectangle(xPosition, yPosition,
|
||||
(int)IconEIO.VSCROLL_THUMB.width, height);
|
||||
(int)IconEIO.VSCROLL_THUMB_OFF.width, height);
|
||||
btnUp = new Rectangle(xPosition, yPosition,
|
||||
(int)IconEIO.UP_ARROW_OFF.width, (int)IconEIO.UP_ARROW_OFF.height);
|
||||
btnDown = new Rectangle(xPosition, yPosition + Math.max(0, height - (int)IconEIO.DOWN_ARROW_OFF.height),
|
||||
(int)IconEIO.DOWN_ARROW_OFF.width, (int)IconEIO.DOWN_ARROW_OFF.height);
|
||||
thumbArea = new Rectangle(xPosition, yPosition + btnUp.height,
|
||||
(int)IconEIO.VSCROLL_THUMB.width, Math.max(0, height - (btnUp.height + btnDown.height)));
|
||||
(int)IconEIO.VSCROLL_THUMB_OFF.width, Math.max(0, height - (btnUp.height + btnDown.height)));
|
||||
}
|
||||
|
||||
public int getScrollPos() {
|
||||
@@ -109,10 +109,14 @@ public class VScrollbarEIO {
|
||||
|
||||
if(scrollMax > 0) {
|
||||
int thumbPos = getThumbPosition();
|
||||
boolean hoverThumb = thumbArea.contains(mouseX, mouseY) &&
|
||||
mouseY >= thumbPos && mouseY < thumbPos + (int)IconEIO.VSCROLL_THUMB.height;
|
||||
|
||||
IconEIO iconThumb = hoverThumb ? IconEIO.VSCROLL_THUMB_HOVER : IconEIO.VSCROLL_THUMB;
|
||||
boolean hoverThumb = thumbArea.contains(mouseX, mouseY) && mouseY >= thumbPos && mouseY < thumbPos + (int) IconEIO.VSCROLL_THUMB_OFF.height;
|
||||
|
||||
IconEIO iconThumb;
|
||||
if(pressedThumb) {
|
||||
iconThumb = IconEIO.VSCROLL_THUMB_HOVER_ON;
|
||||
} else {
|
||||
iconThumb = hoverThumb ? IconEIO.VSCROLL_THUMB_HOVER_OFF : IconEIO.VSCROLL_THUMB_OFF;
|
||||
}
|
||||
iconThumb.renderIcon(thumbArea.x, thumbPos, false);
|
||||
}
|
||||
|
||||
@@ -125,7 +129,7 @@ public class VScrollbarEIO {
|
||||
if(scrollMax > 0 && thumbArea.contains(x, y)) {
|
||||
int thumbPos = getThumbPosition();
|
||||
pressedUp = y < thumbPos;
|
||||
pressedDown = y >= thumbPos + (int)IconEIO.VSCROLL_THUMB.height;
|
||||
pressedDown = y >= thumbPos + (int)IconEIO.VSCROLL_THUMB_OFF.height;
|
||||
pressedThumb = !pressedUp && !pressedDown;
|
||||
} else {
|
||||
pressedUp = btnUp.contains(x, y);
|
||||
@@ -144,8 +148,8 @@ public class VScrollbarEIO {
|
||||
|
||||
public boolean mouseClickMove(int x, int y, int button, long time) {
|
||||
if(pressedThumb) {
|
||||
int pos = y - (thumbArea.y + (int)IconEIO.VSCROLL_THUMB.height/2);
|
||||
int len = thumbArea.height - (int)IconEIO.VSCROLL_THUMB.height;
|
||||
int pos = y - (thumbArea.y + (int)IconEIO.VSCROLL_THUMB_OFF.height/2);
|
||||
int len = thumbArea.height - (int)IconEIO.VSCROLL_THUMB_OFF.height;
|
||||
if(len > 0) {
|
||||
setScrollPos(Math.round(pos * (float)scrollMax / (float)len));
|
||||
}
|
||||
@@ -172,7 +176,7 @@ public class VScrollbarEIO {
|
||||
}
|
||||
|
||||
protected int getThumbPosition() {
|
||||
return thumbArea.y + (thumbArea.height - (int)IconEIO.VSCROLL_THUMB.height) * scrollPos / scrollMax;
|
||||
return thumbArea.y + (thumbArea.height - (int)IconEIO.VSCROLL_THUMB_OFF.height) * scrollPos / scrollMax;
|
||||
}
|
||||
|
||||
protected int limitPos(int pos) {
|
||||
|
||||
Reference in new issue
Block a user