From 9a0f3d15dfaac41657bb549c7e246d2ac81fdf4c Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Tue, 3 May 2022 12:29:09 -0700 Subject: web: use generic JS functions for manipulating DOM --- web/web_svg.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'web/web_svg.c') diff --git a/web/web_svg.c b/web/web_svg.c index 9b8f25d..6524754 100644 --- a/web/web_svg.c +++ b/web/web_svg.c @@ -206,10 +206,10 @@ int draw_numbers(int elemc, struct elem **elemv) return elemc; } -void draw_elemv(int layer, int elemc, struct elem **elemv) +void append_elemv(char *sel, int elemc, struct elem **elemv) { - EM_ASM({svgDrawElemv($0, $1, $2, $3, $4, $5, $6, $7)}, - layer, elemc, elemv, + EM_ASM({svgAppendElemv($0, $1, $2, $3, $4, $5, $6, $7)}, + sel, elemc, elemv, offsetof(struct elem, name), offsetof(struct elem, n_attrs), offsetof(struct elem, attr_names), offsetof(struct elem, attr_vals), offsetof(struct elem, content)); @@ -237,20 +237,26 @@ void svg_draw_board() elemc = draw_spider(elemc, elemv); elemc = draw_numbers(elemc, elemv); - draw_elemv(0, elemc, elemv); + append_elemv("#dartboard .base", elemc, elemv); for (int i = 0; i < elemc; ++i) free(elemv[i]); free(elemv); } -void svg_draw_point(double x, double y) { +void svg_draw_point(double x, double y) +{ struct elem *e = gen_circle(8, "#33f"); elem_add_attr(e, "stroke", "#ff0"); elem_add_attr(e, "stroke-width", "2"); elem_add_attr_double(e, "cx", x); elem_add_attr_double(e, "cy", y); - draw_elemv(1, 1, &e); + append_elemv("#dartboard .overlay", 1, &e); elem_free(e); } + +void svg_clear_points() +{ + EM_ASM({elemSetContent($0, $1)}, "#dartboard .overlay", NULL); +} -- cgit v1.2.3-70-g09d2