aboutsummaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c
index b077484..2900a2f 100644
--- a/src/util.c
+++ b/src/util.c
@@ -29,6 +29,33 @@ void color_print(FILE *stream, color_t *color)
fprintf(stream, "#%02x%02x%02x%02x", r, g, b, a);
}
+char *gradient_to_string(gradient_t *gradient)
+{
+ char buffer[256];
+ const size_t max = sizeof(buffer);
+
+ int start = 0;
+ for (size_t i = 0; i < gradient->length; i++) {
+ unsigned int r = gradient->colors[i].r * 255,
+ g = gradient->colors[i].g * 255,
+ b = gradient->colors[i].b * 255,
+ a = gradient->colors[i].a * 255;
+
+ start += snprintf(buffer + start, max - start, "#%02x%02x%02x%02x", r, g, b, a);
+ if (i != gradient->length - 1)
+ start += snprintf(buffer + start, max - start, ", ");
+ }
+
+ return strslice(buffer, 0, start);
+}
+
+void gradient_free(gradient_t *gradient)
+{
+ free(gradient->colors);
+ if (gradient->cached != NULL)
+ cairo_pattern_destroy(gradient->cached);
+}
+
const struct timespec timespec_from_ms(long ms)
{
struct timespec ts = {