@@ -5,6 +5,7 @@ import com.lambda.graphics.buffer.vao.vertex.VertexAttrib
55import com.lambda.graphics.buffer.vao.vertex.VertexMode
66import com.lambda.graphics.renderer.gui.font.glyph.GlyphInfo
77import com.lambda.graphics.shader.Shader
8+ import com.lambda.module.modules.client.LambdaMoji
89import com.lambda.module.modules.client.RenderSettings
910import com.lambda.util.math.ColorUtils.a
1011import com.lambda.util.math.ColorUtils.setAlpha
@@ -13,7 +14,7 @@ import java.awt.Color
1314
1415class FontRenderer (
1516 private val font : LambdaFont ,
16- private val emojis : LambdaMoji
17+ private val emojis : LambdaEmoji
1718) {
1819 private val vao = VAO (VertexMode .TRIANGLES , VertexAttrib .Group .FONT )
1920
@@ -24,7 +25,7 @@ class FontRenderer(
2425 * Parses the emojis in the given text.
2526 *
2627 * @param text The text to parse.
27- * @return A list of pairs containing the glyph info and the range of the emoji in the text.
28+ * @return A list of pairs containing the glyph info and the range of the emoji in the text.
2829 */
2930 fun parseEmojis (text : String ) =
3031 mutableListOf<Pair <GlyphInfo , IntRange >>().apply {
@@ -102,36 +103,44 @@ class FontRenderer(
102103
103104 val emojis = parseEmojis(text)
104105
105- repeat(text.length) { index ->
106- fun draw (info : GlyphInfo , color : Color , offset : Double = 0.0) {
107- val scaledSize = info.size * actualScale
108- val pos1 = Vec2d (posX, posY) + offset * actualScale
109- val pos2 = pos1 + scaledSize
106+ fun draw (info : GlyphInfo , color : Color , offset : Double = 0.0) {
107+ val scaledSize = info.size * actualScale
108+ val pos1 = Vec2d (posX, posY) + offset * actualScale
109+ val pos2 = pos1 + scaledSize
110110
111- block(info, pos1, pos2, color)
112- if (offset == 0.0 ) posX + = scaledSize.x + scaledGap
113- }
111+ block(info, pos1, pos2, color)
112+ if (offset == 0.0 ) posX + = scaledSize.x + scaledGap
113+ }
114114
115- // Check if there's an emoji
116- emojis.firstOrNull { index in it.second }?.let { emoji ->
117- // Replace first emoji char by an emoji glyph and skip the other ones
118- if (index == emoji.second.first) {
119- draw(emoji.first, emojiColor)
120- }
115+ var index = 0
116+ textProcessor@ while (index < text.length) {
117+ var innerLoopContact = false // Instead of using BreakContinueInInlineLambdas, we use this
121118
122- return @repeat
119+ if (LambdaMoji .isEnabled) {
120+ // Check if there are emojis to render
121+ emojis.firstOrNull { index in it.second }?.let { emoji ->
122+ if (index == emoji.second.first) draw(emoji.first, emojiColor)
123+
124+ // Skip the emoji
125+ index = emoji.second.last + 1
126+ innerLoopContact = true
127+ }
123128 }
124129
130+ if (innerLoopContact) continue @textProcessor
131+
125132 // Render chars
126- font[text[index]]?.let { info ->
127- // Draw a shadow before
128- if (shadow && RenderSettings .shadow && shadowShift > 0.0 ) {
129- draw(info, shadowColor, shadowShift)
130- }
133+ val charInfo = font[text[index]] ? : continue @textProcessor
131134
132- // Draw actual char over the shadow
133- draw(info, color)
135+ // Draw a shadow before
136+ if (shadow && RenderSettings .shadow && shadowShift > 0.0 ) {
137+ draw(charInfo, shadowColor, shadowShift)
134138 }
139+
140+ // Draw actual char over the shadow
141+ draw(charInfo, color)
142+
143+ index++
135144 }
136145 }
137146
0 commit comments