diff --git a/apps/plasma.c b/apps/plasma.c index 9ad030f8..bd8903ec 100644 --- a/apps/plasma.c +++ b/apps/plasma.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -171,6 +172,8 @@ int main (int argc, char ** argv) { } } + wait(NULL); + yutani_close(yctx, wina); return 0; } diff --git a/lib/decor-fancy.c b/lib/decor-fancy.c index f715ef53..f7e2dbc0 100644 --- a/lib/decor-fancy.c +++ b/lib/decor-fancy.c @@ -3,7 +3,7 @@ #include #include #include -#include +#include #define INACTIVE 9 @@ -79,19 +79,19 @@ static void render_decorations_fancy(yutani_window_t * window, gfx_context_t * c #define EXTRA_SPACE 40 - if (draw_string_width(tmp_title) + EXTRA_SPACE > width) { - while (t_l >= 0 && (draw_string_width(tmp_title) + EXTRA_SPACE > width)) { + if (draw_sdf_string_width(tmp_title, 18) + EXTRA_SPACE > width) { + while (t_l >= 0 && (draw_sdf_string_width(tmp_title, 18) + EXTRA_SPACE > width)) { tmp_title[t_l] = '\0'; t_l--; } } if (strlen(tmp_title)) { - int title_offset = (width / 2) - (draw_string_width(tmp_title) / 2); + int title_offset = (width / 2) - (draw_sdf_string_width(tmp_title, 18) / 2); if (decors_active == 0) { - draw_string(ctx, title_offset, TEXT_OFFSET, rgb(226,226,226), tmp_title); + draw_sdf_string(ctx, title_offset, TEXT_OFFSET, tmp_title, 18, rgb(226,226,226)); } else { - draw_string(ctx, title_offset, TEXT_OFFSET, rgb(147,147,147), tmp_title); + draw_sdf_string(ctx, title_offset, TEXT_OFFSET, tmp_title, 18, rgb(147,147,147)); } } diff --git a/lib/sdf.c b/lib/sdf.c index 2838f7b4..b586001f 100644 --- a/lib/sdf.c +++ b/lib/sdf.c @@ -116,10 +116,13 @@ struct { {0,0}, }; +static int loaded = 0; + __attribute__((constructor)) static void _init_sdf(void) { /* Load the font. */ load_sprite(&_font_data, "/usr/share/sdf.bmp"); + loaded = 1; } static int draw_sdf_character(gfx_context_t * ctx, int32_t x, int32_t y, int ch, int size, uint32_t color, sprite_t * tmp) { @@ -136,12 +139,13 @@ static int draw_sdf_character(gfx_context_t * ctx, int32_t x, int32_t y, int ch, } double scale = (double)size / 50.0; - size_t width = _char_data[ch].width * scale; + int width = _char_data[ch].width * scale; int fx = ((BASE_WIDTH * ch) % _font_data.width) * scale; int fy = (((BASE_WIDTH * ch) / _font_data.width) * BASE_HEIGHT) * scale; int height = BASE_HEIGHT * ((double)size / 50.0); + /* ignore size */ for (int j = 0; j < height; ++j) { for (int i = 0; i < width; ++i) { @@ -166,6 +170,8 @@ static int draw_sdf_character(gfx_context_t * ctx, int32_t x, int32_t y, int ch, int draw_sdf_string(gfx_context_t * ctx, int32_t x, int32_t y, char * str, int size, uint32_t color) { + if (!loaded) return 0; + double scale = (double)size / 50.0; sprite_t * tmp = create_sprite(scale * _font_data.width, scale * _font_data.height, ALPHA_OPAQUE); gfx_context_t * t = init_graphics_sprite(tmp);