summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam NAILI2017-12-22 18:31:33 +0100
committerAdam NAILI2017-12-22 18:31:33 +0100
commita05d3ad97d513c03d671059a5bae18487af23e24 (patch)
treee5ff2cf856974f1d535937ab7ca96772a56a323c /src
parenta42fdf7d5c9712297f1bbe3dd0951baa8ee32447 (diff)
downloadmorpher-a05d3ad97d513c03d671059a5bae18487af23e24.tar.gz
Updating doc of button, implementing button_is_selected, button_print, button_click_test (debug click handling), button_init
Diffstat (limited to 'src')
-rw-r--r--src/gui/button.c56
1 files changed, 56 insertions, 0 deletions
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 @@
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
10bool button_is_selected(int x, int y, Button *button) {
11 assert(x >= 0);
12 assert(y >= 0);
13 assert(button != NULL);
14 int x1 = button->component.x_pos;
15 int y1 = button->component.y_pos;
16 int x2 = button->component.x_pos + button->component.width;
17 int y2 = button->component.y_pos + button->component.height;
18 if (x >= x1 && x <= x2 && y >= y1 && y <= y2) {
19 return true;
20 }
21 return false;
22}
23
24void button_print(Component *parameterSelf) {
25 assert(parameterSelf != NULL);
26 Button *self = (Button *) parameterSelf;
27 MLV_draw_adapted_text_box(self->component.x_pos, self->component.y_pos, self->label, self->sizeInterligne,
28 MLV_COLOR_BLACK, MLV_COLOR_WHITE, MLV_COLOR_DARK_GREY, MLV_TEXT_CENTER);
29}
30
31void button_click_test(int x, int y, Component *parameterSelf) {
32 assert(x >= 0);
33 assert(y >= 0);
34 assert(parameterSelf != NULL);
35 Button *self = (Button *) parameterSelf;
36 if (button_is_selected(x, y, self)) {
37 printf("OK\n");
38 }
39}
40
41void
42button_init(Button *button, const char *text, int sizeInterligne, int x_pos, int y_pos, ClickHandler clickHandler) {
43 assert(button != NULL);
44 assert(text != NULL);
45 assert(sizeInterligne >= 0);
46 assert(x_pos >= 0);
47 assert(y_pos >= 0);
48 button->label = malloc_or_die(sizeof(char) * (strlen(text) + 1));
49 strcpy(button->label, text);
50 button->sizeInterligne = sizeInterligne;
51 MLV_get_size_of_adapted_text_box(text, sizeInterligne, &button->component.width, &button->component.height);
52 button->component.x_pos = x_pos;
53 button->component.y_pos = y_pos;
54 button->component.print_method = button_print;
55 button->component.click_handler = clickHandler;
56}