From 32aa49a2299ea2bf95b72631dfafac7090c3c6e9 Mon Sep 17 00:00:00 2001 From: Federico Angelilli Date: Thu, 11 Jul 2024 23:09:27 +0200 Subject: Print color --- src/util.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'src/util.c') diff --git a/src/util.c b/src/util.c index b658769..303942e 100644 --- a/src/util.c +++ b/src/util.c @@ -5,6 +5,28 @@ #include "util.h" +char *color_to_string(color_t *color) +{ + unsigned int r = color->r * 255, + g = color->g * 255, + b = color->b * 255, + a = color->a * 255; + + char buffer[32]; + int n = snprintf(buffer, 32, "#%02x%02x%02x%02x", r, g, b, a); + return strslice(buffer, 0, n); +} + +void color_print(FILE *stream, color_t *color) +{ + unsigned int r = color->r * 255, + g = color->g * 255, + b = color->b * 255, + a = color->a * 255; + + fprintf(stream, "#%02x%02x%02x%02x", r, g, b, a); +} + struct timespec timespec_diff(struct timespec a, struct timespec b) { bool over = (b.tv_nsec - a.tv_nsec) < 0; @@ -21,9 +43,9 @@ bool timespec_greater(struct timespec a, struct timespec b) || (a.tv_sec == b.tv_sec && a.tv_nsec > b.tv_nsec); } -void timespec_print(struct timespec *ts) +void timespec_print(FILE *stream, struct timespec *ts) { - printf("%ld.%.9ld", ts->tv_sec, ts->tv_nsec); + fprintf(stream, "%ld.%.9ld", ts->tv_sec, ts->tv_nsec); } bool check_rect(int px, int py, int x, int y, int w, int h) -- cgit v1.2.3