From 82908f7397658b12d045df103db0f32779f33089 Mon Sep 17 00:00:00 2001 From: Juuxel Date: Sun, 1 Sep 2019 00:58:49 +0300 Subject: Improve scrolling again --- .../github/cottonmc/cotton/gui/client/CottonClientScreen.java | 11 +++++++---- .../cottonmc/cotton/gui/client/CottonInventoryScreen.java | 11 +++++++---- .../java/io/github/cottonmc/cotton/gui/widget/WPanel.java | 6 ------ 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 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. */ -- cgit