Skip to content

Commit

Permalink
Fix scroll bar drag click (#608)
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Robertz <dream-master@gmx.net>
  • Loading branch information
Alexdoru and Dream-Master authored Nov 17, 2024
1 parent 4b4dad3 commit 9146056
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/main/java/appeng/client/gui/AEBaseGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ protected void mouseClickMove(final int x, final int y, final int c, final long
final ItemStack itemstack = this.mc.thePlayer.inventory.getItemStack();

if (this.getScrollBar() != null) {
this.getScrollBar().click(this, x - this.guiLeft, y - this.guiTop);
this.getScrollBar().clickMove(y - this.guiTop);
}

if (slot instanceof SlotFake && itemstack != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ protected void mouseClicked(final int xCoord, final int yCoord, final int btn) {
@Override
protected void mouseClickMove(final int x, final int y, final int c, final long d) {
final int currentScroll = this.processingScrollBar.getCurrentScroll();
this.processingScrollBar.click(this, x - this.guiLeft, y - this.guiTop);
this.processingScrollBar.clickMove(y - this.guiTop);
super.mouseClickMove(x, y, c, d);

if (currentScroll != this.processingScrollBar.getCurrentScroll()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ public void sendCPUSwitch(int serial) {
*/
public void mouseClickMove(int xCoord, int yCoord) {
if (cpuScrollbar != null) {
cpuScrollbar.click(parent, xCoord, yCoord);
cpuScrollbar.clickMove(yCoord);
}
}

Expand Down
17 changes: 16 additions & 1 deletion src/main/java/appeng/client/gui/widgets/GuiScrollbar.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class GuiScrollbar implements IScrollSource {
private int minScroll = 0;
private int currentScroll = 0;
private boolean visible = true;
private boolean isLatestClickOnScrollbar;

public void setTexture(final String base, final String file, final int shiftX, final int shiftY) {
txtBase = base;
Expand Down Expand Up @@ -133,12 +134,26 @@ public void click(final AEBaseGui aeBaseGui, final int x, final int y) {
if (this.getRange() == 0) {
return;
}

if (this.contains(x, y)) {
this.currentScroll = (y - this.displayY);
this.currentScroll = this.minScroll + ((this.currentScroll * 2 * this.getRange() / this.height));
this.currentScroll = (this.currentScroll + 1) >> 1;
this.applyRange();
isLatestClickOnScrollbar = true;
} else {
isLatestClickOnScrollbar = false;
}
}

public void clickMove(final int y) {
if (this.getRange() == 0 || !isLatestClickOnScrollbar) {
return;
}
if (y >= this.displayY && y <= this.displayY + this.height) {
this.currentScroll = (y - this.displayY);
this.currentScroll = this.minScroll + ((this.currentScroll * 2 * this.getRange() / this.height));
this.currentScroll = (this.currentScroll + 1) >> 1;
this.applyRange();
}
}

Expand Down

0 comments on commit 9146056

Please sign in to comment.