From 92feb3c130966202c7caa6d9bf3a3800c97ca7a1 Mon Sep 17 00:00:00 2001 From: Federico Angelilli Date: Tue, 14 May 2024 12:04:22 +0200 Subject: Start working on mirroring --- src/button.c | 23 +++++++++++++++++++++++ src/button.h | 3 +++ src/comet.c | 9 ++++++--- src/state.h | 2 -- 4 files changed, 32 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/button.c b/src/button.c index aac4ec0..b11f5b1 100644 --- a/src/button.c +++ b/src/button.c @@ -86,6 +86,29 @@ void button_set_width(Button *btn, int max, int min) btn->min_width = min; } +Button *button_copy(Button *btn) +{ + if (btn->simple) { + ButtonSimple *copy = g_malloc0(sizeof(ButtonSimple)); + memcpy(copy, CAST(btn, ButtonSimple), sizeof(ButtonSimple)); + copy->text = g_strdup(CAST(btn, ButtonSimple)->text); + copy->btn.anim = NULL; + // NOTE: What to do with data? + return CAST(copy, Button); + } else { + ButtonGroup *copy = g_malloc0(sizeof(ButtonGroup)); + memcpy(copy, CAST(btn, ButtonGroup), sizeof(ButtonGroup)); + copy->btn.anim = NULL; + copy->children = NULL; + + for (GList *it = CAST(btn, ButtonGroup)->children; it != NULL; it = it->next) { + copy->children = g_list_prepend(copy->children, button_copy(it->data)); + } + copy->children = g_list_reverse(copy->children); + return CAST(copy, Button); + } +} + void button_destroy(Button *btn) { animation_destroy(btn->anim); diff --git a/src/button.h b/src/button.h index a87d3e8..4b6c834 100644 --- a/src/button.h +++ b/src/button.h @@ -25,6 +25,7 @@ struct Button { int line_width; int max_width; int min_width; + // TODO: Make animations not depend on the button Animation *anim; }; @@ -67,6 +68,8 @@ void button_set_line(Button *btn, Color line_color, int line_width); void button_set_width(Button *btn, int max, int min); +Button *button_copy(Button *btn); + void button_destroy(Button *btn); #endif diff --git a/src/comet.c b/src/comet.c index 86023fc..b97f8bd 100644 --- a/src/comet.c +++ b/src/comet.c @@ -303,7 +303,8 @@ int main(int argc, char **argv) State *state = state_create("$1", win, draw); Window *win2 = window_create(con); - int y_padding2 = EVEN(round(screen_height * 0.204)); + int x_padding2 = EVEN(round(screen_width * 0.025)); + int y_padding2 = screen_height - height - EVEN(round(screen_height * 0.005)); PangoContext *context2 = pango_cairo_create_context(window_get_context(win2)); @@ -312,7 +313,7 @@ int main(int argc, char **argv) draw_set_separator(draw2, 10); draw_set_font(draw2, "Hack 13 Bold"); draw_set_context(draw2, context); - draw_set_size(draw2, height, x_padding, x_padding, y_padding2); + draw_set_size(draw2, height, x_padding2, x_padding2 * 3, y_padding2); State *state2 = state_create("$2", win2, draw2); @@ -409,7 +410,9 @@ int main(int argc, char **argv) state_order_button(state2); // TODO: Mirroring - //state2->btns = state->btns; + //for (GList *it = state->btns; it != NULL; it = it->next) { + // state_add_button(state2, button_copy(it->data)); + //} connect_add_state(con, state); connect_add_state(con, state2); diff --git a/src/state.h b/src/state.h index 32d3ada..6ea331f 100644 --- a/src/state.h +++ b/src/state.h @@ -21,8 +21,6 @@ struct State { State *state_create(const char *label, Window *win, Drawer *draw); -State *state_create_copy(const char *label, State *target); - void state_add_button(State *state, Button *btn); void state_remove_button(State *state, Button *btn); -- cgit v1.2.3