diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/button.c | 15 | ||||
-rw-r--r-- | src/gui/component.c | 3 | ||||
-rw-r--r-- | src/gui/group.c | 3 | ||||
-rw-r--r-- | src/gui/pictureframe.c | 90 |
4 files changed, 95 insertions, 16 deletions
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 @@ | |||
6 | #include <MLV/MLV_all.h> | 6 | #include <MLV/MLV_all.h> |
7 | #include <gui/component.h> | 7 | #include <gui/component.h> |
8 | 8 | ||
9 | |||
10 | bool button_is_selected(int x, int y, Button *button) { | 9 | bool button_is_selected(int x, int y, Button *button) { |
11 | assert(x >= 0); | 10 | assert(x >= 0); |
12 | assert(y >= 0); | 11 | assert(y >= 0); |
@@ -33,11 +32,22 @@ void button_click_test(int x, int y, Component *parameterSelf) { | |||
33 | assert(y >= 0); | 32 | assert(y >= 0); |
34 | assert(parameterSelf != NULL); | 33 | assert(parameterSelf != NULL); |
35 | Button *self = (Button *) parameterSelf; | 34 | Button *self = (Button *) parameterSelf; |
36 | if (button_is_selected(x, y, self) && self->component.activated) { | 35 | if (button_is_selected(x, y, self) && mode == WAITING_BUTTON) { |
37 | printf("OK\n"); | 36 | printf("OK\n"); |
38 | } | 37 | } |
39 | } | 38 | } |
40 | 39 | ||
40 | void button_click_add_constraint(int x, int y, Component *parameterSelf){ | ||
41 | assert(x >= 0); | ||
42 | assert(y >= 0); | ||
43 | assert(parameterSelf != NULL); | ||
44 | Button *self = (Button *) parameterSelf; | ||
45 | if (button_is_selected(x, y, self) && mode == WAITING_BUTTON) { | ||
46 | mode = INSERT_ORIGIN; | ||
47 | } | ||
48 | } | ||
49 | |||
50 | |||
41 | void | 51 | void |
42 | button_init(Button *button, const char *text, int sizeInterligne, int x_pos, int y_pos, ClickHandler clickHandler) { | 52 | button_init(Button *button, const char *text, int sizeInterligne, int x_pos, int y_pos, ClickHandler clickHandler) { |
43 | assert(button != NULL); | 53 | assert(button != NULL); |
@@ -51,7 +61,6 @@ button_init(Button *button, const char *text, int sizeInterligne, int x_pos, int | |||
51 | MLV_get_size_of_adapted_text_box(text, sizeInterligne, &button->component.width, &button->component.height); | 61 | MLV_get_size_of_adapted_text_box(text, sizeInterligne, &button->component.width, &button->component.height); |
52 | button->component.x_pos = x_pos; | 62 | button->component.x_pos = x_pos; |
53 | button->component.y_pos = y_pos; | 63 | button->component.y_pos = y_pos; |
54 | button->component.activated = true; | ||
55 | button->component.print_method = button_print; | 64 | button->component.print_method = button_print; |
56 | button->component.click_handler = clickHandler; | 65 | button->component.click_handler = clickHandler; |
57 | } | 66 | } |
diff --git a/src/gui/component.c b/src/gui/component.c new file mode 100644 index 0000000..07fb336 --- /dev/null +++ b/src/gui/component.c | |||
@@ -0,0 +1,3 @@ | |||
1 | #include <gui/component.h> | ||
2 | |||
3 | Mode mode = WAITING_BUTTON; | ||
diff --git a/src/gui/group.c b/src/gui/group.c index 11a0583..af9abac 100644 --- a/src/gui/group.c +++ b/src/gui/group.c | |||
@@ -22,7 +22,7 @@ void group_click_handler(int x_pos, int y_pos, Component *parameterSelf) { | |||
22 | assert(parameterSelf != NULL); | 22 | assert(parameterSelf != NULL); |
23 | Group *self = (Group *) parameterSelf; | 23 | Group *self = (Group *) parameterSelf; |
24 | 24 | ||
25 | if (self->group_head != NULL && self->component.activated) { | 25 | if (self->group_head != NULL) { |
26 | GroupElement *p = self->group_head; | 26 | GroupElement *p = self->group_head; |
27 | while (p != NULL) { | 27 | while (p != NULL) { |
28 | p->sub_component->click_handler(x_pos, y_pos, p->sub_component); | 28 | p->sub_component->click_handler(x_pos, y_pos, p->sub_component); |
@@ -42,7 +42,6 @@ void group_init(Group *group, int width, int height, int x_pos, int y_pos, int m | |||
42 | group->component.height = height; | 42 | group->component.height = height; |
43 | group->component.x_pos = x_pos; | 43 | group->component.x_pos = x_pos; |
44 | group->component.y_pos = y_pos; | 44 | group->component.y_pos = y_pos; |
45 | group->component.activated = true; | ||
46 | group->component.print_method = group_print; | 45 | group->component.print_method = group_print; |
47 | group->component.click_handler = group_click_handler; | 46 | group->component.click_handler = group_click_handler; |
48 | group->margin = margin; | 47 | group->margin = margin; |
diff --git a/src/gui/pictureframe.c b/src/gui/pictureframe.c index 543ba4c..e4081a7 100644 --- a/src/gui/pictureframe.c +++ b/src/gui/pictureframe.c | |||
@@ -1,29 +1,98 @@ | |||
1 | #include <assert.h> | 1 | #include <assert.h> |
2 | #include <gui/pictureframe.h> | 2 | #include <gui/pictureframe.h> |
3 | #include <MLV/MLV_all.h> | 3 | #include <MLV/MLV_all.h> |
4 | #include <common/time.h> | ||
4 | 5 | ||
5 | CartesianVector pictureframe_origin_split(const CartesianMapping *cartesianMapping) { | 6 | CartesianVector pictureframe_origin_split(const CartesianMapping *cartesianMapping) { |
6 | 7 | return cartesianMapping->origin; | |
7 | } | 8 | } |
8 | 9 | ||
9 | CartesianVector pictureframe_target_split(const CartesianMapping *cartesianMapping) { | 10 | CartesianVector pictureframe_target_split(const CartesianMapping *cartesianMapping) { |
10 | 11 | return cartesianMapping->target; | |
11 | } | 12 | } |
12 | 13 | ||
13 | void pictureframe_print(Component *parameterSelf) { | 14 | void pictureframe_print(Component *parameterSelf) { |
14 | PictureFrame *self = (PictureFrame *) parameterSelf; | 15 | PictureFrame *self = (PictureFrame *) parameterSelf; |
15 | /*DEBUG*/ | 16 | MLV_draw_image(self->canvas->mlv, self->component.x_pos, self->component.y_pos); |
16 | MLV_draw_filled_rectangle(self->component.x_pos, self->component.y_pos, self->component.width, self->component.height, | 17 | TriangleMap *p = self->morphing->first; |
17 | MLV_COLOR_RED); | 18 | CartesianVector p1; |
18 | /**/ | 19 | CartesianVector p2; |
20 | CartesianVector p3; | ||
21 | CartesianVector pointToPrint1; | ||
22 | CartesianVector pointToPrint2; | ||
23 | CartesianVector pointToPrint3; | ||
24 | while(p != NULL){ | ||
25 | p1 = self->cartesianMappingDivision(&(p->vertices[0])); | ||
26 | p2 = self->cartesianMappingDivision(&(p->vertices[1])); | ||
27 | p3 = self->cartesianMappingDivision(&(p->vertices[2])); | ||
28 | |||
29 | pointToPrint1 = pictureframe_conversion_to_picture(p1.x,p1.y,self); | ||
30 | pointToPrint2 = pictureframe_conversion_to_picture(p2.x,p2.y,self); | ||
31 | pointToPrint3 = pictureframe_conversion_to_picture(p3.x,p3.y,self); | ||
32 | |||
33 | MLV_draw_filled_circle(pointToPrint1.x,pointToPrint1.y,2,MLV_COLOR_RED); | ||
34 | MLV_draw_filled_circle(pointToPrint2.x,pointToPrint2.y,2,MLV_COLOR_RED); | ||
35 | MLV_draw_filled_circle(pointToPrint3.x,pointToPrint3.y,2,MLV_COLOR_RED); | ||
36 | |||
37 | MLV_draw_line(pointToPrint1.x,pointToPrint1.y,pointToPrint2.x,pointToPrint2.y,MLV_COLOR_RED); | ||
38 | MLV_draw_line(pointToPrint1.x,pointToPrint1.y,pointToPrint3.x,pointToPrint3.y,MLV_COLOR_RED); | ||
39 | MLV_draw_line(pointToPrint3.x,pointToPrint3.y,pointToPrint2.x,pointToPrint2.y,MLV_COLOR_RED); | ||
40 | p = p->next; | ||
41 | } | ||
42 | } | ||
43 | |||
44 | bool pictureframe_is_selected(int x, int y, PictureFrame *pictureFrame) { | ||
45 | assert(x >= 0); | ||
46 | assert(y >= 0); | ||
47 | assert(pictureFrame != NULL); | ||
48 | int x1 = pictureFrame->component.x_pos; | ||
49 | int y1 = pictureFrame->component.y_pos; | ||
50 | int x2 = pictureFrame->component.x_pos + pictureFrame->component.width; | ||
51 | int y2 = pictureFrame->component.y_pos + pictureFrame->component.height; | ||
52 | if (x >= x1 && x <= x2 && y >= y1 && y <= y2) { | ||
53 | return true; | ||
54 | } | ||
55 | return false; | ||
56 | } | ||
57 | |||
58 | CartesianVector pictureframe_conversion_to_origin(int x, int y, PictureFrame *pictureFrame) { | ||
59 | CartesianVector vector; | ||
60 | vector.x = x - pictureFrame->component.x_pos; | ||
61 | vector.y = y - pictureFrame->component.y_pos; | ||
62 | return vector; | ||
63 | } | ||
64 | |||
65 | CartesianVector pictureframe_conversion_to_picture(int x, int y, PictureFrame *pictureFrame) { | ||
66 | CartesianVector vector; | ||
67 | vector.x = x + pictureFrame->component.x_pos; | ||
68 | vector.y = y + pictureFrame->component.y_pos; | ||
69 | return vector; | ||
70 | } | ||
71 | |||
72 | void pictureframe_click_handler_origin(int x_pos, int y_pos, Component *parameterSelf) { | ||
73 | PictureFrame *self = (PictureFrame *) parameterSelf; | ||
74 | if (pictureframe_is_selected(x_pos, y_pos, self) && mode == INSERT_ORIGIN) { | ||
75 | CartesianVector vector = pictureframe_conversion_to_origin(x_pos,y_pos,self); | ||
76 | MLV_draw_filled_circle(x_pos,y_pos,2,MLV_COLOR_BLUE); | ||
77 | savedPoint = vector; | ||
78 | MLV_actualise_window(); | ||
79 | mode = INSERT_TARGET; | ||
80 | } | ||
19 | } | 81 | } |
20 | 82 | ||
21 | void pictureframe_click_handler(int x_pos, int y_pos, Component *parameterSelf) { | 83 | void pictureframe_click_handler_target(int x_pos, int y_pos, Component *parameterSelf) { |
22 | printf("ClickHandler pictureframe activated \n"); | 84 | PictureFrame *self = (PictureFrame *) parameterSelf; |
85 | if (pictureframe_is_selected(x_pos, y_pos, self) && mode == INSERT_TARGET) { | ||
86 | CartesianVector vector = pictureframe_conversion_to_origin(x_pos,y_pos,self); | ||
87 | printf("(%d,%d) | (%d,%d)\n",savedPoint.x,savedPoint.y,vector.x,vector.y); | ||
88 | morphing_add_constraint(self->morphing,savedPoint,vector); | ||
89 | printf("OK\n"); | ||
90 | mode = PRINTING; | ||
91 | } | ||
23 | } | 92 | } |
24 | 93 | ||
25 | void pictureframe_init(PictureFrame *pictureFrame, int width, int height, int x_pos, int y_pos, | 94 | void pictureframe_init(PictureFrame *pictureFrame, int width, int height, int x_pos, int y_pos, |
26 | CartesianMappingDivision cartesianMappingDivision, Morphing *morphing, Canvas *canvas) { | 95 | CartesianMappingDivision cartesianMappingDivision, Morphing *morphing, Canvas *canvas,ClickHandler clickHandler) { |
27 | assert(pictureFrame != NULL); | 96 | assert(pictureFrame != NULL); |
28 | assert(width > 0); | 97 | assert(width > 0); |
29 | assert(height > 0); | 98 | assert(height > 0); |
@@ -36,9 +105,8 @@ void pictureframe_init(PictureFrame *pictureFrame, int width, int height, int x_ | |||
36 | pictureFrame->component.height = height; | 105 | pictureFrame->component.height = height; |
37 | pictureFrame->component.x_pos = x_pos; | 106 | pictureFrame->component.x_pos = x_pos; |
38 | pictureFrame->component.y_pos = y_pos; | 107 | pictureFrame->component.y_pos = y_pos; |
39 | pictureFrame->component.activated = true; | ||
40 | pictureFrame->component.print_method = pictureframe_print; | 108 | pictureFrame->component.print_method = pictureframe_print; |
41 | pictureFrame->component.click_handler = pictureframe_click_handler; | 109 | pictureFrame->component.click_handler = clickHandler; |
42 | pictureFrame->morphing = morphing; | 110 | pictureFrame->morphing = morphing; |
43 | pictureFrame->canvas = canvas; | 111 | pictureFrame->canvas = canvas; |
44 | pictureFrame->cartesianMappingDivision = cartesianMappingDivision; | 112 | pictureFrame->cartesianMappingDivision = cartesianMappingDivision; |