summaryrefslogtreecommitdiff
path: root/src/gui/gui.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/gui.c')
-rw-r--r--src/gui/gui.c97
1 files changed, 47 insertions, 50 deletions
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
8GUI *gui_init(const char *fpath1, const char *fpath2) { 7GUI *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
91void gui_handle_event(GUI *gui) { 81void 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: 100 case PRINTING_BUTTONS:
106 button_init(gui->button5, labelFrame, 10, gui->button5->component.x_pos, gui->button5->component.y_pos, 101 free(gui->button5->label);
107 button_click_none); 102 gui->button5->label = malloc_or_die(sizeof(char) * (strlen(labelFrame) + 1));
103 strcpy(gui->button5->label, labelFrame);
108 window_print_buttons(gui->window); 104 window_print_buttons(gui->window);
109 mode = WAITING_BUTTON_SHOW; 105 mode = WAITING_BUTTON_SHOW;
110 break; 106 break;
@@ -112,7 +108,7 @@ void gui_handle_event(GUI *gui) {
112 window_rendering(gui->window, gui->pictureFrame1, gui->canvasSrc, gui->canvasTrg, gui->morphing); 108 window_rendering(gui->window, gui->pictureFrame1, gui->canvasSrc, gui->canvasTrg, gui->morphing);
113 break; 109 break;
114 case INSERT_TARGET: 110 case INSERT_TARGET:
115 if (gui->keyboardButton == MLV_KEYBOARD_ESCAPE) { 111 if (keyboardButton == MLV_KEYBOARD_ESCAPE) {
116 window_print_pictureframes(gui->window); 112 window_print_pictureframes(gui->window);
117 mode = WAITING_BUTTON_SHOW; 113 mode = WAITING_BUTTON_SHOW;
118 } 114 }
@@ -122,19 +118,20 @@ void gui_handle_event(GUI *gui) {
122 } 118 }
123} 119}
124 120
125void gui_free(GUI *gui) { 121void gui_destroy(GUI *gui) {
126 window_free(gui->window); 122 window_destroy(gui->window);
127 canvas_destroy(gui->canvasSrc); 123 canvas_destroy(gui->canvasSrc);
128 canvas_destroy(gui->canvasTrg); 124 canvas_destroy(gui->canvasTrg);
129 morphing_destroy(gui->morphing); 125 morphing_destroy(gui->morphing);
130 126
131 free(gui->button1); 127 button_destroy(gui->button1);
132 free(gui->button2); 128 button_destroy(gui->button2);
133 free(gui->button3); 129 button_destroy(gui->button3);
134 free(gui->button4); 130 button_destroy(gui->button4);
135 free(gui->button5); 131 button_destroy(gui->button5);
136 free(gui->button6); 132 button_destroy(gui->button6);
137 free(gui->button7); 133 button_destroy(gui->button7);
138 free(gui->pictureFrame1); 134
139 free(gui->pictureFrame2); 135 pictureframe_destroy(gui->pictureFrame1);
136 pictureframe_destroy(gui->pictureFrame2);
140} \ No newline at end of file 137} \ No newline at end of file