]> git.mcshandy.xyz Git - picker/commitdiff
Some config management changes and small things
authorRandy McShandy <randy@mcshandy.xyz>
Sun, 1 Oct 2023 17:30:57 +0000 (12:30 -0500)
committerRandy McShandy <randy@mcshandy.xyz>
Sun, 1 Oct 2023 17:30:57 +0000 (12:30 -0500)
source/config.h
source/main.c
source/rendering.c
source/structs.h

index 042685b85d8c505f598a46931f85e2ecb9af1383..cda34ca6e3fea1b7bf3deec5909b3f5f630b131d 100644 (file)
@@ -2,38 +2,39 @@
 #define __PICKER_CONFIG__
 #include "structs.h"
 
-const float config_ui_scale = 1.0f;
+// Multiple units need to include config.h now
+
+Runtime_Info runtime =
+{
+       .framerate = 30,
+       .font_path = "/usr/share/fonts/TTF/iosevka-term-regular.ttf",
+       .font_size = 32,
+};
 
-Runtime_Info runtime;
 Window_Layout config_layout = {
        // Master window scale and dimensions
        .window = (SDL_FRect){
                .x = 0.0f,
-               .y = 0.0f,
-               .w = config_ui_scale*512.0f,
-               .h = config_ui_scale*512.0f
+                       .y = 0.0f,
+                       .w = 512.0f,
+                       .h = 512.0f
        },
 
-       // satisfying rel.[xy]*2 == .[wh] centers axis in parent container
+// satisfying rel.[xy]*2 == .[wh] centers axis in parent container
        .hsl_square.rel                                         =       (SDL_FRect){.x = 0.05, .y = 0.05, .w = 0.50, .h = 0.50},
        .hue_slider.rel                                         =       (SDL_FRect){.x = 0.70, .y = 0.05, .w = 0.08, .h = 0.50},
        .final_sample.rel                                       =       (SDL_FRect){.x = 0.05, .y = 0.65, .w = 0.20, .h = 0.20},
        .info_container.rel                             =       (SDL_FRect){.x = 0.05, .y = 0.65, .w = 0.90, .h = 0.30},
-               .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.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.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}
+       .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.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.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-term-regular.ttf";
-const int config_font_size = 32;
-const int config_framerate = 30;
-
 #endif //__PICKER_CONFIG__
 
index 7feaca11f698f6d3317bdb99d96895affe35cf8c..09f05fdc041e94400157215ccb54621403c5241f 100644 (file)
@@ -20,9 +20,6 @@ int init()
        runtime.active_hsl = (HSL_Color){.h = 0, .s = 100, .l = 50};
        runtime.active_rgb = hsl_to_rgb(runtime.active_hsl);
 
-       TTF_Init();
-       runtime.font = TTF_OpenFont(config_font_path, config_font_size);
-       assert(runtime.font != NULL);
        init_renderer(&runtime);
        runtime.keep_alive = 1;
 
@@ -33,7 +30,7 @@ int main(void)
 {
        struct timespec ts_start;
        struct timespec ts_end;
-       float time_step = 1000.0f/config_framerate;
+       float time_step = 1000.0f/runtime.framerate;
 
        if(init() != 0)
        {
@@ -51,16 +48,13 @@ int main(void)
                delay(time_step - frameproc_ms);
        }
 
-       TTF_Quit();
-       int32_t refresh_layout(Runtime_Info* runtime);
+       shutdown_renderer(&runtime);
        return 0;
 }
 
 void killterm_handler(int signum)
 {
        shutdown_renderer(&runtime);
-       TTF_CloseFont(runtime.font);
-       TTF_Quit();
        exit(0);
 }
 
index 1bff5849664868521945550621ada96ee2d8ba9d..aeb706b2046df9fff660b608a2ef6f3cfd9a0a2d 100644 (file)
@@ -22,6 +22,13 @@ sdl_group mgr;
 int32_t refresh_layout(Runtime_Info* runtime)
 {
        NULL_CHECK(runtime);
+
+       int win_w, win_h;
+       // SDL_GetWindowSize(mgr.win, &win_w, &win_h);
+       SDL_GetRendererOutputSize(mgr.rend, &win_w, &win_h);
+       runtime->layout.window.w = win_w;
+       runtime->layout.window.h = win_h;
+
        // this would be really cool to turn into some stack-based type of thing
        render_container(&runtime->layout.window, &runtime->layout.hsl_square);
        render_container(&runtime->layout.window, &runtime->layout.hue_slider);
@@ -50,6 +57,8 @@ int32_t init_renderer(Runtime_Info* runtime)
                exit(__LINE__);
        }
 
+       // SDL_WINDOW_RESIZABLE forces terminal swallow and tiling doesn't like it
+       // Figure something out later
        mgr.win = SDL_CreateWindow("Color Picker", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, runtime->layout.window.w, runtime->layout.window.h, 0);
        if (mgr.win == NULL)
        {
@@ -66,6 +75,10 @@ int32_t init_renderer(Runtime_Info* runtime)
 
        SDL_SetRenderDrawBlendMode(mgr.rend, SDL_BLENDMODE_BLEND);
 
+       TTF_Init();
+       runtime->font = TTF_OpenFont(runtime->font_path, runtime->font_size);
+       assert(runtime->font != NULL);
+
        init_text_container(&runtime->layout.red_component, 64);
        init_text_container(&runtime->layout.green_component, 64);
        init_text_container(&runtime->layout.blue_component, 64);
@@ -88,6 +101,8 @@ int32_t shutdown_renderer(Runtime_Info* runtime)
        free_text_container(&runtime->layout.sat_component);
        free_text_container(&runtime->layout.lum_component);
 
+       TTF_CloseFont(runtime->font);
+       TTF_Quit();
        SDL_DestroyRenderer(mgr.rend);
        SDL_DestroyWindow(mgr.win);
        SDL_Quit();
index 3f87fbd2e7ab766f8de7867759d26698560168a9..d818b5eaca87e5e04eab50dc5f48d88967c670fd 100644 (file)
@@ -77,7 +77,9 @@ typedef struct
        Window_Layout layout;
 
        int keep_alive;
-
+       const int framerate;
+       const int font_size;
+       const char font_path[128];
        TTF_Font* font;
 
 } Runtime_Info;