diff options
3 files changed, 35 insertions, 0 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 ea388d1..91cf7b5 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 @@ -169,6 +169,19 @@ 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(); + int containerX = (int)mouseX-left; + int containerY = (int)mouseY-top; + + WWidget child = root.hit(containerX, containerY); + child.onMouseScroll(containerX - child.getAbsoluteX(), containerY - child.getAbsoluteY(), amount); + return true; + } + + @Override public boolean charTyped(char ch, int keyCode) { if (description.getFocus()==null) return false; description.getFocus().onCharTyped(ch); 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 9883427..3a7f5c2 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 @@ -156,6 +156,19 @@ 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(); + int containerX = (int)mouseX-left; + int containerY = (int)mouseY-top; + + WWidget child = root.hit(containerX, containerY); + child.onMouseScroll(containerX - child.getAbsoluteX(), containerY - child.getAbsoluteY(), amount); + return true; + } + + @Override protected void drawBackground(float partialTicks, int mouseX, int mouseY) {} //This is just an AbstractContainerScreen thing; most Screens don't work this way. public void paint(int mouseX, int mouseY) { diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java index 1bbbf85..e4c5746 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java @@ -106,6 +106,15 @@ public class WWidget { } /** + * Notifies this widget that the mouse has been scrolled inside its bounds. + * @param x The X coordinate of the event, in widget-space (0 is the left edge of this widget) + * @param y The Y coordinate of the event, in widget-space (0 is the top edge of this widget) + * @param amount The scrolled amount. Positive values are up and negative values are down. + */ + public void onMouseScroll(int x, int y, double amount) { + } + + /** * Notifies this widget that a character has been typed. This method is subject to key repeat, * and may be called for characters that do not directly have a corresponding keyboard key. * @param ch the character typed |