Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
CTCaer
GitHub Repository: CTCaer/hekate
Path: blob/master/bdk/libs/lvgl/lv_misc/lv_area.h
1476 views
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
/*********************
15
* INCLUDES
16
*********************/
17
#include <string.h>
18
#include <utils/types.h>
19
20
/*********************
21
* DEFINES
22
*********************/
23
#define LV_COORD_MAX (16383) /*To avoid overflow don't let the max [-32,32k] range */
24
#define LV_COORD_MIN (-16384)
25
26
/**********************
27
* TYPEDEFS
28
**********************/
29
typedef int16_t lv_coord_t;
30
31
typedef struct
32
{
33
lv_coord_t x;
34
lv_coord_t y;
35
} lv_point_t;
36
37
typedef struct
38
{
39
lv_coord_t x1;
40
lv_coord_t y1;
41
lv_coord_t x2;
42
lv_coord_t y2;
43
} lv_area_t;
44
45
/**********************
46
* GLOBAL PROTOTYPES
47
**********************/
48
49
/**
50
* Initialize an area
51
* @param area_p pointer to an area
52
* @param x1 left coordinate of the area
53
* @param y1 top coordinate of the area
54
* @param x2 right coordinate of the area
55
* @param y2 bottom coordinate of the area
56
*/
57
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);
58
59
/**
60
* Copy an area
61
* @param dest pointer to the destination area
62
* @param src pointer to the source area
63
*/
64
inline static void lv_area_copy(lv_area_t * dest, const lv_area_t * src)
65
{
66
memcpy(dest, src, sizeof(lv_area_t));
67
}
68
69
/**
70
* Get the width of an area
71
* @param area_p pointer to an area
72
* @return the width of the area (if x1 == x2 -> width = 1)
73
*/
74
static inline lv_coord_t lv_area_get_width(const lv_area_t * area_p)
75
{
76
return area_p->x2 - area_p->x1 + 1;
77
}
78
79
/**
80
* Get the height of an area
81
* @param area_p pointer to an area
82
* @return the height of the area (if y1 == y2 -> height = 1)
83
*/
84
static inline lv_coord_t lv_area_get_height(const lv_area_t * area_p)
85
{
86
return area_p->y2 - area_p->y1 + 1;
87
}
88
89
/**
90
* Set the width of an area
91
* @param area_p pointer to an area
92
* @param w the new width of the area (w == 1 makes x1 == x2)
93
*/
94
void lv_area_set_width(lv_area_t * area_p, lv_coord_t w);
95
96
/**
97
* Set the height of an area
98
* @param area_p pointer to an area
99
* @param h the new height of the area (h == 1 makes y1 == y2)
100
*/
101
void lv_area_set_height(lv_area_t * area_p, lv_coord_t h);
102
103
/**
104
* Set the position of an area (width and height will be kept)
105
* @param area_p pointer to an area
106
* @param x the new x coordinate of the area
107
* @param y the new y coordinate of the area
108
*/
109
void lv_area_set_pos(lv_area_t * area_p, lv_coord_t x, lv_coord_t y);
110
111
/**
112
* Return with area of an area (x * y)
113
* @param area_p pointer to an area
114
* @return size of area
115
*/
116
uint32_t lv_area_get_size(const lv_area_t * area_p);
117
118
/**
119
* Get the common parts of two areas
120
* @param res_p pointer to an area, the result will be stored her
121
* @param a1_p pointer to the first area
122
* @param a2_p pointer to the second area
123
* @return false: the two area has NO common parts, res_p is invalid
124
*/
125
bool lv_area_intersect(lv_area_t * res_p, const lv_area_t * a1_p, const lv_area_t * a2_p);
126
127
/**
128
* Join two areas into a third which involves the other two
129
* @param res_p pointer to an area, the result will be stored here
130
* @param a1_p pointer to the first area
131
* @param a2_p pointer to the second area
132
*/
133
void lv_area_join(lv_area_t * a_res_p, const lv_area_t * a1_p, const lv_area_t * a2_p);
134
135
/**
136
* Check if a point is on an area
137
* @param a_p pointer to an area
138
* @param p_p pointer to a point
139
* @return false:the point is out of the area
140
*/
141
bool lv_area_is_point_on(const lv_area_t * a_p, const lv_point_t * p_p);
142
143
/**
144
* Check if two area has common parts
145
* @param a1_p pointer to an area.
146
* @param a2_p pointer to an other area
147
* @return false: a1_p and a2_p has no common parts
148
*/
149
bool lv_area_is_on(const lv_area_t * a1_p, const lv_area_t * a2_p);
150
151
/**
152
* Check if an area is fully on an other
153
* @param ain_p pointer to an area which could be on aholder_p
154
* @param aholder pointer to an area which could involve ain_p
155
* @return
156
*/
157
bool lv_area_is_in(const lv_area_t * ain_p, const lv_area_t * aholder_p);
158
159
/**********************
160
* MACROS
161
**********************/
162
163
#ifdef __cplusplus
164
} /* extern "C" */
165
#endif
166
167
168
#endif
169
170