Skip to content

Commit

Permalink
Working transparent text ;-)
Browse files Browse the repository at this point in the history
  • Loading branch information
CHiPs44 committed Feb 16, 2023
1 parent 4a7f990 commit 76d3456
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions src/hagl_char.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ hagl_put_char_styled(void const *_surface, wchar_t code, int16_t x0, int16_t y0,
uint8_t set, status;
hagl_bitmap_t bitmap;
fontx_glyph_t glyph;
bool reverse;
hagl_color_t background_color;
hagl_color_t foreground_color;
bool reverse = style->mode & HAGL_CHAR_MODE_REVERSE ? true : false;
hagl_color_t foreground_color = reverse ? style->background_color : style->foreground_color;
hagl_color_t background_color = reverse ? style->foreground_color : style->background_color;
hagl_color_t transparent_color = foreground_color == 0 ? 1 : 0;

status = fontx_glyph(&glyph, code, style->font);
if (0 != status) {
Expand All @@ -97,7 +98,6 @@ hagl_put_char_styled(void const *_surface, wchar_t code, int16_t x0, int16_t y0,
}

hagl_bitmap_init(&bitmap, glyph.width, glyph.height, surface->depth, (uint8_t *)buffer);

hagl_color_t *ptr = (hagl_color_t *) bitmap.buffer;

for (uint8_t y = 0; y < glyph.height; y++) {
Expand All @@ -107,6 +107,8 @@ hagl_put_char_styled(void const *_surface, wchar_t code, int16_t x0, int16_t y0,
{
if (set) {
*ptr = foreground_color;
} else {
*ptr = transparent_color;
}
} else {
if (set) {
Expand All @@ -124,16 +126,33 @@ hagl_put_char_styled(void const *_surface, wchar_t code, int16_t x0, int16_t y0,
style->scale_x_numerator <= 1 && style->scale_x_denominator <= 1
&& style->scale_y_numerator <= 1 && style->scale_y_denominator <= 1
) {
hagl_blit(_surface, x0, y0, &bitmap);
if (style->mode & HAGL_CHAR_MODE_TRANSPARENT)
{
hagl_blit_transparent(_surface, x0, y0, &bitmap, transparent_color);
} else {
hagl_blit(_surface, x0, y0, &bitmap);
}
return bitmap.width;
} else {
hagl_blit_xywh(
_surface,
x0, y0,
bitmap.width * style->scale_x_numerator / style->scale_x_denominator,
bitmap.height * style->scale_y_numerator / style->scale_y_denominator,
&bitmap
);
if (style->mode & HAGL_CHAR_MODE_TRANSPARENT)
{
hagl_blit_xywh_transparent(
_surface,
x0, y0,
bitmap.width * style->scale_x_numerator / style->scale_x_denominator,
bitmap.height * style->scale_y_numerator / style->scale_y_denominator,
&bitmap,
transparent_color
);
} else {
hagl_blit_xywh(
_surface,
x0, y0,
bitmap.width * style->scale_x_numerator / style->scale_x_denominator,
bitmap.height * style->scale_y_numerator / style->scale_y_denominator,
&bitmap
);
}
return bitmap.width * style->scale_x_numerator / style->scale_x_denominator;
}
}
Expand Down

0 comments on commit 76d3456

Please sign in to comment.