diff --git a/src/main/java/de/johni0702/minecraft/gui/container/AbstractGuiOverlay.java b/src/main/java/de/johni0702/minecraft/gui/container/AbstractGuiOverlay.java index 46f5e842..6c5853d4 100644 --- a/src/main/java/de/johni0702/minecraft/gui/container/AbstractGuiOverlay.java +++ b/src/main/java/de/johni0702/minecraft/gui/container/AbstractGuiOverlay.java @@ -38,6 +38,7 @@ import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; +import org.lwjgl.input.Mouse; import org.lwjgl.util.Dimension; import org.lwjgl.util.Point; import org.lwjgl.util.ReadableDimension; @@ -235,6 +236,14 @@ public abstract class AbstractGuiOverlay> extend forEach(Tickable.class).tick(); } + @Override + public void handleMouseInput() throws IOException { + super.handleMouseInput(); + if (Mouse.hasWheel() && Mouse.getEventDWheel() != 0) { + forEach(Scrollable.class).scroll(MouseUtils.getMousePos(), Mouse.getEventDWheel()); + } + } + @Override public void onGuiClosed() { mouseVisible = false; diff --git a/src/main/java/de/johni0702/minecraft/gui/container/AbstractGuiScreen.java b/src/main/java/de/johni0702/minecraft/gui/container/AbstractGuiScreen.java index 52a615d9..71a639af 100644 --- a/src/main/java/de/johni0702/minecraft/gui/container/AbstractGuiScreen.java +++ b/src/main/java/de/johni0702/minecraft/gui/container/AbstractGuiScreen.java @@ -32,10 +32,12 @@ import de.johni0702.minecraft.gui.function.*; import eu.crushedpixel.replaymod.utils.MouseUtils; import lombok.Getter; import lombok.Setter; +import net.minecraft.client.gui.ScaledResolution; import net.minecraft.crash.CrashReport; import net.minecraft.crash.CrashReportCategory; import net.minecraft.util.ReportedException; import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; import org.lwjgl.util.Dimension; import org.lwjgl.util.Point; import org.lwjgl.util.ReadableDimension; @@ -194,6 +196,14 @@ public abstract class AbstractGuiScreen> extends forEach(Tickable.class).tick(); } + @Override + public void handleMouseInput() throws IOException { + super.handleMouseInput(); + if (Mouse.hasWheel() && Mouse.getEventDWheel() != 0) { + forEach(Scrollable.class).scroll(MouseUtils.getMousePos(), Mouse.getEventDWheel()); + } + } + @Override public void onGuiClosed() { forEach(Closeable.class).close(); diff --git a/src/main/java/de/johni0702/minecraft/gui/function/Scrollable.java b/src/main/java/de/johni0702/minecraft/gui/function/Scrollable.java new file mode 100644 index 00000000..e5ccebab --- /dev/null +++ b/src/main/java/de/johni0702/minecraft/gui/function/Scrollable.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2015 johni0702 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package de.johni0702.minecraft.gui.function; + +import org.lwjgl.util.ReadablePoint; + +public interface Scrollable { + /** + * Called when the user scrolled. + * @param mousePosition Global position of the mouse. + * @param dWheel Wheel movement (positive is upwards, negative is downwards) + * @return {@code true} if this event should be consumed, + * {@code false} if it should be delivered to other elements as well + */ + boolean scroll(ReadablePoint mousePosition, int dWheel); +}