From 0e60e90233c79ac1a61130928a114f198ba633f2 Mon Sep 17 00:00:00 2001 From: randy Date: Tue, 26 Sep 2023 22:53:07 -0500 Subject: [PATCH] Improve text rendering so it doesn't just fill a container but actuall respects font size, and UI rearrange --- source/config.h | 13 ++++++------- source/rendering.c | 21 +++++++++++++++------ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/source/config.h b/source/config.h index 7c9a8bf..4046b78 100644 --- a/source/config.h +++ b/source/config.h @@ -22,18 +22,17 @@ Window_Layout config_layout = { .info_boxes.rel = (SDL_FRect){.x = 0.25, .y = 0.00, .w = 0.75, .h = 1.00}, .rgb_info.rel = (SDL_FRect){.x = 0.00, .y = 0.00, .w = 1.00, .h = 0.50}, .red_component.body.rel = (SDL_FRect){.x = 0.00, .y = 0.00, .w = 0.30, .h = 1.00}, - .green_component.body.rel = (SDL_FRect){.x = 0.35, .y = 0.00, .w = 0.30, .h = 1.00}, - .blue_component.body.rel = (SDL_FRect){.x = 0.70, .y = 0.00, .w = 0.30, .h = 1.00}, - .hsl_info.rel = (SDL_FRect){.x = 0.00, .y = 0.50, .w = 1.00, .h = 0.50}, + .green_component.body.rel = (SDL_FRect){.x = 0.00, .y = 0.40, .w = 0.30, .h = 1.00}, + .blue_component.body.rel = (SDL_FRect){.x = 0.00, .y = 0.80, .w = 0.30, .h = 1.00}, + .hsl_info.rel = (SDL_FRect){.x = 0.50, .y = 0.00, .w = 1.00, .h = 0.50}, .hue_component.body.rel = (SDL_FRect){.x = 0.00, .y = 0.00, .w = 0.30, .h = 1.00}, - .sat_component.body.rel = (SDL_FRect){.x = 0.35, .y = 0.00, .w = 0.30, .h = 1.00}, - .lum_component.body.rel = (SDL_FRect){.x = 0.70, .y = 0.00, .w = 0.30, .h = 1.00} + .sat_component.body.rel = (SDL_FRect){.x = 0.00, .y = 0.40, .w = 0.30, .h = 1.00}, + .lum_component.body.rel = (SDL_FRect){.x = 0.00, .y = 0.80, .w = 0.30, .h = 1.00} }; // For now we need a full path, maybe OpenFont can do automatic lookup const char config_font_path[] = "/usr/share/fonts/TTF/iosevka-fixed-regular.ttf"; -// This currently acts more like a static resolution scale rather than font size -const int config_font_size = 128; +const int config_font_size = 36; const int config_framerate = 30; #endif //__PICKER_CONFIG__ diff --git a/source/rendering.c b/source/rendering.c index e9324db..38e8341 100644 --- a/source/rendering.c +++ b/source/rendering.c @@ -170,8 +170,17 @@ int32_t free_text_container(Text_Container* tc) int32_t render_text_container(Runtime_Info* runtime, Text_Container* tc) { + // basics tc->surface = TTF_RenderText_Solid(runtime->font, tc->text, black); tc->texture = SDL_CreateTextureFromSurface(mgr.rend, tc->surface); + + // Adjust text rendering so it doesn't fill the whole element + int width, height; + SDL_QueryTexture(tc->texture, NULL, NULL, &width, &height); + tc->body.real.w = (float)width; + tc->body.real.h = (float)height; + + // slap it in there SDL_RenderCopyF(mgr.rend, tc->texture, NULL, &tc->body.real); // we'll keep this implicit to rendering for now to keep @@ -183,12 +192,12 @@ int32_t render_text_container(Runtime_Info* runtime, Text_Container* tc) // https://stackoverflow.com/questions/22886500/how-to-render-text-in-sdl2 int32_t render_info_boxes(Runtime_Info* runtime, SDL_FRect* container) { - sprintf(runtime->layout.red_component.text, "R:%d/%X\0", runtime->active_rgb.r, runtime->active_rgb.r); - sprintf(runtime->layout.green_component.text, "G:%d/%X\0", runtime->active_rgb.g, runtime->active_rgb.g); - sprintf(runtime->layout.blue_component.text, "B:%d/%X\0", runtime->active_rgb.b, runtime->active_rgb.b); - sprintf(runtime->layout.hue_component.text, "H:%d/%X\0", runtime->active_hsl.h, runtime->active_hsl.h); - sprintf(runtime->layout.sat_component.text, "S:%d/%X\0", runtime->active_hsl.s, runtime->active_hsl.s); - sprintf(runtime->layout.lum_component.text, "L:%d/%X\0", runtime->active_hsl.l, runtime->active_hsl.l); + sprintf(runtime->layout.red_component.text, "R:%03d/x%02X\0", runtime->active_rgb.r, runtime->active_rgb.r); + sprintf(runtime->layout.green_component.text, "G:%03d/x%02X\0", runtime->active_rgb.g, runtime->active_rgb.g); + sprintf(runtime->layout.blue_component.text, "B:%03d/x%02X\0", runtime->active_rgb.b, runtime->active_rgb.b); + sprintf(runtime->layout.hue_component.text, "H:%03d/x%02X\0", runtime->active_hsl.h, runtime->active_hsl.h); + sprintf(runtime->layout.sat_component.text, "S:%03d/x%02X\0", runtime->active_hsl.s, runtime->active_hsl.s); + sprintf(runtime->layout.lum_component.text, "L:%03d/x%02X\0", runtime->active_hsl.l, runtime->active_hsl.l); render_text_container(runtime, &runtime->layout.red_component); render_text_container(runtime, &runtime->layout.green_component); -- 2.49.0