#include "rendering.h"
#include "structs.h"
+#include "config.h"
-runtime_info runtime;
void killterm_handler(int signum);
int init()
signal(SIGKILL, killterm_handler);
signal(SIGTERM, killterm_handler);
- float scale = 1.0f;
- runtime.layout.window = (SDL_FRect){.x = 0.0f, .y = 0.0f, .w = scale*512.0f, .h = scale*512.0f};
-
- // satisfying rel.[xy]*2 == .[wh] centers axis in parent container
- runtime.layout.rgb_square.rel = (SDL_FRect){.x = 0.05, .y = 0.05, .w = 0.5, .h = 0.5};
- runtime.layout.hue_slider.rel = (SDL_FRect){.x = 0.70, .y = 0.05, .w = .08, .h = 0.5};
- runtime.layout.final_sample.rel = (SDL_FRect){.x = 0.05, .y = .65, .w = 0.20, .h = 0.20};
- runtime.layout.info_container.rel = (SDL_FRect){.x = 0.05, .y = .65, .w = .9, .h = .30};
- runtime.layout.info_boxes.rel = (SDL_FRect){.x = .25, .y = 0.00, .w = 0.75, .h = 1.00};
- runtime.layout.rgb_info.rel = (SDL_FRect){.x = 0.00, .y = 0.00, .w = 1.00, .h = 0.50};
- runtime.layout.red.rel = (SDL_FRect){.x = 0.00, .y = 0.00, .w = 0.30, .h = 1.00};
- runtime.layout.green.rel = (SDL_FRect){.x = 0.35, .y = 0.00, .w = 0.30, .h = 1.00};
- runtime.layout.blue.rel = (SDL_FRect){.x = 0.70, .y = 0.00, .w = 0.30, .h = 1.00};
- runtime.layout.hsl_info.rel = (SDL_FRect){.x = 0.00, .y = 0.50, .w = 1.00, .h = 0.50};
- runtime.layout.hue.rel = (SDL_FRect){.x = 0.00, .y = 0.00, .w = 0.30, .h = 1.00};
- runtime.layout.saturation.rel = (SDL_FRect){.x = 0.35, .y = 0.00, .w = 0.30, .h = 1.00};
- runtime.layout.luminence.rel = (SDL_FRect){.x = 0.70, .y = 0.00, .w = 0.30, .h = 1.00};
-
+ runtime.layout = config_layout;
runtime.active_hsl = (HSL_Color){.h = 0, .s = 100, .l = 50};
runtime.active_rgb = hsl_to_rgb(runtime.active_hsl);
TTF_Init();
- // Probably figure out how to get reliable fonts
- runtime.font = TTF_OpenFont("/usr/share/fonts/TTF/iosevka-fixed-regular.ttf", 64);
+ runtime.font = TTF_OpenFont(config_font_path, config_font_size);
assert(runtime.font != NULL);
init_renderer(&runtime);
int main(void)
{
- int quit = 0;
struct timespec ts_start;
struct timespec ts_end;
- float time_step = 1000.0f/30;
+ float time_step = 1000.0f/config_framerate;
if(init() != 0)
{
delay(time_step - frameproc_ms);
}
- killterm_handler(15);
-
return 0;
}
void killterm_handler(int signum)
{
- printf("handling sig %d, bye bye\n", signum);
shutdown_renderer();
-
exit(0);
}
sdl_group mgr;
-int32_t init_renderer(runtime_info* runtime)
+int32_t init_renderer(Runtime_Info* runtime)
{
SDL_SetMainReady();
if (SDL_Init(SDL_INIT_VIDEO))
// this would be really cool to turn into some stack-based type of thing
// Also, if resizing is disabled, this can be moved to a static initialization section
// orrrr, maybe we can finally do callbacks
- render_container(runtime, &runtime->layout.window, &runtime->layout.rgb_square, green);
+ render_container(runtime, &runtime->layout.window, &runtime->layout.hsl_square, green);
render_container(runtime, &runtime->layout.window, &runtime->layout.hue_slider, green);
render_container(runtime, &runtime->layout.window, &runtime->layout.info_container, blue);
render_container(runtime, &runtime->layout.window, &runtime->layout.final_sample, green);
// Rename this eventually
// It's actually HSL
-int32_t render_rgb_square(runtime_info* runtime, SDL_FRect* container)
+int32_t render_hsl_square(Runtime_Info* runtime, SDL_FRect* container)
{
HSL_Color active_hsl = runtime->active_hsl;
SDL_Color hsl_pixel;
// I guess not much other way than good ol' n^2
// hmmm we'll fix this later
-
active_hsl.s = 0;
active_hsl.l = 0;
for (int r = 0; r < container->w; r++)
return 0;
}
-int32_t render_color_preview(runtime_info* runtime, SDL_FRect* container)
+int32_t render_color_preview(Runtime_Info* runtime, SDL_FRect* container)
{
runtime->active_rgb = hsl_to_rgb(runtime->active_hsl);
SDL_SetRenderDrawColor(mgr.rend, unroll_sdl_color(runtime->active_rgb));
// https://stackoverflow.com/questions/22886500/how-to-render-text-in-sdl2
// This is horrible horrible horrible
-int32_t render_info_boxes(runtime_info* runtime, SDL_FRect* container)
+// Look away
+int32_t render_info_boxes(Runtime_Info* runtime, SDL_FRect* container)
{
char red_string[32];
char blu_string[32];
SDL_DestroyTexture(runtime->layout.lum_component_text_tex);
}
-int32_t render_vertical_hue_spectrum(runtime_info* runtime, SDL_FRect* container)
+int32_t render_vertical_hue_spectrum(Runtime_Info* runtime, SDL_FRect* container)
{
int hue_slice_scale = container->h;
}
// REALLY this should be "generate layout", and not a true rendering step
-int32_t render_container(runtime_info* runtime, SDL_FRect* parent, Layout_Rect* child, SDL_Color color)
+int32_t render_container(Runtime_Info* runtime, SDL_FRect* parent, Layout_Rect* child, SDL_Color color)
{
SDL_SetRenderDrawColor(mgr.rend, unroll_sdl_color(color));
child->real = fr_margin_adjust(*parent, child->rel);
return 0;
}
-int32_t display(runtime_info* runtime)
+int32_t display(Runtime_Info* runtime)
{
SDL_SetRenderDrawColor(mgr.rend, 0xCB, 0xCB, 0xCB, 0xCB);
SDL_RenderClear(mgr.rend);
render_color_preview(runtime, &runtime->layout.final_sample.real);
render_vertical_hue_spectrum(runtime, &runtime->layout.hue_slider.real);
- render_rgb_square(runtime, &runtime->layout.rgb_square.real);
+ render_hsl_square(runtime, &runtime->layout.hsl_square.real);
render_info_boxes(runtime, &runtime->layout.info_boxes.real);
SDL_RenderPresent(mgr.rend);
return 0;
}
-int32_t check_inputs(runtime_info* runtime)
+int32_t check_inputs(Runtime_Info* runtime)
{
while(SDL_PollEvent(&(mgr.event)))
{
}
sdl_group;
-int32_t init_renderer(runtime_info* runtime);
+int32_t init_renderer(Runtime_Info* runtime);
int32_t shutdown_renderer();
int32_t delay(int32_t delay_time);
-int32_t display(runtime_info* runtime);
-int32_t check_inputs(runtime_info* runtime);
+int32_t display(Runtime_Info* runtime);
+int32_t check_inputs(Runtime_Info* runtime);
-int32_t render_container(runtime_info* runtime, SDL_FRect* parent, Layout_Rect* child, SDL_Color color);
+int32_t render_container(Runtime_Info* runtime, SDL_FRect* parent, Layout_Rect* child, SDL_Color color);
SDL_FRect fr_add(const SDL_FRect left, const SDL_FRect right);
SDL_FRect fr_subtract(const SDL_FRect left, const SDL_FRect right);
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
#define Relative_Rect SDL_FRect
-
#include <stdint.h>
// A placeable rect, with relative components to its parent,
{
// Tabbing these to visually indicate layout
SDL_FRect window;
- Layout_Rect rgb_square; // big clicky draggy square
+ Layout_Rect hsl_square; // big clicky draggy square
Layout_Rect hue_slider; // HSV slider bar
Layout_Rect info_container;
Layout_Rect final_sample; // small square showing full selected color
TTF_Font* font;
-} runtime_info;
+} Runtime_Info;
#endif // STRUCTS__