Add FontUtil.kt

This commit is contained in:
Username404-59 2021-05-01 19:21:45 +02:00
parent 833cac5ccd
commit b3201bfa3c
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
2 changed files with 17 additions and 2 deletions

View File

@ -0,0 +1,13 @@
package fr.username404.snowygui.gui
import com.mojang.blaze3d.vertex.PoseStack
import net.minecraft.client.Minecraft
object FontUtil {
fun drawScaled(stack: PoseStack, text: String, x: Double, y: Double, scaleFactor: Float, color: Int = 0x000000) {
stack.scale(scaleFactor, scaleFactor, scaleFactor)
Minecraft.getInstance().font.draw(stack, text, (x / scaleFactor).toFloat(), (y / scaleFactor).toFloat(), color)
val factorToOriginal = 1F / scaleFactor
stack.scale(factorToOriginal, factorToOriginal, factorToOriginal)
}
}

View File

@ -3,10 +3,10 @@ package fr.username404.snowygui.gui.elements
import com.mojang.blaze3d.systems.RenderSystem
import com.mojang.blaze3d.vertex.PoseStack
import fr.username404.snowygui.gui.ColoredElement
import fr.username404.snowygui.gui.FontUtil
import fr.username404.snowygui.gui.Renderable.Rendering.defaultRectFunc
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.components.events.GuiEventListener
class ClickButton(
@ -61,6 +61,8 @@ class ClickButton(
defaultRectFunc()
RenderSystem.enableTexture()
RenderSystem.disableBlend()
if (Title != null) Minecraft.getInstance().font.draw(poseStack, Title, x.toFloat() + 1, y.toFloat(), 0x000000)
if (Title != null && poseStack != null) {
FontUtil.drawScaled(poseStack, Title, x + 1, y + 1, 0.75F)
}
}
}