summaryrefslogtreecommitdiff
path: root/src/gui/group.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/group.c')
-rw-r--r--src/gui/group.c88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/gui/group.c b/src/gui/group.c
new file mode 100644
index 0000000..11a0583
--- /dev/null
+++ b/src/gui/group.c
@@ -0,0 +1,88 @@
1#include <stdlib.h>
2#include <gui/group.h>
3#include <common/mem.h>
4#include <assert.h>
5#include <gui/component.h>
6#include "MLV/MLV_shape.h"
7#include "MLV/MLV_window.h"
8
9void group_print(Component *parameterSelf) {
10 assert(parameterSelf != NULL);
11 Group *self = (Group *) parameterSelf;
12 if (self->group_head != NULL) {
13 GroupElement *p = self->group_head;
14 while (p != NULL) {
15 p->sub_component->print_method(p->sub_component);
16 p = p->next;
17 }
18 }
19}
20
21void group_click_handler(int x_pos, int y_pos, Component *parameterSelf) {
22 assert(parameterSelf != NULL);
23 Group *self = (Group *) parameterSelf;
24
25 if (self->group_head != NULL && self->component.activated) {
26 GroupElement *p = self->group_head;
27 while (p != NULL) {
28 p->sub_component->click_handler(x_pos, y_pos, p->sub_component);
29 p = p->next;
30 }
31 }
32}
33
34void group_init(Group *group, int width, int height, int x_pos, int y_pos, int margin) {
35 assert(group != NULL);
36 assert(width > 0);
37 assert(height > 0);
38 assert(x_pos >= 0);
39 assert(y_pos >= 0);
40 assert(margin >= 0);
41 group->component.width = width;
42 group->component.height = height;
43 group->component.x_pos = x_pos;
44 group->component.y_pos = y_pos;
45 group->component.activated = true;
46 group->component.print_method = group_print;
47 group->component.click_handler = group_click_handler;
48 group->margin = margin;
49}
50
51void group_free(Group *group) {
52 assert(group != NULL);
53 if (group->group_head != NULL) {
54 GroupElement *p = group->group_head;
55 while (p != NULL) {
56 GroupElement *tmp = p;
57 p = p->next;
58 free(tmp);
59 }
60 group->group_head = NULL;
61 }
62}
63
64void group_add_component(Group *group, Component *component) {
65 assert(group != NULL);
66 assert(component != NULL);
67 /*Initialize the new node*/
68 GroupElement *tmp = malloc_or_die(sizeof(GroupElement));
69 tmp->sub_component = component;
70 tmp->next = NULL;
71 if (group->group_head != NULL) {
72 GroupElement *p = group->group_head;
73 /*Browsing*/
74 while (p->next != NULL) {
75 p = p->next;
76 }
77 p->next = tmp;
78 /*Modifying for margin*/
79 tmp->sub_component->y_pos = p->sub_component->y_pos;
80 tmp->sub_component->x_pos = p->sub_component->x_pos + p->sub_component->width + group->margin;
81 } else {
82 tmp->sub_component->y_pos = group->component.y_pos;
83 tmp->sub_component->x_pos = group->component.x_pos;
84 group->group_head = tmp;
85
86 }
87}
88