aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/shedaniel/rei/impl/InternalWidgets.java
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2020-04-01 20:01:34 +0800
committershedaniel <daniel@shedaniel.me>2020-04-01 20:01:34 +0800
commit66abc317e5fc36a397ca1cc919e388fbe143956b (patch)
tree915cc4799d89297b8d4bd2dbe1046c177f4d1627 /src/main/java/me/shedaniel/rei/impl/InternalWidgets.java
parent3919ec1e15d6eb9a8aa4564bb2d4e4dfdbeb54e3 (diff)
downloadRoughlyEnoughItems-66abc317e5fc36a397ca1cc919e388fbe143956b.tar.gz
RoughlyEnoughItems-66abc317e5fc36a397ca1cc919e388fbe143956b.tar.bz2
RoughlyEnoughItems-66abc317e5fc36a397ca1cc919e388fbe143956b.zip
ScrollingContainer & SubsetsMenu && 20w18b
Signed-off-by: shedaniel <daniel@shedaniel.me>
Diffstat (limited to 'src/main/java/me/shedaniel/rei/impl/InternalWidgets.java')
-rw-r--r--src/main/java/me/shedaniel/rei/impl/InternalWidgets.java80
1 files changed, 71 insertions, 9 deletions
diff --git a/src/main/java/me/shedaniel/rei/impl/InternalWidgets.java b/src/main/java/me/shedaniel/rei/impl/InternalWidgets.java
index e43ea2e14..eb662fe3c 100644
--- a/src/main/java/me/shedaniel/rei/impl/InternalWidgets.java
+++ b/src/main/java/me/shedaniel/rei/impl/InternalWidgets.java
@@ -24,6 +24,7 @@
package me.shedaniel.rei.impl;
import com.google.common.collect.Lists;
+import com.mojang.blaze3d.systems.RenderSystem;
import it.unimi.dsi.fastutil.ints.IntList;
import me.shedaniel.math.Rectangle;
import me.shedaniel.math.impl.PointHelper;
@@ -179,11 +180,15 @@ public final class InternalWidgets {
};
}
- public static LateRenderable wrapLateRenderable(WidgetWithBounds widget) {
+ public static WidgetWithBounds wrapLateRenderable(WidgetWithBounds widget) {
return new LateRenderableWidgetWithBounds(widget);
}
- public static LateRenderable wrapLateRenderable(Widget widget) {
+ public static WidgetWithBounds wrapTranslate(WidgetWithBounds widget, float x, float y, float z) {
+ return new WidgetWithBoundsWithTranslate(widget, x, y, z);
+ }
+
+ public static Widget wrapLateRenderable(Widget widget) {
return new LateRenderableWidget(widget);
}
@@ -210,6 +215,15 @@ public final class InternalWidgets {
public List<? extends Element> children() {
return widgets;
}
+
+ @Override
+ public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
+ for (Widget widget : this.widgets) {
+ if (widget.mouseScrolled(mouseX, mouseY, amount))
+ return true;
+ }
+ return false;
+ }
}
private static class LateRenderableWidget extends Widget implements LateRenderable {
@@ -219,20 +233,21 @@ public final class InternalWidgets {
this.widget = widget;
}
-
@Override
- public void lateRender(int mouseX, int mouseY, float delta) {
+ public void render(int mouseX, int mouseY, float delta) {
this.widget.setZ(getZ());
this.widget.render(mouseX, mouseY, delta);
}
@Override
- public void render(int mouseX, int mouseY, float delta) {}
-
- @Override
public List<? extends Element> children() {
return Collections.singletonList(this.widget);
}
+
+ @Override
+ public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
+ return this.widget.mouseScrolled(mouseX, mouseY, amount);
+ }
}
private static class LateRenderableWidgetWithBounds extends WidgetWithBounds implements LateRenderable {
@@ -242,24 +257,71 @@ public final class InternalWidgets {
this.widget = widget;
}
+ @Override
+ public @NotNull Rectangle getBounds() {
+ return this.widget.getBounds();
+ }
@Override
- public void lateRender(int mouseX, int mouseY, float delta) {
+ public void render(int mouseX, int mouseY, float delta) {
this.widget.setZ(getZ());
this.widget.render(mouseX, mouseY, delta);
}
@Override
+ public boolean containsMouse(double mouseX, double mouseY) {
+ return this.widget.containsMouse(mouseX, mouseY);
+ }
+
+ @Override
+ public List<? extends Element> children() {
+ return Collections.singletonList(this.widget);
+ }
+
+ @Override
+ public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
+ return this.widget.mouseScrolled(mouseX, mouseY, amount);
+ }
+ }
+
+ private static class WidgetWithBoundsWithTranslate extends WidgetWithBounds implements LateRenderable {
+ private final WidgetWithBounds widget;
+ private final float x, y, z;
+
+ public WidgetWithBoundsWithTranslate(WidgetWithBounds widget, float x, float y, float z) {
+ this.widget = widget;
+ this.x = x;
+ this.y = y;
+ this.z = z;
+ }
+
+ @Override
public @NotNull Rectangle getBounds() {
return this.widget.getBounds();
}
@Override
- public void render(int mouseX, int mouseY, float delta) {}
+ public void render(int mouseX, int mouseY, float delta) {
+ RenderSystem.pushMatrix();
+ RenderSystem.translatef(x, y, z);
+ this.widget.setZ(getZ());
+ this.widget.render(mouseX, mouseY, delta);
+ RenderSystem.popMatrix();
+ }
+
+ @Override
+ public boolean containsMouse(double mouseX, double mouseY) {
+ return this.widget.containsMouse(mouseX, mouseY);
+ }
@Override
public List<? extends Element> children() {
return Collections.singletonList(this.widget);
}
+
+ @Override
+ public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
+ return this.widget.mouseScrolled(mouseX, mouseY, amount);
+ }
}
}