summaryrefslogtreecommitdiff
path: root/web/web_svg.c
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2022-05-05 02:08:11 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2022-05-05 02:08:25 -0700
commit9ea94a3ac33559c956946a5c49aa2536b218e0fc (patch)
tree08cbe1fc490bc41eb7a700408586d9fcda21468b /web/web_svg.c
parentd5cc3a92f6fd8533b2e1b6240016a402c6fa20ff (diff)
downloaddartboat-9ea94a3ac33559c956946a5c49aa2536b218e0fc.tar.gz
dartboat-9ea94a3ac33559c956946a5c49aa2536b218e0fc.tar.xz
web: clean up scoreboard and dom functions
Diffstat (limited to 'web/web_svg.c')
-rw-r--r--web/web_svg.c80
1 files changed, 40 insertions, 40 deletions
diff --git a/web/web_svg.c b/web/web_svg.c
index ab712f8..0a6c00f 100644
--- a/web/web_svg.c
+++ b/web/web_svg.c
@@ -20,13 +20,13 @@
#define C_WIRE "#909ca0"
#define C_WIRE_INNER "#d8e6ec"
-static inline struct elem *svg_elem_init(char *name, int size_attrs)
+static inline struct dom_elem *svg_elem_init(char *name, int size_attrs)
{
- return elem_init("http://www.w3.org/2000/svg", name, size_attrs);
+ return dom_elem_init("http://www.w3.org/2000/svg", name, size_attrs);
}
// draws a ring if angles are equal
-struct elem *gen_arc(double a1, double a2, double r1, double r2, char *col)
+struct dom_elem *gen_arc(double a1, double a2, double r1, double r2, char *col)
{
struct ccoords cc1 = pol_to_cart(
(struct pcoords){ .a = (a1 == a2 ? 1 : a2), .r = r1 });
@@ -37,8 +37,8 @@ struct elem *gen_arc(double a1, double a2, double r1, double r2, char *col)
struct ccoords cc4 = pol_to_cart(
(struct pcoords){ .a = (a1 == a2 ? 1 : a2), .r = r2 });
- struct elem *e = svg_elem_init("path", 2);
- elem_add_attr(e, "fill", col);
+ struct dom_elem *e = svg_elem_init("path", 2);
+ dom_elem_add_attr(e, "fill", col);
char buf[512];
int buflen = 0;
@@ -56,47 +56,47 @@ struct elem *gen_arc(double a1, double a2, double r1, double r2, char *col)
r2, r2, cc3.x, cc3.y);
buf[buflen++] = 'Z';
buf[buflen++] = 0;
- elem_add_attr(e, "d", buf);
+ dom_elem_add_attr(e, "d", buf);
return e;
}
-struct elem *gen_segment(double a, double r1, double r2, char *col)
+struct dom_elem *gen_segment(double a, double r1, double r2, char *col)
{
return gen_arc(a - SECTOR_WIDTH/2, a + SECTOR_WIDTH/2, r1, r2, col);
}
-struct elem *gen_ring(double r, double w, char *col)
+struct dom_elem *gen_ring(double r, double w, char *col)
{
return gen_arc(0, 0, r - w/2, r + w/2, col);
}
-struct elem *gen_circle(double r, char *col)
+struct dom_elem *gen_circle(double r, char *col)
{
- struct elem *e = svg_elem_init("circle", 2);
- elem_add_attr(e, "fill", col);
- elem_add_attr_double(e, "r", r);
+ struct dom_elem *e = svg_elem_init("circle", 2);
+ dom_elem_add_attr(e, "fill", col);
+ dom_elem_add_attrd(e, "r", r);
return e;
}
-struct elem *gen_line(double a, double r1, double r2, double w, char *col)
+struct dom_elem *gen_line(double a, double r1, double r2, double w, char *col)
{
struct ccoords cc1 = pol_to_cart((struct pcoords){ .a = a, .r = r1 });
struct ccoords cc2 = pol_to_cart((struct pcoords){ .a = a, .r = r2 });
- struct elem *e = svg_elem_init("line", 6);
- elem_add_attr(e, "stroke", col);
- elem_add_attr_double(e, "x1", cc1.x);
- elem_add_attr_double(e, "y1", cc1.y);
- elem_add_attr_double(e, "x2", cc2.x);
- elem_add_attr_double(e, "y2", cc2.y);
- elem_add_attr_double(e, "stroke-width", w);
+ struct dom_elem *e = svg_elem_init("line", 6);
+ dom_elem_add_attr(e, "stroke", col);
+ dom_elem_add_attrd(e, "x1", cc1.x);
+ dom_elem_add_attrd(e, "y1", cc1.y);
+ dom_elem_add_attrd(e, "x2", cc2.x);
+ dom_elem_add_attrd(e, "y2", cc2.y);
+ dom_elem_add_attrd(e, "stroke-width", w);
return e;
}
-int draw_spider(int elemc, struct elem **elemv)
+int draw_spider(int elemc, struct dom_elem **elemv)
{
for (int i = 5; i > 1; --i) {
elemv[elemc++] = gen_ring(OUTER_DISTS[i], WIRE_WIDTH, C_WIRE);
@@ -123,18 +123,18 @@ int draw_spider(int elemc, struct elem **elemv)
return elemc;
}
-int draw_numbers(int elemc, struct elem **elemv)
+int draw_numbers(int elemc, struct dom_elem **elemv)
{
elemv[elemc++] = gen_ring(DIAMETER/2 - WIRE_WIDTH*4, WIRE_WIDTH,
"#ddd");
int r = DIAMETER/2 - 33/2;
for (int i = 0; i < 20; ++i) {
- struct elem *e = elemv[elemc++] = svg_elem_init("text", 5);
- elem_add_attr(e, "font-size", "33");
- elem_add_attr(e, "fill", "#fff");
- elem_add_attr(e, "text-anchor", "middle");
- elem_add_attr(e, "dominant-baseline", "central");
+ struct dom_elem *e = elemv[elemc++] = svg_elem_init("text", 5);
+ dom_elem_add_attr(e, "font-size", "33");
+ dom_elem_add_attr(e, "fill", "#fff");
+ dom_elem_add_attr(e, "text-anchor", "middle");
+ dom_elem_add_attr(e, "dominant-baseline", "central");
char buf[512];
double a = 90 - i*SECTOR_WIDTH;
@@ -143,7 +143,7 @@ int draw_numbers(int elemc, struct elem **elemv)
(struct pcoords){ .a = a, .r = r });
sprintf(buf, "scale(1 -1) translate(%f %f) rotate(%f)",
cc.x, -cc.y, a <= 180 ? 90 -a : 270 -a);
- elem_add_attr(e, "transform", buf);
+ dom_elem_add_attr(e, "transform", buf);
e->content = malloc(3);
sprintf(e->content, "%d", SECTORS[i]);
@@ -154,7 +154,7 @@ int draw_numbers(int elemc, struct elem **elemv)
void svg_draw_board()
{
- struct elem **elemv = malloc(200 * sizeof(*elemv));
+ struct dom_elem **elemv = malloc(200 * sizeof(*elemv));
int elemc = 0;
elemv[elemc++] = gen_circle(DIAMETER/2, C_BLACK);
@@ -176,26 +176,26 @@ void svg_draw_board()
elemc = draw_spider(elemc, elemv);
elemc = draw_numbers(elemc, elemv);
- append_elemv("#dartboard .base", elemc, elemv);
+ dom_append_elemv("#dartboard .base", elemc, elemv);
for (int i = 0; i < elemc; ++i)
- elem_free(elemv[i]);
+ dom_elem_free(elemv[i]);
free(elemv);
}
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);
-
- append_elemv("#dartboard .overlay", 1, &e);
- elem_free(e);
+ struct dom_elem *e = gen_circle(8, "#33f");
+ dom_elem_add_attr(e, "stroke", "#ff0");
+ dom_elem_add_attr(e, "stroke-width", "2");
+ dom_elem_add_attrd(e, "cx", x);
+ dom_elem_add_attrd(e, "cy", y);
+
+ dom_append_elemv("#dartboard .overlay", 1, &e);
+ dom_elem_free(e);
}
void svg_clear_points()
{
- dom_elem_set_content("#dartboard .overlay", NULL);
+ dom_set_content("#dartboard .overlay", NULL);
}