]> mj.ucw.cz Git - leo.git/blobdiff - sym.c
Symbols: Comparison, disabling, and iterating
[leo.git] / sym.c
diff --git a/sym.c b/sym.c
index 8f28f078aaae5ab039b8cc166925827deac94d41..67a718d9ea7b8bac5a56bd798d376d8a5a3d7ebb 100644 (file)
--- a/sym.c
+++ b/sym.c
 #undef CLAMP           // FIXME: Fix in libucw?
 #define CLAMP(x,min,max) ({ typeof(x) _t=x; (_t < min) ? min : (_t > max) ? max : _t; })       /** Clip a number @x to interval [@min,@max] **/
 
+static struct symbolizer symbolizer_disabled = {
+  .name = "disabled",
+};
+
 static struct symbolizer *symbolizers[] = {
   [SYMBOLIZER_INVALID] = NULL,
   [SYMBOLIZER_POINT] = &symbolizer_point,
@@ -27,6 +31,7 @@ static struct symbolizer *symbolizers[] = {
   [SYMBOLIZER_AREA] = &symbolizer_area,
   [SYMBOLIZER_TEXT] = &symbolizer_text,
   [SYMBOLIZER_LINEIMG] = &symbolizer_lineimg,
+  [SYMBOLIZER_DISABLED] = &symbolizer_disabled,
 };
 
 struct mempool *sym_mp;
@@ -131,7 +136,8 @@ static void sym_draw(struct symbol *sym, z_index_t zindex, struct svg *svg)
   ASSERT(sym->type && sym->type < SYMBOLIZER_MAX);
   if (debug_dump_symbols)
     printf("Drawing symbol <%s> at z-index %u for %s\n", symbolizers[sym->type]->name, zindex, STK_OSM_NAME(sym->o));
-  symbolizers[sym->type]->draw(sym, svg);
+  if (symbolizers[sym->type]->draw)
+    symbolizers[sym->type]->draw(sym, svg);
 }
 
 void sym_draw_all(struct svg *svg)
@@ -146,3 +152,25 @@ void sym_draw_all(struct svg *svg)
   for (uns i = 0; i < GARY_SIZE(sym_planned); i++)
     sym_draw(sym_planned[i].sym, sym_planned[i].zindex, svg);
 }
+
+void sym_for_all_planned(void (*callback)(struct symbol *s))
+{
+  for (uns i = 0; i < GARY_SIZE(sym_planned); i++)
+    callback(sym_planned[i].sym);
+}
+
+bool sym_same_attrs_p(struct symbol *x, struct symbol *y)
+{
+  if (x->type != y->type)
+    return 0;
+
+  if (!symbolizers[x->type]->same_p)
+    return 0;
+
+  return (*symbolizers[x->type]->same_p)(x, y);
+}
+
+void sym_disable(struct symbol *sym)
+{
+  sym->type = SYMBOLIZER_DISABLED;
+}