diff options
| author | shedaniel <daniel@shedaniel.me> | 2022-06-26 04:09:06 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2022-06-26 04:09:06 +0800 |
| commit | f4ec48ad1539bdc0ea5f54931740adf4bcb0560b (patch) | |
| tree | 71255dcb6ff80c2907702979e7b56f2c01676e82 /api/src/main/java/me/shedaniel | |
| parent | ff93cf4977b66cd8d276b77c8c69404684abe17b (diff) | |
| download | RoughlyEnoughItems-f4ec48ad1539bdc0ea5f54931740adf4bcb0560b.tar.gz RoughlyEnoughItems-f4ec48ad1539bdc0ea5f54931740adf4bcb0560b.tar.bz2 RoughlyEnoughItems-f4ec48ad1539bdc0ea5f54931740adf4bcb0560b.zip | |
Adapt scissors to transform
Diffstat (limited to 'api/src/main/java/me/shedaniel')
| -rw-r--r-- | api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/CloseableScissors.java | 12 | ||||
| -rw-r--r-- | api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widget.java | 24 |
2 files changed, 36 insertions, 0 deletions
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/CloseableScissors.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/CloseableScissors.java new file mode 100644 index 000000000..226c33ffc --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/CloseableScissors.java @@ -0,0 +1,12 @@ +package me.shedaniel.rei.api.client.gui.widgets; + +import org.jetbrains.annotations.ApiStatus; + +import java.io.Closeable; + +@ApiStatus.NonExtendable +@ApiStatus.Experimental +public interface CloseableScissors extends Closeable { + @Override + void close(); +} diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widget.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widget.java index 3c753e747..1c70c616d 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widget.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widget.java @@ -26,6 +26,7 @@ package me.shedaniel.rei.api.client.gui.widgets; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Matrix4f; import com.mojang.math.Vector4f; +import me.shedaniel.clothconfig2.api.ScissorsHandler; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; import me.shedaniel.math.impl.PointHelper; @@ -35,7 +36,11 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; +import java.io.Closeable; +import java.io.IOException; import java.util.Stack; /** @@ -115,4 +120,23 @@ public abstract class Widget extends AbstractContainerEventHandler implements ne public void render(PoseStack matrices, Rectangle bounds, int mouseX, int mouseY, float delta) { render(matrices, mouseX, mouseY, delta); } + + @ApiStatus.Experimental + public static CloseableScissors scissor(PoseStack matrices, Rectangle bounds) { + return scissor(matrices.last().pose(), bounds); + } + + @ApiStatus.Experimental + public static CloseableScissors scissor(Matrix4f matrix, Rectangle bounds) { + Vector4f vec1 = new Vector4f((float) bounds.x, (float) bounds.y, 0, 1); + vec1.transform(matrix); + Vector4f vec2 = new Vector4f((float) bounds.getMaxX(), (float) bounds.getMaxY(), 0, 1); + vec2.transform(matrix); + int x1 = Math.round(vec1.x()); + int x2 = Math.round(vec2.x()); + int y1 = Math.round(vec1.y()); + int y2 = Math.round(vec2.y()); + ScissorsHandler.INSTANCE.scissor(new Rectangle(Math.min(x1, x2), Math.min(y1, y2), Math.abs(x2 - x1), Math.abs(y2 - y1))); + return ScissorsHandler.INSTANCE::removeLastScissor; + } } |
