aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt39
1 files changed, 33 insertions, 6 deletions
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 {