diff options
| author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-09-16 12:34:18 +0200 |
|---|---|---|
| committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-09-16 12:34:18 +0200 |
| commit | 4293cfd919c3c93d4532534f722c407d7ad1370d (patch) | |
| tree | f9f612f021ef7f4283d74312edfaca30badc6749 /src/main/java/at/hannibal2/skyhanni/utils/renderables | |
| parent | 538e3ceb76f8e0b590291ce9aa90aa94896cdcb6 (diff) | |
| parent | 024ba52fb69b6cd44b4e31542867f802de656f15 (diff) | |
| download | SkyHanni-cum.tar.gz SkyHanni-cum.tar.bz2 SkyHanni-cum.zip | |
Merge branch 'beta' into cumcum
# Conflicts:
# src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt
# src/main/java/at/hannibal2/skyhanni/config/features/AshfangConfig.java
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils/renderables')
| -rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/renderables/RenderLineTooltips.kt | 32 | ||||
| -rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt | 39 |
2 files changed, 57 insertions, 14 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/renderables/RenderLineTooltips.kt b/src/main/java/at/hannibal2/skyhanni/utils/renderables/RenderLineTooltips.kt index 2cf20ee72..68aebd04e 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/renderables/RenderLineTooltips.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/renderables/RenderLineTooltips.kt @@ -13,11 +13,15 @@ import java.awt.Color object RenderLineTooltips { - fun drawHoveringText(posX: Int, posY: Int, tips: List<String?>, stack: ItemStack? = null) { + fun drawHoveringText( + posX: Int, posY: Int, tips: List<String?>, stack: ItemStack? = null, + mouseX: Int = Utils.getMouseX(), + mouseY: Int = Utils.getMouseY() + ) { if (tips.isNotEmpty()) { var textLines = tips - val x = Utils.getMouseX() + 12 - posX - val y = Utils.getMouseY() - 10 - posY + val x = mouseX + 12 - posX + val y = mouseY - 10 - posY val color: Char = stack?.getLore()?.lastOrNull()?.take(4)?.get(1) ?: Utils.getPrimaryColourCode(textLines[0]) val colourInt = Minecraft.getMinecraft().fontRendererObj.getColorCode(color) @@ -187,7 +191,15 @@ object RenderLineTooltips { GlStateManager.disableLighting() } - private fun drawGradientRect(zLevel: Int, left: Int, top: Int, right: Int, bottom: Int, startColor: Int, endColor: Int) { + private fun drawGradientRect( + zLevel: Int, + left: Int, + top: Int, + right: Int, + bottom: Int, + startColor: Int, + endColor: Int + ) { val startAlpha = (startColor shr 24 and 255).toFloat() / 255.0f val startRed = (startColor shr 16 and 255).toFloat() / 255.0f val startGreen = (startColor shr 8 and 255).toFloat() / 255.0f @@ -204,10 +216,14 @@ object RenderLineTooltips { val tessellator = Tessellator.getInstance() val worldrenderer = tessellator.worldRenderer worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR) - worldrenderer.pos(right.toDouble(), top.toDouble(), zLevel.toDouble()).color(startRed, startGreen, startBlue, startAlpha).endVertex() - worldrenderer.pos(left.toDouble(), top.toDouble(), zLevel.toDouble()).color(startRed, startGreen, startBlue, startAlpha).endVertex() - worldrenderer.pos(left.toDouble(), bottom.toDouble(), zLevel.toDouble()).color(endRed, endGreen, endBlue, endAlpha).endVertex() - worldrenderer.pos(right.toDouble(), bottom.toDouble(), zLevel.toDouble()).color(endRed, endGreen, endBlue, endAlpha).endVertex() + worldrenderer.pos(right.toDouble(), top.toDouble(), zLevel.toDouble()) + .color(startRed, startGreen, startBlue, startAlpha).endVertex() + worldrenderer.pos(left.toDouble(), top.toDouble(), zLevel.toDouble()) + .color(startRed, startGreen, startBlue, startAlpha).endVertex() + worldrenderer.pos(left.toDouble(), bottom.toDouble(), zLevel.toDouble()) + .color(endRed, endGreen, endBlue, endAlpha).endVertex() + worldrenderer.pos(right.toDouble(), bottom.toDouble(), zLevel.toDouble()) + .color(endRed, endGreen, endBlue, endAlpha).endVertex() tessellator.draw() GlStateManager.shadeModel(7424) GlStateManager.disableBlend() diff --git a/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt b/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt index 81ddaabde..b3ba7f906 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt @@ -18,12 +18,13 @@ import kotlin.math.max interface Renderable { val width: Int val height: Int - fun isHovered(posX: Int, posY: Int) = - Utils.getMouseX() in (posX..posX + width) - && Utils.getMouseY() in (posY..posY + height) // TODO: adjust for variable height? + fun isHovered(posX: Int, posY: Int) = currentRenderPassMousePosition?.let { (x, y) -> + x in (posX..posX + width) + && y in (posY..posY + height) // TODO: adjust for variable height? + } ?: false /** - * N.B.: the offset is absolute, not relative to the position and shouldn't be used for rendering + * Pos x and pos y are relative to the mouse position. * (the GL matrix stack should already be pre transformed) */ fun render(posX: Int, posY: Int) @@ -32,6 +33,19 @@ interface Renderable { val logger = LorenzLogger("debug/renderable") val list = mutableMapOf<Pair<Int, Int>, List<Int>>() + var currentRenderPassMousePosition: Pair<Int, Int>? = null + private set + + fun <T> withMousePosition(posX: Int, posY: Int, block: () -> T): T { + val last = currentRenderPassMousePosition + try { + currentRenderPassMousePosition = Pair(posX, posY) + return block() + } finally { + currentRenderPassMousePosition = last + } + } + fun fromAny(any: Any?, itemScale: Double = 1.0): Renderable? = when (any) { null -> placeholder(12) is Renderable -> any @@ -101,7 +115,14 @@ interface Renderable { } } - fun hoverTips(text: String, tips: List<String>, indexes: List<Int> = listOf(), stack: ItemStack? = null, bypassChecks: Boolean = false, condition: () -> Boolean = { true }): Renderable { + fun hoverTips( + text: String, + tips: List<String>, + indexes: List<Int> = listOf(), + stack: ItemStack? = null, + bypassChecks: Boolean = false, + condition: () -> Boolean = { true } + ): Renderable { val render = string(text) return object : Renderable { @@ -116,7 +137,13 @@ interface Renderable { list[Pair(posX, posY)] = indexes GlStateManager.pushMatrix() GlStateManager.translate(0F, 0F, 400F) - RenderLineTooltips.drawHoveringText(posX, posY, tips, stack) + + RenderLineTooltips.drawHoveringText( + posX, posY, tips, + stack, + currentRenderPassMousePosition?.first ?: Utils.getMouseX(), + currentRenderPassMousePosition?.second ?: Utils.getMouseY(), + ) GlStateManager.popMatrix() } } else { |
