diff options
author | Adam NAILI | 2017-12-22 19:11:06 +0100 |
---|---|---|
committer | Adam NAILI | 2017-12-22 19:11:06 +0100 |
commit | f3e1ec505dab2d68f7d5ce542f1693d00d7f0537 (patch) | |
tree | b36fb250f311cbbf295a962d75a6ea4d226c763f /src/gui | |
parent | 1a4d7b44eaefd7831860b2ffdf178b00af3e1c7e (diff) | |
download | morpher-f3e1ec505dab2d68f7d5ce542f1693d00d7f0537.tar.gz |
Updating doc of group, correcting chained list behaviour, completing implementation of group_init, implementing group_print and group_click_handler to delegate on components
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/group.c | 65 |
1 files changed, 45 insertions, 20 deletions
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 @@ | |||
2 | #include <gui/group.h> | 2 | #include <gui/group.h> |
3 | #include <common/mem.h> | 3 | #include <common/mem.h> |
4 | #include <assert.h> | 4 | #include <assert.h> |
5 | #include <gui/component.h> | ||
5 | #include "MLV/MLV_shape.h" | 6 | #include "MLV/MLV_shape.h" |
6 | #include "MLV/MLV_window.h" | 7 | #include "MLV/MLV_window.h" |
7 | 8 | ||
8 | void group_print(void *parameter) { | 9 | void group_print(Component *parameterSelf) { |
9 | Group *group = (Group *) parameter; | 10 | assert(parameterSelf != NULL); |
10 | /*DEBUG*/ | 11 | Group *self = (Group *) parameterSelf; |
11 | MLV_draw_filled_rectangle(group->component.x_pos, group->component.y_pos, group->component.width, | 12 | if (self->group_head != NULL) { |
12 | group->component.height, MLV_COLOR_AQUAMARINE); | 13 | GroupElement *p = self->group_head; |
13 | /**/ | 14 | while (p != NULL) { |
14 | MLV_actualise_window(); | 15 | p->sub_component->print_method(p->sub_component); |
16 | p = p->next; | ||
17 | } | ||
18 | } | ||
19 | } | ||
20 | |||
21 | void group_click_handler(int x_pos, int y_pos, Component *parameterSelf) { | ||
22 | assert(parameterSelf != NULL); | ||
23 | Group *self = (Group *) parameterSelf; | ||
24 | if (self->group_head != NULL) { | ||
25 | GroupElement *p = self->group_head; | ||
26 | while (p != NULL) { | ||
27 | p->sub_component->click_handler(x_pos, y_pos, p->sub_component); | ||
28 | p = p->next; | ||
29 | } | ||
30 | } | ||
15 | } | 31 | } |
16 | 32 | ||
17 | void group_init(Group *group, int width, int height, int x_pos, int y_pos, int padding) { | 33 | void group_init(Group *group, int width, int height, int x_pos, int y_pos, int margin) { |
18 | assert(group != NULL); | 34 | assert(group != NULL); |
19 | assert(width > 0); | 35 | assert(width > 0); |
20 | assert(height > 0); | 36 | assert(height > 0); |
21 | assert(x_pos >= 0); | 37 | assert(x_pos >= 0); |
22 | assert(y_pos >= 0); | 38 | assert(y_pos >= 0); |
23 | assert(padding >= 0); | 39 | assert(margin >= 0); |
24 | group->component.width = width; | 40 | group->component.width = width; |
25 | group->component.height = height; | 41 | group->component.height = height; |
26 | group->component.x_pos = x_pos; | 42 | group->component.x_pos = x_pos; |
27 | group->component.y_pos = y_pos; | 43 | group->component.y_pos = y_pos; |
28 | group->component.print_method = group_print; | 44 | group->component.print_method = group_print; |
29 | group->padding = padding; | 45 | group->component.click_handler = group_click_handler; |
46 | group->margin = margin; | ||
30 | } | 47 | } |
31 | 48 | ||
32 | void group_free(Group *group) { | 49 | void group_free(Group *group) { |
50 | assert(group != NULL); | ||
33 | if (group->group_head != NULL) { | 51 | if (group->group_head != NULL) { |
34 | GroupElement *p = group->group_head; | 52 | GroupElement *p = group->group_head; |
35 | while (p->next != NULL) { | 53 | while (p != NULL) { |
36 | GroupElement *tmp = group->group_head; | 54 | GroupElement *tmp = p; |
37 | p = p->next; | 55 | p = p->next; |
38 | free(tmp); | 56 | free(tmp); |
39 | } | 57 | } |
@@ -42,20 +60,27 @@ void group_free(Group *group) { | |||
42 | } | 60 | } |
43 | 61 | ||
44 | void group_add_component(Group *group, Component *component) { | 62 | void group_add_component(Group *group, Component *component) { |
63 | assert(group != NULL); | ||
64 | assert(component != NULL); | ||
65 | /*Initialize the new node*/ | ||
66 | GroupElement *tmp = malloc_or_die(sizeof(GroupElement)); | ||
67 | tmp->sub_component = component; | ||
68 | tmp->next = NULL; | ||
45 | if (group->group_head != NULL) { | 69 | if (group->group_head != NULL) { |
46 | /*Initialize the new node*/ | ||
47 | GroupElement *tmp = malloc_or_die(sizeof(GroupElement)); | ||
48 | tmp->sub_component = component; | ||
49 | tmp->next = NULL; | ||
50 | GroupElement *p = group->group_head; | 70 | GroupElement *p = group->group_head; |
51 | /*Browsing*/ | 71 | /*Browsing*/ |
52 | while (p->next != NULL) { | 72 | while (p->next != NULL) { |
53 | p = p->next; | 73 | p = p->next; |
54 | } | 74 | } |
55 | p->next = tmp; | 75 | p->next = tmp; |
76 | /*Modifying for margin*/ | ||
77 | tmp->sub_component->y_pos = p->sub_component->y_pos; | ||
78 | tmp->sub_component->x_pos = p->sub_component->x_pos + p->sub_component->width + group->margin; | ||
56 | } else { | 79 | } else { |
57 | group->group_head = malloc_or_die(sizeof(GroupElement)); | 80 | tmp->sub_component->y_pos = group->component.y_pos; |
58 | group->group_head->sub_component = component; | 81 | tmp->sub_component->x_pos = group->component.x_pos; |
59 | group->group_head->next = NULL; | 82 | group->group_head = tmp; |
83 | |||
60 | } | 84 | } |
61 | } \ No newline at end of file | 85 | } |
86 | |||