]> git.mcshandy.xyz Git - picker/commitdiff
Improve text rendering so it doesn't just fill a container but actuall respects font...
authorrandy <randy@mcshandy.xyz>
Wed, 27 Sep 2023 03:53:07 +0000 (22:53 -0500)
committerrandy <randy@mcshandy.xyz>
Wed, 27 Sep 2023 03:53:07 +0000 (22:53 -0500)
source/config.h
source/rendering.c

index 7c9a8bfe7c59bb5c4a5613d76853405c347d4bd7..4046b7861902150ee93bd08b703ebe7acdd07d73 100644 (file)
@@ -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__
index e9324db649834c3058c04952a818abb265826ab2..38e83410d4f3aa518f4601a7b73c0f9cef4630cd 100644 (file)
@@ -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);