diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/button.c | 75 | ||||
-rw-r--r-- | src/gui/component.c | 6 | ||||
-rw-r--r-- | src/gui/pictureframe.c | 64 |
3 files changed, 110 insertions, 35 deletions
diff --git a/src/gui/button.c b/src/gui/button.c index a1fa1cf..03addf8 100644 --- a/src/gui/button.c +++ b/src/gui/button.c | |||
@@ -32,21 +32,88 @@ void button_click_test(int x, int y, Component *parameterSelf) { | |||
32 | assert(y >= 0); | 32 | assert(y >= 0); |
33 | assert(parameterSelf != NULL); | 33 | assert(parameterSelf != NULL); |
34 | Button *self = (Button *) parameterSelf; | 34 | Button *self = (Button *) parameterSelf; |
35 | if (button_is_selected(x, y, self) && mode == WAITING_BUTTON) { | 35 | if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) { |
36 | printf("OK\n"); | ||
37 | } | 36 | } |
38 | } | 37 | } |
39 | 38 | ||
40 | void button_click_add_constraint(int x, int y, Component *parameterSelf){ | 39 | void button_click_add_constraint(int x, int y, Component *parameterSelf) { |
41 | assert(x >= 0); | 40 | assert(x >= 0); |
42 | assert(y >= 0); | 41 | assert(y >= 0); |
43 | assert(parameterSelf != NULL); | 42 | assert(parameterSelf != NULL); |
44 | Button *self = (Button *) parameterSelf; | 43 | Button *self = (Button *) parameterSelf; |
45 | if (button_is_selected(x, y, self) && mode == WAITING_BUTTON) { | 44 | if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) { |
46 | mode = INSERT_ORIGIN; | 45 | mode = INSERT_ORIGIN; |
47 | } | 46 | } |
48 | } | 47 | } |
49 | 48 | ||
49 | void button_click_show_hide(int x, int y, Component *parameterSelf) { | ||
50 | assert(x >= 0); | ||
51 | assert(y >= 0); | ||
52 | assert(parameterSelf != NULL); | ||
53 | Button *self = (Button *) parameterSelf; | ||
54 | if (button_is_selected(x, y, self)) { | ||
55 | if (mode == WAITING_BUTTON_SHOW) { | ||
56 | mode = WAITING_BUTTON_HIDE; | ||
57 | } else if (mode == WAITING_BUTTON_HIDE) { | ||
58 | mode = WAITING_BUTTON_SHOW; | ||
59 | } | ||
60 | } | ||
61 | } | ||
62 | |||
63 | void button_click_exit(int x, int y, Component *parameterSelf) { | ||
64 | assert(x >= 0); | ||
65 | assert(y >= 0); | ||
66 | assert(parameterSelf != NULL); | ||
67 | Button *self = (Button *) parameterSelf; | ||
68 | if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) { | ||
69 | mode = EXITING; | ||
70 | } | ||
71 | } | ||
72 | |||
73 | void button_click_less_frame(int x, int y, Component *parameterSelf) { | ||
74 | assert(x >= 0); | ||
75 | assert(y >= 0); | ||
76 | assert(parameterSelf != NULL); | ||
77 | Button *self = (Button *) parameterSelf; | ||
78 | if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) { | ||
79 | if (frame > 2) { | ||
80 | frame = frame / 2; | ||
81 | sprintf(labelFrame,"%03d frames", frame); | ||
82 | mode = PRINTING_BUTTONS; | ||
83 | } | ||
84 | } | ||
85 | } | ||
86 | |||
87 | void button_click_more_frame(int x, int y, Component *parameterSelf) { | ||
88 | assert(x >= 0); | ||
89 | assert(y >= 0); | ||
90 | assert(parameterSelf != NULL); | ||
91 | Button *self = (Button *) parameterSelf; | ||
92 | if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) { | ||
93 | if (frame < 256) { | ||
94 | frame = frame * 2; | ||
95 | sprintf(labelFrame,"%03d frames", frame); | ||
96 | mode = PRINTING_BUTTONS; | ||
97 | } | ||
98 | } | ||
99 | } | ||
100 | |||
101 | void button_click_rendering(int x,int y, Component *parameterSelf) { | ||
102 | assert(x >= 0); | ||
103 | assert(y >= 0); | ||
104 | assert(parameterSelf != NULL); | ||
105 | Button *self = (Button *) parameterSelf; | ||
106 | if (button_is_selected(x, y, self) && (mode == WAITING_BUTTON_SHOW || mode == WAITING_BUTTON_HIDE)) { | ||
107 | mode = RENDERING; | ||
108 | } | ||
109 | } | ||
110 | |||
111 | void button_click_none(int x, int y, Component *parameterSelf) { | ||
112 | assert(x >= 0); | ||
113 | assert(y >= 0); | ||
114 | assert(parameterSelf != NULL); | ||
115 | } | ||
116 | |||
50 | 117 | ||
51 | void | 118 | void |
52 | button_init(Button *button, const char *text, int sizeInterligne, int x_pos, int y_pos, ClickHandler clickHandler) { | 119 | button_init(Button *button, const char *text, int sizeInterligne, int x_pos, int y_pos, ClickHandler clickHandler) { |
diff --git a/src/gui/component.c b/src/gui/component.c index 07fb336..3eb31c5 100644 --- a/src/gui/component.c +++ b/src/gui/component.c | |||
@@ -1,3 +1,7 @@ | |||
1 | #include <gui/component.h> | 1 | #include <gui/component.h> |
2 | 2 | ||
3 | Mode mode = WAITING_BUTTON; | 3 | Mode mode = WAITING_BUTTON_SHOW; |
4 | |||
5 | int frame = 2; | ||
6 | |||
7 | char labelFrame[20]; | ||
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); |