diff options
-rw-r--r-- | include/gui/button.h | 3 | ||||
-rw-r--r-- | include/gui/component.h | 6 | ||||
-rw-r--r-- | include/gui/pictureframe.h | 38 | ||||
-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 | ||||
-rw-r--r-- | test/gui/group.c | 2 | ||||
-rw-r--r-- | test/gui/pictureframe.c | 35 |
9 files changed, 160 insertions, 35 deletions
diff --git a/include/gui/button.h b/include/gui/button.h index 6f91e37..26d7970 100644 --- a/include/gui/button.h +++ b/include/gui/button.h | |||
@@ -1,6 +1,5 @@ | |||
1 | #ifndef UPEM_MORPHING_BUTTON | 1 | #ifndef UPEM_MORPHING_BUTTON |
2 | #define UPEM_MORPHING_BUTTON | 2 | #define UPEM_MORPHING_BUTTON |
3 | |||
4 | /** | 3 | /** |
5 | * File: button.h | 4 | * File: button.h |
6 | * Buttons handling | 5 | * Buttons handling |
@@ -58,6 +57,7 @@ void button_print(Component *parameterSelf); | |||
58 | */ | 57 | */ |
59 | void button_click_test(int x, int y, Component *parameterSelf); | 58 | void button_click_test(int x, int y, Component *parameterSelf); |
60 | 59 | ||
60 | void button_click_add_constraint(int x, int y, Component *parameterSelf); | ||
61 | /** | 61 | /** |
62 | * Function: button_is_selected | 62 | * Function: button_is_selected |
63 | * Checks if the button is selected or not. | 63 | * Checks if the button is selected or not. |
@@ -70,6 +70,7 @@ void button_click_test(int x, int y, Component *parameterSelf); | |||
70 | * Returns: | 70 | * Returns: |
71 | * A bool from stdbool | 71 | * A bool from stdbool |
72 | */ | 72 | */ |
73 | |||
73 | bool button_is_selected(int x, int y, Button *button); | 74 | bool button_is_selected(int x, int y, Button *button); |
74 | 75 | ||
75 | #endif | 76 | #endif |
diff --git a/include/gui/component.h b/include/gui/component.h index dd101dc..0e8f437 100644 --- a/include/gui/component.h +++ b/include/gui/component.h | |||
@@ -1,7 +1,10 @@ | |||
1 | #ifndef UPEM_C_COMPONENT_H | 1 | #ifndef UPEM_C_COMPONENT_H |
2 | #define UPEM_C_COMPONENT_H | 2 | #define UPEM_C_COMPONENT_H |
3 | typedef enum { | ||
4 | WAITING_BUTTON, INSERT_ORIGIN, INSERT_TARGET,PRINTING | ||
5 | } Mode; | ||
3 | 6 | ||
4 | #include <stdbool.h> | 7 | extern Mode mode; |
5 | /** | 8 | /** |
6 | * File: component.h | 9 | * File: component.h |
7 | * Windows and components handling. | 10 | * Windows and components handling. |
@@ -38,7 +41,6 @@ typedef void (*PrintMethod)(struct Component *); | |||
38 | typedef struct Component { | 41 | typedef struct Component { |
39 | int width, height; | 42 | int width, height; |
40 | int x_pos, y_pos; | 43 | int x_pos, y_pos; |
41 | bool activated; | ||
42 | ClickHandler click_handler; | 44 | ClickHandler click_handler; |
43 | PrintMethod print_method; | 45 | PrintMethod print_method; |
44 | } Component; | 46 | } Component; |
diff --git a/include/gui/pictureframe.h b/include/gui/pictureframe.h index 1f5407c..f06a530 100644 --- a/include/gui/pictureframe.h +++ b/include/gui/pictureframe.h | |||
@@ -1,13 +1,14 @@ | |||
1 | #ifndef UPEM_MORPHING_PITUREFRAME | 1 | #ifndef UPEM_MORPHING_PITUREFRAME |
2 | #define UPEM_MORPHING_PITUREFRAME | 2 | #define UPEM_MORPHING_PITUREFRAME |
3 | 3 | ||
4 | #include <blender/canvas.h> | ||
5 | #include <morpher/morphing.h> | 4 | #include <morpher/morphing.h> |
5 | #include <painter/canvas.h> | ||
6 | #include "component.h" | 6 | #include "component.h" |
7 | |||
8 | /** | 7 | /** |
9 | * File: pictureframe.h | 8 | * File: pictureframe.h |
10 | */ | 9 | */ |
10 | |||
11 | CartesianVector savedPoint; | ||
11 | /** | 12 | /** |
12 | * Type: CartesianMappingDivision | 13 | * Type: CartesianMappingDivision |
13 | * Type of functions needed to split CartesianMapping and keep only the CartesianVector needed, related to the type of PictureFrame involved | 14 | * Type of functions needed to split CartesianMapping and keep only the CartesianVector needed, related to the type of PictureFrame involved |
@@ -49,8 +50,24 @@ CartesianVector pictureframe_origin_split(const CartesianMapping *cartesianMappi | |||
49 | */ | 50 | */ |
50 | CartesianVector pictureframe_target_split(const CartesianMapping *cartesianMapping); | 51 | CartesianVector pictureframe_target_split(const CartesianMapping *cartesianMapping); |
51 | 52 | ||
53 | bool pictureframe_is_selected(int x, int y, PictureFrame *pictureFrame); | ||
54 | |||
55 | /** | ||
56 | * Function: pictureframe_conversion_to_origin | ||
57 | * Returns the relative coordinate on the picture corresponding to the input values | ||
58 | * | ||
59 | * Parameters: | ||
60 | * x - value on x axis from the origin of the window to convert | ||
61 | * y - value on y axis from the origin of the window to convert | ||
62 | * *pictureFrame - pointer to the reference pictureframe that will give his relative coordinates | ||
63 | */ | ||
64 | CartesianVector pictureframe_conversion_to_origin(int x, int y, PictureFrame *pictureFrame); | ||
65 | |||
66 | CartesianVector pictureframe_conversion_to_picture(int x, int y, PictureFrame *pictureFrame); | ||
67 | |||
52 | void pictureframe_init(PictureFrame *pictureFrame, int width, int height, int x_pos, int y_pos, | 68 | void pictureframe_init(PictureFrame *pictureFrame, int width, int height, int x_pos, int y_pos, |
53 | CartesianMappingDivision cartesianMappingDivision, Morphing *morphing, Canvas *canvas); | 69 | CartesianMappingDivision cartesianMappingDivision, Morphing *morphing, Canvas *canvas, |
70 | ClickHandler clickHandler); | ||
54 | 71 | ||
55 | void pictureframe_free(PictureFrame *pictureFrame); | 72 | void pictureframe_free(PictureFrame *pictureFrame); |
56 | 73 | ||
@@ -73,7 +90,18 @@ void pictureframe_draw_canvas(PictureFrame *pictureFrame); | |||
73 | void pictureframe_print(Component *parameterSelf); | 90 | void pictureframe_print(Component *parameterSelf); |
74 | 91 | ||
75 | /** | 92 | /** |
76 | * Function: pictureframe_click_handler | 93 | * Function: pictureframe_click_handler_origin |
94 | * Adds a point on the coordinate of the picture that the mouse is pointing. | ||
95 | * | ||
96 | * Parameters: | ||
97 | * x_pos - coordinate on x axis of the mouse | ||
98 | * y_pos - coordinate on y axis of the mouse | ||
99 | * *parameterSelf - pointer that will be casted into a PictureFrame | ||
100 | */ | ||
101 | void pictureframe_click_handler_origin(int x_pos, int y_pos, Component *parameterSelf); | ||
102 | |||
103 | /** | ||
104 | * Function: pictureframe_click_handler_target | ||
77 | * Adds a point on the coordinate of the picture that the mouse is pointing. | 105 | * Adds a point on the coordinate of the picture that the mouse is pointing. |
78 | * | 106 | * |
79 | * Parameters: | 107 | * Parameters: |
@@ -81,7 +109,7 @@ void pictureframe_print(Component *parameterSelf); | |||
81 | * y_pos - coordinate on y axis of the mouse | 109 | * y_pos - coordinate on y axis of the mouse |
82 | * *parameterSelf - pointer that will be casted into a PictureFrame | 110 | * *parameterSelf - pointer that will be casted into a PictureFrame |
83 | */ | 111 | */ |
84 | void pictureframe_click_handler(int x_pos, int y_pos, Component *parameterSelf); | 112 | void pictureframe_click_handler_target(int x_pos, int y_pos, Component *parameterSelf); |
85 | 113 | ||
86 | 114 | ||
87 | #endif | 115 | #endif |
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 | } |