From 61fb70975c9bba5d3bc98659724b4ca577050540 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Sat, 18 Sep 2021 13:42:37 +0900 Subject: [PATCH] shadow opacity configuration --- .../terrarumsansbitmap/gdx/GameFontBase.kt | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/net/torvald/terrarumsansbitmap/gdx/GameFontBase.kt b/src/net/torvald/terrarumsansbitmap/gdx/GameFontBase.kt index 0f10a1c..b313f0a 100755 --- a/src/net/torvald/terrarumsansbitmap/gdx/GameFontBase.kt +++ b/src/net/torvald/terrarumsansbitmap/gdx/GameFontBase.kt @@ -103,9 +103,13 @@ class GameFontBase( val magFilter: Texture.TextureFilter = Texture.TextureFilter.Nearest, var errorOnUnknownChar: Boolean = false, val textCacheSize: Int = 256, - val debug: Boolean = false + val debug: Boolean = false, + val shadowAlpha: Float = 0.5f, + val shadowAlphaPremultiply: Boolean = false ) : BitmapFont() { + constructor(fontDir: String, noShadow: Boolean, flipY: Boolean, invertShadow: Boolean) : this(fontDir, noShadow, flipY, invertShadow, Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest, false, 256, false) + /** * lowercase AND the height is equal to x-height (e.g. lowercase B, D, F, H, K, L, ... does not count */ @@ -1160,10 +1164,17 @@ class GameFontBase( // to be opaque if (pixel and 0xFF == 0xFF) { val newPixel = pixmap.getPixel(x + it.first, y + it.second) - val newColour = pixel.and(0xFFFFFF00.toInt()) or 0x80 + val newColour = Color(); Color.rgba8888ToColor(newColour, pixel) + newColour.a = shadowAlpha + + if (shadowAlphaPremultiply) { + newColour.r *= shadowAlpha + newColour.g *= shadowAlpha + newColour.b *= shadowAlpha + } if (newPixel and 0xFF == 0) { - pixmap.drawPixel(x + it.first, y + it.second, newColour) + pixmap.drawPixel(x + it.first, y + it.second, newColour.toRGBA8888()) } } }