LittlevGL  3.20.00.19
lv_canvas.h
Go to the documentation of this file.
1 
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 LV_USE_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 {
37  lv_img_ext_t img; /*Ext. of ancestor*/
38  /*New data for this type */
39  lv_img_dsc_t dsc;
40 } lv_canvas_ext_t;
41 
42 /*Styles*/
43 enum {
44  LV_CANVAS_STYLE_MAIN,
45 };
46 typedef uint8_t lv_canvas_style_t;
47 
48 /**********************
49  * GLOBAL PROTOTYPES
50  **********************/
51 
58 lv_obj_t * lv_canvas_create(lv_obj_t * par, const lv_obj_t * copy);
59 
60 /*=====================
61  * Setter functions
62  *====================*/
63 
76 void lv_canvas_set_buffer(lv_obj_t * canvas, void * buf, lv_coord_t w, lv_coord_t h, lv_img_cf_t cf);
77 
85 void lv_canvas_set_px(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_color_t c);
86 
97 void lv_canvas_set_palette(lv_obj_t * canvas, uint8_t id, lv_color_t c);
98 
105 void lv_canvas_set_style(lv_obj_t * canvas, lv_canvas_style_t type, const lv_style_t * style);
106 
107 /*=====================
108  * Getter functions
109  *====================*/
110 
118 lv_color_t lv_canvas_get_px(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y);
119 
125 lv_img_dsc_t * lv_canvas_get_img(lv_obj_t * canvas);
126 
133 const lv_style_t * lv_canvas_get_style(const lv_obj_t * canvas, lv_canvas_style_t type);
134 
135 /*=====================
136  * Other functions
137  *====================*/
138 
149 void lv_canvas_copy_buf(lv_obj_t * canvas, const void * to_copy, lv_coord_t x, lv_coord_t y, lv_coord_t w,
150  lv_coord_t h);
151 
165 void lv_canvas_rotate(lv_obj_t * canvas, lv_img_dsc_t * img, int16_t angle, lv_coord_t offset_x, lv_coord_t offset_y,
166  int32_t pivot_x, int32_t pivot_y);
167 
173 void lv_canvas_fill_bg(lv_obj_t * canvas, lv_color_t color);
174 
184 void lv_canvas_draw_rect(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_coord_t w, lv_coord_t h,
185  const lv_style_t * style);
186 
197 void lv_canvas_draw_text(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_coord_t max_w, const lv_style_t * style,
198  const char * txt, lv_label_align_t align);
199 
206 void lv_canvas_draw_img(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, const void * src, const lv_style_t * style);
207 
215 void lv_canvas_draw_line(lv_obj_t * canvas, const lv_point_t * points, uint32_t point_cnt, const lv_style_t * style);
216 
224 void lv_canvas_draw_polygon(lv_obj_t * canvas, const lv_point_t * points, uint32_t point_cnt, const lv_style_t * style);
225 
236 void lv_canvas_draw_arc(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_coord_t r, int32_t start_angle,
237  int32_t end_angle, const lv_style_t * style);
238 
239 /**********************
240  * MACROS
241  **********************/
242 #define LV_CANVAS_BUF_SIZE_TRUE_COLOR(w, h) ((LV_COLOR_SIZE / 8) * w * h)
243 #define LV_CANVAS_BUF_SIZE_TRUE_COLOR_CHROMA_KEYED(w, h) ((LV_COLOR_SIZE / 8) * w * h)
244 #define LV_CANVAS_BUF_SIZE_TRUE_COLOR_ALPHA(w, h) (LV_IMG_PX_SIZE_ALPHA_BYTE * w * h)
245 
246 /*+ 1: to be sure no fractional row*/
247 #define LV_CANVAS_BUF_SIZE_ALPHA_1BIT(w, h) ((((w / 8) + 1) * h))
248 #define LV_CANVAS_BUF_SIZE_ALPHA_2BIT(w, h) ((((w / 4) + 1) * h))
249 #define LV_CANVAS_BUF_SIZE_ALPHA_4BIT(w, h) ((((w / 2) + 1) * h))
250 #define LV_CANVAS_BUF_SIZE_ALPHA_8BIT(w, h) ((w * h))
251 
252 /*4 * X: for palette*/
253 #define LV_CANVAS_BUF_SIZE_INDEXED_1BIT(w, h) (LV_CANVAS_BUF_SIZE_ALPHA_1BIT(w, h) + 4 * 2)
254 #define LV_CANVAS_BUF_SIZE_INDEXED_2BIT(w, h) (LV_CANVAS_BUF_SIZE_ALPHA_2BIT(w, h) + 4 * 4)
255 #define LV_CANVAS_BUF_SIZE_INDEXED_4BIT(w, h) (LV_CANVAS_BUF_SIZE_ALPHA_4BIT(w, h) + 4 * 16)
256 #define LV_CANVAS_BUF_SIZE_INDEXED_8BIT(w, h) (LV_CANVAS_BUF_SIZE_ALPHA_8BIT(w, h) + 4 * 256)
257 
258 #endif /*LV_USE_CANVAS*/
259 
260 #ifdef __cplusplus
261 } /* extern "C" */
262 #endif
263 
264 #endif /*LV_CANVAS_H*/
uint8_t lv_img_cf_t
Definition: lv_img_decoder.h:116
Definition: lv_area.h:39
Definition: lv_obj.h:184
struct _lv_obj_t * par
Definition: lv_obj.h:186
Definition: lv_img_decoder.h:120
Definition: lv_style.h:57
© Copyright 1995-2019, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale