-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Mouse Interactions with Scrollbar
- Loading branch information
1 parent
f9407b9
commit 5212756
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
src/main/java/com/nomiceu/nomilabs/mixin/betterp2p/WidgetScrollBarMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.nomiceu.nomilabs.mixin.betterp2p; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import com.projecturanus.betterp2p.client.gui.widget.WidgetScrollBar; | ||
|
||
/** | ||
* Fixes clicking scrollbar. | ||
*/ | ||
@Mixin(value = WidgetScrollBar.class, remap = false) | ||
public abstract class WidgetScrollBarMixin { | ||
|
||
@Shadow | ||
protected abstract int getRange(); | ||
|
||
@Shadow | ||
private int displayX; | ||
|
||
@Shadow | ||
private int width; | ||
|
||
@Shadow | ||
private int displayY; | ||
|
||
@Shadow | ||
private int height; | ||
|
||
@Shadow | ||
private int currentScroll; | ||
|
||
@Shadow | ||
private int minScroll; | ||
|
||
@Shadow | ||
private boolean moving; | ||
|
||
@Shadow | ||
protected abstract void applyRange(); | ||
|
||
@Inject(method = "click", at = @At("HEAD"), cancellable = true) | ||
private void properlyHandleClick(int x, int y, CallbackInfo ci) { | ||
ci.cancel(); | ||
if (getRange() == 0) { | ||
return; | ||
} | ||
|
||
if (y > displayY && y <= displayY + height) { | ||
if (x > displayX && x <= displayX + width) { | ||
currentScroll = y - displayY; | ||
currentScroll = minScroll + currentScroll * 2 * getRange() / height; | ||
currentScroll = (currentScroll + 1) >> 1; | ||
applyRange(); | ||
moving = true; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters