aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorJuuxel <kasperi.kauppi@gmail.com>2019-09-01 00:58:49 +0300
committerJuuxel <kasperi.kauppi@gmail.com>2019-09-01 00:58:49 +0300
commit82908f7397658b12d045df103db0f32779f33089 (patch)
tree104c7d721455508a23984c0ec4213399fd23219a /src/main
parent60ec3fbc34d8266c15aeb1d0be7795efd821d73d (diff)
downloadLibGui-82908f7397658b12d045df103db0f32779f33089.tar.gz
LibGui-82908f7397658b12d045df103db0f32779f33089.tar.bz2
LibGui-82908f7397658b12d045df103db0f32779f33089.zip
Improve scrolling again
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java11
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java11
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java6
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.
*/