diff options
Diffstat (limited to 'src/gui/pictureframe.c')
-rw-r--r-- | src/gui/pictureframe.c | 64 |
1 files changed, 34 insertions, 30 deletions
diff --git a/src/gui/pictureframe.c b/src/gui/pictureframe.c index e4081a7..4126f59 100644 --- a/src/gui/pictureframe.c +++ b/src/gui/pictureframe.c | |||
@@ -1,7 +1,6 @@ | |||
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> | ||
5 | 4 | ||
6 | CartesianVector pictureframe_origin_split(const CartesianMapping *cartesianMapping) { | 5 | CartesianVector pictureframe_origin_split(const CartesianMapping *cartesianMapping) { |
7 | return cartesianMapping->origin; | 6 | return cartesianMapping->origin; |
@@ -11,33 +10,39 @@ CartesianVector pictureframe_target_split(const CartesianMapping *cartesianMappi | |||
11 | return cartesianMapping->target; | 10 | return cartesianMapping->target; |
12 | } | 11 | } |
13 | 12 | ||
13 | void pictureframe_draw_canvas(PictureFrame *pictureFrame){ | ||
14 | MLV_draw_image(pictureFrame->canvas->mlv, pictureFrame->component.x_pos, pictureFrame->component.y_pos); | ||
15 | } | ||
16 | |||
14 | void pictureframe_print(Component *parameterSelf) { | 17 | void pictureframe_print(Component *parameterSelf) { |
15 | PictureFrame *self = (PictureFrame *) parameterSelf; | 18 | PictureFrame *self = (PictureFrame *) parameterSelf; |
16 | MLV_draw_image(self->canvas->mlv, self->component.x_pos, self->component.y_pos); | 19 | pictureframe_draw_canvas(self); |
17 | TriangleMap *p = self->morphing->first; | 20 | if (mode != WAITING_BUTTON_HIDE) { |
18 | CartesianVector p1; | 21 | TriangleMap *p = self->morphing->first; |
19 | CartesianVector p2; | 22 | CartesianVector p1; |
20 | CartesianVector p3; | 23 | CartesianVector p2; |
21 | CartesianVector pointToPrint1; | 24 | CartesianVector p3; |
22 | CartesianVector pointToPrint2; | 25 | CartesianVector pointToPrint1; |
23 | CartesianVector pointToPrint3; | 26 | CartesianVector pointToPrint2; |
24 | while(p != NULL){ | 27 | CartesianVector pointToPrint3; |
25 | p1 = self->cartesianMappingDivision(&(p->vertices[0])); | 28 | while (p != NULL) { |
26 | p2 = self->cartesianMappingDivision(&(p->vertices[1])); | 29 | p1 = self->cartesianMappingDivision(&(p->vertices[0])); |
27 | p3 = self->cartesianMappingDivision(&(p->vertices[2])); | 30 | p2 = self->cartesianMappingDivision(&(p->vertices[1])); |
31 | p3 = self->cartesianMappingDivision(&(p->vertices[2])); | ||
28 | 32 | ||
29 | pointToPrint1 = pictureframe_conversion_to_picture(p1.x,p1.y,self); | 33 | pointToPrint1 = pictureframe_conversion_to_picture(p1.x, p1.y, self); |
30 | pointToPrint2 = pictureframe_conversion_to_picture(p2.x,p2.y,self); | 34 | pointToPrint2 = pictureframe_conversion_to_picture(p2.x, p2.y, self); |
31 | pointToPrint3 = pictureframe_conversion_to_picture(p3.x,p3.y,self); | 35 | pointToPrint3 = pictureframe_conversion_to_picture(p3.x, p3.y, self); |
32 | 36 | ||
33 | MLV_draw_filled_circle(pointToPrint1.x,pointToPrint1.y,2,MLV_COLOR_RED); | 37 | 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); | 38 | 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); | 39 | MLV_draw_filled_circle(pointToPrint3.x, pointToPrint3.y, 2, MLV_COLOR_RED); |
36 | 40 | ||
37 | MLV_draw_line(pointToPrint1.x,pointToPrint1.y,pointToPrint2.x,pointToPrint2.y,MLV_COLOR_RED); | 41 | 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); | 42 | 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); | 43 | MLV_draw_line(pointToPrint3.x, pointToPrint3.y, pointToPrint2.x, pointToPrint2.y, MLV_COLOR_RED); |
40 | p = p->next; | 44 | p = p->next; |
45 | } | ||
41 | } | 46 | } |
42 | } | 47 | } |
43 | 48 | ||
@@ -72,8 +77,8 @@ CartesianVector pictureframe_conversion_to_picture(int x, int y, PictureFrame *p | |||
72 | void pictureframe_click_handler_origin(int x_pos, int y_pos, Component *parameterSelf) { | 77 | void pictureframe_click_handler_origin(int x_pos, int y_pos, Component *parameterSelf) { |
73 | PictureFrame *self = (PictureFrame *) parameterSelf; | 78 | PictureFrame *self = (PictureFrame *) parameterSelf; |
74 | if (pictureframe_is_selected(x_pos, y_pos, self) && mode == INSERT_ORIGIN) { | 79 | if (pictureframe_is_selected(x_pos, y_pos, self) && mode == INSERT_ORIGIN) { |
75 | CartesianVector vector = pictureframe_conversion_to_origin(x_pos,y_pos,self); | 80 | CartesianVector vector = pictureframe_conversion_to_origin(x_pos, y_pos, self); |
76 | MLV_draw_filled_circle(x_pos,y_pos,2,MLV_COLOR_BLUE); | 81 | MLV_draw_filled_circle(x_pos, y_pos, 2, MLV_COLOR_BLUE); |
77 | savedPoint = vector; | 82 | savedPoint = vector; |
78 | MLV_actualise_window(); | 83 | MLV_actualise_window(); |
79 | mode = INSERT_TARGET; | 84 | mode = INSERT_TARGET; |
@@ -83,16 +88,15 @@ void pictureframe_click_handler_origin(int x_pos, int y_pos, Component *paramete | |||
83 | void pictureframe_click_handler_target(int x_pos, int y_pos, Component *parameterSelf) { | 88 | void pictureframe_click_handler_target(int x_pos, int y_pos, Component *parameterSelf) { |
84 | PictureFrame *self = (PictureFrame *) parameterSelf; | 89 | PictureFrame *self = (PictureFrame *) parameterSelf; |
85 | if (pictureframe_is_selected(x_pos, y_pos, self) && mode == INSERT_TARGET) { | 90 | if (pictureframe_is_selected(x_pos, y_pos, self) && mode == INSERT_TARGET) { |
86 | CartesianVector vector = pictureframe_conversion_to_origin(x_pos,y_pos,self); | 91 | 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); | 92 | morphing_add_constraint(self->morphing, savedPoint, vector); |
88 | morphing_add_constraint(self->morphing,savedPoint,vector); | ||
89 | printf("OK\n"); | ||
90 | mode = PRINTING; | 93 | mode = PRINTING; |
91 | } | 94 | } |
92 | } | 95 | } |
93 | 96 | ||
94 | void pictureframe_init(PictureFrame *pictureFrame, int width, int height, int x_pos, int y_pos, | 97 | void pictureframe_init(PictureFrame *pictureFrame, int width, int height, int x_pos, int y_pos, |
95 | CartesianMappingDivision cartesianMappingDivision, Morphing *morphing, Canvas *canvas,ClickHandler clickHandler) { | 98 | CartesianMappingDivision cartesianMappingDivision, Morphing *morphing, Canvas *canvas, |
99 | ClickHandler clickHandler) { | ||
96 | assert(pictureFrame != NULL); | 100 | assert(pictureFrame != NULL); |
97 | assert(width > 0); | 101 | assert(width > 0); |
98 | assert(height > 0); | 102 | assert(height > 0); |