diff options
author | Adam NAILI | 2017-12-31 17:52:59 +0100 |
---|---|---|
committer | Adam NAILI | 2017-12-31 17:52:59 +0100 |
commit | 3e6c3cea17042e83d8e48b87abd89c617a2f70f3 (patch) | |
tree | 0d6b22c672e670daa3cb464668500535af0ee988 /src/gui | |
parent | e275a679a1fb9377dd1a74329420ce6e95a03da3 (diff) | |
parent | f1d17a0bb9d1ba98cc94488ecbdb539f123b33ab (diff) | |
download | morpher-3e6c3cea17042e83d8e48b87abd89c617a2f70f3.tar.gz |
Merge remote-tracking branch 'origin/gui'
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/button.c | 133 | ||||
-rw-r--r-- | src/gui/component.c | 7 | ||||
-rw-r--r-- | src/gui/group.c | 87 | ||||
-rw-r--r-- | src/gui/pictureframe.c | 117 | ||||
-rw-r--r-- | src/gui/window.c | 60 |
5 files changed, 404 insertions, 0 deletions
diff --git a/src/gui/button.c b/src/gui/button.c new file mode 100644 index 0000000..03addf8 --- /dev/null +++ b/src/gui/button.c | |||
@@ -0,0 +1,133 @@ | |||
1 | #include <gui/button.h> | ||
2 | #include <stdlib.h> | ||
3 | #include <assert.h> | ||
4 | #include <common/mem.h> | ||
5 | #include <string.h> | ||
6 | #include <MLV/MLV_all.h> | ||
7 | #include <gui/component.h> | ||
8 | |||
9 | bool button_is_selected(int x, int y, Button *button) { | ||
10 | assert(x >= 0); | ||
11 | assert(y >= 0); | ||
12 | assert(button != NULL); | ||
13 | int x1 = button->component.x_pos; | ||
14 | int y1 = button->component.y_pos; | ||
15 | int x2 = button->component.x_pos + button->component.width; | ||
16 | int y2 = button->component.y_pos + button->component.height; | ||
17 | if (x >= x1 && x <= x2 && y >= y1 && y <= y2) { | ||
18 | return true; | ||
19 | } | ||
20 | return false; | ||
21 | } | ||
22 | |||
23 | void button_print(Component *parameterSelf) { | ||
24 | assert(parameterSelf != NULL); | ||
25 | Button *self = (Button *) parameterSelf; | ||
26 | MLV_draw_adapted_text_box(self->component.x_pos, self->component.y_pos, self->label, self->sizeInterligne, | ||
27 | MLV_COLOR_BLACK, MLV_COLOR_WHITE, MLV_COLOR_DARK_GREY, MLV_TEXT_CENTER); | ||
28 | } | ||
29 | |||
30 | void button_click_test(int x, int y, Component *parameterSelf) { | ||
31 | assert(x >= 0); | ||
32 | assert(y >= 0); | ||
33 | assert(parameterSelf != NULL); | ||
34 | Button *self = (Button *) parameterSelf; | ||
35 | if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) { | ||
36 | } | ||
37 | } | ||
38 | |||
39 | void button_click_add_constraint(int x, int y, Component *parameterSelf) { | ||
40 | assert(x >= 0); | ||
41 | assert(y >= 0); | ||
42 | assert(parameterSelf != NULL); | ||
43 | Button *self = (Button *) parameterSelf; | ||
44 | if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) { | ||
45 | mode = INSERT_ORIGIN; | ||
46 | } | ||
47 | } | ||
48 | |||
49 | void button_click_show_hide(int x, int y, Component *parameterSelf) { | ||
50 | assert(x >= 0); | ||
51 | assert(y >= 0); | ||
52 | assert(parameterSelf != NULL); | ||
53 | Button *self = (Button *) parameterSelf; | ||
54 | if (button_is_selected(x, y, self)) { | ||
55 | if (mode == WAITING_BUTTON_SHOW) { | ||
56 | mode = WAITING_BUTTON_HIDE; | ||
57 | } else if (mode == WAITING_BUTTON_HIDE) { | ||
58 | mode = WAITING_BUTTON_SHOW; | ||
59 | } | ||
60 | } | ||
61 | } | ||
62 | |||
63 | void button_click_exit(int x, int y, Component *parameterSelf) { | ||
64 | assert(x >= 0); | ||
65 | assert(y >= 0); | ||
66 | assert(parameterSelf != NULL); | ||
67 | Button *self = (Button *) parameterSelf; | ||
68 | if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) { | ||
69 | mode = EXITING; | ||
70 | } | ||
71 | } | ||
72 | |||
73 | void button_click_less_frame(int x, int y, Component *parameterSelf) { | ||
74 | assert(x >= 0); | ||
75 | assert(y >= 0); | ||
76 | assert(parameterSelf != NULL); | ||
77 | Button *self = (Button *) parameterSelf; | ||
78 | if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) { | ||
79 | if (frame > 2) { | ||
80 | frame = frame / 2; | ||
81 | sprintf(labelFrame,"%03d frames", frame); | ||
82 | mode = PRINTING_BUTTONS; | ||
83 | } | ||
84 | } | ||
85 | } | ||
86 | |||
87 | void button_click_more_frame(int x, int y, Component *parameterSelf) { | ||
88 | assert(x >= 0); | ||
89 | assert(y >= 0); | ||
90 | assert(parameterSelf != NULL); | ||
91 | Button *self = (Button *) parameterSelf; | ||
92 | if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) { | ||
93 | if (frame < 256) { | ||
94 | frame = frame * 2; | ||
95 | sprintf(labelFrame,"%03d frames", frame); | ||
96 | mode = PRINTING_BUTTONS; | ||
97 | } | ||
98 | } | ||
99 | } | ||
100 | |||
101 | void button_click_rendering(int x,int y, Component *parameterSelf) { | ||
102 | assert(x >= 0); | ||
103 | assert(y >= 0); | ||
104 | assert(parameterSelf != NULL); | ||
105 | Button *self = (Button *) parameterSelf; | ||
106 | if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) { | ||
107 | mode = RENDERING; | ||
108 | } | ||
109 | } | ||
110 | |||
111 | void button_click_none(int x, int y, Component *parameterSelf) { | ||
112 | assert(x >= 0); | ||
113 | assert(y >= 0); | ||
114 | assert(parameterSelf != NULL); | ||
115 | } | ||
116 | |||
117 | |||
118 | void | ||
119 | button_init(Button *button, const char *text, int sizeInterligne, int x_pos, int y_pos, ClickHandler clickHandler) { | ||
120 | assert(button != NULL); | ||
121 | assert(text != NULL); | ||
122 | assert(sizeInterligne >= 0); | ||
123 | assert(x_pos >= 0); | ||
124 | assert(y_pos >= 0); | ||
125 | button->label = malloc_or_die(sizeof(char) * (strlen(text) + 1)); | ||
126 | strcpy(button->label, text); | ||
127 | button->sizeInterligne = sizeInterligne; | ||
128 | MLV_get_size_of_adapted_text_box(text, sizeInterligne, &button->component.width, &button->component.height); | ||
129 | button->component.x_pos = x_pos; | ||
130 | button->component.y_pos = y_pos; | ||
131 | button->component.print_method = button_print; | ||
132 | button->component.click_handler = clickHandler; | ||
133 | } | ||
diff --git a/src/gui/component.c b/src/gui/component.c new file mode 100644 index 0000000..3eb31c5 --- /dev/null +++ b/src/gui/component.c | |||
@@ -0,0 +1,7 @@ | |||
1 | #include <gui/component.h> | ||
2 | |||
3 | Mode mode = WAITING_BUTTON_SHOW; | ||
4 | |||
5 | int frame = 2; | ||
6 | |||
7 | char labelFrame[20]; | ||
diff --git a/src/gui/group.c b/src/gui/group.c new file mode 100644 index 0000000..af9abac --- /dev/null +++ b/src/gui/group.c | |||
@@ -0,0 +1,87 @@ | |||
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 | |||
9 | void 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 | |||
21 | void 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) { | ||
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 | |||
34 | void 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.print_method = group_print; | ||
46 | group->component.click_handler = group_click_handler; | ||
47 | group->margin = margin; | ||
48 | } | ||
49 | |||
50 | void group_free(Group *group) { | ||
51 | assert(group != NULL); | ||
52 | if (group->group_head != NULL) { | ||
53 | GroupElement *p = group->group_head; | ||
54 | while (p != NULL) { | ||
55 | GroupElement *tmp = p; | ||
56 | p = p->next; | ||
57 | free(tmp); | ||
58 | } | ||
59 | group->group_head = NULL; | ||
60 | } | ||
61 | } | ||
62 | |||
63 | void group_add_component(Group *group, Component *component) { | ||
64 | assert(group != NULL); | ||
65 | assert(component != NULL); | ||
66 | /*Initialize the new node*/ | ||
67 | GroupElement *tmp = malloc_or_die(sizeof(GroupElement)); | ||
68 | tmp->sub_component = component; | ||
69 | tmp->next = NULL; | ||
70 | if (group->group_head != NULL) { | ||
71 | GroupElement *p = group->group_head; | ||
72 | /*Browsing*/ | ||
73 | while (p->next != NULL) { | ||
74 | p = p->next; | ||
75 | } | ||
76 | p->next = tmp; | ||
77 | /*Modifying for margin*/ | ||
78 | tmp->sub_component->y_pos = p->sub_component->y_pos; | ||
79 | tmp->sub_component->x_pos = p->sub_component->x_pos + p->sub_component->width + group->margin; | ||
80 | } else { | ||
81 | tmp->sub_component->y_pos = group->component.y_pos; | ||
82 | tmp->sub_component->x_pos = group->component.x_pos; | ||
83 | group->group_head = tmp; | ||
84 | |||
85 | } | ||
86 | } | ||
87 | |||
diff --git a/src/gui/pictureframe.c b/src/gui/pictureframe.c new file mode 100644 index 0000000..4126f59 --- /dev/null +++ b/src/gui/pictureframe.c | |||
@@ -0,0 +1,117 @@ | |||
1 | #include <assert.h> | ||
2 | #include <gui/pictureframe.h> | ||
3 | #include <MLV/MLV_all.h> | ||
4 | |||
5 | CartesianVector pictureframe_origin_split(const CartesianMapping *cartesianMapping) { | ||
6 | return cartesianMapping->origin; | ||
7 | } | ||
8 | |||
9 | CartesianVector pictureframe_target_split(const CartesianMapping *cartesianMapping) { | ||
10 | return cartesianMapping->target; | ||
11 | } | ||
12 | |||
13 | void pictureframe_draw_canvas(PictureFrame *pictureFrame){ | ||
14 | MLV_draw_image(pictureFrame->canvas->mlv, pictureFrame->component.x_pos, pictureFrame->component.y |