diff options
author | Adam NAILI | 2018-01-03 19:40:51 +0100 |
---|---|---|
committer | Adam NAILI | 2018-01-03 19:40:51 +0100 |
commit | 2f3d8ebc9b5e10e56bed5da316f5ef098dda0997 (patch) | |
tree | e2df4b6eaf81cb72f6fef75f6cf7324b0e671f23 /src/gui | |
parent | 54dac24c8f7be833124a90bafdca78810fc0d96a (diff) | |
download | morpher-2f3d8ebc9b5e10e56bed5da316f5ef098dda0997.tar.gz |
Updating documentation, cleaning includes, updating report
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/button.c | 44 | ||||
-rw-r--r-- | src/gui/gui.c | 97 | ||||
-rw-r--r-- | src/gui/pictureframe.c | 76 | ||||
-rw-r--r-- | src/gui/window.c | 35 |
4 files changed, 122 insertions, 130 deletions
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 @@ | |||
1 | #include <gui/button.h> | ||
2 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <stdbool.h> | ||
3 | #include <assert.h> | 3 | #include <assert.h> |
4 | #include <common/mem.h> | ||
5 | #include <string.h> | 4 | #include <string.h> |
6 | #include <MLV/MLV_all.h> | 5 | #include "gui/button.h" |
7 | #include <gui/component.h> | 6 | #include "MLV/MLV_all.h" |
7 | #include "common/mem.h" | ||
8 | 8 | ||
9 | bool button_is_selected(int x, int y, Button *button) { | 9 | |
10 | static bool button_is_selected(int x, int y, Button *button) { | ||
10 | assert(button != NULL); | 11 | assert(button != NULL); |
11 | int x1 = button->component.x_pos; | 12 | int x1 = button->component.x_pos; |
12 | int y1 = button->component.y_pos; | 13 | int y1 = button->component.y_pos; |
13 | int x2 = button->component.x_pos + button->component.width; | 14 | int x2 = button->component.x_pos + button->component.width; |
14 | int y2 = button->component.y_pos + button->component.height; | 15 | int y2 = button->component.y_pos + button->component.height; |
15 | if (x >= x1 && x <= x2 && y >= y1 && y <= y2) { | 16 | return x >= x1 && x <= x2 && y >= y1 && y <= y2; |
16 | return true; | ||
17 | } | ||
18 | return false; | ||
19 | } | 17 | } |
20 | 18 | ||
21 | void button_print(Component *parameterSelf) { | 19 | static void button_print(Component *parameterSelf) { |
22 | assert(parameterSelf != NULL); | 20 | assert(parameterSelf != NULL); |
23 | Button *self = (Button *) parameterSelf; | 21 | Button *self = (Button *) parameterSelf; |
24 | MLV_draw_adapted_text_box(self->component.x_pos, self->component.y_pos, self->label, self->sizeInterligne, | 22 | MLV_draw_adapted_text_box(self->component.x_pos, self->component.y_pos, self->label, self->sizeInterligne, |
25 | MLV_COLOR_BLACK, MLV_COLOR_WHITE, MLV_COLOR_DARK_GREY, MLV_TEXT_CENTER); | 23 | MLV_COLOR_BLACK, MLV_COLOR_WHITE, MLV_COLOR_DARK_GREY, MLV_TEXT_CENTER); |
26 | } | 24 | } |
27 | 25 | ||
28 | void button_click_test(int x, int y, Component *parameterSelf) { | ||
29 | assert(parameterSelf != NULL); | ||
30 | Button *self = (Button *) parameterSelf; | ||
31 | if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) { | ||
32 | } | ||
33 | } | ||
34 | |||
35 | void button_click_add_constraint(int x, int y, Component *parameterSelf) { | 26 | void button_click_add_constraint(int x, int y, Component *parameterSelf) { |
36 | assert(parameterSelf != NULL); | 27 | assert(parameterSelf != NULL); |
37 | Button *self = (Button *) parameterSelf; | 28 | Button *self = (Button *) parameterSelf; |
@@ -66,7 +57,7 @@ void button_click_less_frame(int x, int y, Component *parameterSelf) { | |||
66 | if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) { | 57 | if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) { |
67 | if (frame > 2) { | 58 | if (frame > 2) { |
68 | frame = frame / 2; | 59 | frame = frame / 2; |
69 | sprintf(labelFrame,"%03d frames", frame); | 60 | sprintf(labelFrame, "%03d frames", frame); |
70 | mode = PRINTING_BUTTONS; | 61 | mode = PRINTING_BUTTONS; |
71 | } | 62 | } |
72 | } | 63 | } |
@@ -78,13 +69,13 @@ void button_click_more_frame(int x, int y, Component *parameterSelf) { | |||
78 | if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) { | 69 | if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) { |
79 | if (frame < 256) { | 70 | if (frame < 256) { |
80 | frame = frame * 2; | 71 | frame = frame * 2; |
81 | sprintf(labelFrame,"%03d frames", frame); | 72 | sprintf(labelFrame, "%03d frames", frame); |
82 | mode = PRINTING_BUTTONS; | 73 | mode = PRINTING_BUTTONS; |
83 | } | 74 | } |
84 | } | 75 | } |
85 | } | 76 | } |
86 | 77 | ||
87 | void button_click_rendering(int x,int y, Component *parameterSelf) { | 78 | void button_click_rendering(int x, int y, Component *parameterSelf) { |
88 | assert(parameterSelf != NULL); | 79 | assert(parameterSelf != NULL); |
89 | Button *self = (Button *) parameterSelf; | 80 | Button *self = (Button *) parameterSelf; |
90 | if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) { | 81 | 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) { | |||
96 | assert(parameterSelf != NULL); | 87 | assert(parameterSelf != NULL); |
97 | } | 88 | } |
98 | 89 | ||
99 | 90 | Button *button_create(const char *text, int sizeInterligne, int x_pos, int y_pos, ClickHandler clickHandler) { | |
100 | void | ||
101 | button_init(Button *button, const char *text, int sizeInterligne, int x_pos, int y_pos, ClickHandler clickHandler) { | ||
102 | assert(button != NULL); | ||
103 | assert(text != NULL); | 91 | assert(text != NULL); |
104 | assert(sizeInterligne >= 0); | 92 | assert(sizeInterligne >= 0); |
105 | assert(x_pos >= 0); | 93 | assert(x_pos >= 0); |
106 | assert(y_pos >= 0); | 94 | assert(y_pos >= 0); |
95 | Button *button = malloc_or_die(sizeof(Button)); | ||
107 | button->label = malloc_or_die(sizeof(char) * (strlen(text) + 1)); | 96 | button->label = malloc_or_die(sizeof(char) * (strlen(text) + 1)); |
108 | strcpy(button->label, text); | 97 | strcpy(button->label, text); |
109 | button->sizeInterligne = sizeInterligne; | 98 | button->sizeInterligne = sizeInterligne; |
@@ -112,4 +101,11 @@ button_init(Button *button, const char *text, int sizeInterligne, int x_pos, int | |||
112 | button->component.y_pos = y_pos; | 101 | button->component.y_pos = y_pos; |
113 | button->component.print_method = button_print; | 102 | button->component.print_method = button_print; |
114 | button->component.click_handler = clickHandler; | 103 | button->component.click_handler = clickHandler; |
104 | return button; | ||
115 | } | 105 | } |
106 | |||
107 | void button_destroy(Button *button){ | ||
108 | assert(button != NULL); | ||
109 | free(button->label); | ||
110 | free(button); | ||
111 | } \ No newline at end of file | ||
diff --git a/src/gui/gui.c b/src/gui/gui.c index 3982f68..ced2661 100644 --- a/src/gui/gui.c +++ b/src/gui/gui.c | |||
@@ -1,22 +1,18 @@ | |||
1 | #include <gui/window.h> | 1 | #include "gui/window.h" |
2 | #include <gui/gui.h> | 2 | #include "gui/gui.h" |
3 | #include <common/mem.h> | 3 | #include "common/mem.h" |
4 | #include <MLV/MLV_all.h> | 4 | #include "MLV/MLV_all.h" |
5 | #include <gui/button.h> | ||
6 | 5 | ||
7 | 6 | ||
8 | GUI *gui_init(const char *fpath1, const char *fpath2) { | 7 | GUI *gui_create(const char *fpath1, const char *fpath2) { |
9 | GUI *gui = malloc_or_die(sizeof(GUI)); | 8 | GUI *gui = malloc_or_die(sizeof(GUI)); |
10 | 9 | gui->window = window_create(500, 500, "Morphing"); | |
11 | gui->window = malloc_or_die(sizeof(Window)); | ||
12 | window_init(gui->window, 500, 500, "Morphing"); | ||
13 | window_create(gui->window); | ||
14 | gui->canvasSrc = canvas_create_from_image(fpath1); | 10 | gui->canvasSrc = canvas_create_from_image(fpath1); |
15 | gui->canvasTrg = canvas_create_from_image(fpath2); | 11 | gui->canvasTrg = canvas_create_from_image(fpath2); |
16 | if (gui->canvasSrc->mlv == NULL || gui->canvasTrg->mlv == NULL) { | 12 | if (gui->canvasSrc->mlv == NULL || gui->canvasTrg->mlv == NULL) { |
17 | canvas_destroy(gui->canvasSrc); | 13 | canvas_destroy(gui->canvasSrc); |
18 | canvas_destroy(gui->canvasTrg); | 14 | canvas_destroy(gui->canvasTrg); |
19 | /*window_free(gui->window);*/ | 15 | window_destroy(gui->window); |
20 | fprintf(stderr, "Impossible to create an image from the path given. Verify the two paths.\n"); | 16 | fprintf(stderr, "Impossible to create an image from the path given. Verify the two paths.\n"); |
21 | exit(-4); | 17 | exit(-4); |
22 | } | 18 | } |
@@ -31,7 +27,7 @@ GUI *gui_init(const char *fpath1, const char *fpath2) { | |||
31 | if (canvasSrcWidth != canvasTrgWidth || canvasSrcHeight != canvasTrgHeight) { | 27 | if (canvasSrcWidth != canvasTrgWidth || canvasSrcHeight != canvasTrgHeight) { |
32 | canvas_destroy(gui->canvasSrc); | 28 | canvas_destroy(gui->canvasSrc); |
33 | canvas_destroy(gui->canvasTrg); | 29 | canvas_destroy(gui->canvasTrg); |
34 | window_free(gui->window); | 30 | window_destroy(gui->window); |
35 | fprintf(stderr, "The two pictures do not have the same size\n"); | 31 | fprintf(stderr, "The two pictures do not have the same size\n"); |
36 | exit(-5); | 32 | exit(-5); |
37 | } | 33 | } |
@@ -41,14 +37,6 @@ GUI *gui_init(const char *fpath1, const char *fpath2) { | |||
41 | 37 | ||
42 | MLV_change_window_size((unsigned int) gui->window->width, (unsigned int) gui->window->height); | 38 | MLV_change_window_size((unsigned int) gui->window->width, (unsigned int) gui->window->height); |
43 | 39 | ||
44 | gui->button1 = malloc_or_die(sizeof(Button)); | ||
45 | gui->button2 = malloc_or_die(sizeof(Button)); | ||
46 | gui->button3 = malloc_or_die(sizeof(Button)); | ||
47 | gui->button4 = malloc_or_die(sizeof(Button)); | ||
48 | gui->button5 = malloc_or_die(sizeof(Button)); | ||
49 | gui->button6 = malloc_or_die(sizeof(Button)); | ||
50 | gui->button7 = malloc_or_die(sizeof(Button)); | ||
51 | |||
52 | gui->pictureFrame1 = malloc_or_die(sizeof(PictureFrame)); | 40 | gui->pictureFrame1 = malloc_or_die(sizeof(PictureFrame)); |
53 | gui->pictureFrame2 = malloc_or_die(sizeof(PictureFrame)); | 41 | gui->pictureFrame2 = malloc_or_die(sizeof(PictureFrame)); |
54 | 42 | ||
@@ -56,20 +44,22 @@ GUI *gui_init(const char *fpath1, const char *fpath2) { | |||
56 | 44 | ||
57 | 45 | ||
58 | sprintf(labelFrame, "%03d frames", frame); | 46 | sprintf(labelFrame, "%03d frames", frame); |
59 | button_init(gui->button1, "Add constraint point", 10, 0, 0, button_click_add_constraint); | 47 | gui->button1 = button_create("Add constraint point", 10, 0, 0, button_click_add_constraint); |
60 | button_init(gui->button2, "Show/Hide", 10, 0, 0, button_click_show_hide); | 48 | gui->button2 = button_create("Show/Hide", 10, 0, 0, button_click_show_hide); |
61 | button_init(gui->button3, "Start rendering", 10, 0, 0, button_click_rendering); | 49 | gui->button3 = button_create("Start rendering", 10, 0, 0, button_click_rendering); |
62 | button_init(gui->button4, "<<<", 10, 0, 0, button_click_less_frame); | 50 | gui->button4 = button_create("<<<", 10, 0, 0, button_click_less_frame); |
63 | button_init(gui->button5, labelFrame, 10, 0, 0, button_click_none); | 51 | gui->button5 = button_create(labelFrame, 10, 0, 0, button_click_none); |
64 | button_init(gui->button6, ">>>", 10, 0, 0, button_click_more_frame); | 52 | gui->button6 = button_create(">>>", 10, 0, 0, button_click_more_frame); |
65 | button_init(gui->button7, "Exit", 10, 0, 0, button_click_exit); | 53 | gui->button7 = button_create("Exit", 10, 0, 0, button_click_exit); |
66 | 54 | ||
67 | pictureframe_init(gui->pictureFrame1, canvasSrcWidth, canvasSrcHeight, 0, 0, pictureframe_origin_split, gui->morphing, | 55 | gui->pictureFrame1 = pictureframe_create(canvasSrcWidth, canvasSrcHeight, 0, 0, pictureframe_origin_split, |
68 | gui->canvasSrc, | 56 | gui->morphing, |
69 | pictureframe_click_handler_origin); | 57 | gui->canvasSrc, |
70 | pictureframe_init(gui->pictureFrame2, canvasSrcWidth, canvasSrcHeight, 0, 0, pictureframe_target_split, gui->morphing, | 58 | pictureframe_click_handler_origin); |
71 | gui->canvasTrg, | 59 | gui->pictureFrame2 = pictureframe_create(canvasSrcWidth, canvasSrcHeight, 0, 0, pictureframe_target_split, |
72 | pictureframe_click_handler_target); | 60 | gui->morphing, |
61 | gui->canvasTrg, | ||
62 | pictureframe_click_handler_target); | ||
73 | 63 | ||
74 | window_add_pictureframe(gui->window, gui->pictureFrame1); | 64 | window_add_pictureframe(gui->window, gui->pictureFrame1); |
75 | window_add_pictureframe(gui->window, gui->pictureFrame2); | 65 | window_add_pictureframe(gui->window, gui->pictureFrame2); |
@@ -89,8 +79,13 @@ GUI *gui_init(const char *fpath1, const char *fpath2) { | |||
89 | } | 79 | } |
90 | 80 | ||
91 | void gui_handle_event(GUI *gui) { | 81 | void gui_handle_event(GUI *gui) { |
92 | window_click_keyboard_handler(gui->window, &gui->keyboardButton, &gui->keyboardModifier, &gui->unicode, &gui->mouse_x, | 82 | MLV_Keyboard_button keyboardButton; |
93 | &gui->mouse_y); | 83 | MLV_Keyboard_modifier keyboardModifier; |
84 | int unicode; | ||
85 | int mouse_x; | ||
86 | int mouse_y; | ||
87 | window_click_keyboard_handler(gui->window, &keyboardButton, &keyboardModifier, &unicode, &mouse_x, | ||
88 | &mouse_y); | ||
94 | switch (mode) { | 89 | switch (mode) { |
95 | case PRINTING: | 90 | case PRINTING: |
96 | window_print_pictureframes(gui->window); | 91 | window_print_pictureframes(gui->window); |
@@ -103,8 +98,9 @@ void gui_handle_event(GUI *gui) { | |||
103 | window_print_pictureframes(gui->window); | 98 | window_print_pictureframes(gui->window); |
104 | break; | 99 | break; |
105 | case PRINTING_BUTTONS: |