diff options
author | Juuxel <6596629+Juuxel@users.noreply.github.com> | 2020-01-19 21:05:43 +0200 |
---|---|---|
committer | Juuxel <6596629+Juuxel@users.noreply.github.com> | 2020-01-19 21:05:43 +0200 |
commit | 993c1e793b35bd6a356f8a5b96c551aa954d8116 (patch) | |
tree | 5d3dc681ba49ee1ad9c6cff6208494a7039c99a9 /src | |
parent | e5844474fa0ac3391c40dc6d2bbac126ea3f7496 (diff) | |
download | LibGui-993c1e793b35bd6a356f8a5b96c551aa954d8116.tar.gz LibGui-993c1e793b35bd6a356f8a5b96c551aa954d8116.tar.bz2 LibGui-993c1e793b35bd6a356f8a5b96c551aa954d8116.zip |
Add dragging deltas into WWidget.onMouseDrag, add WWidget.onMouseMove
Closes #30. Closes #31.
Diffstat (limited to 'src')
4 files changed, 62 insertions, 12 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/CottonCraftingController.java b/src/main/java/io/github/cottonmc/cotton/gui/CottonCraftingController.java index 2b9edc2..f3a23c6 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/CottonCraftingController.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/CottonCraftingController.java @@ -287,8 +287,8 @@ public class CottonCraftingController extends CraftingContainer<Inventory> imple return null; } - public void doMouseDrag(int x, int y, int button) { - if (rootPanel!=null) rootPanel.onMouseDrag(x, y, button); + public void doMouseDrag(int x, int y, int button, double deltaX, double deltaY) { + if (rootPanel!=null) rootPanel.onMouseDrag(x, y, button, deltaX, deltaY); } public void doClick(int x, int y, int button) { 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 d8a986f..be13275 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 @@ -151,19 +151,19 @@ public class CottonClientScreen extends Screen implements TextHoverRendererScree } @Override - public boolean mouseDragged(double mouseX, double mouseY, int mouseButton, double unknown_1, double unknown_2) { - if (description.getRootPanel()==null) return super.mouseDragged(mouseX, mouseY, mouseButton, unknown_1, unknown_2); - boolean result = super.mouseDragged(mouseX, mouseY, mouseButton, unknown_1, unknown_2); + public boolean mouseDragged(double mouseX, double mouseY, int mouseButton, double deltaX, double deltaY) { + if (description.getRootPanel()==null) return super.mouseDragged(mouseX, mouseY, mouseButton, deltaX, deltaY); + boolean result = super.mouseDragged(mouseX, mouseY, mouseButton, deltaX, deltaY); int containerX = (int)mouseX-left; int containerY = (int)mouseY-top; if (lastResponder!=null) { - lastResponder.onMouseDrag(containerX-lastResponder.getAbsoluteX(), containerY-lastResponder.getAbsoluteY(), mouseButton); + lastResponder.onMouseDrag(containerX-lastResponder.getAbsoluteX(), containerY-lastResponder.getAbsoluteY(), mouseButton, deltaX, deltaY); return result; } else { if (containerX<0 || containerY<0 || containerX>=width || containerY>=height) return result; - description.getRootPanel().onMouseDrag(containerX, containerY, mouseButton); + description.getRootPanel().onMouseDrag(containerX, containerY, mouseButton, deltaX, deltaY); } return result; } @@ -180,7 +180,19 @@ public class CottonClientScreen extends Screen implements TextHoverRendererScree child.onMouseScroll(containerX - child.getAbsoluteX(), containerY - child.getAbsoluteY(), amount); return true; } - + + @Override + public void mouseMoved(double mouseX, double mouseY) { + if (description.getRootPanel()==null) return; + + WPanel root = description.getRootPanel(); + int containerX = (int)mouseX-left; + int containerY = (int)mouseX-top; + + WWidget child = root.hit(containerX, containerY); + child.onMouseMove(containerX - child.getAbsoluteX(), containerY - child.getAbsoluteY()); + } + @Override public boolean charTyped(char ch, int keyCode) { if (description.getFocus()==null) return false; 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 2813c0f..ed494dc 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 @@ -142,18 +142,18 @@ public class CottonInventoryScreen<T extends CottonCraftingController> extends A } @Override - public boolean mouseDragged(double mouseX, double mouseY, int mouseButton, double unknown_1, double unknown_2) { - boolean result = super.mouseDragged(mouseX, mouseY, mouseButton, unknown_1, unknown_2); + public boolean mouseDragged(double mouseX, double mouseY, int mouseButton, double deltaX, double deltaY) { + boolean result = super.mouseDragged(mouseX, mouseY, mouseButton, deltaX, deltaY); int containerX = (int)mouseX-x; int containerY = (int)mouseY-y; if (lastResponder!=null) { - lastResponder.onMouseDrag(containerX-lastResponder.getAbsoluteX(), containerY-lastResponder.getAbsoluteY(), mouseButton); + lastResponder.onMouseDrag(containerX-lastResponder.getAbsoluteX(), containerY-lastResponder.getAbsoluteY(), mouseButton, deltaX, deltaY); return result; } else { if (containerX<0 || containerY<0 || containerX>=width || containerY>=height) return result; - description.doMouseDrag(containerX, containerY, mouseButton); + description.doMouseDrag(containerX, containerY, mouseButton, deltaX, deltaY); } return result; } @@ -170,6 +170,18 @@ public class CottonInventoryScreen<T extends CottonCraftingController> extends A child.onMouseScroll(containerX - child.getAbsoluteX(), containerY - child.getAbsoluteY(), amount); return true; } + + @Override + public void mouseMoved(double mouseX, double mouseY) { + if (description.getRootPanel()==null) return; + + WPanel root = description.getRootPanel(); + int containerX = (int)mouseX-x; + int containerY = (int)mouseX-y; + + WWidget child = root.hit(containerX, containerY); + child.onMouseMove(containerX - child.getAbsoluteX(), containerY - child.getAbsoluteY()); + } @Override protected void drawBackground(float partialTicks, int mouseX, int mouseY) {} //This is just an AbstractContainerScreen thing; most Screens don't work this way. 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 e4c5746..062c560 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 @@ -78,6 +78,22 @@ public class WWidget { } /** + * Notifies this widget that the mouse has been moved while pressed and 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 button The mouse button that was used. Button numbering is consistent with LWJGL Mouse (0=left, 1=right, 2=mousewheel click) + * @param deltaX The amount of dragging on the X axis + * @param deltaY The amount of dragging on the Y axis + * + * @since 1.5.0 + * @implSpec The default implementation calls {@link #onMouseDrag(int, int, int)}. + */ + public void onMouseDrag(int x, int y, int button, double deltaX, double deltaY) { + onMouseDrag(x, y, button); + } + + /** * Notifies this widget that the mouse has been moved while pressed and 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) @@ -113,6 +129,16 @@ public class WWidget { */ public void onMouseScroll(int x, int y, double amount) { } + + /** + * Notifies this widget that the mouse has been moved while 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) + * @since 1.5.0 + */ + public void onMouseMove(int x, int y) { + } /** * Notifies this widget that a character has been typed. This method is subject to key repeat, |