Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
CTCaer
GitHub Repository: CTCaer/hekate
Path: blob/master/bdk/libs/lvgl/lv_objx/lv_canvas.h
1476 views
1
/**
2
* @file lv_canvas.h
3
*
4
*/
5
6
#ifndef LV_CANVAS_H
7
#define LV_CANVAS_H
8
9
#ifdef __cplusplus
10
extern "C" {
11
#endif
12
13
/*********************
14
* INCLUDES
15
*********************/
16
#ifdef LV_CONF_INCLUDE_SIMPLE
17
#include "lv_conf.h"
18
#else
19
#include "../../lv_conf.h"
20
#endif
21
22
#if USE_LV_CANVAS != 0
23
24
#include "../lv_core/lv_obj.h"
25
#include "../lv_objx/lv_img.h"
26
27
/*********************
28
* DEFINES
29
*********************/
30
31
/**********************
32
* TYPEDEFS
33
**********************/
34
/*Data of canvas*/
35
typedef struct {
36
lv_img_ext_t img; /*Ext. of ancestor*/
37
/*New data for this type */
38
lv_img_dsc_t dsc;
39
} lv_canvas_ext_t;
40
41
42
/*Styles*/
43
enum {
44
LV_CANVAS_STYLE_MAIN,
45
};
46
typedef uint8_t lv_canvas_style_t;
47
48
49
/**********************
50
* GLOBAL PROTOTYPES
51
**********************/
52
53
/**
54
* Create a canvas object
55
* @param par pointer to an object, it will be the parent of the new canvas
56
* @param copy pointer to a canvas object, if not NULL then the new object will be copied from it
57
* @return pointer to the created canvas
58
*/
59
lv_obj_t * lv_canvas_create(lv_obj_t * par, const lv_obj_t * copy);
60
61
/*=====================
62
* Setter functions
63
*====================*/
64
65
/**
66
* Set a buffer for the canvas.
67
* @param buf a buffer where the content of the canvas will be.
68
* The required size is (lv_img_color_format_get_px_size(cf) * w * h) / 8)
69
* It can be allocated with `lv_mem_alloc()` or
70
* it can be statically allocated array (e.g. static lv_color_t buf[100*50]) or
71
* it can be an address in RAM or external SRAM
72
* @param canvas pointer to a canvas object
73
* @param w width of the canvas
74
* @param h height of the canvas
75
* @param cf color format. The following formats are supported:
76
* LV_IMG_CF_TRUE_COLOR, LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED, LV_IMG_CF_INDEXES_1/2/4/8BIT
77
*/
78
void lv_canvas_set_buffer(lv_obj_t * canvas, void * buf, lv_coord_t w, lv_coord_t h, lv_img_cf_t cf);
79
80
/**
81
* Set the color of a pixel on the canvas
82
* @param canvas
83
* @param x x coordinate of the point to set
84
* @param y x coordinate of the point to set
85
* @param c color of the point
86
*/
87
void lv_canvas_set_px(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_color_t c);
88
89
/**
90
* Set a style of a canvas.
91
* @param canvas pointer to canvas object
92
* @param type which style should be set
93
* @param style pointer to a style
94
*/
95
void lv_canvas_set_style(lv_obj_t * canvas, lv_canvas_style_t type, lv_style_t * style);
96
97
/*=====================
98
* Getter functions
99
*====================*/
100
101
/**
102
* Get the color of a pixel on the canvas
103
* @param canvas
104
* @param x x coordinate of the point to set
105
* @param y x coordinate of the point to set
106
* @return color of the point
107
*/
108
lv_color_t lv_canvas_get_px(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y);
109
110
/**
111
* Get style of a canvas.
112
* @param canvas pointer to canvas object
113
* @param type which style should be get
114
* @return style pointer to the style
115
*/
116
lv_style_t * lv_canvas_get_style(const lv_obj_t * canvas, lv_canvas_style_t type);
117
118
/*=====================
119
* Other functions
120
*====================*/
121
122
/**
123
* Copy a buffer to the canvas
124
* @param canvas pointer to a canvas object
125
* @param to_copy buffer to copy. The color format has to match with the canvas's buffer color format
126
* @param w width of the buffer to copy
127
* @param h height of the buffer to copy
128
* @param x left side of the destination position
129
* @param y top side of the destination position
130
*/
131
void lv_canvas_copy_buf(lv_obj_t * canvas, const void * to_copy, lv_coord_t w, lv_coord_t h, lv_coord_t x, lv_coord_t y);
132
133
/**
134
* Multiply a buffer with the canvas
135
* @param canvas pointer to a canvas object
136
* @param to_copy buffer to copy (multiply). LV_IMG_CF_TRUE_COLOR_ALPHA is not supported
137
* @param w width of the buffer to copy
138
* @param h height of the buffer to copy
139
* @param x left side of the destination position
140
* @param y top side of the destination position
141
*/
142
void lv_canvas_mult_buf(lv_obj_t * canvas, void * to_copy, lv_coord_t w, lv_coord_t h, lv_coord_t x, lv_coord_t y);
143
144
/**
145
* Draw circle function of the canvas
146
* @param canvas pointer to a canvas object
147
* @param x0 x coordinate of the circle
148
* @param y0 y coordinate of the circle
149
* @param radius radius of the circle
150
* @param color border color of the circle
151
*/
152
void lv_canvas_draw_circle(lv_obj_t * canvas, lv_coord_t x0, lv_coord_t y0, lv_coord_t radius, lv_color_t color);
153
154
/**
155
* Draw line function of the canvas
156
* @param canvas pointer to a canvas object
157
* @param point1 start point of the line
158
* @param point2 end point of the line
159
* @param color color of the line
160
*
161
* NOTE: The lv_canvas_draw_line function originates from https://github.com/jb55/bresenham-line.c.
162
*/
163
void lv_canvas_draw_line(lv_obj_t * canvas, lv_point_t point1, lv_point_t point2, lv_color_t color);
164
165
/**
166
* Draw triangle function of the canvas
167
* @param canvas pointer to a canvas object
168
* @param points edge points of the triangle
169
* @param color line color of the triangle
170
*/
171
void lv_canvas_draw_triangle(lv_obj_t * canvas, lv_point_t * points, lv_color_t color);
172
173
/**
174
* Draw rectangle function of the canvas
175
* @param canvas pointer to a canvas object
176
* @param points edge points of the rectangle
177
* @param color line color of the rectangle
178
*/
179
void lv_canvas_draw_rect(lv_obj_t * canvas, lv_point_t * points, lv_color_t color);
180
181
/**
182
* Draw polygon function of the canvas
183
* @param canvas pointer to a canvas object
184
* @param points edge points of the polygon
185
* @param size edge count of the polygon
186
* @param color line color of the polygon
187
*/
188
void lv_canvas_draw_polygon(lv_obj_t * canvas, lv_point_t * points, size_t size, lv_color_t color);
189
190
/**
191
* Fill polygon function of the canvas
192
* @param canvas pointer to a canvas object
193
* @param points edge points of the polygon
194
* @param size edge count of the polygon
195
* @param boundary_color line color of the polygon
196
* @param fill_color fill color of the polygon
197
*/
198
void lv_canvas_fill_polygon(lv_obj_t * canvas, lv_point_t * points, size_t size, lv_color_t boundary_color, lv_color_t fill_color);
199
/**
200
* Boundary fill function of the canvas
201
* @param canvas pointer to a canvas object
202
* @param x x coordinate of the start position (seed)
203
* @param y y coordinate of the start position (seed)
204
* @param boundary_color edge/boundary color of the area
205
* @param fill_color fill color of the area
206
*/
207
void lv_canvas_boundary_fill4(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_color_t boundary_color, lv_color_t fill_color);
208
209
/**
210
* Flood fill function of the canvas
211
* @param canvas pointer to a canvas object
212
* @param x x coordinate of the start position (seed)
213
* @param y y coordinate of the start position (seed)
214
* @param fill_color fill color of the area
215
* @param bg_color background color of the area
216
*/
217
void lv_canvas_flood_fill(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_color_t fill_color, lv_color_t bg_color);
218
219
/**********************
220
* MACROS
221
**********************/
222
223
#endif /*USE_LV_CANVAS*/
224
225
#ifdef __cplusplus
226
} /* extern "C" */
227
#endif
228
229
#endif /*LV_CANVAS_H*/
230
231