diff options
| author | Martin Stensgård <mastensg@mastensg.net> | 2025-07-06 21:50:48 +0200 |
|---|---|---|
| committer | Martin Stensgård <mastensg@mastensg.net> | 2025-07-06 21:50:48 +0200 |
| commit | 6b274b041c40c4c7c71894d82e6b02733006609e (patch) | |
| tree | fa145093de5a89c6a02c464d6d78d92be02fcf96 | |
| parent | 18e51d63cc0da747df0968ca4c1fe8b3b1e2696b (diff) | |
opplysning: less main
| -rw-r--r-- | opplysning.c | 105 |
1 files changed, 53 insertions, 52 deletions
diff --git a/opplysning.c b/opplysning.c index 1e2dd92..3d47da8 100644 --- a/opplysning.c +++ b/opplysning.c @@ -174,11 +174,12 @@ load_the_events(void) ++num_events; } - sqlite3_close(db); -} + if (sqlite3_finalize(stmt)) + errx(1, "sqlite3_finalize: %s", sqlite3_errmsg(db)); -const char *the_non_ascii = "ÄÅÉËÞÜÚÍÓÖÁÐFGHÏŒØÆŒ©®BÑΜ" - "äåéëþüúíóöáðfghïœøæœ©®bñµß"; + if (sqlite3_close(db)) + errx(1, "sqlite3_close: %s", sqlite3_errmsg(db)); +} struct ray { Shader shader; @@ -194,6 +195,38 @@ struct ray { }; struct ray R; +const char *the_non_ascii = "ÄÅÉËÞÜÚÍÓÖÁÐFGHÏŒØÆŒ©®BÑΜ" + "äåéëþüúíóöáðfghïœøæœ©®bñµß"; + +void +ray_init(void) +{ + SetTraceLogLevel(LOG_WARNING); + InitWindow(SCREEN_W, SCREEN_H, "opplysning"); + SetTargetFPS(60); + + char *codes = calloc(128 + strlen(the_non_ascii), 1); + if (!codes) + err(1, "calloc"); + for (int i = 1; i < 128; ++i) + codes[i] = i; + memcpy(codes + 128, the_non_ascii, strlen(the_non_ascii)); + int ncp = 0; + int *cp = LoadCodepoints(codes + 1, &ncp); + R.font_h = LoadFontEx("font/adventpro-bold.ttf", 60, cp, ncp); + R.font_p = LoadFontEx("font/NHaasGroteskTXPro-55Rg.ttf", 40, cp, ncp); + UnloadCodepoints(cp); + free(codes); + + R.bg = RAYWHITE; + R.fg = BLACK; + R.hd = (Color){0xf0, 0x4a, 0x00, 0xff}; + + R.shader = LoadShader(0, "s.glsl"); + R.shader_u_time = GetShaderLocation(R.shader, "u_time"); + R.target = LoadRenderTexture(SCREEN_W, SCREEN_H); +} + void blur(int x, int y, Font f, Color c, char *s) { @@ -219,6 +252,18 @@ line(int x, int y, Font f, Color c, const char *s) } void +draw_time(int x, int y) +{ + struct timespec now = {0}; + clock_gettime(CLOCK_REALTIME, &now); + struct tm *ti = localtime(&now.tv_sec); + char ts[64] = {0}; + snprintf(ts, sizeof(ts), "%02d:%02d", ti->tm_hour, ti->tm_min); + Vector2 v2_ts = MeasureTextEx(R.font_h, ts, R.font_h.baseSize, 0); + line(x - v2_ts.x / 2, y, R.font_h, R.fg, ts); +} + +void draw_one_event(int x, int y, const struct event *e) { char s[64] = {0}; @@ -252,62 +297,18 @@ draw_events(int x, int y, size_t numevents, } } -void -ray_init(void) -{ - SetTraceLogLevel(LOG_WARNING); - InitWindow(SCREEN_W, SCREEN_H, "opplysning"); - SetTargetFPS(60); - - char *codes = calloc(128 + strlen(the_non_ascii), 1); - if (!codes) - err(1, "calloc"); - for (int i = 1; i < 128; ++i) - codes[i] = i; - memcpy(codes + 128, the_non_ascii, strlen(the_non_ascii)); - int ncp = 0; - int *cp = LoadCodepoints(codes + 1, &ncp); - R.font_h = LoadFontEx("font/adventpro-bold.ttf", 60, cp, ncp); - R.font_p = LoadFontEx("font/NHaasGroteskTXPro-55Rg.ttf", 40, cp, ncp); - UnloadCodepoints(cp); - free(codes); - - R.bg = RAYWHITE; - R.fg = BLACK; - R.hd = (Color){0xf0, 0x4a, 0x00, 0xff}; - - R.shader = LoadShader(0, "s.glsl"); - R.shader_u_time = GetShaderLocation(R.shader, "u_time"); - R.target = LoadRenderTexture(SCREEN_W, SCREEN_H); -} - int main(void) { - load_the_events(); ray_init(); - - int fx = 0; while (!WindowShouldClose()) { - struct timespec now = {0}; - clock_gettime(CLOCK_REALTIME, &now); - struct tm *ti = localtime(&now.tv_sec); - char ts[64] = {0}; - snprintf(ts, sizeof(ts), "%02d:%02d", ti->tm_hour, ti->tm_min); - - if (IsKeyPressed(KEY_F)) - fx = !fx; - + num_events = 0; + load_the_events(); BeginDrawing(); ClearBackground(R.bg); - Vector2 v2_ts = - MeasureTextEx(R.font_h, ts, R.font_h.baseSize, 0); - line(SCREEN_W / 2 - v2_ts.x / 2, 0, R.font_h, R.fg, ts); - - draw_events(0, 0, num_events, the_events); - + draw_time(SCREEN_W / 2, 0); + draw_events(SCREEN_W / 2, 0, num_events, the_events); EndDrawing(); } - CloseWindow(); } |
