From f3e1ec505dab2d68f7d5ce542f1693d00d7f0537 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Fri, 22 Dec 2017 19:11:06 +0100 Subject: Updating doc of group, correcting chained list behaviour, completing implementation of group_init, implementing group_print and group_click_handler to delegate on components --- src/gui/group.c | 65 +++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 45 insertions(+), 20 deletions(-) (limited to 'src/gui') diff --git a/src/gui/group.c b/src/gui/group.c index cb50b1c..d287205 100644 --- a/src/gui/group.c +++ b/src/gui/group.c @@ -2,38 +2,56 @@ #include #include #include +#include #include "MLV/MLV_shape.h" #include "MLV/MLV_window.h" -void group_print(void *parameter) { - Group *group = (Group *) parameter; - /*DEBUG*/ - MLV_draw_filled_rectangle(group->component.x_pos, group->component.y_pos, group->component.width, - group->component.height, MLV_COLOR_AQUAMARINE); - /**/ - MLV_actualise_window(); +void group_print(Component *parameterSelf) { + assert(parameterSelf != NULL); + Group *self = (Group *) parameterSelf; + if (self->group_head != NULL) { + GroupElement *p = self->group_head; + while (p != NULL) { + p->sub_component->print_method(p->sub_component); + p = p->next; + } + } +} + +void group_click_handler(int x_pos, int y_pos, Component *parameterSelf) { + assert(parameterSelf != NULL); + Group *self = (Group *) parameterSelf; + if (self->group_head != NULL) { + GroupElement *p = self->group_head; + while (p != NULL) { + p->sub_component->click_handler(x_pos, y_pos, p->sub_component); + p = p->next; + } + } } -void group_init(Group *group, int width, int height, int x_pos, int y_pos, int padding) { +void group_init(Group *group, int width, int height, int x_pos, int y_pos, int margin) { assert(group != NULL); assert(width > 0); assert(height > 0); assert(x_pos >= 0); assert(y_pos >= 0); - assert(padding >= 0); + assert(margin >= 0); group->component.width = width; group->component.height = height; group->component.x_pos = x_pos; group->component.y_pos = y_pos; group->component.print_method = group_print; - group->padding = padding; + group->component.click_handler = group_click_handler; + group->margin = margin; } void group_free(Group *group) { + assert(group != NULL); if (group->group_head != NULL) { GroupElement *p = group->group_head; - while (p->next != NULL) { - GroupElement *tmp = group->group_head; + while (p != NULL) { + GroupElement *tmp = p; p = p->next; free(tmp); } @@ -42,20 +60,27 @@ void group_free(Group *group) { } void group_add_component(Group *group, Component *component) { + assert(group != NULL); + assert(component != NULL); + /*Initialize the new node*/ + GroupElement *tmp = malloc_or_die(sizeof(GroupElement)); + tmp->sub_component = component; + tmp->next = NULL; if (group->group_head != NULL) { - /*Initialize the new node*/ - GroupElement *tmp = malloc_or_die(sizeof(GroupElement)); - tmp->sub_component = component; - tmp->next = NULL; GroupElement *p = group->group_head; /*Browsing*/ while (p->next != NULL) { p = p->next; } p->next = tmp; + /*Modifying for margin*/ + tmp->sub_component->y_pos = p->sub_component->y_pos; + tmp->sub_component->x_pos = p->sub_component->x_pos + p->sub_component->width + group->margin; } else { - group->group_head = malloc_or_die(sizeof(GroupElement)); - group->group_head->sub_component = component; - group->group_head->next = NULL; + tmp->sub_component->y_pos = group->component.y_pos; + tmp->sub_component->x_pos = group->component.x_pos; + group->group_head = tmp; + } -} \ No newline at end of file +} + -- cgit v1.2.3