diff options
| author | KonAki <konaki@anokonaki.org> | 2026-10-12 13:45:27 +0800 |
|---|---|---|
| committer | KonAki <konaki@anokonaki.org> | 2026-10-12 13:45:27 +0800 |
| commit | 6dd2b5cb0cc6a9a1b1856be5e5198c3692e5f74d (patch) | |
| tree | 293518e4b3b0b028cc06cdaeffb562e3d7c90389 /kon/konfont.h | |
| parent | 79edd4027ab956c441c660367c497508c99696bb (diff) | |
konsofren: opt-in 3d, light pass, tinted images. text honours alpha
Diffstat (limited to 'kon/konfont.h')
| -rw-r--r-- | kon/konfont.h | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/kon/konfont.h b/kon/konfont.h index 1e01b01..aa6f863 100644 --- a/kon/konfont.h +++ b/kon/konfont.h @@ -55,6 +55,7 @@ int kon_fontResize(kon_font_t *font, float pixelHeight); /*** text draw declarations ***/ +/* x, y is the left end of the baseline. color is 0xAARRGGBB, the alpha fades the text. ascii only for now, anything else is skipped */ void kon_drawText(kon_framebuffer_t *fb, kon_font_t *font, int x, int y, const char *text, uint32_t color); void kon_measureText(kon_font_t *font, const char *text, int *outWidth, int *outHeight); @@ -183,7 +184,7 @@ static void kon_fontDrawBuiltin_(kon_framebuffer_t *fb, const kon_font_t *font, int s = font->scale; int top = y - KON_BUILTIN_BASELINE * s; - color = (color & 0x00FFFFFFu) | 0xFF000000u; + if (color >> 24 == 0) return; for (const char *p = text; *p; p++) { unsigned char c = (unsigned char)*p; @@ -331,6 +332,9 @@ void kon_drawText(kon_framebuffer_t *fb, kon_font_t *font, int x, int y, const c } uint32_t baseColor = color & 0x00FFFFFF; + uint32_t colorAlpha = color >> 24; + + if (colorAlpha == 0) return; float cursorX = (float)x; float cursorY = (float)y; @@ -364,6 +368,7 @@ void kon_drawText(kon_framebuffer_t *fb, kon_font_t *font, int x, int y, const c for (int gx = gx0; gx < gx1; gx++) { uint32_t alpha = in[gx]; + if (colorAlpha != 0xFF) alpha = (alpha * colorAlpha + 127) / 255; if (alpha == 0) continue; if (alpha == 0xFF) { |
