From 5d46228ed837a4dcacf775c275291f4d0883dd7c Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sun, 27 Mar 2022 23:02:48 +0200 Subject: [PATCH] Symbols: Cloning, so far only for sym_line --- sym-line.c | 9 +++++++++ sym.c | 10 ++++++++-- sym.h | 4 +++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/sym-line.c b/sym-line.c index 74d6d56..e4dfdbc 100644 --- a/sym-line.c +++ b/sym-line.c @@ -215,11 +215,20 @@ static bool sym_line_same_p(struct symbol *xx, struct symbol *yy) return 1; } +static struct symbol *sym_line_clone(struct symbol *src) +{ + struct sym_line *s = (struct sym_line *) src; + struct sym_line *d = sym_line_new(s->s.o); + memcpy((byte *)d + sizeof(struct symbol), (byte *)s + sizeof(struct symbol), sizeof(struct sym_line) - sizeof(struct symbol)); + return &d->s; +} + struct symbolizer symbolizer_line = { .name = "line", .draw = sym_line_draw, .gen = sym_line_gen, .same_p = sym_line_same_p, + .clone = sym_line_clone, }; struct sym_line *sym_line_new(struct osm_object *o) diff --git a/sym.c b/sym.c index 67a718d..8d64d2a 100644 --- a/sym.c +++ b/sym.c @@ -153,10 +153,10 @@ void sym_draw_all(struct svg *svg) sym_draw(sym_planned[i].sym, sym_planned[i].zindex, svg); } -void sym_for_all_planned(void (*callback)(struct symbol *s)) +void sym_for_all_planned(void (*callback)(struct symbol *s, z_index_t zindex)) { for (uns i = 0; i < GARY_SIZE(sym_planned); i++) - callback(sym_planned[i].sym); + callback(sym_planned[i].sym, sym_planned[i].zindex); } bool sym_same_attrs_p(struct symbol *x, struct symbol *y) @@ -174,3 +174,9 @@ void sym_disable(struct symbol *sym) { sym->type = SYMBOLIZER_DISABLED; } + +struct symbol *sym_clone(struct symbol *s) +{ + ASSERT(symbolizers[s->type]->clone); + return symbolizers[s->type]->clone(s); +} diff --git a/sym.h b/sym.h index f5d7524..23be8d2 100644 --- a/sym.h +++ b/sym.h @@ -35,6 +35,7 @@ struct symbolizer { void (*gen)(struct osm_object *o, struct style_info *si, struct svg *svg); void (*init)(void); bool (*same_p)(struct symbol *x, struct symbol *y); + struct symbol *(*clone)(struct symbol *src); }; extern struct mempool *sym_mp; @@ -57,11 +58,12 @@ void sym_init(void); void *sym_new(enum symbolizer_type type, struct osm_object *o, size_t size); void sym_plan(struct symbol *sym, z_index_t zindex); void sym_draw_all(struct svg *svg); -void sym_for_all_planned(void (*callback)(struct symbol *s)); +void sym_for_all_planned(void (*callback)(struct symbol *s, z_index_t zindex)); void sym_from_style(struct osm_object *o, struct style_results *sr, struct svg *svg); z_index_t sym_zindex(struct osm_object *o, struct style_info *si, double default_mzi); bool sym_same_attrs_p(struct symbol *x, struct symbol *y); void sym_disable(struct symbol *s); +struct symbol *sym_clone(struct symbol *s); /* sym-point.c handles point symbols and icons */ -- 2.39.2