diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-05-05 02:08:11 -0700 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-05-05 02:08:25 -0700 |
commit | 9ea94a3ac33559c956946a5c49aa2536b218e0fc (patch) | |
tree | 08cbe1fc490bc41eb7a700408586d9fcda21468b | |
parent | d5cc3a92f6fd8533b2e1b6240016a402c6fa20ff (diff) | |
download | dartboat-9ea94a3ac33559c956946a5c49aa2536b218e0fc.tar.gz dartboat-9ea94a3ac33559c956946a5c49aa2536b218e0fc.tar.xz |
web: clean up scoreboard and dom functions
-rw-r--r-- | web/static/style.css | 1 | ||||
-rw-r--r-- | web/web_dom.c | 44 | ||||
-rw-r--r-- | web/web_dom.h | 31 | ||||
-rw-r--r-- | web/web_opts.c | 4 | ||||
-rw-r--r-- | web/web_prompt.c | 40 | ||||
-rw-r--r-- | web/web_scoreboard.c | 124 | ||||
-rw-r--r-- | web/web_svg.c | 80 |
7 files changed, 164 insertions, 160 deletions
diff --git a/web/static/style.css b/web/static/style.css index 89f4267..51dac74 100644 --- a/web/static/style.css +++ b/web/static/style.css @@ -361,6 +361,7 @@ div#visits div { } div#visits .visit-col1 { grid-column: 2; } +div#visits .visit-col2 { grid-column: 3; } div#visits .visit-col3 { color: #666; grid-column: 4; } div#visits .p0 { color: #e00018; } div#visits .p20 { color: #e06000; } diff --git a/web/web_dom.c b/web/web_dom.c index 9e7684a..5ce7a3f 100644 --- a/web/web_dom.c +++ b/web/web_dom.c @@ -7,9 +7,9 @@ #include <emscripten/emscripten.h> -struct elem *elem_init(char *ns, char *name, int size_attrs) +struct dom_elem *dom_elem_init(char *ns, char *name, int size_attrs) { - struct elem *e = malloc(sizeof(*e)); + struct dom_elem *e = malloc(sizeof(*e)); e->ns = ns ? strdup(ns) : NULL; e->name = strdup(name); @@ -23,7 +23,7 @@ struct elem *elem_init(char *ns, char *name, int size_attrs) return e; } -void elem_free(struct elem *e) +void dom_elem_free(struct dom_elem *e) { for(int i = 0; i < e->n_attrs; ++i) { free(e->attr_names[i]); @@ -37,7 +37,7 @@ void elem_free(struct elem *e) free(e); } -void elem_add_attr(struct elem *e, char *name, char *val) +void dom_elem_add_attr(struct dom_elem *e, char *name, char *val) { if (e->n_attrs == e->size_attrs) { e->size_attrs *= 2; @@ -51,66 +51,66 @@ void elem_add_attr(struct elem *e, char *name, char *val) e->attr_vals[e->n_attrs++] = strdup(val); } -void elem_add_attr_double(struct elem *e, char *name, double val) +void dom_elem_add_attrd(struct dom_elem *e, char *name, double val) { char str[512]; sprintf(str, "%f", val); - elem_add_attr(e, name, str); + dom_elem_add_attr(e, name, str); } -void append_elemv(char *sel, int elemc, struct elem **elemv) +void dom_append_elemv(char *sel, int elemc, struct dom_elem **elemv) { EM_ASM({elemAppendElemv($0, $1, $2, $3, $4, $5, $6, $7, $8)}, sel, elemc, elemv, - offsetof(struct elem, ns), - offsetof(struct elem, name), - offsetof(struct elem, content), - offsetof(struct elem, n_attrs), - offsetof(struct elem, attr_names), - offsetof(struct elem, attr_vals)); + offsetof(struct dom_elem, ns), + offsetof(struct dom_elem, name), + offsetof(struct dom_elem, content), + offsetof(struct dom_elem, n_attrs), + offsetof(struct dom_elem, attr_names), + offsetof(struct dom_elem, attr_vals)); } -inline char *dom_elem_get_content(char *sel) +inline char *dom_get_content(char *sel) { return (char *)EM_ASM_INT({return elemGetContent($0)}, sel); } -inline void dom_elem_set_content(char *sel, char *str) +inline void dom_set_content(char *sel, char *str) { EM_ASM({elemSetContent($0, $1)}, sel, str); } -inline void dom_elem_set_value(char *sel, char *str) +inline void dom_set_value(char *sel, char *str) { EM_ASM({elemSetValue($0, $1)}, sel, str); } -inline bool dom_elem_has_class(char *sel, char *class) +inline bool dom_has_class(char *sel, char *class) { return EM_ASM_INT({return elemHasClass($0, $1)}, sel, class); } -inline void dom_elem_add_class(char *sel, char *class) +inline void dom_add_class(char *sel, char *class) { EM_ASM({elemAddClass($0, $1)}, sel, class); } -inline void dom_elem_remove_class(char *sel, char *class) +inline void dom_remove_class(char *sel, char *class) { EM_ASM({elemRemoveClass($0, $1)}, sel, class); } -inline void dom_elem_toggle_class(char *sel, char *class) +inline void dom_toggle_class(char *sel, char *class) { EM_ASM({elemToggleClass($0, $1)}, sel, class); } -inline void dom_elem_set_uniq_class(char *sel, char *class, char *sel_set) +inline void dom_set_uniq_class(char *sel, char *class, char *sel_set) { EM_ASM({elemSetUniqClass($0, $1, $2)}, sel, class, sel_set); } -inline void dom_elem_scroll_to_bottom(char *sel) +inline void dom_scroll_to_bottom(char *sel) { EM_ASM({elemScrollToBottom($0)}, sel); } diff --git a/web/web_dom.h b/web/web_dom.h index 12205c2..41ac46d 100644 --- a/web/web_dom.h +++ b/web/web_dom.h @@ -3,28 +3,29 @@ #include <stdbool.h> -struct elem { +struct dom_elem { char *ns, *name, *content; int n_attrs, size_attrs; char **attr_names, **attr_vals; }; -struct elem *elem_init(char *ns, char *name, int size_attrs); -void elem_free(struct elem *e); -void elem_add_attr(struct elem *e, char *name, char *val); -void elem_add_attr_double(struct elem *e, char *name, double val); -void append_elemv(char *sel, int elemc, struct elem **elemv); +struct dom_elem *dom_elem_init(char *ns, char *name, int size_attrs); +void dom_elem_free(struct dom_elem *e); +void dom_elem_add_attr(struct dom_elem *e, char *name, char *val); +void dom_elem_add_attrd(struct dom_elem *e, char *name, double val); -char *dom_elem_get_content(char *sel); -void dom_elem_set_content(char *sel, char *str); -void dom_elem_set_value(char *sel, char *str); +void dom_append_elemv(char *sel, int elemc, struct dom_elem **elemv); -bool dom_elem_has_class(char *sel, char *class); -void dom_elem_add_class(char *sel, char *class); -void dom_elem_remove_class(char *sel, char *class); -void dom_elem_toggle_class(char *sel, char *class); -void dom_elem_set_uniq_class(char *sel, char *class, char *sel_set); +char *dom_get_content(char *sel); +void dom_set_content(char *sel, char *str); +void dom_set_value(char *sel, char *str); -void dom_elem_scroll_to_bottom(char *sel); +bool dom_has_class(char *sel, char *class); +void dom_add_class(char *sel, char *class); +void dom_remove_class(char *sel, char *class); +void dom_toggle_class(char *sel, char *class); +void dom_set_uniq_class(char *sel, char *class, char *sel_set); + +void dom_scroll_to_bottom(char *sel); #endif diff --git a/web/web_opts.c b/web/web_opts.c index f255a83..553e05d 100644 --- a/web/web_opts.c +++ b/web/web_opts.c @@ -69,7 +69,7 @@ void opts_init() char buf[64]; sprintf(buf, "%d", delay_ms); - dom_elem_set_value("#delay", buf); + dom_set_value("#delay", buf); int len = sprintf(buf, "%4.2f", horizontal_stdev); char *dot = strchr(buf, '.'); @@ -80,7 +80,7 @@ void opts_init() *ptr = 0; } } - dom_elem_set_value("#stdev", buf); + dom_set_value("#stdev", buf); } void store_opt(char *opt, char *val) diff --git a/web/web_prompt.c b/web/web_prompt.c index 06aa089..0278817 100644 --- a/web/web_prompt.c +++ b/web/web_prompt.c @@ -22,7 +22,7 @@ enum prompt_mode pm; void oi() { - dom_elem_add_class("#oi", "visible"); + dom_add_class("#oi", "visible"); oi_timeout = EM_ASM_INT({return scheduleCCall($0, $1)}, "clear_oi", 3000); } @@ -32,7 +32,7 @@ void clear_oi() { if (!oi_timeout) return; - dom_elem_remove_class("#oi", "visible"); + dom_remove_class("#oi", "visible"); EM_ASM({clearTimeout($0)}, oi_timeout); oi_timeout = 0; } @@ -78,11 +78,11 @@ static inline void free_flushed_str(char *flushed, char *buffered) void prompt_flush() { if (buffered_str_changed(prompt_buffered.msgl, prompt_flushed.msgl)) - dom_elem_set_content("#prompt-msg-l", prompt_buffered.msgl); + dom_set_content("#prompt-msg-l", prompt_buffered.msgl); if (buffered_str_changed(prompt_buffered.msgr, prompt_flushed.msgr)) - dom_elem_set_content("#prompt-msg-r", prompt_buffered.msgr); + dom_set_content("#prompt-msg-r", prompt_buffered.msgr); if (buffered_str_changed(prompt_buffered.input, prompt_flushed.input)) - dom_elem_set_content("#prompt-input", prompt_buffered.input); + dom_set_content("#prompt-input", prompt_buffered.input); free_flushed_str(prompt_flushed.msgl, prompt_buffered.msgl); free_flushed_str(prompt_flushed.msgr, prompt_buffered.msgr); @@ -96,11 +96,11 @@ void set_prompt_mode(enum prompt_mode mode) pm = mode; if (pm != PM_DARTBOARD) - dom_elem_add_class("#prompt", "active"); + dom_add_class("#prompt", "active"); else - dom_elem_remove_class("#prompt", "active"); + dom_remove_class("#prompt", "active"); - dom_elem_set_uniq_class( + dom_set_uniq_class( pm == PM_DARTBOARD ? "#keypad-dartboard" : pm == PM_SELECT_MODE ? "#keypad-select_mode" : "#keypad-default", @@ -112,8 +112,8 @@ void prompt_visit() set_prompt_mode(PM_VISIT); prompt_set_msgl("Enter points:"); prompt_set_msgr(NULL); - dom_elem_set_content("#key-submit", "OK"); - dom_elem_set_content("#key-rem", "REMAINING"); + dom_set_content("#key-submit", "OK"); + dom_set_content("#key-rem", "REMAINING"); } void prompt_bot_visit() @@ -128,8 +128,8 @@ void prompt_num_darts() set_prompt_mode(PM_NUM_DARTS); prompt_set_msgl("Darts needed?"); prompt_set_msgr(NULL); - dom_elem_set_content("#key-submit", "OK"); - dom_elem_set_content("#key-rem", "REMAINING"); + dom_set_content("#key-submit", "OK"); + dom_set_content("#key-rem", "REMAINING"); } void prompt_end_match() @@ -140,16 +140,16 @@ void prompt_end_match() state->mode == M_PVC && state->legs[1]->rem <= 0 ? "Bot wins. :(" : "You win! :)"); prompt_set_msgr(NULL); - dom_elem_set_content("#key-submit", "END MATCH"); - dom_elem_set_content("#key-rem", "REMATCH"); + dom_set_content("#key-submit", "END MATCH"); + dom_set_content("#key-rem", "REMATCH"); } void prompt_select_mode() { - dom_elem_set_uniq_class(NULL, "visible", "[id$=-info-inner]"); + dom_set_uniq_class(NULL, "visible", "[id$=-info-inner]"); for (int pn = 1; pn < 3; ++pn) clear_player_info(pn); - dom_elem_set_content("#visits", NULL); + dom_set_content("#visits", NULL); set_prompt_mode(PM_SELECT_MODE); prompt_set_msgl("Select match mode:"); @@ -160,26 +160,26 @@ bool key_is_active(char *k) { char sel[64]; sprintf(sel, "#key-%s", k); - return dom_elem_has_class(sel, "active"); + return dom_has_class(sel, "active"); } void toggle_key(char *k) { char sel[64]; sprintf(sel, "#key-%s", k); - dom_elem_toggle_class(sel, "active"); + dom_toggle_class(sel, "active"); } void deactivate_key(char *k) { char sel[64]; sprintf(sel, "#key-%s", k); - dom_elem_remove_class(sel, "active"); + dom_remove_class(sel, "active"); } char *prompt_get() { - return dom_elem_get_content("#prompt-input"); + return dom_get_content("#prompt-input"); } void prompt_handle_pre(char *command) diff --git a/web/web_scoreboard.c b/web/web_scoreboard.c index 1d28cbf..f5afcc5 100644 --- a/web/web_scoreboard.c +++ b/web/web_scoreboard.c @@ -27,7 +27,7 @@ void scoreboard_set_player_active(int pn) else sprintf(sel, "#p%d-info", pn); - dom_elem_set_uniq_class(psel, "active", "[id$=-info]"); + dom_set_uniq_class(psel, "active", "[id$=-info]"); } static inline void buffer_str(char *str, char **buffer, char *flushed) @@ -83,25 +83,25 @@ void scoreboard_flush_player_info(int pn) if (buffered_str_changed(buffered_info[pn-1].name, flushed_info[pn-1].name)) { strcpy(sel + len, "name"); - dom_elem_set_content(sel, buffered_info[pn-1].name); + dom_set_content(sel, buffered_info[pn-1].name); } if (buffered_str_changed(buffered_info[pn-1].rem, flushed_info[pn-1].rem)) { strcpy(sel + len, "rem"); - dom_elem_set_content(sel, buffered_info[pn-1].rem); + dom_set_content(sel, buffered_info[pn-1].rem); } if (buffered_str_changed(buffered_info[pn-1].sugg, flushed_info[pn-1].sugg)) { strcpy(sel + len, "sugg"); - dom_elem_set_content(sel, buffered_info[pn-1].sugg); + dom_set_content(sel, buffered_info[pn-1].sugg); } if (buffered_str_changed(buffered_info[pn-1].avg, flushed_info[pn-1].avg)) { strcpy(sel + len, "avg"); - dom_elem_set_content(sel, buffered_info[pn-1].avg); + dom_set_content(sel, buffered_info[pn-1].avg); } free_flushed_str(flushed_info[pn-1].name, buffered_info[pn-1].name); @@ -172,7 +172,7 @@ void show_player_info(int pn) { char sel[64]; sprintf(sel, "#p%d-info-inner", pn); - dom_elem_add_class(sel, "visible"); + dom_add_class(sel, "visible"); } void clear_player_info(int pn) @@ -183,83 +183,85 @@ void clear_player_info(int pn) scoreboard_set_player_avg(pn, 0); } -struct elem *gen_div(char *str, char *class) +static struct dom_elem *create_div(char *str, char *class) { - struct elem *e = elem_init(NULL, "div", 1); + struct dom_elem *e = dom_elem_init(NULL, "div", 1); e->content = strdup(str); - elem_add_attr(e, "class", class); + dom_elem_add_attr(e, "class", class); return e; } -void add_colour_class(char *buf, int pts) +static const char *points_class(int pts) { - if (pts >= 180) - strcat(buf, " p180"); - else if (pts >= 140) - strcat(buf, " p140"); - else if (pts >= 100) - strcat(buf, " p100"); - else if (pts >= 60) - strcat(buf, " p60"); - else if (pts >= 40) - strcat(buf, " p40"); - else if (pts >= 20) - strcat(buf, " p20"); - else - strcat(buf, " p0"); + return (pts >= 180) ? "p180" : + (pts >= 140) ? "p140" : + (pts >= 100) ? "p100" : + (pts >= 60) ? "p60" : + (pts >= 40) ? "p40" : + (pts >= 20) ? "p20" : + "p0"; } void draw_visits() { - dom_elem_set_content("#visits", NULL); + dom_set_content("#visits", NULL); int n_visits = state->legs[0]->n_visits > state->legs[1]->n_visits ? state->legs[0]->n_visits : state->legs[1]->n_visits; - struct elem **elemv = malloc(6 * n_visits * sizeof(*elemv)); + struct dom_elem **elemv = malloc(6 * n_visits * sizeof(*elemv)); int elemc = 0; + char buf[32], buf2[32]; + snprintf(buf, sizeof(buf), "%d", state->legs[0]->start); + elemv[elemc++] = create_div(buf, "visit-col2"); + elemv[elemc++] = create_div("0", "visit-col3"); + if (state->mode != M_P) { + snprintf(buf, sizeof(buf), "%d", state->legs[1]->start); + elemv[elemc++] = create_div(buf, "visit-col4"); + } + for (int i = 0; i < n_visits; ++i) { - char buf[32], buf2[32]; struct visit *v = state->legs[0]->visits + i; - sprintf(buf, "%d", v->points); - strcpy(buf2, "visit-col1"); - add_colour_class(buf2, v->points); - elemv[elemc++] = gen_div(buf, buf2); - sprintf(buf, "%d", v->rem); - elemv[elemc++] = gen_div(buf, "visit-col2"); - - sprintf(buf, "%d", i + 1); - elemv[elemc++] = gen_div(buf, "visit-col3"); - - if (i < state->legs[1]->n_visits) { - v = state->legs[1]->visits + i; - sprintf(buf, "%d", v->rem); - elemv[elemc++] = gen_div(buf, "visit-col4"); - sprintf(buf, "%d", v->points); - strcpy(buf2, "visit-col5"); - add_colour_class(buf2, v->points); - elemv[elemc++] = gen_div(buf, buf2); - - strcpy(buf, "… "); - for (int j = 0; j < v->n_darts; ++j) { - char *n = segment_name(v->darts[j]); - sprintf(buf + strlen(buf), - j == 0 ? "%4s" : " %4s", n); // FIXME - free(n); - } - elemv[elemc++] = gen_div(buf, "visit-col6"); - } else { - elemv[elemc++] = gen_div("", "visit-col4"); - elemv[elemc++] = gen_div("", "visit-col5"); - elemv[elemc++] = gen_div("", "visit-col6"); + + snprintf(buf, sizeof(buf), "%d", v->points); + snprintf(buf2, sizeof(buf2), "%s %s", + "visit-col1", points_class(v->points)); + elemv[elemc++] = create_div(buf, buf2); + + snprintf(buf, sizeof(buf), "%d", v->rem); + elemv[elemc++] = create_div(buf, "visit-col2"); + + snprintf(buf, sizeof(buf), "%d", i + 1); + elemv[elemc++] = create_div(buf, "visit-col3"); + + if (i >= state->legs[1]->n_visits) + continue; + v = state->legs[1]->visits + i; + + snprintf(buf, sizeof(buf), "%d", v->rem); + elemv[elemc++] = create_div(buf, "visit-col4"); + + snprintf(buf, sizeof(buf), "%d", v->points); + snprintf(buf2, sizeof(buf2), "%s %s", + "visit-col5", points_class(v->points)); + elemv[elemc++] = create_div(buf, buf2); + + char *pbuf = stpcpy(buf, "…"); + for (int j = 0; j < v->n_darts; ++j) { + char *n = segment_name(v->darts[j]); + snprintf(pbuf + (j * 5), + sizeof(buf) - (pbuf + (j * 5) - buf), + " %4s", n); + free(n); } + elemv[elemc++] = create_div(buf, "visit-col6"); } - append_elemv("#visits", elemc, elemv); + dom_append_elemv("#visits", elemc, elemv); for (int i = 0; i < elemc; ++i) - elem_free(elemv[i]); + dom_elem_free(elemv[i]); free(elemv); - dom_elem_scroll_to_bottom("#visits"); + dom_scroll_to_bottom("#visits"); } 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); } |