From 0284f5ac8509db302115d1c2d838d0c6b5725bea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Wed, 26 Dec 2018 15:30:47 +0100 Subject: [PATCH] decoration: configurable graphical effects, added to a particle --- CMakeLists.txt | 3 +++ decoration.h | 10 ++++++++++ decorations/background.c | 39 +++++++++++++++++++++++++++++++++++++++ decorations/background.h | 6 ++++++ 4 files changed, 58 insertions(+) create mode 100644 decoration.h create mode 100644 decorations/background.c create mode 100644 decorations/background.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 026b3cd..2c216bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,7 @@ pkg_check_modules(UDEV REQUIRED libudev) # Module/battery add_executable(f00bar bar.c bar.h config.c config.h + decoration.h font.c font.h log.c log.h main.c @@ -34,6 +35,8 @@ add_executable(f00bar xcb.c xcb.h yml.c yml.h + decorations/background.c decorations/background.h + particles/list.c particles/list.h particles/map.c particles/map.h particles/ramp.c particles/ramp.h diff --git a/decoration.h b/decoration.h new file mode 100644 index 0000000..b40602c --- /dev/null +++ b/decoration.h @@ -0,0 +1,10 @@ +#pragma once + +#include + +struct deco { + void *private; + void (*expose)(const struct deco *deco, cairo_t *cr, + int x, int y, int width, int height); + void (*destroy)(struct deco *deco); +}; diff --git a/decorations/background.c b/decorations/background.c new file mode 100644 index 0000000..b0a15a6 --- /dev/null +++ b/decorations/background.c @@ -0,0 +1,39 @@ +#include "background.h" + +#include + +struct private { + struct rgba color; +}; + +static void +destroy(struct deco *deco) +{ + struct private *d = deco->private; + free(d); + free(deco); +} + +static void +expose(const struct deco *deco, cairo_t *cr, int x, int y, int width, int height) +{ + const struct private *d = deco->private; + cairo_set_source_rgba( + cr, d->color.red, d->color.green, d->color.blue, d->color.alpha); + cairo_rectangle(cr, x, y, width, height); + cairo_fill(cr); +} + +struct deco * +deco_background(struct rgba color) +{ + struct private *priv = malloc(sizeof(*priv)); + priv->color = color; + + struct deco *deco = malloc(sizeof(*deco)); + deco->private = priv; + deco->expose = &expose; + deco->destroy = &destroy; + + return deco; +} diff --git a/decorations/background.h b/decorations/background.h new file mode 100644 index 0000000..b926e2f --- /dev/null +++ b/decorations/background.h @@ -0,0 +1,6 @@ +#pragma once + +#include "../color.h" +#include "../decoration.h" + +struct deco *deco_background(struct rgba color);