From a7e6f8a296b536966cee49f8de105960970d04c5 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Sat, 9 Dec 2017 01:58:10 +0100 Subject: Creating source file window.c --- src/gui/window.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/gui/window.c (limited to 'src/gui') diff --git a/src/gui/window.c b/src/gui/window.c new file mode 100644 index 0000000..2b4c7e0 --- /dev/null +++ b/src/gui/window.c @@ -0,0 +1,13 @@ +#include "gui/window.h" + +void window_init(Window *window, int width, int height, char *title) { +//TODO +} + +void window_free(Window *window) { +//TODO +} + +void window_add_component(Window *window, Component *component) { +//TODO +} -- cgit v1.2.3 From 2aed52d89856847ea394b06d7b70782fa6b21d24 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Sun, 10 Dec 2017 13:01:42 +0100 Subject: Implementing init, free, add_button, add_pictureframe functions for window --- src/gui/window.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'src/gui') diff --git a/src/gui/window.c b/src/gui/window.c index 2b4c7e0..bd96050 100644 --- a/src/gui/window.c +++ b/src/gui/window.c @@ -1,13 +1,30 @@ -#include "gui/window.h" +#include +#include +#include +#include "string.h" +#include "assert.h" void window_init(Window *window, int width, int height, char *title) { -//TODO + window = malloc_or_die(sizeof(window)); + assert(width > 0); + assert(height > 0); + window->width = width; + window->height = height; + assert(title != NULL); + strcpy(window->title,title); + window->group_buttons = malloc_or_die(sizeof(Group)); + window->group_pictureframe = malloc_or_die(sizeof(Group)); } void window_free(Window *window) { -//TODO + group_free(window->group_buttons); + group_free(window->group_pictureframe); } -void window_add_component(Window *window, Component *component) { -//TODO +void window_add_button(Window *window, Component *component){ + group_add_component(window->group_buttons,component); } + +void window_add_pictureframe(Window *window, Component *component){ + group_add_component(window->group_pictureframe,component); +} \ No newline at end of file -- cgit v1.2.3 From ed99a651c4e0c1a162f416ec384cef7df4268a88 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Sun, 10 Dec 2017 18:31:02 +0100 Subject: Deleting the documentation button_free and the prototype --- src/gui/group.c | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/gui/group.c (limited to 'src/gui') diff --git a/src/gui/group.c b/src/gui/group.c new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/gui/group.c @@ -0,0 +1 @@ + -- cgit v1.2.3 From 8ad5554529a9f1a6d128582af5aec13c792f0932 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Sun, 10 Dec 2017 18:33:11 +0100 Subject: Update doc and reworking structure and signature of init function for group --- src/gui/group.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/gui') diff --git a/src/gui/group.c b/src/gui/group.c index 8b13789..dc48c50 100644 --- a/src/gui/group.c +++ b/src/gui/group.c @@ -1 +1,26 @@ +#include +#include +void group_init(Group *group, int width, int height, int x_pos, int y_pos, int padding) { + group->component.width = width; + group->component.height = height; + group->component.x_pos = x_pos; + group->component.y_pos = y_pos; + group->padding = padding; +} + +void group_free(Group *group) { + if (group->group_head != NULL) { + GroupElement *p = group->group_head; + while (p->next != NULL) { + GroupElement *tmp = group->group_head; + p = p->next; + free(tmp); + } + group->group_head = NULL; + } +} + +void group_add_component(Group *group, Component *component) { + +} \ No newline at end of file -- cgit v1.2.3 From bd3864dda0ca20a2d234bda525e6cd7c21d4f729 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Sun, 10 Dec 2017 18:39:27 +0100 Subject: Modification of the implementation of init, free and successful test for the init function (creation of a window with the right parameters) --- src/gui/window.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'src/gui') diff --git a/src/gui/window.c b/src/gui/window.c index bd96050..81af66a 100644 --- a/src/gui/window.c +++ b/src/gui/window.c @@ -1,30 +1,39 @@ #include #include -#include +#include "gui/window.h" +#include "common/mem.h" #include "string.h" #include "assert.h" +#include "MLV/MLV_window.h" void window_init(Window *window, int width, int height, char *title) { - window = malloc_or_die(sizeof(window)); assert(width > 0); assert(height > 0); window->width = width; window->height = height; assert(title != NULL); - strcpy(window->title,title); + window->title = malloc_or_die(sizeof(char) * (strlen(title) + 1)); + strcpy(window->title, title); window->group_buttons = malloc_or_die(sizeof(Group)); + group_init(window->group_buttons, 5); window->group_pictureframe = malloc_or_die(sizeof(Group)); + group_init(window->group_pictureframe, 5); } void window_free(Window *window) { + free(window->title); group_free(window->group_buttons); group_free(window->group_pictureframe); } -void window_add_button(Window *window, Component *component){ - group_add_component(window->group_buttons,component); +void window_add_button(Window *window, Component *component) { + group_add_component(window->group_buttons, component); } -void window_add_pictureframe(Window *window, Component *component){ - group_add_component(window->group_pictureframe,component); +void window_add_pictureframe(Window *window, Component *component) { + group_add_component(window->group_pictureframe, component); +} + +void window_create(Window *window) { + MLV_create_window(window->title, window->title, (unsigned int) window->width, (unsigned int) window->height); } \ No newline at end of file -- cgit v1.2.3 From 26bb3df365ed43dd415be8ac870da8ac8991b425 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Tue, 12 Dec 2017 13:13:24 +0100 Subject: Adding beta version of print function, working on implementation of the linked list (add + free) --- src/gui/group.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'src/gui') diff --git a/src/gui/group.c b/src/gui/group.c index dc48c50..ac2c440 100644 --- a/src/gui/group.c +++ b/src/gui/group.c @@ -1,11 +1,31 @@ #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_init(Group *group, int width, int height, int x_pos, int y_pos, int padding) { + assert(group != NULL); + assert(width>0); + assert(height>0); + assert(x_pos>=0); + assert(y_pos>=0); + assert(padding>=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; } @@ -22,5 +42,20 @@ void group_free(Group *group) { } void group_add_component(Group *group, Component *component) { - + 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; + } else { + group->group_head = malloc_or_die(sizeof(GroupElement)); + group->group_head->sub_component = component; + group->group_head->next = NULL; + } } \ No newline at end of file -- cgit v1.2.3 From e96c998be9e867e328d393966a60599dc3c37e3a Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Tue, 12 Dec 2017 13:18:22 +0100 Subject: Adding asserts, fixing the call of group_init that changed --- src/gui/window.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/gui') diff --git a/src/gui/window.c b/src/gui/window.c index 81af66a..7b5a75f 100644 --- a/src/gui/window.c +++ b/src/gui/window.c @@ -1,5 +1,7 @@ #include #include +#include +#include #include "gui/window.h" #include "common/mem.h" #include "string.h" @@ -7,6 +9,7 @@ #include "MLV/MLV_window.h" void window_init(Window *window, int width, int height, char *title) { + assert(window != NULL); assert(width > 0); assert(height > 0); window->width = width; @@ -15,9 +18,9 @@ void window_init(Window *window, int width, int height, char *title) { window->title = malloc_or_die(sizeof(char) * (strlen(title) + 1)); strcpy(window->title, title); window->group_buttons = malloc_or_die(sizeof(Group)); - group_init(window->group_buttons, 5); + group_init(window->group_buttons,window->width,100,0,window->height-100,5); window->group_pictureframe = malloc_or_die(sizeof(Group)); - group_init(window->group_pictureframe, 5); + group_init(window->group_pictureframe,window->width,window->height-100,0,0,5); } void window_free(Window *window) { -- cgit v1.2.3 From a42fdf7d5c9712297f1bbe3dd0951baa8ee32447 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Tue, 12 Dec 2017 13:25:56 +0100 Subject: Formatting files --- src/gui/group.c | 10 +++++----- src/gui/window.c | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src/gui') diff --git a/src/gui/group.c b/src/gui/group.c index ac2c440..cb50b1c 100644 --- a/src/gui/group.c +++ b/src/gui/group.c @@ -16,11 +16,11 @@ void group_print(void *parameter) { void group_init(Group *group, int width, int height, int x_pos, int y_pos, int padding) { assert(group != NULL); - assert(width>0); - assert(height>0); - assert(x_pos>=0); - assert(y_pos>=0); - assert(padding>=0); + assert(width > 0); + assert(height > 0); + assert(x_pos >= 0); + assert(y_pos >= 0); + assert(padding >= 0); group->component.width = width; group->component.height = height; group->component.x_pos = x_pos; diff --git a/src/gui/window.c b/src/gui/window.c index 7b5a75f..2c84aeb 100644 --- a/src/gui/window.c +++ b/src/gui/window.c @@ -18,9 +18,9 @@ void window_init(Window *window, int width, int height, char *title) { window->title = malloc_or_die(sizeof(char) * (strlen(title) + 1)); strcpy(window->title, title); window->group_buttons = malloc_or_die(sizeof(Group)); - group_init(window->group_buttons,window->width,100,0,window->height-100,5); + group_init(window->group_buttons, window->width, 100, 0, window->height - 100, 5); window->group_pictureframe = malloc_or_die(sizeof(Group)); - group_init(window->group_pictureframe,window->width,window->height-100,0,0,5); + group_init(window->group_pictureframe, window->width, window->height - 100, 0, 0, 5); } void window_free(Window *window) { -- cgit v1.2.3 From a05d3ad97d513c03d671059a5bae18487af23e24 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Fri, 22 Dec 2017 18:31:33 +0100 Subject: Updating doc of button, implementing button_is_selected, button_print, button_click_test (debug click handling), button_init --- src/gui/button.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/gui/button.c (limited to 'src/gui') diff --git a/src/gui/button.c b/src/gui/button.c new file mode 100644 index 0000000..fbdc172 --- /dev/null +++ b/src/gui/button.c @@ -0,0 +1,56 @@ +#include +#include +#include +#include +#include +#include +#include + + +bool button_is_selected(int x, int y, Button *button) { + assert(x >= 0); + assert(y >= 0); + assert(button != NULL); + int x1 = button->component.x_pos; + int y1 = button->component.y_pos; + int x2 = button->component.x_pos + button->component.width; + int y2 = button->component.y_pos + button->component.height; + if (x >= x1 && x <= x2 && y >= y1 && y <= y2) { + return true; + } + return false; +} + +void button_print(Component *parameterSelf) { + assert(parameterSelf != NULL); + Button *self = (Button *) parameterSelf; + MLV_draw_adapted_text_box(self->component.x_pos, self->component.y_pos, self->label, self->sizeInterligne, + MLV_COLOR_BLACK, MLV_COLOR_WHITE, MLV_COLOR_DARK_GREY, MLV_TEXT_CENTER); +} + +void button_click_test(int x, int y, Component *parameterSelf) { + assert(x >= 0); + assert(y >= 0); + assert(parameterSelf != NULL); + Button *self = (Button *) parameterSelf; + if (button_is_selected(x, y, self)) { + printf("OK\n"); + } +} + +void +button_init(Button *button, const char *text, int sizeInterligne, int x_pos, int y_pos, ClickHandler clickHandler) { + assert(button != NULL); + assert(text != NULL); + assert(sizeInterligne >= 0); + assert(x_pos >= 0); + assert(y_pos >= 0); + button->label = malloc_or_die(sizeof(char) * (strlen(text) + 1)); + strcpy(button->label, text); + button->sizeInterligne = sizeInterligne; + MLV_get_size_of_adapted_text_box(text, sizeInterligne, &button->component.width, &button->component.height); + button->component.x_pos = x_pos; + button->component.y_pos = y_pos; + button->component.print_method = button_print; + button->component.click_handler = clickHandler; +} -- cgit v1.2.3 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 From e84ae1203b8cd7a51d93ec77a5a2663e7496eef5 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Fri, 22 Dec 2017 19:14:55 +0100 Subject: Adding asserts, modifying signatures of function for more precise type, implementing window_add functions, window_print functions --- src/gui/window.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) (limited to 'src/gui') diff --git a/src/gui/window.c b/src/gui/window.c index 2c84aeb..6e287e5 100644 --- a/src/gui/window.c +++ b/src/gui/window.c @@ -1,8 +1,8 @@ #include #include +#include +#include #include -#include -#include "gui/window.h" #include "common/mem.h" #include "string.h" #include "assert.h" @@ -12,9 +12,9 @@ void window_init(Window *window, int width, int height, char *title) { assert(window != NULL); assert(width > 0); assert(height > 0); + assert(title != NULL); window->width = width; window->height = height; - assert(title != NULL); window->title = malloc_or_die(sizeof(char) * (strlen(title) + 1)); strcpy(window->title, title); window->group_buttons = malloc_or_die(sizeof(Group)); @@ -24,19 +24,37 @@ void window_init(Window *window, int width, int height, char *title) { } void window_free(Window *window) { + assert(window != NULL); free(window->title); group_free(window->group_buttons); group_free(window->group_pictureframe); } -void window_add_button(Window *window, Component *component) { - group_add_component(window->group_buttons, component); +void window_add_button(Window *window, Button *button) { + assert(window != NULL); + assert(button != NULL); + group_add_component(window->group_buttons, &(button->component)); } -void window_add_pictureframe(Window *window, Component *component) { - group_add_component(window->group_pictureframe, component); +void window_add_pictureframe(Window *window, PictureFrame *pictureFrame) { + assert(window != NULL); + assert(pictureFrame != NULL); + group_add_component(window->group_pictureframe, &(pictureFrame->component)); } void window_create(Window *window) { + assert(window != NULL); MLV_create_window(window->title, window->title, (unsigned int) window->width, (unsigned int) window->height); +} + +void window_print_buttons(Window *window) { + assert(window != NULL); + window->group_buttons->component.print_method(&(window->group_buttons->component)); + MLV_actualise_window(); +} + +void window_print_pictureframes(Window *window) { + assert(window != NULL); + window->group_pictureframe->component.print_method(&(window->group_pictureframe->component)); + MLV_actualise_window(); } \ No newline at end of file -- cgit v1.2.3 From ee98053ef83869033713c8c7d6d487457d6443d8 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Wed, 27 Dec 2017 17:16:20 +0100 Subject: Implementing the locking system to disable components --- src/gui/button.c | 3 ++- src/gui/group.c | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'src/gui') diff --git a/src/gui/button.c b/src/gui/button.c index fbdc172..96cbd9a 100644 --- a/src/gui/button.c +++ b/src/gui/button.c @@ -33,7 +33,7 @@ void button_click_test(int x, int y, Component *parameterSelf) { assert(y >= 0); assert(parameterSelf != NULL); Button *self = (Button *) parameterSelf; - if (button_is_selected(x, y, self)) { + if (button_is_selected(x, y, self) && self->component.activated) { printf("OK\n"); } } @@ -51,6 +51,7 @@ button_init(Button *button, const char *text, int sizeInterligne, int x_pos, int MLV_get_size_of_adapted_text_box(text, sizeInterligne, &button->component.width, &button->component.height); button->component.x_pos = x_pos; button->component.y_pos = y_pos; + button->component.activated = true; button->component.print_method = button_print; button->component.click_handler = clickHandler; } diff --git a/src/gui/group.c b/src/gui/group.c index d287205..11a0583 100644 --- a/src/gui/group.c +++ b/src/gui/group.c @@ -21,7 +21,8 @@ void group_print(Component *parameterSelf) { void group_click_handler(int x_pos, int y_pos, Component *parameterSelf) { assert(parameterSelf != NULL); Group *self = (Group *) parameterSelf; - if (self->group_head != NULL) { + + if (self->group_head != NULL && self->component.activated) { GroupElement *p = self->group_head; while (p != NULL) { p->sub_component->click_handler(x_pos, y_pos, p->sub_component); @@ -41,6 +42,7 @@ void group_init(Group *group, int width, int height, int x_pos, int y_pos, int m group->component.height = height; group->component.x_pos = x_pos; group->component.y_pos = y_pos; + group->component.activated = true; group->component.print_method = group_print; group->component.click_handler = group_click_handler; group->margin = margin; -- cgit v1.2.3 From aaf57e5ee1e0cf74afdbdf56293f1afd7e79e6b0 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Thu, 28 Dec 2017 16:22:43 +0100 Subject: Reworking signatures of pictureframe function, beginning of implementation, debug tests --- src/gui/pictureframe.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/gui/pictureframe.c (limited to 'src/gui') diff --git a/src/gui/pictureframe.c b/src/gui/pictureframe.c new file mode 100644 index 0000000..543ba4c --- /dev/null +++ b/src/gui/pictureframe.c @@ -0,0 +1,45 @@ +#include +#include +#include + +CartesianVector pictureframe_origin_split(const CartesianMapping *cartesianMapping) { + +} + +CartesianVector pictureframe_target_split(const CartesianMapping *cartesianMapping) { + +} + +void pictureframe_print(Component *parameterSelf) { + PictureFrame *self = (PictureFrame *) parameterSelf; + /*DEBUG*/ + MLV_draw_filled_rectangle(self->component.x_pos, self->component.y_pos, self->component.width, self->component.height, + MLV_COLOR_RED); + /**/ +} + +void pictureframe_click_handler(int x_pos, int y_pos, Component *parameterSelf) { + printf("ClickHandler pictureframe activated \n"); +} + +void pictureframe_init(PictureFrame *pictureFrame, int width, int height, int x_pos, int y_pos, + CartesianMappingDivision cartesianMappingDivision, Morphing *morphing, Canvas *canvas) { + assert(pictureFrame != NULL); + assert(width > 0); + assert(height > 0); + assert(x_pos >= 0); + assert(y_pos >= 0); + assert(cartesianMappingDivision != NULL); + assert(morphing != NULL); + assert(canvas != NULL); + pictureFrame->component.width = width; + pictureFrame->component.height = height; + pictureFrame->component.x_pos = x_pos; + pictureFrame->component.y_pos = y_pos; + pictureFrame->component.activated = true; + pictureFrame->component.print_method = pictureframe_print; + pictureFrame->component.click_handler = pictureframe_click_handler; + pictureFrame->morphing = morphing; + pictureFrame->canvas = canvas; + pictureFrame->cartesianMappingDivision = cartesianMappingDivision; +} \ No newline at end of file -- cgit v1.2.3 From 9ed3c28a0335137d34e51d5fd49be6e523f65a89 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Thu, 28 Dec 2017 22:52:28 +0100 Subject: Implementing the add constraint feature, need to be fixed --- src/gui/button.c | 15 +++++++-- src/gui/component.c | 3 ++ src/gui/group.c | 3 +- src/gui/pictureframe.c | 90 ++++++++++++++++++++++++++++++++++++++++++++------ 4 files changed, 95 insertions(+), 16 deletions(-) create mode 100644 src/gui/component.c (limited to 'src/gui') diff --git a/src/gui/button.c b/src/gui/button.c index 96cbd9a..a1fa1cf 100644 --- a/src/gui/button.c +++ b/src/gui/button.c @@ -6,7 +6,6 @@ #include #include - bool button_is_selected(int x, int y, Button *button) { assert(x >= 0); assert(y >= 0); @@ -33,11 +32,22 @@ void button_click_test(int x, int y, Component *parameterSelf) { assert(y >= 0); assert(parameterSelf != NULL); Button *self = (Button *) parameterSelf; - if (button_is_selected(x, y, self) && self->component.activated) { + if (button_is_selected(x, y, self) && mode == WAITING_BUTTON) { printf("OK\n"); } } +void button_click_add_constraint(int x, int y, Component *parameterSelf){ + assert(x >= 0); + assert(y >= 0); + assert(parameterSelf != NULL); + Button *self = (Button *) parameterSelf; + if (button_is_selected(x, y, self) && mode == WAITING_BUTTON) { + mode = INSERT_ORIGIN; + } +} + + void button_init(Button *button, const char *text, int sizeInterligne, int x_pos, int y_pos, ClickHandler clickHandler) { assert(button != NULL); @@ -51,7 +61,6 @@ button_init(Button *button, const char *text, int sizeInterligne, int x_pos, int MLV_get_size_of_adapted_text_box(text, sizeInterligne, &button->component.width, &button->component.height); button->component.x_pos = x_pos; button->component.y_pos = y_pos; - button->component.activated = true; button->component.print_method = button_print; button->component.click_handler = clickHandler; } diff --git a/src/gui/component.c b/src/gui/component.c new file mode 100644 index 0000000..07fb336 --- /dev/null +++ b/src/gui/component.c @@ -0,0 +1,3 @@ +#include + +Mode mode = WAITING_BUTTON; diff --git a/src/gui/group.c b/src/gui/group.c index 11a0583..af9abac 100644 --- a/src/gui/group.c +++ b/src/gui/group.c @@ -22,7 +22,7 @@ void group_click_handler(int x_pos, int y_pos, Component *parameterSelf) { assert(parameterSelf != NULL); Group *self = (Group *) parameterSelf; - if (self->group_head != NULL && self->component.activated) { + 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); @@ -42,7 +42,6 @@ void group_init(Group *group, int width, int height, int x_pos, int y_pos, int m group->component.height = height; group->component.x_pos = x_pos; group->component.y_pos = y_pos; - group->component.activated = true; group->component.print_method = group_print; group->component.click_handler = group_click_handler; group->margin = margin; diff --git a/src/gui/pictureframe.c b/src/gui/pictureframe.c index 543ba4c..e4081a7 100644 --- a/src/gui/pictureframe.c +++ b/src/gui/pictureframe.c @@ -1,29 +1,98 @@ #include #include #include +#include CartesianVector pictureframe_origin_split(const CartesianMapping *cartesianMapping) { - + return cartesianMapping->origin; } CartesianVector pictureframe_target_split(const CartesianMapping *cartesianMapping) { - + return cartesianMapping->target; } void pictureframe_print(Component *parameterSelf) { PictureFrame *self = (PictureFrame *) parameterSelf; - /*DEBUG*/ - MLV_draw_filled_rectangle(self->component.x_pos, self->component.y_pos, self->component.width, self->component.height, - MLV_COLOR_RED); - /**/ + MLV_draw_image(self->canvas->mlv, self->component.x_pos, self->component.y_pos); + TriangleMap *p = self->morphing->first; + CartesianVector p1; + CartesianVector p2; + CartesianVector p3; + CartesianVector pointToPrint1; + CartesianVector pointToPrint2; + CartesianVector pointToPrint3; + while(p != NULL){ + p1 = self->cartesianMappingDivision(&(p->vertices[0])); + p2 = self->cartesianMappingDivision(&(p->vertices[1])); + p3 = self->cartesianMappingDivision(&(p->vertices[2])); + + pointToPrint1 = pictureframe_conversion_to_picture(p1.x,p1.y,self); + pointToPrint2 = pictureframe_conversion_to_picture(p2.x,p2.y,self); + pointToPrint3 = pictureframe_conversion_to_picture(p3.x,p3.y,self); + + MLV_draw_filled_circle(pointToPrint1.x,pointToPrint1.y,2,MLV_COLOR_RED); + MLV_draw_filled_circle(pointToPrint2.x,pointToPrint2.y,2,MLV_COLOR_RED); + MLV_draw_filled_circle(pointToPrint3.x,pointToPrint3.y,2,MLV_COLOR_RED); + + MLV_draw_line(pointToPrint1.x,pointToPrint1.y,pointToPrint2.x,pointToPrint2.y,MLV_COLOR_RED); + MLV_draw_line(pointToPrint1.x,pointToPrint1.y,pointToPrint3.x,pointToPrint3.y,MLV_COLOR_RED); + MLV_draw_line(pointToPrint3.x,pointToPrint3.y,pointToPrint2.x,pointToPrint2.y,MLV_COLOR_RED); + p = p->next; + } +} + +bool pictureframe_is_selected(int x, int y, PictureFrame *pictureFrame) { + assert(x >= 0); + assert(y >= 0); + assert(pictureFrame != NULL); + int x1 = pictureFrame->component.x_pos; + int y1 = pictureFrame->component.y_pos; + int x2 = pictureFrame->component.x_pos + pictureFrame->component.width; + int y2 = pictureFrame->component.y_pos + pictureFrame->component.height; + if (x >= x1 && x <= x2 && y >= y1 && y <= y2) { + return true; + } + return false; +} + +CartesianVector pictureframe_conversion_to_origin(int x, int y, PictureFrame *pictureFrame) { + CartesianVector vector; + vector.x = x - pictureFrame->component.x_pos; + vector.y = y - pictureFrame->component.y_pos; + return vector; +} + +CartesianVector pictureframe_conversion_to_picture(int x, int y, PictureFrame *pictureFrame) { + CartesianVector vector; + vector.x = x + pictureFrame->component.x_pos; + vector.y = y + pictureFrame->component.y_pos; + return vector; +} + +void pictureframe_click_handler_origin(int x_pos, int y_pos, Component *parameterSelf) { + PictureFrame *self = (PictureFrame *) parameterSelf; + if (pictureframe_is_selected(x_pos, y_pos, self) && mode == INSERT_ORIGIN) { + CartesianVector vector = pictureframe_conversion_to_origin(x_pos,y_pos,self); + MLV_draw_filled_circle(x_pos,y_pos,2,MLV_COLOR_BLUE); + savedPoint = vector; + MLV_actualise_window(); + mode = INSERT_TARGET; + } } -void pictureframe_click_handler(int x_pos, int y_pos, Component *parameterSelf) { - printf("ClickHandler pictureframe activated \n"); +void pictureframe_click_handler_target(int x_pos, int y_pos, Component *parameterSelf) { + PictureFrame *self = (PictureFrame *) parameterSelf; + if (pictureframe_is_selected(x_pos, y_pos, self) && mode == INSERT_TARGET) { + CartesianVector vector = pictureframe_conversion_to_origin(x_pos,y_pos,self); + printf("(%d,%d) | (%d,%d)\n",savedPoint.x,savedPoint.y,vector.x,vector.y); + morphing_add_constraint(self->morphing,savedPoint,vector); + printf("OK\n"); + mode = PRINTING; + } } void pictureframe_init(PictureFrame *pictureFrame, int width, int height, int x_pos, int y_pos, - CartesianMappingDivision cartesianMappingDivision, Morphing *morphing, Canvas *canvas) { + CartesianMappingDivision cartesianMappingDivision, Morphing *morphing, Canvas *canvas,ClickHandler clickHandler) { assert(pictureFrame != NULL); assert(width > 0); assert(height > 0); @@ -36,9 +105,8 @@ void pictureframe_init(PictureFrame *pictureFrame, int width, int height, int x_ pictureFrame->component.height = height; pictureFrame->component.x_pos = x_pos; pictureFrame->component.y_pos = y_pos; - pictureFrame->component.activated = true; pictureFrame->component.print_method = pictureframe_print; - pictureFrame->component.click_handler = pictureframe_click_handler; + pictureFrame->component.click_handler = clickHandler; pictureFrame->morphing = morphing; pictureFrame->canvas = canvas; pictureFrame->cartesianMappingDivision = cartesianMappingDivision; -- cgit v1.2.3 From 41da8b54ed619ea869ca286cd8ec02e105e21c19 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Sun, 31 Dec 2017 15:00:23 +0100 Subject: Implementing all kinds of buttons. Rendering to fix --- src/gui/button.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++--- src/gui/component.c | 6 +++- src/gui/pictureframe.c | 64 ++++++++++++++++++++++-------------------- 3 files changed, 110 insertions(+), 35 deletions(-) (limited to 'src/gui') diff --git a/src/gui/button.c b/src/gui/button.c index a1fa1cf..03addf8 100644 --- a/src/gui/button.c +++ b/src/gui/button.c @@ -32,21 +32,88 @@ void button_click_test(int x, int y, Component *parameterSelf) { assert(y >= 0); assert(parameterSelf != NULL); Button *self = (Button *) parameterSelf; - if (button_is_selected(x, y, self) && mode == WAITING_BUTTON) { - printf("OK\n"); + if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) { } } -void button_click_add_constraint(int x, int y, Component *parameterSelf){ +void button_click_add_constraint(int x, int y, Component *parameterSelf) { assert(x >= 0); assert(y >= 0); assert(parameterSelf != NULL); Button *self = (Button *) parameterSelf; - if (button_is_selected(x, y, self) && mode == WAITING_BUTTON) { + if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) { mode = INSERT_ORIGIN; } } +void button_click_show_hide(int x, int y, Component *parameterSelf) { + assert(x >= 0); + assert(y >= 0); + assert(parameterSelf != NULL); + Button *self = (Button *) parameterSelf; + if (button_is_selected(x, y, self)) { + if (mode == WAITING_BUTTON_SHOW) { + mode = WAITING_BUTTON_HIDE; + } else if (mode == WAITING_BUTTON_HIDE) { + mode = WAITING_BUTTON_SHOW; + } + } +} + +void button_click_exit(int x, int y, Component *parameterSelf) { + assert(x >= 0); + assert(y >= 0); + assert(parameterSelf != NULL); + Button *self = (Button *) parameterSelf; + if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) { + mode = EXITING; + } +} + +void button_click_less_frame(int x, int y, Component *parameterSelf) { + assert(x >= 0); + assert(y >= 0); + assert(parameterSelf != NULL); + Button *self = (Button *) parameterSelf; + if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) { + if (frame > 2) { + frame = frame / 2; + sprintf(labelFrame,"%03d frames", frame); + mode = PRINTING_BUTTONS; + } + } +} + +void button_click_more_frame(int x, int y, Component *parameterSelf) { + assert(x >= 0); + assert(y >= 0); + assert(parameterSelf != NULL); + Button *self = (Button *) parameterSelf; + if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) { + if (frame < 256) { + frame = frame * 2; + sprintf(labelFrame,"%03d frames", frame); + mode = PRINTING_BUTTONS; + } + } +} + +void button_click_rendering(int x,int y, Component *parameterSelf) { + assert(x >= 0); + assert(y >= 0); + assert(parameterSelf != NULL); + Button *self = (Button *) parameterSelf; + if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) { + mode = RENDERING; + } +} + +void button_click_none(int x, int y, Component *parameterSelf) { + assert(x >= 0); + assert(y >= 0); + assert(parameterSelf != NULL); +} + void button_init(Button *button, const char *text, int sizeInterligne, int x_pos, int y_pos, ClickHandler clickHandler) { diff --git a/src/gui/component.c b/src/gui/component.c index 07fb336..3eb31c5 100644 --- a/src/gui/component.c +++ b/src/gui/component.c @@ -1,3 +1,7 @@ #include -Mode mode = WAITING_BUTTON; +Mode mode = WAITING_BUTTON_SHOW; + +int frame = 2; + +char labelFrame[20]; diff --git a/src/gui/pictureframe.c b/src/gui/pictureframe.c index e4081a7..4126f59 100644 --- a/src/gui/pictureframe.c +++ b/src/gui/pictureframe.c @@ -1,7 +1,6 @@ #include #include #include -#include CartesianVector pictureframe_origin_split(const CartesianMapping *cartesianMapping) { return cartesianMapping->origin; @@ -11,33 +10,39 @@ CartesianVector pictureframe_target_split(const CartesianMapping *cartesianMappi return cartesianMapping->target; } +void pictureframe_draw_canvas(PictureFrame *pictureFrame){ + MLV_draw_image(pictureFrame->canvas->mlv, pictureFrame->component.x_pos, pictureFrame->component.y_pos); +} + void pictureframe_print(Component *parameterSelf) { PictureFrame *self = (PictureFrame *) parameterSelf; - MLV_draw_image(self->canvas->mlv, self->component.x_pos, self->component.y_pos); - TriangleMap *p = self->morphing->first; - CartesianVector p1; - CartesianVector p2; - CartesianVector p3; - CartesianVector pointToPrint1; - CartesianVector pointToPrint2; - CartesianVector pointToPrint3; - while(p != NULL){ - p1 = self->cartesianMappingDivision(&(p->vertices[0])); - p2 = self->cartesianMappingDivision(&(p->vertices[1])); - p3 = self->cartesianMappingDivision(&(p->vertices[2])); + pictureframe_draw_canvas(self); + if (mode != WAITING_BUTTON_HIDE) { + TriangleMap *p = self->morphing->first; + CartesianVector p1; + CartesianVector p2; + CartesianVector p3; + CartesianVector pointToPrint1; + CartesianVector pointToPrint2; + CartesianVector pointToPrint3; + while (p != NULL) { + p1 = self->cartesianMappingDivision(&(p->vertices[0])); + p2 = self->cartesianMappingDivision(&(p->vertices[1])); + p3 = self->cartesianMappingDivision(&(p->vertices[2])); - pointToPrint1 = pictureframe_conversion_to_picture(p1.x,p1.y,self); - pointToPrint2 = pictureframe_conversion_to_picture(p2.x,p2.y,self); - pointToPrint3 = pictureframe_conversion_to_picture(p3.x,p3.y,self); + pointToPrint1 = pictureframe_conversion_to_picture(p1.x, p1.y, self); + pointToPrint2 = pictureframe_conversion_to_picture(p2.x, p2.y, self); + pointToPrint3 = pictureframe_conversion_to_picture(p3.x, p3.y, self); - MLV_draw_filled_circle(pointToPrint1.x,pointToPrint1.y,2,MLV_COLOR_RED); - MLV_draw_filled_circle(pointToPrint2.x,pointToPrint2.y,2,MLV_COLOR_RED); - MLV_draw_filled_circle(pointToPrint3.x,pointToPrint3.y,2,MLV_COLOR_RED); + MLV_draw_filled_circle(pointToPrint1.x, pointToPrint1.y, 2, MLV_COLOR_RED); + MLV_draw_filled_circle(pointToPrint2.x, pointToPrint2.y, 2, MLV_COLOR_RED); + MLV_draw_filled_circle(pointToPrint3.x, pointToPrint3.y, 2, MLV_COLOR_RED); - MLV_draw_line(pointToPrint1.x,pointToPrint1.y,pointToPrint2.x,pointToPrint2.y,MLV_COLOR_RED); - MLV_draw_line(pointToPrint1.x,pointToPrint1.y,pointToPrint3.x,pointToPrint3.y,MLV_COLOR_RED); - MLV_draw_line(pointToPrint3.x,pointToPrint3.y,pointToPrint2.x,pointToPrint2.y,MLV_COLOR_RED); - p = p->next; + MLV_draw_line(pointToPrint1.x, pointToPrint1.y, pointToPrint2.x, pointToPrint2.y, MLV_COLOR_RED); + MLV_draw_line(pointToPrint1.x, pointToPrint1.y, pointToPrint3.x, pointToPrint3.y, MLV_COLOR_RED); + MLV_draw_line(pointToPrint3.x, pointToPrint3.y, pointToPrint2.x, pointToPrint2.y, MLV_COLOR_RED); + p = p->next; + } } } @@ -72,8 +77,8 @@ CartesianVector pictureframe_conversion_to_picture(int x, int y, PictureFrame *p void pictureframe_click_handler_origin(int x_pos, int y_pos, Component *parameterSelf) { PictureFrame *self = (PictureFrame *) parameterSelf; if (pictureframe_is_selected(x_pos, y_pos, self) && mode == INSERT_ORIGIN) { - CartesianVector vector = pictureframe_conversion_to_origin(x_pos,y_pos,self); - MLV_draw_filled_circle(x_pos,y_pos,2,MLV_COLOR_BLUE); + CartesianVector vector = pictureframe_conversion_to_origin(x_pos, y_pos, self); + MLV_draw_filled_circle(x_pos, y_pos, 2, MLV_COLOR_BLUE); savedPoint = vector; MLV_actualise_window(); mode = INSERT_TARGET; @@ -83,16 +88,15 @@ void pictureframe_click_handler_origin(int x_pos, int y_pos, Component *paramete void pictureframe_click_handler_target(int x_pos, int y_pos, Component *parameterSelf) { PictureFrame *self = (PictureFrame *) parameterSelf; if (pictureframe_is_selected(x_pos, y_pos, self) && mode == INSERT_TARGET) { - CartesianVector vector = pictureframe_conversion_to_origin(x_pos,y_pos,self); - printf("(%d,%d) | (%d,%d)\n",savedPoint.x,savedPoint.y,vector.x,vector.y); - morphing_add_constraint(self->morphing,savedPoint,vector); - printf("OK\n"); + CartesianVector vector = pictureframe_conversion_to_origin(x_pos, y_pos, self); + morphing_add_constraint(self->morphing, savedPoint, vector); mode = PRINTING; } } void pictureframe_init(PictureFrame *pictureFrame, int width, int height, int x_pos, int y_pos, - CartesianMappingDivision cartesianMappingDivision, Morphing *morphing, Canvas *canvas,ClickHandler clickHandler) { + CartesianMappingDivision cartesianMappingDivision, Morphing *morphing, Canvas *canvas, + ClickHandler clickHandler) { assert(pictureFrame != NULL); assert(width > 0); assert(height > 0); -- cgit v1.2.3