Add FontUtil.kt
This commit is contained in:
parent
833cac5ccd
commit
b3201bfa3c
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,10 +3,10 @@ package fr.username404.snowygui.gui.elements
|
||||||
import com.mojang.blaze3d.systems.RenderSystem
|
import com.mojang.blaze3d.systems.RenderSystem
|
||||||
import com.mojang.blaze3d.vertex.PoseStack
|
import com.mojang.blaze3d.vertex.PoseStack
|
||||||
import fr.username404.snowygui.gui.ColoredElement
|
import fr.username404.snowygui.gui.ColoredElement
|
||||||
|
import fr.username404.snowygui.gui.FontUtil
|
||||||
import fr.username404.snowygui.gui.Renderable.Rendering.defaultRectFunc
|
import fr.username404.snowygui.gui.Renderable.Rendering.defaultRectFunc
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import net.minecraft.client.Minecraft
|
|
||||||
import net.minecraft.client.gui.components.events.GuiEventListener
|
import net.minecraft.client.gui.components.events.GuiEventListener
|
||||||
|
|
||||||
class ClickButton(
|
class ClickButton(
|
||||||
|
@ -61,6 +61,8 @@ class ClickButton(
|
||||||
defaultRectFunc()
|
defaultRectFunc()
|
||||||
RenderSystem.enableTexture()
|
RenderSystem.enableTexture()
|
||||||
RenderSystem.disableBlend()
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue