@@ -20,6 +20,7 @@ package com.lambda.gui
2020import com.lambda.Lambda.mc
2121import com.lambda.core.Loadable
2222import com.lambda.gui.dsl.ImGuiBuilder
23+ import com.lambda.module.modules.client.GuiSettings
2324import com.lambda.util.path
2425import com.mojang.blaze3d.opengl.GlStateManager
2526import com.mojang.blaze3d.systems.RenderSystem
@@ -32,6 +33,7 @@ import net.minecraft.client.gl.GlBackend
3233import net.minecraft.client.texture.GlTexture
3334import org.lwjgl.opengl.GL11.glViewport
3435import org.lwjgl.opengl.GL30.GL_FRAMEBUFFER
36+ import kotlin.math.abs
3537
3638object DearImGui : Loadable {
3739 val implGlfw = ImGuiImplGlfw ()
@@ -42,8 +44,46 @@ object DearImGui : Loadable {
4244 ImGuiConfigFlags .NavEnableSetMousePos or // Move the cursor using the keyboard
4345 ImGuiConfigFlags .DockingEnable
4446
47+ private var lastScale = 0f
48+ private var lastScaleChangeTimestamp = 0L
49+ private var scaleChanged = false
50+ private var targetScale = 0f
51+
52+ private fun updateScale (scale : Float ) {
53+ val scaleFactor = if (lastScale > 0 ) scale / lastScale else scale
54+ ImGui .getStyle().scaleAllSizes(scaleFactor)
55+
56+ io.fonts.clear()
57+ val baseFontSize = 13f
58+ io.fonts.addFontFromFileTTF(" fonts/FiraSans-Regular.ttf" .path, baseFontSize * scale)
59+ io.fonts.build()
60+
61+ implGl3.createFontsTexture()
62+ }
63+
4564 fun render (block : ImGuiBuilder .() -> Unit ) {
46- // Minecraft will not bind the framebuffer unless it is needed, so do it manually and hope Vulcan never gets real:tm:
65+ val scale = (GuiSettings .scaleSetting / 100.0 ).toFloat()
66+
67+ if (lastScale == 0f ) {
68+ targetScale = scale
69+ updateScale(targetScale)
70+ lastScale = targetScale
71+ }
72+
73+ if (scale > 0 && abs(scale - lastScale) > 0.001f ) {
74+ if (abs(scale - targetScale) > 0.001f ) {
75+ lastScaleChangeTimestamp = System .currentTimeMillis()
76+ scaleChanged = true
77+ targetScale = scale
78+ }
79+ }
80+
81+ if (scaleChanged && (lastScaleChangeTimestamp + 1000 < System .currentTimeMillis())) {
82+ updateScale(targetScale)
83+ lastScale = targetScale
84+ scaleChanged = false
85+ }
86+
4787 val framebuffer = mc.framebuffer
4888 val prevFramebuffer = (framebuffer.getColorAttachment() as GlTexture ).getOrCreateFramebuffer((RenderSystem .getDevice() as GlBackend ).framebufferManager, null )
4989
@@ -73,11 +113,6 @@ object DearImGui : Loadable {
73113
74114 io.configFlags = DEFAULT_FLAGS
75115 io.iniFilename = " lambda.ini"
76- (13 .. 24 ).forEach { size ->
77- io.fonts.addFontFromFileTTF(" fonts/FiraSans-Bold.ttf" .path, size.toFloat())
78- io.fonts.addFontFromFileTTF(" fonts/FiraSans-Regular.ttf" .path, size.toFloat())
79- }
80- io.fonts.build()
81116
82117 implGlfw.init (mc.window.handle, true )
83118 implGl3.init ()
0 commit comments