exposable: add a "common" constructor and default destructor

This commit is contained in:
Daniel Eklöf 2018-12-29 12:51:31 +01:00
parent acda1a4b21
commit e8d8bf70d3
6 changed files with 59 additions and 33 deletions

View file

@ -14,6 +14,20 @@ struct exposable_private {
int left_spacing, right_spacing;
};
static void
exposable_destroy(struct exposable *exposable)
{
struct exposable_private *e = exposable->private;
for (size_t i = 0; i < e->count; i++)
e->exposables[i]->destroy(e->exposables[i]);
free(e->exposables);
free(e->widths);
free(e);
exposable_default_destroy(exposable);
}
static int
begin_expose(struct exposable *exposable, cairo_t *cr)
{
@ -55,16 +69,8 @@ expose(const struct exposable *exposable, cairo_t *cr, int x, int y, int height)
}
static void
exposable_destroy(struct exposable *exposable)
{
struct exposable_private *e = exposable->private;
for (size_t i = 0; i < e->count; i++)
e->exposables[i]->destroy(e->exposables[i]);
free(e->exposables);
free(e->widths);
free(e);
free(exposable);
}
static struct exposable *
@ -84,9 +90,8 @@ instantiate(const struct particle *particle, const struct tag_set *tags)
e->exposables[i] = pp->instantiate(pp, tags);
}
struct exposable *exposable = malloc(sizeof(*exposable));
struct exposable *exposable = exposable_common_new(particle, NULL);
exposable->private = e;
exposable->particle = particle;
exposable->destroy = &exposable_destroy;
exposable->begin_expose = &begin_expose;
exposable->expose = &expose;