diff options
Diffstat (limited to 'src')
3 files changed, 14 insertions, 14 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java index 26176e7..11d7dbd 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java @@ -171,12 +171,15 @@ public class CottonClientScreen extends Screen { @Override public boolean mouseScrolled(double mouseX, double mouseY, double amount) { if (description.getRootPanel()==null) return super.mouseScrolled(mouseX, mouseY, amount); + WPanel root = description.getRootPanel(); - WWidget child = root.hit((int) mouseX - left, (int) mouseY - top); + int containerX = (int)mouseX-left; + int containerY = (int)mouseY-top; + + WWidget child = root.hit(containerX, containerY); if (child == root) return false; - // Use root.onMouseScroll to work in cases where the hit result is in a nested panel - // and the mouse position can't be moved to the widget space by subtracting the widget's position - root.onMouseScroll((int) mouseX - left, (int) mouseY - top, amount); + + child.onMouseScroll(containerX - child.getAbsoluteX(), containerY - child.getAbsoluteY(), amount); return true; } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java index 961d6f9..e3df6d6 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java @@ -144,12 +144,15 @@ public class CottonInventoryScreen<T extends CottonCraftingController> extends A @Override public boolean mouseScrolled(double mouseX, double mouseY, double amount) { if (description.getRootPanel()==null) return super.mouseScrolled(mouseX, mouseY, amount); + WPanel root = description.getRootPanel(); - WWidget child = root.hit((int) mouseX - left, (int) mouseY - top); + int containerX = (int)mouseX-left; + int containerY = (int)mouseY-top; + + WWidget child = root.hit(containerX, containerY); if (child == root) return false; - // Use root.onMouseScroll to work in cases where the hit result is in a nested panel - // and the mouse position can't be moved to the widget space by subtracting the widget's position - root.onMouseScroll((int) mouseX - left, (int) mouseY - top, amount); + + child.onMouseScroll(containerX - child.getAbsoluteX(), containerY - child.getAbsoluteY(), amount); return true; } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java index 14faa2d..33ca28c 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java @@ -119,12 +119,6 @@ public abstract class WPanel extends WWidget { } }*/ - @Override - public void onMouseScroll(int x, int y, double amount) { - WWidget child = hit(x, y); - if (child != this) child.onMouseScroll(x - child.getX(), y - child.getY(), amount); - } - /** * Finds the most specific child node at this location. */ |