summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam NAILI2017-12-22 19:11:06 +0100
committerAdam NAILI2017-12-22 19:11:06 +0100
commitf3e1ec505dab2d68f7d5ce542f1693d00d7f0537 (patch)
treeb36fb250f311cbbf295a962d75a6ea4d226c763f
parent1a4d7b44eaefd7831860b2ffdf178b00af3e1c7e (diff)
downloadmorpher-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
-rw-r--r--include/gui/group.h26
-rw-r--r--src/gui/group.c65
2 files changed, 64 insertions, 27 deletions
diff --git a/include/gui/group.h b/include/gui/group.h
index 88fffbc..2a02ee4 100644
--- a/include/gui/group.h
+++ b/include/gui/group.h
@@ -28,22 +28,33 @@ typedef struct _GroupElement {
28 * Parameters: 28 * Parameters:
29 * component - Component used for the Group to catch clicks and handle print to delegate to the components contented in it 29 * component - Component used for the Group to catch clicks and handle print to delegate to the components contented in it
30 * *group_head - pointer to the head of the list that regroup all the components contained inside of the group 30 * *group_head - pointer to the head of the list that regroup all the components contained inside of the group
31 * padding - padding for all components 31 * margin - margin for all components
32 */ 32 */
33typedef struct { 33typedef struct {
34 Component component; 34 Component component;
35 GroupElement *group_head; 35 GroupElement *group_head;
36 int padding; 36 int margin;
37} Group; 37} Group;
38 38
39/** 39/**
40 * Function: group_print 40 * Function: group_print
41 * Print method for a group (BETA VERSION). 41 * Print method for a group that will print all components contained in.
42 * 42 *
43 * Parameters: 43 * Parameters:
44 * *parameter - pointer that will be casted into a Group to print 44 * *parameterSelf - pointer that will be casted into a Group to print
45 */ 45 */
46void group_print(void *parameter); 46void group_print(Component *parameterSelf);
47
48/**
49 * Function: group_click_handler
50 * Delegates the click handling to the component contained inside.
51 *
52 * Parameters:
53 * x_pos - position of the mouse on x axis
54 * y_pos - position of the mouse on y axis
55 * *parameterSelf - pointer that will be casted into a Group to print
56 */
57void group_click_handler(int x_pos, int y_pos, Component *parameterSelf);
47 58
48/** 59/**
49 * Function: group_init 60 * Function: group_init
@@ -55,9 +66,9 @@ void group_print(void *parameter);
55 * height - height of the current group 66 * height - height of the current group
56 * x_pos - position on the x axis from the upper left corner 67 * x_pos - position on the x axis from the upper left corner
57 * y_pos - position on the y axis from the upper left corner 68 * y_pos - position on the y axis from the upper left corner
58 * padding - space between each components 69 * margin - space between each components
59 */ 70 */
60void group_init(Group *group, int width, int height, int x_pos, int y_pos, int padding); 71void group_init(Group *group, int width, int height, int x_pos, int y_pos, int margin);
61 72
62/** 73/**
63 * Function: group_free 74 * Function: group_free
@@ -78,4 +89,5 @@ void group_free(Group *group);
78 */ 89 */
79void group_add_component(Group *group, Component *component); 90void group_add_component(Group *group, Component *component);
80 91
92
81#endif 93#endif
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
8void group_print(void *parameter) { 9void 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
21void 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
17void group_init(Group *group, int width, int height, int x_pos, int y_pos, int padding) { 33void 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
32void group_free(Group *group) { 49void 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
44void group_add_component(Group *group, Component *component) { 62void 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