diff options
author | Falkreon <falkreon@gmail.com> | 2019-09-01 01:39:05 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-01 01:39:05 -0500 |
commit | 07495df1f9f39f730e88060cd30c9e14c9721b19 (patch) | |
tree | 3fa10873bdbcc567bbeef24db4d897e99c0cf0ca /src/main/java | |
parent | 2cc575fe73c909daf05a1a6b9aa7785631e5049f (diff) | |
parent | e17a411ca512b6b08a577941f04659d7d007ec3d (diff) | |
download | LibGui-07495df1f9f39f730e88060cd30c9e14c9721b19.tar.gz LibGui-07495df1f9f39f730e88060cd30c9e14c9721b19.tar.bz2 LibGui-07495df1f9f39f730e88060cd30c9e14c9721b19.zip |
Merge pull request #12 from Juuxel/scrolling
Mouse scrolling event
Diffstat (limited to 'src/main/java')
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 |