1 #include "../../lv_examples.h"
2 #if LV_USE_CANVAS && LV_BUILD_EXAMPLES
3
4 #define CANVAS_WIDTH 80
5 #define CANVAS_HEIGHT 40
6
7 /**
8 * Create a transparent canvas with transparency
9 */
lv_example_canvas_2(void)10 void lv_example_canvas_2(void)
11 {
12 lv_obj_set_style_bg_color(lv_screen_active(), lv_palette_lighten(LV_PALETTE_RED, 5), 0);
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_obj_center(canvas);
22
23 /*Red background (There is no dedicated alpha channel in indexed images so LV_OPA_COVER is ignored)*/
24 lv_canvas_fill_bg(canvas, lv_palette_main(LV_PALETTE_BLUE), LV_OPA_COVER);
25
26 /*Create hole on the canvas*/
27 uint32_t x;
28 uint32_t y;
29 for(y = 10; y < 20; y++) {
30 for(x = 5; x < 75; x++) {
31 lv_canvas_set_px(canvas, x, y, lv_palette_main(LV_PALETTE_BLUE), LV_OPA_50);
32 }
33 }
34
35 for(y = 20; y < 30; y++) {
36 for(x = 5; x < 75; x++) {
37 lv_canvas_set_px(canvas, x, y, lv_palette_main(LV_PALETTE_BLUE), LV_OPA_20);
38 }
39 }
40
41 for(y = 30; y < 40; y++) {
42 for(x = 5; x < 75; x++) {
43 lv_canvas_set_px(canvas, x, y, lv_palette_main(LV_PALETTE_BLUE), LV_OPA_0);
44 }
45 }
46 }
47 #endif
48