Skip to content

Commit

Permalink
fix: Fixed color in Font Renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
slmpc committed Jan 21, 2025
1 parent 022e934 commit 38d4403
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ data class ColorRGB(val rgba: Int) {
constructor(r: Int, g: Int, b: Int, a: Int) :
this(
(r and 255 shl 24) or
(g and 255 shl 16) or
(b and 255 shl 8) or
(a and 255)
(g and 255 shl 16) or
(b and 255 shl 8) or
(a and 255)
)

constructor(r: Float, g: Float, b: Float) :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,35 @@ class FontRenderer(
}

private fun getColor(ch: Char): ColorRGB =
when (ch) {
'r' -> ColorRGB(255, 0, 0)
'g' -> ColorRGB(0, 255, 0)
'b' -> ColorRGB(0, 0, 255)
else -> ColorRGB.WHITE
ci[ch]?.let { return ColorRGB(it) } ?: ColorRGB.WHITE

companion object {
val ci: MutableMap<Char, Int> = mutableMapOf<Char, Int>().also {
it['0'] = 0x000000FF.toInt()
it['1'] = 0x0000AAFF.toInt()
it['2'] = 0x00AA00FF.toInt()
it['3'] = 0x00AAAAFF.toInt()
it['4'] = 0xAA0000FF.toInt()
it['5'] = 0xAA00AAFF.toInt()
it['6'] = 0xFFAA00FF.toInt()
it['7'] = 0xAAAAAAFF.toInt()
it['8'] = 0x555555FF.toInt()
it['9'] = 0x5555FFFF.toInt()

it['a'] = 0x55FF55FF.toInt()
it['b'] = 0x55FFFFFF.toInt()
it['c'] = 0xFF5555FF.toInt()
it['d'] = 0xFF55FFFF.toInt()
it['e'] = 0xFFFF55FF.toInt()
it['f'] = 0xFFFFFFFF.toInt()

it['A'] = 0x55FF55FF.toInt()
it['B'] = 0x55FFFFFF.toInt()
it['C'] = 0xFF5555FF.toInt()
it['D'] = 0xFF55FFFF.toInt()
it['E'] = 0xFFFF55FF.toInt()
it['F'] = 0xFFFFFFFF.toInt()
}
}

}

0 comments on commit 38d4403

Please sign in to comment.