aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/com/dulkirfabric/features
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/com/dulkirfabric/features')
-rw-r--r--src/main/kotlin/com/dulkirfabric/features/RenderBoxTest.kt6
-rw-r--r--src/main/kotlin/com/dulkirfabric/features/TooltipImpl.kt52
2 files changed, 44 insertions, 14 deletions
diff --git a/src/main/kotlin/com/dulkirfabric/features/RenderBoxTest.kt b/src/main/kotlin/com/dulkirfabric/features/RenderBoxTest.kt
index af76c44..6863479 100644
--- a/src/main/kotlin/com/dulkirfabric/features/RenderBoxTest.kt
+++ b/src/main/kotlin/com/dulkirfabric/features/RenderBoxTest.kt
@@ -14,5 +14,11 @@ object RenderBoxTest {
event.context, Box(0.0, 0.0, 0.0, 1.0, 1.0, 1.0),
Color(255, 255, 255, 255), 10f, true
)
+
+ WorldRenderUtils.drawBox(
+ event.context, Box(2.0, 0.0, 0.0, 3.0, 1.0, 1.0),
+ Color(1, 255, 1, 255), 10f, false
+ )
+
}
} \ No newline at end of file
diff --git a/src/main/kotlin/com/dulkirfabric/features/TooltipImpl.kt b/src/main/kotlin/com/dulkirfabric/features/TooltipImpl.kt
index 100b880..14bc6c5 100644
--- a/src/main/kotlin/com/dulkirfabric/features/TooltipImpl.kt
+++ b/src/main/kotlin/com/dulkirfabric/features/TooltipImpl.kt
@@ -3,36 +3,45 @@ package com.dulkirfabric.features
import com.dulkirfabric.DulkirModFabric.mc
import com.dulkirfabric.events.ClientTickEvent
import com.dulkirfabric.events.MouseScrollEvent
+import com.dulkirfabric.events.TooltipRenderChangeEvent
import meteordevelopment.orbit.EventHandler
import net.minecraft.client.MinecraftClient
import net.minecraft.client.util.InputUtil
+import net.minecraft.client.util.math.MatrixStack
import org.joml.Vector2i
import org.joml.Vector2ic
import org.lwjgl.glfw.GLFW
object TooltipImpl {
- var scaleBuffer = 1f
- var horizontalBuffer = 0.0
- var verticalBuffer = 0.0
-
- var tickScale = 0f
- var tickHorizontal = 0
- var tickVertical = 0
-
- var prevTickX = 0
- var prevTickY = 0
+ private var scaleBuffer = 1f
+ private var horizontalBuffer = 0.0
+ private var verticalBuffer = 0.0
+ private var tickScale = 0f
+ private var tickHorizontal = 0
+ private var tickVertical = 0
+ private var prevTickX = 0
+ private var prevTickY = 0
+ private var prevScale = 1f
+ private var frameScale = 1f
+ private var frameX = 0
+ private var frameY = 0
fun calculatePos(v: Vector2ic): Vector2ic {
// calculate the position of the tooltip based on the scroll amount
val partialTicks = MinecraftClient.getInstance().tickDelta
- val newVec = v.add(prevTickX + ((tickHorizontal - prevTickX) * partialTicks).toInt(),
- prevTickY + ((tickVertical - prevTickY) * partialTicks).toInt(), Vector2i())
+ frameX = v.x() + prevTickX + ((tickHorizontal - prevTickX) * partialTicks).toInt()
+ frameY = v.y() + prevTickY + ((tickVertical - prevTickY) * partialTicks).toInt()
+ val newVec = v.add(-v.x() + frameX, -v.y() + frameY, Vector2i())
return newVec
}
- fun applyScale() {
-
+ fun applyScale(matrices: MatrixStack) {
+ frameScale = prevScale + (tickScale - prevScale) * MinecraftClient.getInstance().tickDelta
+ matrices.scale(frameScale, frameScale, 1f)
+ val newX = frameX / frameScale
+ val newY = frameY / frameScale
+ matrices.translate(newX - frameX, newY - frameY, 0f)
}
@EventHandler
@@ -40,6 +49,7 @@ object TooltipImpl {
// flushes the buffer to a scroll amount this tick, will be interpolated in calculatePos
prevTickX = tickHorizontal
prevTickY = tickVertical
+ prevScale = tickScale
tickHorizontal = horizontalBuffer.toInt()
tickVertical = verticalBuffer.toInt()
tickScale = scaleBuffer
@@ -47,6 +57,7 @@ object TooltipImpl {
@EventHandler
fun onScroll(event: MouseScrollEvent) {
+ // TODO: ignore input in config screen
if (event.verticalScrollAmount == 0.0) return
val handle = MinecraftClient.getInstance().window.handle
if (InputUtil.isKeyPressed(handle, GLFW.GLFW_KEY_LEFT_SHIFT)) {
@@ -57,4 +68,17 @@ object TooltipImpl {
verticalBuffer += (mc.window.height / 108) * event.verticalScrollAmount
}
}
+
+ @EventHandler
+ fun onChange(event: TooltipRenderChangeEvent) {
+ scaleBuffer = 1f
+ horizontalBuffer = 0.0
+ verticalBuffer = 0.0
+ tickScale = 1f
+ tickHorizontal = 0
+ tickVertical = 0
+ prevTickX = 0
+ prevTickY = 0
+ prevScale = 1f
+ }
} \ No newline at end of file