1 /**
2 * @file lv_area.h
3 *
4 */
5
6 #ifndef LV_AREA_H
7 #define LV_AREA_H
8
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12
13 /*********************
14 * INCLUDES
15 *********************/
16 #include "../lv_conf_internal.h"
17 #include <string.h>
18 #include <stdbool.h>
19 #include <stdint.h>
20 #include "lv_mem.h"
21
22 /*********************
23 * DEFINES
24 *********************/
25 /*To avoid overflow don't let the max ranges (reduce with 1000) */
26 #define LV_COORD_MAX ((lv_coord_t)((uint32_t)((uint32_t)1 << (8 * sizeof(lv_coord_t) - 1)) - 1000))
27 #define LV_COORD_MIN (-LV_COORD_MAX)
28
29 LV_EXPORT_CONST_INT(LV_COORD_MAX);
30 LV_EXPORT_CONST_INT(LV_COORD_MIN);
31
32 /**********************
33 * TYPEDEFS
34 **********************/
35
36 /**
37 * Represents a point on the screen.
38 */
39 typedef struct {
40 lv_coord_t x;
41 lv_coord_t y;
42 } lv_point_t;
43
44 /** Represents an area of the screen. */
45 typedef struct {
46 lv_coord_t x1;
47 lv_coord_t y1;
48 lv_coord_t x2;
49 lv_coord_t y2;
50 } lv_area_t;
51
52
53
54 /** Alignments */
55 enum {
56 LV_ALIGN_CENTER = 0,
57 LV_ALIGN_IN_TOP_LEFT,
58 LV_ALIGN_IN_TOP_MID,
59 LV_ALIGN_IN_TOP_RIGHT,
60 LV_ALIGN_IN_BOTTOM_LEFT,
61 LV_ALIGN_IN_BOTTOM_MID,
62 LV_ALIGN_IN_BOTTOM_RIGHT,
63 LV_ALIGN_IN_LEFT_MID,
64 LV_ALIGN_IN_RIGHT_MID,
65 LV_ALIGN_OUT_TOP_LEFT,
66 LV_ALIGN_OUT_TOP_MID,
67 LV_ALIGN_OUT_TOP_RIGHT,
68 LV_ALIGN_OUT_BOTTOM_LEFT,
69 LV_ALIGN_OUT_BOTTOM_MID,
70 LV_ALIGN_OUT_BOTTOM_RIGHT,
71 LV_ALIGN_OUT_LEFT_TOP,
72 LV_ALIGN_OUT_LEFT_MID,
73 LV_ALIGN_OUT_LEFT_BOTTOM,
74 LV_ALIGN_OUT_RIGHT_TOP,
75 LV_ALIGN_OUT_RIGHT_MID,
76 LV_ALIGN_OUT_RIGHT_BOTTOM,
77 };
78 typedef uint8_t lv_align_t;
79
80
81 /**********************
82 * GLOBAL PROTOTYPES
83 **********************/
84
85 /**
86 * Initialize an area
87 * @param area_p pointer to an area
88 * @param x1 left coordinate of the area
89 * @param y1 top coordinate of the area
90 * @param x2 right coordinate of the area
91 * @param y2 bottom coordinate of the area
92 */
93 void lv_area_set(lv_area_t * area_p, lv_coord_t x1, lv_coord_t y1, lv_coord_t x2, lv_coord_t y2);
94
95 /**
96 * Copy an area
97 * @param dest pointer to the destination area
98 * @param src pointer to the source area
99 */
lv_area_copy(lv_area_t * dest,const lv_area_t * src)100 inline static void lv_area_copy(lv_area_t * dest, const lv_area_t * src)
101 {
102 _lv_memcpy_small(dest, src, sizeof(lv_area_t));
103 }
104
105 /**
106 * Get the width of an area
107 * @param area_p pointer to an area
108 * @return the width of the area (if x1 == x2 -> width = 1)
109 */
lv_area_get_width(const lv_area_t * area_p)110 static inline lv_coord_t lv_area_get_width(const lv_area_t * area_p)
111 {
112 return (lv_coord_t)(area_p->x2 - area_p->x1 + 1);
113 }
114
115 /**
116 * Get the height of an area
117 * @param area_p pointer to an area
118 * @return the height of the area (if y1 == y2 -> height = 1)
119 */
lv_area_get_height(const lv_area_t * area_p)120 static inline lv_coord_t lv_area_get_height(const lv_area_t * area_p)
121 {
122 return (lv_coord_t)(area_p->y2 - area_p->y1 + 1);
123 }
124
125 /**
126 * Set the width of an area
127 * @param area_p pointer to an area
128 * @param w the new width of the area (w == 1 makes x1 == x2)
129 */
130 void lv_area_set_width(lv_area_t * area_p, lv_coord_t w);
131
132 /**
133 * Set the height of an area
134 * @param area_p pointer to an area
135 * @param h the new height of the area (h == 1 makes y1 == y2)
136 */
137 void lv_area_set_height(lv_area_t * area_p, lv_coord_t h);
138
139 /**
140 * Set the position of an area (width and height will be kept)
141 * @param area_p pointer to an area
142 * @param x the new x coordinate of the area
143 * @param y the new y coordinate of the area
144 */
145 void _lv_area_set_pos(lv_area_t * area_p, lv_coord_t x, lv_coord_t y);
146
147 /**
148 * Return with area of an area (x * y)
149 * @param area_p pointer to an area
150 * @return size of area
151 */
152 uint32_t lv_area_get_size(const lv_area_t * area_p);
153
154 /**
155 * Get the common parts of two areas
156 * @param res_p pointer to an area, the result will be stored her
157 * @param a1_p pointer to the first area
158 * @param a2_p pointer to the second area
159 * @return false: the two area has NO common parts, res_p is invalid
160 */
161 bool _lv_area_intersect(lv_area_t * res_p, const lv_area_t * a1_p, const lv_area_t * a2_p);
162
163 /**
164 * Join two areas into a third which involves the other two
165 * @param res_p pointer to an area, the result will be stored here
166 * @param a1_p pointer to the first area
167 * @param a2_p pointer to the second area
168 */
169 void _lv_area_join(lv_area_t * a_res_p, const lv_area_t * a1_p, const lv_area_t * a2_p);
170
171 /**
172 * Check if a point is on an area
173 * @param a_p pointer to an area
174 * @param p_p pointer to a point
175 * @param radius radius of area (e.g. for rounded rectangle)
176 * @return false:the point is out of the area
177 */
178 bool _lv_area_is_point_on(const lv_area_t * a_p, const lv_point_t * p_p, lv_coord_t radius);
179
180 /**
181 * Check if two area has common parts
182 * @param a1_p pointer to an area.
183 * @param a2_p pointer to an other area
184 * @return false: a1_p and a2_p has no common parts
185 */
186 bool _lv_area_is_on(const lv_area_t * a1_p, const lv_area_t * a2_p);
187
188 /**
189 * Check if an area is fully on an other
190 * @param ain_p pointer to an area which could be in 'aholder_p'
191 * @param aholder_p pointer to an area which could involve 'ain_p'
192 * @param radius radius of `aholder_p` (e.g. for rounded rectangle)
193 * @return true: `ain_p` is fully inside `aholder_p`
194 */
195 bool _lv_area_is_in(const lv_area_t * ain_p, const lv_area_t * aholder_p, lv_coord_t radius);
196
197
198 /**
199 * Align an area to an other
200 * @param base an are where the other will be aligned
201 * @param to_align the area to align
202 * @param align `LV_ALIGN_...`
203 * @param res x/y coordinates where `to_align` align area should be placed
204 */
205 void _lv_area_align(const lv_area_t * base, const lv_area_t * to_align, lv_align_t align, lv_point_t * res);
206
207 /**********************
208 * MACROS
209 **********************/
210
211 #ifdef __cplusplus
212 } /* extern "C" */
213 #endif
214
215 #endif
216