diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-05-03 12:29:09 -0700 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-05-03 12:29:09 -0700 |
commit | 9a0f3d15dfaac41657bb549c7e246d2ac81fdf4c (patch) | |
tree | 662ca1cb433fd95822d5af0e27ba13388fbd6eac /web/web_svg.c | |
parent | d9add805c3b556d2fa357713bda577f4dc6f2d49 (diff) | |
download | dartboat-9a0f3d15dfaac41657bb549c7e246d2ac81fdf4c.tar.gz dartboat-9a0f3d15dfaac41657bb549c7e246d2ac81fdf4c.tar.xz |
web: use generic JS functions for manipulating DOM
Diffstat (limited to 'web/web_svg.c')
-rw-r--r-- | web/web_svg.c | 18 |
1 files changed, 12 insertions, 6 deletions
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); +} |