diff options
Diffstat (limited to 'src/util.c')
| -rw-r--r-- | src/util.c | 26 |
1 files changed, 24 insertions, 2 deletions
@@ -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) |
