1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00
lvgl/examples/widgets/canvas/lv_example_canvas_2.c

44 lines
1.3 KiB
C
Raw Normal View History

2021-04-08 13:07:48 +02:00
#include "../../lv_examples.h"
2023-02-20 22:18:56 +01:00
#if LV_USE_CANVAS && LV_BUILD_EXAMPLES
2021-02-08 09:53:03 +01:00
#define CANVAS_WIDTH 50
#define CANVAS_HEIGHT 50
/**
* Create a transparent canvas with Chroma keying and indexed color format (palette).
*/
void lv_example_canvas_2(void)
{
/*Create a button to better see the transparency*/
lv_btn_create(lv_scr_act());
2021-02-08 09:53:03 +01:00
/*Create a buffer for the canvas*/
static uint8_t cbuf[LV_CANVAS_BUF_SIZE_INDEXED_1BIT(CANVAS_WIDTH, CANVAS_HEIGHT)];
2021-02-08 09:53:03 +01:00
2021-08-27 12:15:39 +02:00
/*Create a canvas and initialize its palette*/
lv_obj_t * canvas = lv_canvas_create(lv_scr_act());
2023-02-20 22:18:56 +01:00
lv_canvas_set_buffer(canvas, cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_COLOR_FORMAT_I1);
2023-02-20 22:30:16 +01:00
lv_canvas_set_palette(canvas, 0, lv_color_to32(LV_COLOR_CHROMA_KEY));
lv_canvas_set_palette(canvas, 1, lv_color_to32(lv_palette_main(LV_PALETTE_RED)));
2021-02-08 09:53:03 +01:00
/*Create colors with the indices of the palette*/
lv_color_t c0;
lv_color_t c1;
lv_color_set_int(&c0, 0);
lv_color_set_int(&c1, 1);
2021-02-08 09:53:03 +01:00
/*Red background (There is no dedicated alpha channel in indexed images so LV_OPA_COVER is ignored)*/
lv_canvas_fill_bg(canvas, c1, LV_OPA_COVER);
/*Create hole on the canvas*/
uint32_t x;
uint32_t y;
for(y = 10; y < 30; y++) {
for(x = 5; x < 20; x++) {
lv_canvas_set_px(canvas, x, y, c0, LV_OPA_COVER);
2021-02-08 09:53:03 +01:00
}
}
}
#endif