summaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils/renderables
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2023-09-15 09:55:26 +0200
committerGitHub <noreply@github.com>2023-09-15 09:55:26 +0200
commitf5e2667e1ee0f8e663ae32f34f76e1a2bc0b6ada (patch)
tree6fb997272eab7c9d7e026bc865e873afdec4341e /src/main/java/at/hannibal2/skyhanni/utils/renderables
parent54a5b0c591470cf0ee247977ecef7cbdcddc5172 (diff)
downloadskyhanni-f5e2667e1ee0f8e663ae32f34f76e1a2bc0b6ada.tar.gz
skyhanni-f5e2667e1ee0f8e663ae32f34f76e1a2bc0b6ada.tar.bz2
skyhanni-f5e2667e1ee0f8e663ae32f34f76e1a2bc0b6ada.zip
Feature: gui scaling (#464)
Add gui scaling #464
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils/renderables')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/renderables/RenderLineTooltips.kt8
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt39
2 files changed, 38 insertions, 9 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..22675039e 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,13 @@ 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)
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..ed3aa9cfd 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 { mp ->
+ mp.first in (posX..posX + width)
+ && mp.second 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 {