Add support for scrolling in new GUI API

This commit is contained in:
johni0702
2015-10-11 10:39:12 +02:00
parent de322e4b6e
commit 1563af3d46
3 changed files with 55 additions and 0 deletions

View File

@@ -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<T extends AbstractGuiOverlay<T>> 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;

View File

@@ -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<T extends AbstractGuiScreen<T>> 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();

View File

@@ -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);
}