1 #include "../../lv_examples.h"
2 #if LV_USE_CANVAS && LV_BUILD_EXAMPLES
3 
4 #define CANVAS_WIDTH  200
5 #define CANVAS_HEIGHT  150
6 
lv_example_canvas_1(void)7 void lv_example_canvas_1(void)
8 {
9     lv_draw_rect_dsc_t rect_dsc;
10     lv_draw_rect_dsc_init(&rect_dsc);
11     rect_dsc.radius = 10;
12     rect_dsc.bg_opa = LV_OPA_COVER;
13     rect_dsc.bg_grad.dir = LV_GRAD_DIR_HOR;
14     rect_dsc.bg_grad.stops[0].color = lv_palette_main(LV_PALETTE_RED);
15     rect_dsc.bg_grad.stops[1].color = lv_palette_main(LV_PALETTE_BLUE);
16     rect_dsc.border_width = 2;
17     rect_dsc.border_opa = LV_OPA_90;
18     rect_dsc.border_color = lv_color_white();
19     rect_dsc.shadow_width = 5;
20     rect_dsc.shadow_ofs_x = 5;
21     rect_dsc.shadow_ofs_y = 5;
22 
23     lv_draw_label_dsc_t label_dsc;
24     lv_draw_label_dsc_init(&label_dsc);
25     label_dsc.color = lv_palette_main(LV_PALETTE_ORANGE);
26 
27     static lv_color_t cbuf[LV_CANVAS_BUF_SIZE_TRUE_COLOR(CANVAS_WIDTH, CANVAS_HEIGHT)];
28 
29     lv_obj_t * canvas = lv_canvas_create(lv_scr_act());
30     lv_canvas_set_buffer(canvas, cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_IMG_CF_TRUE_COLOR);
31     lv_obj_center(canvas);
32     lv_canvas_fill_bg(canvas, lv_palette_lighten(LV_PALETTE_GREY, 3), LV_OPA_COVER);
33 
34     lv_canvas_draw_rect(canvas, 70, 60, 100, 70, &rect_dsc);
35 
36     lv_canvas_draw_text(canvas, 40, 20, 100, &label_dsc, "Some text on text canvas");
37 
38     /*Test the rotation. It requires another buffer where the original image is stored.
39      *So copy the current image to buffer and rotate it to the canvas*/
40     static lv_color_t cbuf_tmp[CANVAS_WIDTH * CANVAS_HEIGHT];
41     memcpy(cbuf_tmp, cbuf, sizeof(cbuf_tmp));
42     lv_img_dsc_t img;
43     img.data = (void *)cbuf_tmp;
44     img.header.cf = LV_IMG_CF_TRUE_COLOR;
45     img.header.w = CANVAS_WIDTH;
46     img.header.h = CANVAS_HEIGHT;
47 
48     lv_canvas_fill_bg(canvas, lv_palette_lighten(LV_PALETTE_GREY, 3), LV_OPA_COVER);
49     lv_canvas_transform(canvas, &img, 120, LV_IMG_ZOOM_NONE, 0, 0, CANVAS_WIDTH / 2, CANVAS_HEIGHT / 2, true);
50 }
51 
52 #endif
53