From 2f3d8ebc9b5e10e56bed5da316f5ef098dda0997 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Wed, 3 Jan 2018 19:40:51 +0100 Subject: Updating documentation, cleaning includes, updating report --- src/gui/button.c | 44 ++++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 24 deletions(-) (limited to 'src/gui/button.c') diff --git a/src/gui/button.c b/src/gui/button.c index a55796d..35ac2ed 100644 --- a/src/gui/button.c +++ b/src/gui/button.c @@ -1,37 +1,28 @@ -#include #include +#include #include -#include #include -#include -#include +#include "gui/button.h" +#include "MLV/MLV_all.h" +#include "common/mem.h" -bool button_is_selected(int x, int y, Button *button) { + +static bool button_is_selected(int x, int y, Button *button) { 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; + return x >= x1 && x <= x2 && y >= y1 && y <= y2; } -void button_print(Component *parameterSelf) { +static 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(parameterSelf != NULL); - Button *self = (Button *) parameterSelf; - 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) { assert(parameterSelf != NULL); Button *self = (Button *) parameterSelf; @@ -66,7 +57,7 @@ void button_click_less_frame(int x, int y, Component *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); + sprintf(labelFrame, "%03d frames", frame); mode = PRINTING_BUTTONS; } } @@ -78,13 +69,13 @@ void button_click_more_frame(int x, int y, Component *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); + sprintf(labelFrame, "%03d frames", frame); mode = PRINTING_BUTTONS; } } } -void button_click_rendering(int x,int y, Component *parameterSelf) { +void button_click_rendering(int x, int y, Component *parameterSelf) { assert(parameterSelf != NULL); Button *self = (Button *) parameterSelf; if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) { @@ -96,14 +87,12 @@ void button_click_none(int x, int y, Component *parameterSelf) { assert(parameterSelf != NULL); } - -void -button_init(Button *button, const char *text, int sizeInterligne, int x_pos, int y_pos, ClickHandler clickHandler) { - assert(button != NULL); +Button *button_create(const char *text, int sizeInterligne, int x_pos, int y_pos, ClickHandler clickHandler) { assert(text != NULL); assert(sizeInterligne >= 0); assert(x_pos >= 0); assert(y_pos >= 0); + Button *button = malloc_or_die(sizeof(Button)); button->label = malloc_or_die(sizeof(char) * (strlen(text) + 1)); strcpy(button->label, text); button->sizeInterligne = sizeInterligne; @@ -112,4 +101,11 @@ button_init(Button *button, const char *text, int sizeInterligne, int x_pos, int button->component.y_pos = y_pos; button->component.print_method = button_print; button->component.click_handler = clickHandler; + return button; } + +void button_destroy(Button *button){ + assert(button != NULL); + free(button->label); + free(button); +} \ No newline at end of file -- cgit v1.2.3