diff options
Diffstat (limited to 'src/gui/pictureframe.c')
-rw-r--r-- | src/gui/pictureframe.c | 76 |
1 files changed, 41 insertions, 35 deletions
diff --git a/src/gui/pictureframe.c b/src/gui/pictureframe.c index a6a94bf..53a0ed3 100644 --- a/src/gui/pictureframe.c +++ b/src/gui/pictureframe.c | |||
@@ -1,20 +1,35 @@ | |||
1 | #include <assert.h> | 1 | #include <assert.h> |
2 | #include <gui/pictureframe.h> | 2 | #include "common/mem.h" |
3 | #include <MLV/MLV_all.h> | 3 | #include "gui/pictureframe.h" |
4 | #include "MLV/MLV_all.h" | ||
4 | 5 | ||
5 | CartesianVector pictureframe_origin_split(const CartesianMapping *cartesianMapping) { | 6 | static bool pictureframe_is_selected(int x, int y, PictureFrame *pictureFrame) { |
6 | return cartesianMapping->origin; | 7 | assert(pictureFrame != NULL); |
8 | int x1 = pictureFrame->component.x_pos; | ||
9 | int y1 = pictureFrame->component.y_pos; | ||
10 | int x2 = pictureFrame->component.x_pos + pictureFrame->component.width; | ||
11 | int y2 = pictureFrame->component.y_pos + pictureFrame->component.height; | ||
12 | if (x >= x1 && x <= x2 && y >= y1 && y <= y2) { | ||
13 | return true; | ||
14 | } | ||
15 | return false; | ||
7 | } | 16 | } |
8 | 17 | ||
9 | CartesianVector pictureframe_target_split(const CartesianMapping *cartesianMapping) { | 18 | static CartesianVector pictureframe_conversion_to_pic(int x, int y, PictureFrame *pictureFrame) { |
10 | return cartesianMapping->target; | 19 | CartesianVector vector; |
20 | vector.x = x - pictureFrame->component.x_pos; | ||
21 | vector.y = y - pictureFrame->component.y_pos; | ||
22 | return vector; | ||
11 | } | 23 | } |
12 | 24 | ||
13 | void pictureframe_draw_canvas(PictureFrame *pictureFrame){ | 25 | static CartesianVector pictureframe_conversion_to_origin(int x, int y, PictureFrame *pictureFrame) { |
14 | MLV_draw_image(pictureFrame->canvas->mlv, pictureFrame->component.x_pos, pictureFrame->component.y_pos); | 26 | CartesianVector vector; |
27 | vector.x = x + pictureFrame->component.x_pos; | ||
28 | vector.y = y + pictureFrame->component.y_pos; | ||
29 | return vector; | ||
15 | } | 30 | } |
16 | 31 | ||
17 | void pictureframe_print(Component *parameterSelf) { | 32 | static void pictureframe_print(Component *parameterSelf) { |
18 | PictureFrame *self = (PictureFrame *) parameterSelf; | 33 | PictureFrame *self = (PictureFrame *) parameterSelf; |
19 | pictureframe_draw_canvas(self); | 34 | pictureframe_draw_canvas(self); |
20 | if (mode != WAITING_BUTTON_HIDE && mode != RENDERING) { | 35 | if (mode != WAITING_BUTTON_HIDE && mode != RENDERING) { |
@@ -46,30 +61,12 @@ void pictureframe_print(Component *parameterSelf) { | |||
46 | } | 61 | } |
47 | } | 62 | } |
48 | 63 | ||
49 | bool pictureframe_is_selected(int x, int y, PictureFrame *pictureFrame) { | 64 | CartesianVector pictureframe_origin_split(const CartesianMapping *cartesianMapping) { |
50 | assert(pictureFrame != NULL); | 65 | return cartesianMapping->origin; |
51 | int x1 = pictureFrame->component.x_pos; | ||
52 | int y1 = pictureFrame->component.y_pos; | ||
53 | int x2 = pictureFrame->component.x_pos + pictureFrame->component.width; | ||
54 | int y2 = pictureFrame->component.y_pos + pictureFrame->component.height; | ||
55 | if (x >= x1 && x <= x2 && y >= y1 && y <= y2) { | ||
56 | return true; | ||
57 | } | ||
58 | return false; | ||
59 | } | ||
60 | |||
61 | CartesianVector pictureframe_conversion_to_pic(int x, int y, PictureFrame *pictureFrame) { | ||
62 | CartesianVector vector; | ||
63 | vector.x = x - pictureFrame->component.x_pos; | ||
64 | vector.y = y - pictureFrame->component.y_pos; | ||
65 | return vector; | ||
66 | } | 66 | } |
67 | 67 | ||
68 | CartesianVector pictureframe_conversion_to_origin(int x, int y, PictureFrame *pictureFrame) { | 68 | CartesianVector pictureframe_target_split(const CartesianMapping *cartesianMapping) { |
69 | CartesianVector vector; | 69 | return cartesianMapping->target; |
70 | vector.x = x + pictureFrame->component.x_pos; | ||
71 | vector.y = y + pictureFrame->component.y_pos; | ||
72 | return vector; | ||
73 | } | 70 | } |
74 | 71 | ||
75 | void pictureframe_click_handler_origin(int x_pos, int y_pos, Component *parameterSelf) { | 72 | void pictureframe_click_handler_origin(int x_pos, int y_pos, Component *parameterSelf) { |
@@ -92,10 +89,13 @@ void pictureframe_click_handler_target(int x_pos, int y_pos, Component *paramete | |||
92 | } | 89 | } |
93 | } | 90 | } |
94 | 91 | ||
95 | void pictureframe_init(PictureFrame *pictureFrame, int width, int height, int x_pos, int y_pos, | 92 | void pictureframe_draw_canvas(PictureFrame *pictureFrame) { |
96 | CartesianMappingDivision cartesianMappingDivision, Morphing *morphing, Canvas *canvas, | 93 | MLV_draw_image(pictureFrame->canvas->mlv, pictureFrame->component.x_pos, pictureFrame->component.y_pos); |
97 | ClickHandler clickHandler) { | 94 | } |
98 | assert(pictureFrame != NULL); | 95 | |
96 | PictureFrame *pictureframe_create(int width, int height, int x_pos, int y_pos, | ||
97 | CartesianMappingDivision cartesianMappingDivision, Morphing *morphing, Canvas *canvas, | ||
98 | ClickHandler clickHandler) { | ||
99 | assert(width > 0); | 99 | assert(width > 0); |
100 | assert(height > 0); | 100 | assert(height > 0); |
101 | assert(x_pos >= 0); | 101 | assert(x_pos >= 0); |
@@ -103,6 +103,7 @@ void pictureframe_init(PictureFrame *pictureFrame, int width, int height, int x_ | |||
103 | assert(cartesianMappingDivision != NULL); | 103 | assert(cartesianMappingDivision != NULL); |
104 | assert(morphing != NULL); | 104 | assert(morphing != NULL); |
105 | assert(canvas != NULL); | 105 | assert(canvas != NULL); |
106 | PictureFrame *pictureFrame = malloc_or_die(sizeof(PictureFrame)); | ||
106 | pictureFrame->component.width = width; | 107 | pictureFrame->component.width = width; |
107 | pictureFrame->component.height = height; | 108 | pictureFrame->component.height = height; |
108 | pictureFrame->component.x_pos = x_pos; | 109 | pictureFrame->component.x_pos = x_pos; |
@@ -112,4 +113,9 @@ void pictureframe_init(PictureFrame *pictureFrame, int width, int height, int x_ | |||
112 | pictureFrame->morphing = morphing; | 113 | pictureFrame->morphing = morphing; |
113 | pictureFrame->canvas = canvas; | 114 | pictureFrame->canvas = canvas; |
114 | pictureFrame->cartesianMappingDivision = cartesianMappingDivision; | 115 | pictureFrame->cartesianMappingDivision = cartesianMappingDivision; |
116 | return pictureFrame; | ||
117 | } | ||
118 | |||
119 | void pictureframe_destroy(PictureFrame *pictureFrame){ | ||
120 | free(pictureFrame); | ||
115 | } \ No newline at end of file | 121 | } \ No newline at end of file |