From eb000d0a59b915a132e611c7804bbd04f0582651 Mon Sep 17 00:00:00 2001 From: Juuxel <6596629+Juuxel@users.noreply.github.com> Date: Thu, 17 Dec 2020 11:21:11 +0200 Subject: Create InputResult for specifying whether mouse inputs are processed This means that mouse events are propagated upwards the widget tree until they are processed or the root panel is reached. Code duplication in mouse handling was reduced by moving all logic into a new MouseInputHandler helper class. (I'd obviously have them directly in the screen classes if there was only one.) --- .../cottonmc/cotton/gui/SyncedGuiDescription.java | 46 --------- .../cotton/gui/client/CottonClientScreen.java | 74 ++++++-------- .../cotton/gui/client/CottonInventoryScreen.java | 70 ++++++------- .../cottonmc/cotton/gui/impl/CottonScreenImpl.java | 21 ++++ .../cotton/gui/impl/MouseInputHandler.java | 113 +++++++++++++++++++++ .../cotton/gui/widget/WAbstractSlider.java | 20 ++-- .../github/cottonmc/cotton/gui/widget/WButton.java | 5 +- .../github/cottonmc/cotton/gui/widget/WLabel.java | 4 +- .../github/cottonmc/cotton/gui/widget/WPanel.java | 64 ------------ .../cottonmc/cotton/gui/widget/WScrollBar.java | 17 ++-- .../cottonmc/cotton/gui/widget/WTabPanel.java | 7 +- .../github/cottonmc/cotton/gui/widget/WText.java | 7 +- .../cottonmc/cotton/gui/widget/WTextField.java | 6 +- .../cottonmc/cotton/gui/widget/WToggleButton.java | 5 +- .../github/cottonmc/cotton/gui/widget/WWidget.java | 41 ++++---- .../cotton/gui/widget/data/InputResult.java | 12 +++ 16 files changed, 278 insertions(+), 234 deletions(-) create mode 100644 src/main/java/io/github/cottonmc/cotton/gui/impl/CottonScreenImpl.java create mode 100644 src/main/java/io/github/cottonmc/cotton/gui/impl/MouseInputHandler.java create mode 100644 src/main/java/io/github/cottonmc/cotton/gui/widget/data/InputResult.java diff --git a/src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java b/src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java index 83ae894..6f81346 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java @@ -292,52 +292,6 @@ public class SyncedGuiDescription extends ScreenHandler implements GuiDescriptio return inserted; } - @Nullable - public WWidget doMouseUp(int x, int y, int state) { - if (rootPanel!=null) return rootPanel.onMouseUp(x, y, state); - return null; - } - - @Nullable - public WWidget doMouseDown(int x, int y, int button) { - if (rootPanel!=null) return rootPanel.onMouseDown(x, y, button); - return null; - } - - 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) { - if (focus!=null) { - int wx = focus.getAbsoluteX(); - int wy = focus.getAbsoluteY(); - - if (x>=wx && x=wy && y=width || containerY>=height) return result; - if (lastResponder==null) { - lastResponder = description.getRootPanel().hit(containerX, containerY); - if (lastResponder!=null) lastResponder.onMouseDown(containerX-lastResponder.getAbsoluteX(), containerY-lastResponder.getAbsoluteY(), mouseButton); - } else { - //This is a drag instead - } - return result; - + if (containerX<0 || containerY<0 || containerX>=width || containerY>=height) return true; + MouseInputHandler.onMouseDown(description, this, containerX, containerY, mouseButton); + + return true; } @Override public boolean mouseReleased(double mouseX, double mouseY, int mouseButton) { if (description.getRootPanel()==null) return super.mouseReleased(mouseX, mouseY, mouseButton); - boolean result = super.mouseReleased(mouseX, mouseY, mouseButton); + super.mouseReleased(mouseX, mouseY, mouseButton); int containerX = (int)mouseX-left; int containerY = (int)mouseY-top; - - if (lastResponder!=null) { - lastResponder.onMouseUp(containerX-lastResponder.getAbsoluteX(), containerY-lastResponder.getAbsoluteY(), mouseButton); - if (containerX>=0 && containerY>=0 && containerX=width || containerY>=height) return result; - description.getRootPanel().onMouseDrag(containerX, containerY, mouseButton, deltaX, deltaY); - } - return result; + MouseInputHandler.onMouseDrag(description, this, containerX, containerY, mouseButton, deltaX, deltaY); + + return true; } @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); + MouseInputHandler.onMouseScroll(description, containerX, containerY, amount); + return true; } @@ -227,12 +220,9 @@ public class CottonClientScreen extends Screen implements TextHoverRendererScree public void mouseMoved(double mouseX, double mouseY) { if (description.getRootPanel()==null) return; - WPanel root = description.getRootPanel(); int containerX = (int)mouseX-left; int containerY = (int)mouseY-top; - - WWidget child = root.hit(containerX, containerY); - child.onMouseMove(containerX - child.getAbsoluteX(), containerY - child.getAbsoluteY()); + MouseInputHandler.onMouseMove(description, containerX, containerY); } @Override 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 6b21af7..042126d 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 @@ -1,5 +1,7 @@ package io.github.cottonmc.cotton.gui.client; +import io.github.cottonmc.cotton.gui.impl.MouseInputHandler; + import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.client.render.DiffuseLighting; @@ -10,8 +12,10 @@ import net.minecraft.text.Style; import net.minecraft.text.Text; import io.github.cottonmc.cotton.gui.SyncedGuiDescription; +import io.github.cottonmc.cotton.gui.impl.CottonScreenImpl; import io.github.cottonmc.cotton.gui.widget.WPanel; import io.github.cottonmc.cotton.gui.widget.WWidget; +import org.jetbrains.annotations.Nullable; import org.lwjgl.glfw.GLFW; import org.lwjgl.opengl.GL11; @@ -20,7 +24,7 @@ import org.lwjgl.opengl.GL11; * * @param the description type */ -public class CottonInventoryScreen extends HandledScreen implements TextHoverRendererScreen { +public class CottonInventoryScreen extends HandledScreen implements TextHoverRendererScreen, CottonScreenImpl { protected SyncedGuiDescription description; protected WWidget lastResponder = null; @@ -78,6 +82,17 @@ public class CottonInventoryScreen extends Handl this.client.keyboard.setRepeatEvents(false); } + @Nullable + @Override + public WWidget getLastResponder() { + return lastResponder; + } + + @Override + public void setLastResponder(@Nullable WWidget lastResponder) { + this.lastResponder = lastResponder; + } + /** * Clears the heavyweight peers of this screen's GUI description. */ @@ -174,60 +189,40 @@ public class CottonInventoryScreen extends Handl int containerX = (int)mouseX-x; int containerY = (int)mouseY-y; if (containerX<0 || containerY<0 || containerX>=width || containerY>=height) return result; - if (lastResponder==null) { - lastResponder = description.doMouseDown(containerX, containerY, mouseButton); - } else { - //This is a drag instead - } - return result; + MouseInputHandler.onMouseDown(description, this, containerX, containerY, mouseButton); + + return true; } @Override public boolean mouseReleased(double mouseX, double mouseY, int mouseButton) { //Testing shows that STATE IS ACTUALLY BUTTON - boolean result = super.mouseReleased(mouseX, mouseY, mouseButton); + super.mouseReleased(mouseX, mouseY, mouseButton); int containerX = (int)mouseX-x; int containerY = (int)mouseY-y; - - if (lastResponder!=null) { - lastResponder.onMouseUp(containerX-lastResponder.getAbsoluteX(), containerY-lastResponder.getAbsoluteY(), mouseButton); - if (containerX>=0 && containerY>=0 && containerX=width || containerY>=height) return result; - description.doMouseDrag(containerX, containerY, mouseButton, deltaX, deltaY); - } - return result; + MouseInputHandler.onMouseDrag(description, this, containerX, containerY, mouseButton, deltaX, deltaY); + + return true; } @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-x; int containerY = (int)mouseY-y; - - WWidget child = root.hit(containerX, containerY); - child.onMouseScroll(containerX - child.getAbsoluteX(), containerY - child.getAbsoluteY(), amount); + MouseInputHandler.onMouseScroll(description, containerX, containerY, amount); + return true; } @@ -235,12 +230,9 @@ public class CottonInventoryScreen extends Handl public void mouseMoved(double mouseX, double mouseY) { if (description.getRootPanel()==null) return; - WPanel root = description.getRootPanel(); int containerX = (int)mouseX-x; int containerY = (int)mouseY-y; - - WWidget child = root.hit(containerX, containerY); - child.onMouseMove(containerX - child.getAbsoluteX(), containerY - child.getAbsoluteY()); + MouseInputHandler.onMouseMove(description, containerX, containerY); } @Override diff --git a/src/main/java/io/github/cottonmc/cotton/gui/impl/CottonScreenImpl.java b/src/main/java/io/github/cottonmc/cotton/gui/impl/CottonScreenImpl.java new file mode 100644 index 0000000..de8e974 --- /dev/null +++ b/src/main/java/io/github/cottonmc/cotton/gui/impl/CottonScreenImpl.java @@ -0,0 +1,21 @@ +package io.github.cottonmc.cotton.gui.impl; + +import io.github.cottonmc.cotton.gui.widget.WWidget; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.gui.screen.Screen; + +import org.jetbrains.annotations.Nullable; + +@Environment(EnvType.CLIENT) +public interface CottonScreenImpl { + default Screen asScreen() { + return (Screen) this; + } + + @Nullable + WWidget getLastResponder(); + + void setLastResponder(@Nullable WWidget lastResponder); +} diff --git a/src/main/java/io/github/cottonmc/cotton/gui/impl/MouseInputHandler.java b/src/main/java/io/github/cottonmc/cotton/gui/impl/MouseInputHandler.java new file mode 100644 index 0000000..a378d42 --- /dev/null +++ b/src/main/java/io/github/cottonmc/cotton/gui/impl/MouseInputHandler.java @@ -0,0 +1,113 @@ +package io.github.cottonmc.cotton.gui.impl; + +import io.github.cottonmc.cotton.gui.GuiDescription; +import io.github.cottonmc.cotton.gui.widget.WWidget; +import io.github.cottonmc.cotton.gui.widget.data.InputResult; + +import java.util.function.Function; + +import org.jetbrains.annotations.Nullable; + +/** + * The implementation for mouse inputs. + */ +public final class MouseInputHandler { + public static void onMouseDown(GuiDescription description, CottonScreenImpl screen, int containerX, int containerY, int mouseButton) { + if (screen.getLastResponder() == null) { + WWidget lastResponder = description.getRootPanel().hit(containerX, containerY); + screen.setLastResponder(lastResponder); + if (lastResponder != null) { + runTree( + lastResponder, + widget -> widget.onMouseDown(containerX - widget.getAbsoluteX(), containerY - widget.getAbsoluteY(), mouseButton) + ); + } + } else { + // This is a drag instead + } + } + + public static void onMouseUp(GuiDescription description, CottonScreenImpl screen, int containerX, int containerY, int mouseButton) { + WWidget lastResponder = screen.getLastResponder(); + + if (lastResponder != null) { + int width = screen.asScreen().width; + int height = screen.asScreen().height; + + runTree( + lastResponder, + widget -> widget.onMouseUp(containerX - widget.getAbsoluteX(), containerY - widget.getAbsoluteY(), mouseButton) + ); + + if (containerX >= 0 && containerY >= 0 && containerX < width && containerY < height) { + runTree( + lastResponder, + widget -> widget.onClick(containerX - widget.getAbsoluteX(), containerY - widget.getAbsoluteY(), mouseButton) + ); + } + } else { + runTree( + description.getRootPanel().hit(containerX, containerY), + widget -> widget.onMouseUp(containerX - widget.getAbsoluteX(), containerY - widget.getAbsoluteY(), mouseButton) + ); + } + + screen.setLastResponder(null); + } + + public static void onMouseDrag(GuiDescription description, CottonScreenImpl screen, int containerX, int containerY, int mouseButton, double deltaX, double deltaY) { + WWidget lastResponder = screen.getLastResponder(); + + if (lastResponder != null) { + lastResponder.onMouseDrag(containerX - lastResponder.getAbsoluteX(), containerY - lastResponder.getAbsoluteY(), mouseButton, deltaX, deltaY); + } else { + int width = screen.asScreen().width; + int height = screen.asScreen().height; + + if (containerX < 0 || containerY < 0 || containerX >= width || containerY >= height) return; + + runTree( + description.getRootPanel().hit(containerX, containerY), + widget -> widget.onMouseDrag(containerX - widget.getAbsoluteX(), containerY - widget.getAbsoluteY(), mouseButton, deltaX, deltaY) + ); + } + } + + public static void onMouseScroll(GuiDescription description, int containerX, int containerY, double amount) { + runTree( + description.getRootPanel().hit(containerX, containerY), + widget -> widget.onMouseScroll(containerX - widget.getAbsoluteX(), containerY - widget.getAbsoluteY(), amount) + ); + } + + public static void onMouseMove(GuiDescription description, int containerX, int containerY) { + runTree( + description.getRootPanel().hit(containerX, containerY), + widget -> widget.onMouseMove(containerX - widget.getAbsoluteX(), containerY - widget.getAbsoluteY()) + ); + } + + /** + * Traverses the {@code function} up the widget tree until it finds a {@link InputResult#PROCESSED} result. + * + * @param bottom the starting point for the traversal + * @param function the function to run + * @return the first widget to return {@link InputResult#PROCESSED}, or null if none found. + */ + @Nullable + private static WWidget runTree(WWidget bottom, Function function) { + WWidget current = bottom; + + while (current != null) { + InputResult result = function.apply(current); + + if (result == InputResult.PROCESSED) { + break; + } else { + current = current.getParent(); + } + } + + return current; + } +} diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java index 6c422bc..c533bda 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java @@ -1,5 +1,7 @@ package io.github.cottonmc.cotton.gui.widget; +import io.github.cottonmc.cotton.gui.widget.data.InputResult; + import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.util.math.MathHelper; @@ -108,28 +110,31 @@ public abstract class WAbstractSlider extends WWidget { @Environment(EnvType.CLIENT) @Override - public WWidget onMouseDown(int x, int y, int button) { + public InputResult onMouseDown(int x, int y, int button) { // Check if cursor is inside or <=2px away from track if (isMouseInsideBounds(x, y)) { requestFocus(); + return InputResult.PROCESSED; } - return super.onMouseDown(x, y, button); + return InputResult.IGNORED; } @Environment(EnvType.CLIENT) @Override - public void onMouseDrag(int x, int y, int button) { + public InputResult onMouseDrag(int x, int y, int button, double deltaX, double deltaY) { if (isFocused()) { dragging = true; moveSlider(x, y); } + return InputResult.PROCESSED; } @Environment(EnvType.CLIENT) @Override - public void onClick(int x, int y, int button) { + public InputResult onClick(int x, int y, int button) { moveSlider(x, y); if (draggingFinishedListener != null) draggingFinishedListener.accept(value); + return InputResult.PROCESSED; } private void moveSlider(int x, int y) { @@ -160,15 +165,15 @@ public abstract class WAbstractSlider extends WWidget { @Environment(EnvType.CLIENT) @Override - public WWidget onMouseUp(int x, int y, int button) { + public InputResult onMouseUp(int x, int y, int button) { dragging = false; if (draggingFinishedListener != null) draggingFinishedListener.accept(value); - return super.onMouseUp(x, y, button); + return InputResult.PROCESSED; } @Environment(EnvType.CLIENT) @Override - public void onMouseScroll(int x, int y, double amount) { + public InputResult onMouseScroll(int x, int y, double amount) { if (direction == Direction.LEFT || direction == Direction.DOWN) { amount = -amount; } @@ -180,6 +185,7 @@ public abstract class WAbstractSlider extends WWidget { onValueChanged(value); pendingDraggingFinishedFromScrolling = true; } + return InputResult.PROCESSED; } @Environment(EnvType.CLIENT) diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java index deee662..4f0b28c 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java @@ -1,5 +1,7 @@ package io.github.cottonmc.cotton.gui.widget; +import io.github.cottonmc.cotton.gui.widget.data.InputResult; + import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.MinecraftClient; @@ -120,7 +122,7 @@ public class WButton extends WWidget { @Environment(EnvType.CLIENT) @Override - public void onClick(int x, int y, int button) { + public InputResult onClick(int x, int y, int button) { super.onClick(x, y, button); if (enabled && isWithinBounds(x, y)) { @@ -128,6 +130,7 @@ public class WButton extends WWidget { if (onClick!=null) onClick.run(); } + return InputResult.PROCESSED; } @Environment(EnvType.CLIENT) diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java index 2583448..991796b 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java @@ -1,5 +1,6 @@ package io.github.cottonmc.cotton.gui.widget; +import io.github.cottonmc.cotton.gui.widget.data.InputResult; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.MinecraftClient; @@ -111,7 +112,7 @@ public class WLabel extends WWidget { @Environment(EnvType.CLIENT) @Override - public void onClick(int x, int y, int button) { + public InputResult onClick(int x, int y, int button) { Style hoveredTextStyle = getTextStyleAt(x, y); if (hoveredTextStyle != null) { Screen screen = MinecraftClient.getInstance().currentScreen; @@ -119,6 +120,7 @@ public class WLabel extends WWidget { screen.handleTextClick(hoveredTextStyle); } } + return InputResult.PROCESSED; } /** 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 d4b5626..51a10ce 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 @@ -83,70 +83,6 @@ public abstract class WPanel extends WWidget { this.setSize(Math.max(this.getWidth(), pushRight), Math.max(this.getHeight(), pushDown)); } - @Environment(EnvType.CLIENT) - @Override - public WWidget onMouseUp(int x, int y, int button) { - if (children.isEmpty()) return super.onMouseUp(x, y, button); - for(int i=children.size()-1; i>=0; i--) { //Backwards so topmost widgets get priority - WWidget child = children.get(i); - if ( x>=child.getX() && - y>=child.getY() && - x=0; i--) { //Backwards so topmost widgets get priority - WWidget child = children.get(i); - if ( x>=child.getX() && - y>=child.getY() && - x=0; i--) { //Backwards so topmost widgets get priority - WWidget child = children.get(i); - if ( x>=child.getX() && - y>=child.getY() && - x=0; i--) { //Backwards so topmost widgets get priority - WWidget child = children.get(i); - if ( x>=child.getX() && - y>=child.getY() && - xThe default implementation calls {@link #onMouseDrag(int, int, int)} for backwards compatibility. - * * @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) @@ -171,20 +172,11 @@ public class WWidget { * @param deltaY The amount of dragging on the Y axis * * @since 1.5.0 + * @return {@link InputResult#PROCESSED} if the event is handled, {@link InputResult#IGNORED} otherwise. */ @Environment(EnvType.CLIENT) - 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) - * @param button The mouse button that was used. Button numbering is consistent with LWJGL Mouse (0=left, 1=right, 2=mousewheel click) - */ - @Environment(EnvType.CLIENT) - public void onMouseDrag(int x, int y, int button) { + public InputResult onMouseDrag(int x, int y, int button, double deltaX, double deltaY) { + return InputResult.IGNORED; } /** @@ -192,10 +184,11 @@ public class WWidget { * @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) + * @return {@link InputResult#PROCESSED} if the event is handled, {@link InputResult#IGNORED} otherwise. */ @Environment(EnvType.CLIENT) - public WWidget onMouseUp(int x, int y, int button) { - return this; + public InputResult onMouseUp(int x, int y, int button) { + return InputResult.IGNORED; } /** @@ -203,9 +196,11 @@ public class WWidget { * @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) + * @return {@link InputResult#PROCESSED} if the event is handled, {@link InputResult#IGNORED} otherwise. */ @Environment(EnvType.CLIENT) - public void onClick(int x, int y, int button) { + public InputResult onClick(int x, int y, int button) { + return InputResult.IGNORED; } /** @@ -213,9 +208,11 @@ public class WWidget { * @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. + * @return {@link InputResult#PROCESSED} if the event is handled, {@link InputResult#IGNORED} otherwise. */ @Environment(EnvType.CLIENT) - public void onMouseScroll(int x, int y, double amount) { + public InputResult onMouseScroll(int x, int y, double amount) { + return InputResult.IGNORED; } /** @@ -224,9 +221,11 @@ public class WWidget { * @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 + * @return {@link InputResult#PROCESSED} if the event is handled, {@link InputResult#IGNORED} otherwise. */ @Environment(EnvType.CLIENT) - public void onMouseMove(int x, int y) { + public InputResult onMouseMove(int x, int y) { + return InputResult.IGNORED; } /** diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/data/InputResult.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/data/InputResult.java new file mode 100644 index 0000000..991cfd3 --- /dev/null +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/data/InputResult.java @@ -0,0 +1,12 @@ +package io.github.cottonmc.cotton.gui.widget.data; + +/** + * Specifies whether an input event was ignored or processed. + * Used for mouse input events. + * + * @since 4.0.0 + */ +public enum InputResult { + PROCESSED, + IGNORED; +} -- cgit