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/button.c') 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 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 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/gui/button.c') 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; } -- 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 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/gui/button.c') 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; } -- 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 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 71 insertions(+), 4 deletions(-) (limited to 'src/gui/button.c') 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) { -- cgit v1.2.3