1 #include "../../lv_examples.h"
2 #if LV_USE_CANVAS && LV_BUILD_EXAMPLES
3 
4 #if LV_USE_VECTOR_GRAPHIC
5 
6 #define CANVAS_WIDTH  150
7 #define CANVAS_HEIGHT 150
8 
9 /**
10  * Draw a path to the canvas
11  */
lv_example_canvas_8(void)12 void lv_example_canvas_8(void)
13 {
14     /*Create a buffer for the canvas*/
15     LV_DRAW_BUF_DEFINE_STATIC(draw_buf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_COLOR_FORMAT_ARGB8888);
16     LV_DRAW_BUF_INIT_STATIC(draw_buf);
17 
18     /*Create a canvas and initialize its palette*/
19     lv_obj_t * canvas = lv_canvas_create(lv_screen_active());
20     lv_canvas_set_draw_buf(canvas, &draw_buf);
21     lv_canvas_fill_bg(canvas, lv_color_hex3(0xccc), LV_OPA_COVER);
22     lv_obj_center(canvas);
23 
24     lv_layer_t layer;
25     lv_canvas_init_layer(canvas, &layer);
26 
27     lv_vector_dsc_t * dsc = lv_vector_dsc_create(&layer);
28     lv_vector_path_t * path = lv_vector_path_create(LV_VECTOR_PATH_QUALITY_MEDIUM);
29 
30     lv_fpoint_t pts[] = {{10, 10}, {130, 130}, {10, 130}};
31     lv_vector_path_move_to(path, &pts[0]);
32     lv_vector_path_line_to(path, &pts[1]);
33     lv_vector_path_line_to(path, &pts[2]);
34     lv_vector_path_close(path);
35 
36     lv_vector_dsc_set_fill_color(dsc, lv_color_make(0x00, 0x80, 0xff));
37     lv_vector_dsc_add_path(dsc, path);
38 
39     lv_draw_vector(dsc);
40     lv_vector_path_delete(path);
41     lv_vector_dsc_delete(dsc);
42 
43     lv_canvas_finish_layer(canvas, &layer);
44 }
45 #else
46 
lv_example_canvas_8(void)47 void lv_example_canvas_8(void)
48 {
49     /*fallback for online examples*/
50     lv_obj_t * label = lv_label_create(lv_screen_active());
51     lv_label_set_text(label, "Vector graphics is not enabled");
52     lv_obj_center(label);
53 }
54 
55 #endif /*LV_USE_VECTOR_GRAPHIC*/
56 
57 #endif
58