diff options
| author | shedaniel <daniel@shedaniel.me> | 2022-07-06 17:34:35 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2022-07-06 17:34:52 +0800 |
| commit | b23f427dc082c61d8057f395fc80a0150a22ef01 (patch) | |
| tree | 0f2693deab6f0a8b55331c7d9240c44dfb3163d3 /api/src/main/java | |
| parent | 84ce034ad0eeffd6e88ea7a1cae821779b620841 (diff) | |
| download | RoughlyEnoughItems-b23f427dc082c61d8057f395fc80a0150a22ef01.tar.gz RoughlyEnoughItems-b23f427dc082c61d8057f395fc80a0150a22ef01.tar.bz2 RoughlyEnoughItems-b23f427dc082c61d8057f395fc80a0150a22ef01.zip | |
Fix #963
Diffstat (limited to 'api/src/main/java')
| -rw-r--r-- | api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widget.java | 11 | ||||
| -rw-r--r-- | api/src/main/java/me/shedaniel/rei/api/client/util/MatrixUtils.java | 59 |
2 files changed, 61 insertions, 9 deletions
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 16ef576ee..2e683f51a 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 @@ -32,6 +32,7 @@ import me.shedaniel.math.Rectangle; import me.shedaniel.math.impl.PointHelper; import me.shedaniel.rei.api.client.gui.AbstractContainerEventHandler; import me.shedaniel.rei.api.client.gui.Renderer; +import me.shedaniel.rei.api.client.util.MatrixUtils; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.Minecraft; @@ -130,15 +131,7 @@ public abstract class Widget extends AbstractContainerEventHandler implements ne @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))); + ScissorsHandler.INSTANCE.scissor(MatrixUtils.transform(matrix, bounds)); return ScissorsHandler.INSTANCE::removeLastScissor; } } diff --git a/api/src/main/java/me/shedaniel/rei/api/client/util/MatrixUtils.java b/api/src/main/java/me/shedaniel/rei/api/client/util/MatrixUtils.java new file mode 100644 index 000000000..f03d16315 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/client/util/MatrixUtils.java @@ -0,0 +1,59 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 shedaniel + * + * 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 me.shedaniel.rei.api.client.util; + +import com.mojang.math.Matrix4f; +import com.mojang.math.Transformation; +import com.mojang.math.Vector4f; +import me.shedaniel.math.Point; +import me.shedaniel.math.Rectangle; +import org.jetbrains.annotations.ApiStatus; + +@ApiStatus.Experimental +public class MatrixUtils { + public static Matrix4f inverse(Matrix4f matrix) { + Transformation transformation = new Transformation(matrix); + Transformation inverse = transformation.inverse(); + if (inverse != null) inverse.getScale(); // This has a side effect + return inverse == null ? Transformation.identity().getMatrix() : inverse.getMatrix(); + } + + public static Rectangle transform(Matrix4f matrix, Rectangle rectangle) { + Vector4f vec1 = new Vector4f((float) rectangle.x, (float) rectangle.y, 0, 1); + vec1.transform(matrix); + Vector4f vec2 = new Vector4f((float) rectangle.getMaxX(), (float) rectangle.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()); + return new Rectangle(Math.min(x1, x2), Math.min(y1, y2), Math.abs(x2 - x1), Math.abs(y2 - y1)); + } + + public static Point transform(Matrix4f matrix, Point point) { + Vector4f mouse = new Vector4f((float) point.x, (float) point.y, 0, 1); + mouse.transform(matrix); + return new Point(mouse.x(), mouse.y()); + } +} |
