From: Randy McShandy Date: Sun, 1 Oct 2023 17:30:57 +0000 (-0500) Subject: Some config management changes and small things X-Git-Url: http://git.mcshandy.xyz/gitweb.cgi?a=commitdiff_plain;h=b9c905149fcf7dc59a2b536094322a350787ef93;p=picker Some config management changes and small things --- diff --git a/source/config.h b/source/config.h index 042685b..cda34ca 100644 --- a/source/config.h +++ b/source/config.h @@ -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__ diff --git a/source/main.c b/source/main.c index 7feaca1..09f05fd 100644 --- a/source/main.c +++ b/source/main.c @@ -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); } diff --git a/source/rendering.c b/source/rendering.c index 1bff584..aeb706b 100644 --- a/source/rendering.c +++ b/source/rendering.c @@ -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(); diff --git a/source/structs.h b/source/structs.h index 3f87fbd..d818b5e 100644 --- a/source/structs.h +++ b/source/structs.h @@ -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;