]> mj.ucw.cz Git - leo.git/commitdiff
Symbols: Cloning, so far only for sym_line
authorMartin Mares <mj@ucw.cz>
Sun, 27 Mar 2022 21:02:48 +0000 (23:02 +0200)
committerMartin Mares <mj@ucw.cz>
Sun, 27 Mar 2022 21:02:48 +0000 (23:02 +0200)
sym-line.c
sym.c
sym.h

index 74d6d56df8678ec4faac11dab9c2e5d7df7ea551..e4dfdbca6f95bd58957b3844c564f248d898ef7c 100644 (file)
@@ -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 67a718d9ea7b8bac5a56bd798d376d8a5a3d7ebb..8d64d2a161144a6e5407e2c044b91e09827c4e27 100644 (file)
--- 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 f5d75241ea6d6000b1ba12b6abb5a2d1859eaefc..23be8d225f83b502ba662726d2585ee3422bddac 100644 (file)
--- 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 */