aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/util
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2025-11-24 21:49:16 +0100
committerLinnea Gräf <nea@nea.moe>2025-11-24 21:49:16 +0100
commit3f33928c8fefe4816af9d538fa3fce48d5e76f7c (patch)
tree75a01dae80643f0b831a875c10272173130243b7 /src/main/kotlin/util
parent20458e27c44ac498950cfaf408c35e7170d2a875 (diff)
downloadFirmament-3f33928c8fefe4816af9d538fa3fce48d5e76f7c.tar.gz
Firmament-3f33928c8fefe4816af9d538fa3fce48d5e76f7c.tar.bz2
Firmament-3f33928c8fefe4816af9d538fa3fce48d5e76f7c.zip
feat(recipe viewer): moulconfig widget
Diffstat (limited to 'src/main/kotlin/util')
-rw-r--r--src/main/kotlin/util/MoulConfigUtils.kt22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/main/kotlin/util/MoulConfigUtils.kt b/src/main/kotlin/util/MoulConfigUtils.kt
index c0c7ef5..0c65e69 100644
--- a/src/main/kotlin/util/MoulConfigUtils.kt
+++ b/src/main/kotlin/util/MoulConfigUtils.kt
@@ -26,6 +26,7 @@ import kotlin.time.Duration.Companion.seconds
import net.minecraft.client.gui.GuiGraphics
import net.minecraft.client.gui.screens.Screen
import com.mojang.blaze3d.platform.InputConstants
+import me.shedaniel.math.Rectangle
import net.minecraft.network.chat.Component
import moe.nea.firmament.gui.BarComponent
import moe.nea.firmament.gui.FirmButtonComponent
@@ -292,7 +293,22 @@ object MoulConfigUtils {
return component.mouseEvent(mouseEvent, immContext.translated(x, y, w, h))
}
- fun createInPlaceFullContext(drawContext: GuiGraphics?, mouseX: Int, mouseY: Int): GuiImmediateContext {
+ fun <T> createAndTranslateFullContext(
+ drawContext: GuiGraphics?,
+ mouseX: Number, mouseY: Number,
+ rectangle: Rectangle,
+ block: (GuiImmediateContext) -> T
+ ): T {
+ val ctx = createInPlaceFullContext(drawContext, mouseX, mouseY)
+ val pose = drawContext?.pose()
+ pose?.pushMatrix()
+ pose?.translate(rectangle.x.toFloat(), rectangle.y.toFloat())
+ val result = block(ctx.translated(rectangle.x, rectangle.y, rectangle.width, rectangle.height))
+ pose?.popMatrix()
+ return result
+ }
+
+ fun createInPlaceFullContext(drawContext: GuiGraphics?, mouseX: Number, mouseY: Number): GuiImmediateContext {
ErrorUtil.softCheck(
"created moulconfig context with pre-existing translations.",
drawContext?.isUntranslatedGuiDrawContext() != false
@@ -302,8 +318,8 @@ object MoulConfigUtils {
val immContext = GuiImmediateContext(
context,
0, 0, 0, 0,
- mouseX, mouseY,
- mouseX, mouseY,
+ mouseX.toInt(), mouseY.toInt(),
+ mouseX.toInt(), mouseY.toInt(),
mouseX.toFloat(),
mouseY.toFloat()
)